disassemblyAdd.vue 14 KB

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