edit.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="allocateBillEdit-wrap">
  3. <a-page-header :ghost="false" :backIcon="false" class="allocateBillEdit-back" >
  4. <!-- 自定义的二级文字标题 -->
  5. <template slot="subTitle">
  6. <a id="allocateBillEdit-back-btn" href="javascript:;" @click="handleBack"><a-icon type="left" /> 返回列表</a>
  7. <span style="margin: 0 15px;color: #666;">调往对象:{{ $route.params.name || '--' }}</span>
  8. </template>
  9. <!-- 操作区,位于 title 行的行尾 -->
  10. <template slot="extra">
  11. <a-button key="2" id="allocateBillEdit-preview-btn">打印预览</a-button>
  12. <a-button key="1" type="primary" id="allocateBillEdit-print-btn">快速打印</a-button>
  13. </template>
  14. </a-page-header>
  15. <!-- 选择产品 -->
  16. <a-card size="small" :bordered="false" class="allocateBillEdit-cont">
  17. <a-collapse :activeKey="['1']">
  18. <a-collapse-panel key="1" header="选择产品">
  19. <!-- 筛选条件 -->
  20. <div class="table-page-search-wrapper">
  21. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  22. <a-row :gutter="15">
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="产品编码" prop="productCode">
  25. <a-input id="allocateBillEdit-productCode" v-model="queryParam.productCode" placeholder="请输入产品编码" allowClear />
  26. </a-form-item>
  27. </a-col>
  28. <a-col :md="6" :sm="24">
  29. <a-form-item label="产品名称" prop="productName">
  30. <a-input id="allocateBillEdit-productName" v-model="queryParam.productName" placeholder="请输入产品名称" allowClear />
  31. </a-form-item>
  32. </a-col>
  33. <a-col :md="6" :sm="24">
  34. <a-form-item label="原厂编码" prop="productOrigCode">
  35. <a-input id="allocateBillEdit-productOrigCode" v-model="queryParam.productOrigCode" placeholder="请输入原厂编码" allowClear />
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="6" :sm="24" style="margin-bottom: 24px;">
  39. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="storeTransferOutList-refresh">查询</a-button>
  40. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="storeTransferOutList-reset">重置</a-button>
  41. </a-col>
  42. </a-row>
  43. </a-form>
  44. </div>
  45. <!-- 列表 -->
  46. <s-table
  47. class="sTable"
  48. ref="table"
  49. size="small"
  50. :rowKey="(record) => record.stockSn"
  51. :columns="columns"
  52. :customRow="handleClickRow"
  53. :data="loadData"
  54. :scroll="{ x: 1240, y: 300 }"
  55. bordered>
  56. <!-- 操作 -->
  57. <template slot="action" slot-scope="text, record">
  58. <a-button size="small" type="primary" class="button-primary" @click="handleAdd(record)" id="allocateBillEdit-add-btn">添加</a-button>
  59. </template>
  60. </s-table>
  61. </a-collapse-panel>
  62. </a-collapse>
  63. </a-card>
  64. <!-- 已选产品 -->
  65. <a-card size="small" :bordered="false" class="allocateBillEdit-cont">
  66. <a-collapse :activeKey="['1']">
  67. <a-collapse-panel key="1" header="已选产品">
  68. <!-- 总计 -->
  69. <a-alert type="info" showIcon style="margin-bottom:15px">
  70. <div slot="message">总数量:<strong>{{ (productTotal&&productTotal.totalQty) || 0 }}</strong> ,总成本(¥):<strong>{{ (productTotal&&productTotal.totalCost) || 0 }}</strong> ,总售价(¥):<strong>{{ (productTotal&&productTotal.totalPrice) || 0 }}</strong></div>
  71. </a-alert>
  72. <!-- 筛选条件 -->
  73. <a-row :gutter="15">
  74. <a-col :span="17">
  75. <div class="table-page-search-wrapper">
  76. <a-form layout="inline" @keyup.enter.native="getChooseProductList(1)">
  77. <a-row :gutter="15">
  78. <a-col :md="9" :sm="24">
  79. <a-form-item label="产品编码" prop="productCode">
  80. <a-input id="allocateBillEdit-productCode" v-model="chooseQueryParam.productCode" placeholder="请输入产品编码" allowClear />
  81. </a-form-item>
  82. </a-col>
  83. <a-col :md="9" :sm="24">
  84. <a-form-item label="产品名称" prop="productName">
  85. <a-input id="allocateBillEdit-productName" v-model="chooseQueryParam.productName" placeholder="请输入产品名称" allowClear />
  86. </a-form-item>
  87. </a-col>
  88. <a-col :md="6" :sm="24" style="margin-bottom: 24px;">
  89. <a-button type="primary" @click="getChooseProductList(1)" :disabled="chooseDisabled" id="storeTransferOutList-refresh">查询</a-button>
  90. <a-button style="margin-left: 8px" @click="chooseResetSearchForm" :disabled="chooseDisabled" id="storeTransferOutList-reset">重置</a-button>
  91. </a-col>
  92. </a-row>
  93. </a-form>
  94. </div>
  95. </a-col>
  96. <a-col :span="7" style="text-align: right;">
  97. <a-button size="small" id="allocateBillEdit-import-btn">导入明细</a-button>
  98. <a-button size="small" type="danger" style="margin-left: 8px" @click.stop="handleDel('', 'all')" id="chainTransferOutEdit-del-all-btn">整单删除</a-button>
  99. </a-col>
  100. </a-row>
  101. <!-- 列表 -->
  102. <a-table
  103. class="sTable"
  104. ref="chooseTable"
  105. size="small"
  106. :rowKey="(record) => record.id"
  107. :columns="chooseColumns"
  108. :dataSource="chooseLoadData"
  109. :scroll="{ x: 1335, y: 300 }"
  110. :pagination="choosePaginationProps"
  111. bordered>
  112. <!-- 调出数量 -->
  113. <template slot="qty" slot-scope="text, record">
  114. <a-input-number
  115. id="allocateBillEdit-qty"
  116. v-model="record.qty"
  117. :precision="0"
  118. :min="1"
  119. :max="999999"
  120. placeholder="请输入"
  121. @blur="e => qtyBlur(e.target.value, record)"
  122. style="width: 100%;" />
  123. </template>
  124. <!-- 操作 -->
  125. <template slot="action" slot-scope="text, record">
  126. <a-button size="small" type="primary" class="button-error" @click="handleDel(record)" id="allocateBillEdit-del-btn">删除</a-button>
  127. </template>
  128. </a-table>
  129. </a-collapse-panel>
  130. </a-collapse>
  131. </a-card>
  132. <a-affix :offset-bottom="0">
  133. <div style="text-align: center;width: 100%;background-color: #fff;padding: 12px 0;box-shadow: 0 0 20px #dcdee2;">
  134. <a-button
  135. type="primary"
  136. id="allocateBillEdit-submit"
  137. size="large"
  138. class="button-primary"
  139. @click="handleSubmit"
  140. style="padding: 0 60px;">提交</a-button>
  141. </div>
  142. </a-affix>
  143. </div>
  144. </template>
  145. <script>
  146. import { STable, VSelect } from '@/components'
  147. import { queryStockProductPage } from '@/api/stock'
  148. import { allocateBillDetailList, allocateBillDetailCount, allocateBillDetailSave, allocateBillSubmit, allocateBillDetailDel, allocateBillDetailDelAll } from '@/api/allocateBill'
  149. export default {
  150. components: { STable, VSelect },
  151. data () {
  152. return {
  153. queryParam: {
  154. productCode: '',
  155. productName: '',
  156. productOrigCode: ''
  157. },
  158. chooseQueryParam: {
  159. productCode: '',
  160. productName: ''
  161. },
  162. disabled: false, // 查询、重置按钮是否可操作
  163. chooseDisabled: false, // 查询、重置按钮是否可操作
  164. advanced: false, // 高级搜索 展开/关闭
  165. productBrandList: [], // 产品品牌 下拉数据
  166. productTypeList: [], // 产品分类 下拉数据
  167. productType: [],
  168. warehouseList: [], // 仓库 下拉数据
  169. // 表头
  170. columns: [
  171. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  172. { title: '产品编码', dataIndex: 'productCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  173. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  174. { title: '原厂编码', dataIndex: 'productOrigCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  175. { title: '成本价', dataIndex: 'lastStockCost', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  176. { title: '售价', dataIndex: 'productPrice', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  177. { title: '库存数量', dataIndex: 'currentStockQty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  178. { title: '单位', dataIndex: 'productUnit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  179. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  180. ],
  181. // 加载数据方法 必须为 Promise 对象
  182. loadData: parameter => {
  183. this.disabled = true
  184. return queryStockProductPage(Object.assign(parameter, this.queryParam, this.$route.params.dealerSn != ' ' ? { dealerSn: this.$route.params.dealerSn } : {})).then(res => {
  185. const data = res.data
  186. const no = (data.pageNo - 1) * data.pageSize
  187. for (var i = 0; i < data.list.length; i++) {
  188. data.list[i].no = no + i + 1
  189. }
  190. this.disabled = false
  191. return data
  192. })
  193. },
  194. // 表头
  195. chooseColumns: [
  196. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  197. { title: '产品编码', dataIndex: 'productEntity.code', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  198. { title: '产品名称', dataIndex: 'productEntity.name', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  199. { title: '原厂编码', dataIndex: 'productEntity.origCode', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  200. { title: '成本价', dataIndex: 'cost', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  201. { title: '售价', dataIndex: 'price', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  202. { title: '库存数量', dataIndex: 'currentStockQty', width: 100, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  203. { title: '调出数量', scopedSlots: { customRender: 'qty' }, width: 140, align: 'center' },
  204. { title: '单位', dataIndex: 'productEntity.unit', width: 100, align: 'center', customRender: function (text) { return text || '--' } },
  205. { title: '操作', scopedSlots: { customRender: 'action' }, width: 100, align: 'center', fixed: 'right' }
  206. ],
  207. chooseLoadData: [],
  208. choosePageNo: 1, // 分页页码
  209. choosePageSize: 10, // 分页 每页多少条
  210. choosePaginationProps: {
  211. showSizeChanger: true, // 是否可以改变 pageSize
  212. total: 0, // 分页总条数
  213. current: 1,
  214. onShowSizeChange: (current, pageSize) => this.changeChoosePageSize(current, pageSize),
  215. onChange: (current) => this.changeChoosePage(current)
  216. },
  217. productTotal: null // 合计
  218. }
  219. },
  220. methods: {
  221. // 重置
  222. resetSearchForm () {
  223. this.queryParam.productCode = ''
  224. this.queryParam.productName = ''
  225. this.queryParam.productOrigCode = ''
  226. this.$refs.table.refresh(true)
  227. },
  228. // 双击快速添加
  229. handleClickRow (record) {
  230. return {
  231. on: {
  232. dblclick: (event) => {
  233. this.handleAdd(record)
  234. }
  235. }
  236. }
  237. },
  238. // 已选产品 重置
  239. chooseResetSearchForm () {
  240. this.chooseQueryParam.productCode = ''
  241. this.chooseQueryParam.productName = ''
  242. this.choosePageNo = 1
  243. this.choosePageSize = 10
  244. this.choosePaginationProps.total = 0
  245. this.choosePaginationProps.current = 1
  246. this.getChooseProductList(1)
  247. },
  248. // 添加/编辑
  249. handleAdd (row, isEdit) {
  250. const params = {
  251. id: isEdit ? row.id : undefined,
  252. allocateSn: this.$route.params.sn,
  253. cost: isEdit ? row.cost : row.lastStockCost,
  254. price: isEdit ? row.price : row.productPrice,
  255. qty: isEdit ? row.qty : 1, // 添加时调出数量默认为1
  256. productSn: row.productSn
  257. }
  258. if (isEdit) { // 编辑
  259. // 清空数量时,值应保持未清空前的值,因数量不可为空
  260. if (!row.qty || row.qty == row.qtyBackups) {
  261. row.qty = row.qtyBackups
  262. return
  263. }
  264. }
  265. allocateBillDetailSave(params).then(res => {
  266. if (res.status == 200) {
  267. this.$message.success(res.message)
  268. this.$refs.table.refresh()
  269. this.getChooseProductList()
  270. } else {
  271. row.qty = row.qtyBackups
  272. }
  273. })
  274. },
  275. // 删除
  276. handleDel (row, isAll) {
  277. const _this = this
  278. const content = isAll ? '删除后不可恢复,确定要进行整单删除吗?' : '删除后不可恢复,确定要进行删除吗?'
  279. this.$confirm({
  280. title: '提示',
  281. content: content,
  282. centered: true,
  283. onOk () {
  284. if (isAll) { // 整单删除
  285. allocateBillDetailDelAll({ sn: _this.$route.params.sn }).then(res => {
  286. if (res.status == 200) {
  287. _this.$message.success(res.message)
  288. _this.$refs.table.refresh()
  289. _this.getChooseProductList()
  290. }
  291. })
  292. } else { // 单个删除
  293. allocateBillDetailDel({ id: row.id }).then(res => {
  294. if (res.status == 200) {
  295. _this.$message.success(res.message)
  296. _this.$refs.table.refresh()
  297. _this.getChooseProductList()
  298. }
  299. })
  300. }
  301. }
  302. })
  303. },
  304. // 提交
  305. handleSubmit () {
  306. const _this = this
  307. allocateBillSubmit({ sn: this.$route.params.sn }).then(res => {
  308. if (res.status == 200) {
  309. this.$message.success(res.message)
  310. setTimeout(() => {
  311. _this.handleBack()
  312. }, 1000)
  313. }
  314. })
  315. },
  316. // 合计
  317. getDetailCount (params) {
  318. allocateBillDetailCount(params).then(res => {
  319. if (res.status == 200) {
  320. this.productTotal = res.data
  321. } else {
  322. this.productTotal = null
  323. }
  324. })
  325. },
  326. // 返回列表
  327. handleBack () {
  328. this.$router.push({ path: '/allocationManagement/transferOut/list' })
  329. },
  330. // 已选产品 分页 一页多少条change
  331. changeChoosePageSize (current, pageSize) {
  332. this.choosePageNo = current
  333. this.choosePageSize = pageSize
  334. this.getChooseProductList()
  335. },
  336. // 已选产品 分页 页码change
  337. changeChoosePage (current) {
  338. this.choosePageNo = current
  339. this.getChooseProductList()
  340. },
  341. // 已选产品列表数据
  342. getChooseProductList (pageNo) {
  343. this.choosePageNo = this.choosePageNo || pageNo
  344. this.chooseDisabled = true
  345. const params = {
  346. pageNo: this.choosePageNo,
  347. pageSize: this.choosePageSize,
  348. allocateSn: this.$route.params.sn
  349. }
  350. allocateBillDetailList(Object.assign(params, this.chooseQueryParam)).then(res => {
  351. if (res.status == 200) {
  352. // 合计
  353. this.getDetailCount(Object.assign(params, this.chooseQueryParam))
  354. const data = res.data
  355. this.choosePaginationProps.total = Number(res.data.count) || 0
  356. this.choosePaginationProps.current = data.pageNo
  357. const no = (data.pageNo - 1) * data.pageSize
  358. for (var i = 0; i < data.list.length; i++) {
  359. data.list[i].no = no + i + 1
  360. data.list[i].qtyBackups = data.list[i].qty
  361. }
  362. this.chooseLoadData = data.list
  363. this.chooseDisabled = false
  364. } else {
  365. this.choosePaginationProps.total = 0
  366. this.choosePaginationProps.current = 1
  367. this.chooseLoadData = []
  368. }
  369. })
  370. },
  371. // 已选产品 调出数量 blur
  372. qtyBlur (val, record) {
  373. // 光标移出,值发生改变再调用编辑接口
  374. if (val != record.qtyBackups) {
  375. this.handleAdd(record, 'edit')
  376. }
  377. }
  378. },
  379. beforeRouteEnter (to, from, next) {
  380. next(vm => {
  381. vm.getChooseProductList(1)
  382. })
  383. }
  384. }
  385. </script>
  386. <style lang="less">
  387. .allocateBillEdit-wrap{
  388. .allocateBillEdit-back{
  389. margin-bottom: 10px;
  390. }
  391. .allocateBillEdit-cont{
  392. margin-bottom: 10px;
  393. .sub-title{
  394. font-size: 12px;
  395. color: #808695;
  396. margin-left: 10px;
  397. }
  398. .tag-txt{
  399. font-size: 12px;
  400. color: #ed1c24;
  401. }
  402. .edit-circle-btn{
  403. margin-left: 15px;
  404. i{
  405. vertical-align: text-bottom;
  406. }
  407. }
  408. .import-btn{
  409. margin-left: 15px;
  410. }
  411. }
  412. }
  413. </style>