WarehouseForm.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <div>
  3. <el-page-header @back="$parent.pageType=0" content="新增"
  4. style=" padding: 20px 20px 0 20px;"
  5. ></el-page-header>
  6. <warehousing-header ref="header" />
  7. <sales-table :dataList="dataList" :column="column" isOperation isSelection @handleSelection="handleSelection">
  8. <template #bts>
  9. <div>
  10. <el-button type="primary" size="mini" @click="dialogVisible=true">添加</el-button>
  11. <el-button type="danger" size="mini" @click="delChange">删除</el-button>
  12. </div>
  13. </template>
  14. <template #events>
  15. <div>
  16. <el-button type="primary" size="mini" @click="handelSubmit">提交</el-button>
  17. <el-button size="mini" @click="onReset">重置</el-button>
  18. </div>
  19. </template>
  20. <template v-slot:custom="{item:{row,$index}}">
  21. <el-radio :label="1" v-model="row.flag">增加</el-radio>
  22. <el-radio :label="0" v-model="row.flag">减少</el-radio>
  23. </template>
  24. <template v-slot:operation="{item:{row,$index}}">
  25. <el-popconfirm
  26. style="margin-left: 10px"
  27. title="删除?"
  28. @onConfirm="handleDel(row,$index)"
  29. >
  30. <el-button slot="reference" type="text" size="mini">删除</el-button>
  31. </el-popconfirm>
  32. </template>
  33. </sales-table>
  34. <sales-dialog ref="dia" :dialogVisible="dialogVisible" :customerNumber="customerNumber" :func="getDialogList"
  35. @confirm="confirm"
  36. />
  37. </div>
  38. </template>
  39. <script>
  40. import SalesDialog from '@/components/SalesDialog/SalesDialog'
  41. import WarehousingHeader from '@/components/WarehousingHeader/WarehousingHeader'
  42. import SalesTable from '@/components/SalesTable/SalesTable'
  43. import { getcustomerFrontList, addCustomerStockOrder } from '@/api/stock'
  44. import {
  45. addFrontOrder
  46. } from '@/api/sales'
  47. export default {
  48. name: 'WarehouseForm',
  49. components: {
  50. WarehousingHeader,
  51. SalesTable,
  52. SalesDialog
  53. },
  54. data() {
  55. return {
  56. dialogVisible: false,
  57. customerNumber: '',
  58. dataList: [],
  59. selection: [],
  60. flag: 1,
  61. column: [
  62. {
  63. prop: 'materialName',
  64. label: '产品名称',
  65. width: '180'
  66. },
  67. {
  68. prop: 'materialOldNumber',
  69. label: '物料编码',
  70. width: '180'
  71. },
  72. {
  73. prop: 'specification',
  74. label: '规格型号',
  75. width: '300'
  76. },
  77. {
  78. prop: 'stockQty',
  79. label: '库存',
  80. width: '180'
  81. },
  82. {
  83. prop: 'directFlag',
  84. label: '发生方向',
  85. width: '180',
  86. isCustom: true
  87. },
  88. {
  89. prop: 'stockChangeQty',
  90. label: '数量',
  91. width: '180',
  92. isInput: true
  93. },
  94. {
  95. prop: 'remark',
  96. label: '备注',
  97. width: '180',
  98. isInput: true,
  99. type: 'text'
  100. }
  101. ]
  102. }
  103. },
  104. methods: {
  105. onReset() {
  106. Object.assign(this.$data, this.$options.data())
  107. Object.assign(this.$refs.header.$data, this.$refs.header.$options.data())
  108. },
  109. getDialogList(p) {
  110. return getcustomerFrontList(...p)
  111. },
  112. confirm(selected) {
  113. // console.log(selected)
  114. this.dataList = [...this.dataList, ...JSON.parse(JSON.stringify(selected))]
  115. for (let i = 0; i <this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData.length ; i++) {
  116. for (let j = 0; j < this.dataList.length; j++) {
  117. if ( this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData[i].id == this.dataList[j].id || this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData[i].disabled ===false){
  118. this.$set(this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData[i],'disabled',false)
  119. }else{
  120. this.$set(this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData[i],'disabled',true)
  121. }
  122. }
  123. }
  124. this.$refs.header.screenForm.customerName = this.dataList[0].customerName
  125. this.$refs.header.screenForm.customerNumber = this.dataList[0].customerNumber
  126. this.customerNumber = this.dataList[0].customerNumber
  127. this.dialogVisible = false
  128. this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.$refs.tableView.clearSelection()
  129. },
  130. handleDel(item, index) {
  131. this.dataList.splice(index, 1)
  132. this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData.find(k => {
  133. if (k.id == item.id) {
  134. this.$set(k, 'disabled', true)
  135. return
  136. }
  137. })
  138. },
  139. //去掉相同数据
  140. resArr(arr1, arr2) {
  141. return arr1.filter(v => arr2.every(val => val.id != v.id))
  142. },
  143. delChange() {
  144. if (this.dataList.length) {
  145. this.dataList = this.resArr(this.dataList, this.selection)
  146. for (let i = 0; i < this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData.length; i++) {
  147. for (let j = 0; j < this.selected.length; j++) {
  148. if (this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData[i].id == this.selected[j].id) {
  149. // k.disabled = true
  150. this.$set(this.$refs.dia.$refs.pageRef.$refs.zjpage.$refs.tableEl.tableData[i], 'disabled', true)
  151. }
  152. }
  153. }
  154. if (!this.dataList.length) {
  155. this.customerNumber = ''
  156. }
  157. }
  158. },
  159. handleSelection(data) {
  160. this.selection = data
  161. },
  162. handelSubmit() {
  163. for (let i = 0; i < this.dataList.length; i++) {
  164. this.dataList[i].id = ''
  165. this.dataList[i].directFlag = this.dataList[i].flag
  166. if (Number(this.dataList[i].stockChangeQty) < 0) {
  167. this.$errorMsg(`第${i + 1}产品数量有误`)
  168. return
  169. }
  170. if (Number(this.dataList[i].stockChangeQty) == 0 && this.dataList[i].directFlag == 0) {
  171. this.$errorMsg(`第${i + 1}产品数量为0时发生方向只能做增加`)
  172. return
  173. }
  174. }
  175. const params = {
  176. ...this.$refs.header.screenForm,
  177. orders: this.dataList
  178. }
  179. addCustomerStockOrder(params).then(res => {
  180. this.$successMsg('新增成功')
  181. this.$parent.pageType = 0
  182. this.$forceUpdate()
  183. })
  184. }
  185. }
  186. }
  187. </script>
  188. <style scoped>
  189. </style>