disassemblyAdd.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="app-container-form">
  3. <el-form ref="dataForm" :model="dataForm" :rules="rules" label-width="120px" inline>
  4. <h3>拆卸单</h3>
  5. <el-form-item label="拆卸时间" prop="serialDate">
  6. <el-date-picker v-model="dataForm.serialDate" value-format="yyyy-MM-dd HH:mm:ss" type="datetime"
  7. placeholder="选择日期时间" style="width:200px" :disabled="type === 'detail'">
  8. </el-date-picker>
  9. </el-form-item>
  10. <el-form-item label="仓库" prop="warehouseId">
  11. <el-select v-model="dataForm.warehouseId" clearable filterable placeholder="请选择" style="width: 200px;"
  12. :disabled="type === 'detail'" @change="handleChangeWarehouse">
  13. <el-option :key="item.id" v-for="item in warehouseList" :label="item.warehouseName"
  14. :value="item.id">
  15. </el-option>
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item label="经手人" prop="addHandlerId">
  19. <el-select v-model="dataForm.addHandlerId" clearable filterable placeholder="请选择" style="width: 200px"
  20. :disabled="type === 'detail'">
  21. <el-option :key="item.loginId" v-for="item in userSelsctList"
  22. :label="item.deptName + '_' + item.userName" :value="item.loginId">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="拆卸商品" prop="assembleProductId">
  27. <el-select v-model="dataForm.assembleProductId" clearable filterable placeholder="请选择" style="width: 200px;"
  28. :disabled="type === 'detail'">
  29. <el-option :key="item.productId" v-for="item in assembleProducList" :label="item.productName"
  30. :value="item.productId">
  31. </el-option>
  32. </el-select>
  33. </el-form-item>
  34. <el-form-item label="拆卸量" prop="updateNumber">
  35. <el-input-number v-model="dataForm.updateNumber" :min="1" :max="10000"
  36. placeholder="请输入拆卸量" style="width:200px" :disabled="type === 'detail'"></el-input-number>
  37. </el-form-item>
  38. <el-form-item label="拆卸原因" prop="remarks">
  39. <el-input style="width:535px" v-model="dataForm.remarks" :maxlength="120" type="textarea"
  40. :disabled="type === 'detail'" :autosize="{ minRows: 1, maxRows: 4 }"
  41. placeholder="请输入拆卸原因 最大120字"></el-input>
  42. </el-form-item>
  43. <el-form-item label="作废原因" v-if="dataForm.cancelMsg">
  44. <el-input style="width:535px" v-model="dataForm.cancelMsg" type="textarea" disabled :autosize="{ minRows: 1, maxRows: 4 }"></el-input>
  45. </el-form-item>
  46. <div class="mx">
  47. <h3>子商品清单</h3>
  48. <el-button size="small" type="primary" v-if="type !== 'detail'" @click="handleSelectGoods('inventoryEntryInfos')"
  49. icon="el-icon-plus">商品/物料</el-button>
  50. </div>
  51. <el-table size="small" :data="dataForm.inventoryEntryInfos" border :cell-style="{ textAlign: 'center' }"
  52. :header-cell-style="{ textAlign: 'center' }" style="width: 100%">
  53. <el-table-column label="商品编号">
  54. <template slot-scope="scope">
  55. {{ scope.row.productCode }}
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="商品名称">
  59. <template slot-scope="scope">
  60. {{ scope.row.productName }}
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="单价(¥)">
  64. <template slot-scope="scope">
  65. {{ scope.row.createPrice.toFixed(2) }}
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="库存数量">
  69. <template slot-scope="scope">
  70. {{ scope.row.createProductNumber }}
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="入库量">
  74. <template slot-scope="scope">
  75. <el-form-item v-if="type !== 'detail'"
  76. :prop="'inventoryEntryInfos.' + scope.$index + '.updateNumber'"
  77. :rules="{ required: true, message: '入库量不能为空', trigger: 'blur' }" class="tableFormItem">
  78. <el-input-number v-model="scope.row.updateNumber" @change="handleChange(scope.row)"
  79. size="small" :min="1" :max="10000"></el-input-number>
  80. </el-form-item>
  81. <span v-else>{{ scope.row.updateNumber }}</span>
  82. </template>
  83. </el-table-column>
  84. <el-table-column label="备注">
  85. <template slot-scope="scope">
  86. <el-input v-if="type !== 'detail'" :maxlength="99" v-model="scope.row.remarks" />
  87. <span v-else>{{ scope.row.remarks }}</span>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="操作" width="150" v-if="type !== 'detail'">
  91. <template slot-scope="scope">
  92. <el-button size="mini" type="danger"
  93. @click="dataForm.inventoryEntryInfos.splice(scope.$index, 1)">删除</el-button>
  94. </template>
  95. </el-table-column>
  96. </el-table>
  97. </el-form>
  98. <div class="footer">
  99. <el-button type="primary" @click="submitForm" v-if="type !== 'detail'">保存
  100. </el-button>
  101. <el-button @click="roBack()">返回
  102. </el-button>
  103. </div>
  104. </div>
  105. </template>
  106. <script>
  107. import { createDisassembly, updateDisassembly, readDisassembly } from "@/api/disassembly";
  108. import { listGoods } from "@/api/goodsManage";
  109. import { warehouseList } from "@/api/warehouse";
  110. import { allUserList } from "@/api/public";
  111. import waves from "@/directive/waves"; // 水波纹指令
  112. export default {
  113. directives: { waves },
  114. data() {
  115. return {
  116. userSelsctList: [],
  117. assembleProducList: [],
  118. warehouseList: [],
  119. id: '',
  120. type: '',
  121. /** 表单*/
  122. dataForm: {
  123. serialDate: '',
  124. warehouseId: undefined,
  125. updateUserName: undefined,
  126. addHandlerId: undefined,
  127. assembleProductId: undefined,
  128. updateNumber: 1,
  129. remarks: undefined,
  130. inventoryEntryInfos: [],
  131. inventoryOutInfos: []
  132. },
  133. rules: {
  134. serialDate: [
  135. { required: true, message: '请选择拆卸时间', trigger: 'blur' }
  136. ],
  137. warehouseId: [
  138. { required: true, message: '请选择仓库', trigger: 'blur' }
  139. ],
  140. remarks: [
  141. { required: true, message: '请填写拆卸原因', trigger: 'blur' }
  142. ],
  143. addHandlerId: [
  144. { required: true, message: '请选择经手人', trigger: 'blur' }
  145. ],
  146. assembleProductId: [
  147. { required: true, message: '请选择拆卸商品', trigger: 'blur' }
  148. ],
  149. updateNumber: [
  150. { required: true, message: '请输入拆卸数量', trigger: 'blur' }
  151. ],
  152. },
  153. }
  154. },
  155. watch: {
  156. $route: {
  157. immediate: true,
  158. handler(newVal) {
  159. if (this.$route.name === 'disassemblyAdd') {
  160. this.dataForm = {
  161. serialDate: '',
  162. warehouseId: undefined,
  163. updateUserName: undefined,
  164. addHandlerId: undefined,
  165. assembleProductId: undefined,
  166. updateNumber: 1,
  167. remarks: undefined,
  168. inventoryEntryInfos: [],
  169. inventoryOutInfos: []
  170. }
  171. } else if (this.$route.name === 'disassemblyDetail') {
  172. this.type = 'detail'
  173. }
  174. if (this.$route.params.id) {
  175. this.id = this.$route.params.id
  176. this.getDataFormDetail()
  177. }
  178. }
  179. }
  180. },
  181. mounted() {
  182. this.getAssembleProducList();
  183. this.getWarehouseList();
  184. this.getAllUserList();
  185. },
  186. methods: {
  187. handleChangeWarehouse(){
  188. this.getAssembleProducList();
  189. },
  190. /** 获取拆卸商品列表数据 */
  191. getAssembleProducList() {
  192. listGoods({warehouseId: this.dataForm.warehouseId}).then(response => {
  193. this.assembleProducList = response.data.data;
  194. }).catch(() => { });
  195. },
  196. /** 获取仓库列表数据 */
  197. getWarehouseList() {
  198. warehouseList().then(response => {
  199. this.warehouseList = response.data.data;
  200. }).catch(() => { });
  201. },
  202. /** 获取人员列表数据 */
  203. getAllUserList() {
  204. allUserList().then(response => {
  205. this.userSelsctList = response.data.data;
  206. }).catch(() => { });
  207. },
  208. /** 获取详情页面数据 */
  209. getDataFormDetail() {
  210. readDisassembly({ id: this.id }).then(response => {
  211. let dataForm = response.data.data;
  212. dataForm.inventoryEntryInfos = dataForm.inventoryEntryInfos == null ? [] : dataForm.inventoryEntryInfos
  213. dataForm.inventoryOutInfos = dataForm.inventoryOutInfos == null ? [] : dataForm.inventoryOutInfos
  214. this.dataForm = dataForm;
  215. }).catch(() => { })
  216. },
  217. // 选择商品
  218. async handleSelectGoods(val) {
  219. if (!this.dataForm.warehouseId) {
  220. this.$message.error('请先选择仓库!')
  221. return
  222. } else {
  223. let selectedIds = val=='inventoryEntryInfos' ? this.dataForm.inventoryEntryInfos.map(item => item.id) : this.dataForm.inventoryOutInfos.map(item => item.id);
  224. const Goods = await this.$EnPickerGoods({
  225. // goodsApi: '/warehouse-entry/info/inventory',
  226. selectedIds: selectedIds,
  227. goodsApiParams: { warehouseId: this.dataForm.warehouseId, type:'1' }
  228. })
  229. if (!Goods.length) return
  230. if(val=='inventoryEntryInfos'){
  231. const inventoryEntryInfos = Goods.map(item => {
  232. item.updateNumber = 1
  233. item.sumPrice = item.createPrice * 1
  234. return item
  235. })
  236. this.dataForm.inventoryEntryInfos = this.dataForm.inventoryEntryInfos && this.dataForm.inventoryEntryInfos.length ? this.dataForm.inventoryEntryInfos.concat(inventoryEntryInfos) : this.dataForm.inventoryEntryInfos = inventoryEntryInfos
  237. }else{
  238. const inventoryOutInfos = Goods.map(item => {
  239. item.updateNumber = 1
  240. item.sumPrice = item.createPrice * 1
  241. return item
  242. })
  243. this.dataForm.inventoryOutInfos = this.dataForm.inventoryOutInfos && this.dataForm.inventoryOutInfos.length ? this.dataForm.inventoryOutInfos.concat(inventoryOutInfos) : this.dataForm.inventoryOutInfos = inventoryOutInfos
  244. }
  245. }
  246. },
  247. submitForm() {
  248. this.$refs["dataForm"].validate((valid) => {
  249. if (valid) {
  250. if (this.dataForm.inventoryEntryInfos.length == 0) {
  251. this.$message.error('请选择商品/物料!')
  252. return
  253. } else {
  254. if (this.id) {
  255. updateDisassembly(this.dataForm).then(() => {
  256. this.$notify({
  257. title: '成功',
  258. message: '更新成功',
  259. type: 'success',
  260. duration: 2000
  261. })
  262. this.roBack();
  263. })
  264. } else {
  265. createDisassembly(this.dataForm).then(() => {
  266. this.$notify({
  267. title: "成功",
  268. message: "创建成功",
  269. type: "success",
  270. duration: 2000,
  271. });
  272. this.roBack();
  273. })
  274. }
  275. }
  276. }
  277. });
  278. },
  279. handleChange(row) {
  280. if (row.createPrice && row.updateNumber) {
  281. row.sumPrice = row.createPrice * row.updateNumber
  282. }
  283. },
  284. roBack() {
  285. this.$store.dispatch('delVisitedViews', this.$route).then((views) => {
  286. this.$router.push({ name: 'disassembly' })
  287. })
  288. }
  289. }
  290. }
  291. </script>
  292. <style>
  293. /** 底部步骤 */
  294. .footer {
  295. width: 100%;
  296. padding: 10px;
  297. bottom: 0px;
  298. text-align: center;
  299. z-index: 999;
  300. }
  301. .mx {
  302. display: flex;
  303. align-items: center;
  304. justify-content: space-between;
  305. }
  306. /** 表格中输入框样式 */
  307. .tableFormItem {
  308. width: 100%;
  309. margin-bottom: 0;
  310. }
  311. </style>