goodsDetail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <ele-modal
  3. :visible.sync="visible"
  4. :title="title"
  5. v-if="visible"
  6. width="65vw"
  7. append-to-body
  8. :maxable="true"
  9. >
  10. <ele-pro-table
  11. ref="entrustCreateTable"
  12. :columns="columns"
  13. :datasource="goodsList"
  14. :selection.sync="selection"
  15. :current.sync="current"
  16. highlight-current-row
  17. row-key="id"
  18. height="40vh"
  19. >
  20. <template v-slot:quantity="{ row }">
  21. <span>{{ row.quantity }}{{ row.measuringUnit }}</span>
  22. </template>
  23. <!-- <template v-slot:receiveQuantity="{ row }">
  24. <el-input
  25. placeholder=""
  26. v-model="row.receiveQuantity"
  27. :disabled="type == 'detail' || type == 'send'"
  28. >
  29. <template slot="append">{{ row.measuringUnit }}</template>
  30. </el-input>
  31. </template> -->
  32. <template v-slot:receiveQuantity="{ row }">
  33. <el-input placeholder="" v-model="row.receiveQuantity" disabled>
  34. <template slot="append">{{ row.measuringUnit }}</template>
  35. </el-input>
  36. </template>
  37. <template v-slot:weight="{ row }">
  38. <span>{{ row.weight }}{{ row.weightUnit }}</span>
  39. </template>
  40. <template v-slot:rootCategoryLevelId="{ row }">
  41. <el-tag>{{ typeName[Number(row.rootCategoryLevelId)] }}</el-tag>
  42. </template>
  43. </ele-pro-table>
  44. <template v-slot:footer v-if="type != 'detail' && type != 'send'">
  45. <el-button @click="cancel">取消</el-button>
  46. <el-button type="primary" @click="rejectReason"> 驳回 </el-button>
  47. <el-button type="primary" @click="save"> 确认收货 </el-button>
  48. </template>
  49. <!-- 驳回原因弹窗 -->
  50. <el-dialog
  51. :visible.sync="rejectDialogVisible"
  52. v-if="rejectDialogVisible"
  53. title="请输入驳回原因"
  54. width="30vw"
  55. append-to-body
  56. :close-on-click-modal="false"
  57. :before-close="
  58. () => {
  59. rejectDialogVisible = false;
  60. }
  61. "
  62. >
  63. <el-form
  64. ref="rejectForm"
  65. :model="rejectForm"
  66. :rules="rejectRules"
  67. label-width="80px"
  68. >
  69. <el-form-item label="原因" prop="reason">
  70. <el-input
  71. type="textarea"
  72. v-model="rejectForm.reason"
  73. placeholder="请输入驳回原因"
  74. rows="4"
  75. ></el-input>
  76. </el-form-item>
  77. </el-form>
  78. <span slot="footer" class="dialog-footer">
  79. <el-button @click="rejectDialogVisible = false">取消</el-button>
  80. <el-button type="primary" @click="confirmReject">确定</el-button>
  81. </span>
  82. </el-dialog>
  83. </ele-modal>
  84. </template>
  85. <script>
  86. import { pleaseEntrustGoodsDetail } from '@/api/entrust';
  87. import { confirmReceipt, rejectGoods } from '@/api/beEntrusted';
  88. import { typeName } from '@/views/produce/components/common.js';
  89. export default {
  90. data() {
  91. return {
  92. visible: false,
  93. goodsList: [],
  94. selection: [],
  95. current: null,
  96. typeName,
  97. id: '',
  98. type: '',
  99. title: '',
  100. loading: null,
  101. // 驳回弹窗
  102. rejectDialogVisible: false,
  103. rejectForm: { reason: '' },
  104. rejectRules: {
  105. reason: [
  106. { required: true, message: '请输入驳回原因', trigger: 'blur' }
  107. ]
  108. },
  109. itemData: {}
  110. };
  111. },
  112. computed: {
  113. columns() {
  114. return [
  115. {
  116. width: 45,
  117. type: 'selection',
  118. columnKey: 'selection',
  119. align: 'center',
  120. reserveSelection: true
  121. },
  122. {
  123. columnKey: 'index',
  124. label: '序号',
  125. type: 'index',
  126. width: 55,
  127. align: 'center',
  128. showOverflowTooltip: true,
  129. fixed: 'left'
  130. },
  131. {
  132. prop: 'categoryName',
  133. label: '名称',
  134. align: 'center',
  135. minWidth: 110,
  136. showOverflowTooltip: true
  137. },
  138. {
  139. prop: 'brandNum',
  140. label: '牌号',
  141. align: 'center',
  142. minWidth: 110,
  143. showOverflowTooltip: true
  144. },
  145. {
  146. prop: 'batchNo',
  147. label: '批次号',
  148. align: 'center',
  149. minWidth: 110,
  150. showOverflowTooltip: true
  151. },
  152. // {
  153. // prop: 'quantity',
  154. // slot: 'quantity',
  155. // label: '数量',
  156. // align: 'center',
  157. // minWidth: 110,
  158. // showOverflowTooltip: true
  159. // },
  160. {
  161. prop: 'receiveQuantity',
  162. slot: 'receiveQuantity',
  163. label: '接收数量',
  164. align: 'center',
  165. minWidth: 150,
  166. showOverflowTooltip: true,
  167. show: this.type != 'send' ? true : false
  168. },
  169. {
  170. prop: 'workOrderCode',
  171. label: '生产工单号',
  172. align: 'center',
  173. minWidth: 110,
  174. showOverflowTooltip: true
  175. },
  176. {
  177. prop: 'specification',
  178. label: '规格',
  179. align: 'center',
  180. minWidth: 110,
  181. showOverflowTooltip: true
  182. },
  183. {
  184. prop: 'modelType',
  185. label: '型号',
  186. align: 'center',
  187. minWidth: 110,
  188. showOverflowTooltip: true
  189. },
  190. // {
  191. // prop: 'taskName',
  192. // label: '工序',
  193. // align: 'center',
  194. // minWidth: 150,
  195. // showOverflowTooltip: true
  196. // },
  197. {
  198. prop: 'categoryCode',
  199. label: '编码',
  200. align: 'center',
  201. showOverflowTooltip: true
  202. },
  203. {
  204. prop: 'weight',
  205. slot: 'weight',
  206. label: '重量',
  207. align: 'center',
  208. showOverflowTooltip: true
  209. },
  210. {
  211. prop: 'rootCategoryLevelId',
  212. slot: 'rootCategoryLevelId',
  213. label: '类型',
  214. align: 'center',
  215. showOverflowTooltip: true
  216. }
  217. ];
  218. }
  219. },
  220. methods: {
  221. open(item, type) {
  222. this.visible = true;
  223. this.id = item.id;
  224. this.itemData = item;
  225. this.type = type;
  226. this.title = this.type != 'send' ? '收货单' : '发货单';
  227. this.getDetail(item.id);
  228. },
  229. async getDetail(id) {
  230. const detailType = this.type != 'send' ? 1 : 2;
  231. await pleaseEntrustGoodsDetail({
  232. id,
  233. detailType
  234. }).then((res) => {
  235. this.goodsList = [];
  236. res.data.forEach((item) => {
  237. if (this.type != 'detail') {
  238. item.receiveQuantity = item.quantity;
  239. }
  240. item.sendStatus = 2;
  241. this.goodsList.push(this.deepCopy(item));
  242. });
  243. });
  244. },
  245. // save() {
  246. // if (this.selection.length == 0) {
  247. // return this.$message.warning('请先选择一条收货数据!');
  248. // }
  249. // const selectionIds = new Set(this.selection.map((it) => it.id));
  250. // for (let item of this.goodsList) {
  251. // if (!selectionIds.has(item.id)) {
  252. // item.receiveQuantity = 0;
  253. // }
  254. // }
  255. // if (
  256. // Number(this.itemData.sendOutQuantity) <
  257. // Number(this.itemData.formingNum)
  258. // ) {
  259. // this.$confirm('收货数量小于请托数量是否继续收货?', '提示', {
  260. // type: 'warning'
  261. // })
  262. // .then(() => {
  263. // this.loading = this.$loading({
  264. // lock: true,
  265. // text: '加载中',
  266. // background: 'rgba(0, 0, 0, 0.7)'
  267. // });
  268. // confirmReceipt(this.goodsList)
  269. // .then((res) => {
  270. // this.loading.close();
  271. // this.$message.success('收货成功');
  272. // this.$emit('done');
  273. // this.visible = false;
  274. // })
  275. // .catch(() => {
  276. // this.loading.close();
  277. // });
  278. // })
  279. // .catch(() => {});
  280. // } else if (
  281. // Number(this.itemData.sendOutQuantity) ==
  282. // Number(this.itemData.formingNum)
  283. // ) {
  284. // this.loading = this.$loading({
  285. // lock: true,
  286. // text: '加载中',
  287. // background: 'rgba(0, 0, 0, 0.7)'
  288. // });
  289. // confirmReceipt(this.goodsList)
  290. // .then((res) => {
  291. // this.loading.close();
  292. // this.$message.success('收货成功');
  293. // this.$emit('done');
  294. // this.visible = false;
  295. // })
  296. // .catch(() => {
  297. // this.loading.close();
  298. // });
  299. // } else if (
  300. // Number(this.itemData.sendOutQuantity) >
  301. // Number(this.itemData.formingNum)
  302. // ) {
  303. // this.$confirm('收货数量大于请托数量是否继续收货?', '提示', {
  304. // type: 'warning'
  305. // })
  306. // .then(() => {
  307. // this.loading = this.$loading({
  308. // lock: true,
  309. // text: '加载中',
  310. // background: 'rgba(0, 0, 0, 0.7)'
  311. // });
  312. // confirmReceipt(this.goodsList)
  313. // .then((res) => {
  314. // this.loading.close();
  315. // this.$message.success('收货成功');
  316. // this.$emit('done');
  317. // this.visible = false;
  318. // })
  319. // .catch(() => {
  320. // this.loading.close();
  321. // });
  322. // })
  323. // .catch(() => {});
  324. // }
  325. // },
  326. save() {
  327. if (this.selection.length === 0) {
  328. return this.$message.warning('请先选择一条收货数据!');
  329. }
  330. const selectionIds = new Set(this.selection.map((it) => it.id));
  331. this.goodsList.forEach((item) => {
  332. if (!selectionIds.has(item.id)) {
  333. item.receiveQuantity = 0;
  334. }
  335. });
  336. const totalNum = this.selection.reduce(
  337. (total, pro) => total + Number(pro.receiveQuantity || 0),
  338. 0
  339. );
  340. const formingNum = Number(this.itemData.sendOutQuantity);
  341. let confirmMessage = '';
  342. console.log(totalNum, formingNum, '8888');
  343. if (totalNum < formingNum) {
  344. confirmMessage = '收货数量小于请托数量,是否继续收货?';
  345. } else if (totalNum > formingNum) {
  346. confirmMessage = '收货数量大于请托数量,是否继续收货?';
  347. }
  348. const doConfirmReceipt = () => {
  349. this.loading = this.$loading({
  350. lock: true,
  351. text: '加载中',
  352. background: 'rgba(0, 0, 0, 0.7)'
  353. });
  354. confirmReceipt(this.goodsList)
  355. .then(() => {
  356. this.loading.close();
  357. this.$message.success('收货成功');
  358. this.$emit('done');
  359. this.visible = false;
  360. })
  361. .catch(() => {
  362. this.loading.close();
  363. });
  364. };
  365. if (confirmMessage) {
  366. this.$confirm(confirmMessage, '提示', { type: 'warning' })
  367. .then(() => doConfirmReceipt())
  368. .catch(() => {});
  369. } else {
  370. doConfirmReceipt();
  371. }
  372. },
  373. cancel() {
  374. this.visible = false;
  375. },
  376. rejectReason() {
  377. this.rejectDialogVisible = true;
  378. },
  379. confirmReject() {
  380. this.$refs.rejectForm.validate((valid) => {
  381. if (!valid) return;
  382. this.$confirm('确认要驳回该收货单吗?', '提示', { type: 'warning' })
  383. .then(() => {
  384. const ids = this.goodsList.map((it) => {
  385. return it.id;
  386. });
  387. console.log('7777');
  388. rejectGoods({
  389. ids,
  390. applyId: this.id,
  391. beReason: this.rejectForm.reason
  392. }).then(() => {
  393. this.$message.success('驳回成功');
  394. this.rejectDialogVisible = false;
  395. this.visible = false;
  396. this.$emit('done');
  397. });
  398. })
  399. .catch(() => {});
  400. });
  401. },
  402. chooseData(dataList) {
  403. this.goodsList = [];
  404. dataList.forEach((item) => {
  405. this.goodsList.push(this.deepCopy(item));
  406. });
  407. },
  408. deepCopy(obj, hash = new WeakMap()) {
  409. if (obj === null) return null;
  410. if (obj instanceof Date) return new Date(obj);
  411. if (obj instanceof RegExp) return new RegExp(obj);
  412. if (typeof obj !== 'object' && typeof obj !== 'function') return obj;
  413. if (hash.has(obj)) return hash.get(obj);
  414. const result = Array.isArray(obj) ? [] : {};
  415. hash.set(obj, result);
  416. return Object.keys(obj).reduce((acc, key) => {
  417. acc[key] = this.deepCopy(obj[key], hash);
  418. return acc;
  419. }, result);
  420. }
  421. }
  422. };
  423. </script>
  424. <style></style>