goodsDetail.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. <el-button
  11. size="small"
  12. type="primary"
  13. icon="el-icon-plus"
  14. class="ele-btn-icon"
  15. @click="addGoods"
  16. style="margin-bottom: 10px"
  17. v-if="type != 'detail' && type != 'receipt'"
  18. >
  19. 新增在制品
  20. </el-button>
  21. <ele-pro-table
  22. ref="entrustCreateTable"
  23. :columns="columns"
  24. :datasource="goodsList"
  25. :selection.sync="selection"
  26. :current.sync="current"
  27. highlight-current-row
  28. row-key="id"
  29. height="40vh"
  30. >
  31. <template v-slot:quantity="{ row }">
  32. <span>{{ row.quantity }}{{ row.measuringUnit }}</span>
  33. </template>
  34. <template v-slot:weight="{ row }">
  35. <span>{{ row.weight }}{{ row.weightUnit }}</span>
  36. </template>
  37. <template v-slot:receiveQuantity="{ row }">
  38. <el-input
  39. placeholder=""
  40. v-model="row.receiveQuantity"
  41. :disabled="type == 'receipt' && itemData.sendStatus == 4"
  42. >
  43. <template slot="append">{{ row.measuringUnit }}</template>
  44. </el-input>
  45. </template>
  46. <template v-slot:rootCategoryLevelId="{ row }">
  47. <el-tag>{{ typeName[Number(row.rootCategoryLevelId)] }}</el-tag>
  48. </template>
  49. </ele-pro-table>
  50. <template v-slot:footer v-if="type != 'detail' && itemData.sendStatus != 4">
  51. <el-button @click="cancel">取消</el-button>
  52. <el-button type="primary" @click="save"> 确定 </el-button>
  53. </template>
  54. <add-invoice ref="addInvoiceRef" @chooseData="chooseData"></add-invoice>
  55. </ele-modal>
  56. </template>
  57. <script>
  58. import {
  59. pleaseEntrustGoodsDetail,
  60. pleaseEntrustSaveDetail,
  61. pleaseTReceiveGoods
  62. } from '@/api/entrust';
  63. import { typeName } from '@/views/produce/components/common.js';
  64. import addInvoice from './addInvoice.vue';
  65. export default {
  66. components: {
  67. addInvoice
  68. },
  69. data() {
  70. return {
  71. visible: false,
  72. goodsList: [],
  73. selection: [],
  74. current: null,
  75. typeName,
  76. id: '',
  77. title: '',
  78. type: '',
  79. itemData: {},
  80. loading: null
  81. };
  82. },
  83. computed: {
  84. columns() {
  85. return [
  86. {
  87. columnKey: 'index',
  88. label: '序号',
  89. type: 'index',
  90. width: 55,
  91. align: 'center',
  92. showOverflowTooltip: true,
  93. fixed: 'left'
  94. },
  95. {
  96. prop: 'categoryName',
  97. label: '名称',
  98. align: 'center',
  99. minWidth: 110,
  100. showOverflowTooltip: true
  101. },
  102. {
  103. prop: 'brandNum',
  104. label: '牌号',
  105. align: 'center',
  106. minWidth: 110,
  107. showOverflowTooltip: true
  108. },
  109. {
  110. prop: 'batchNo',
  111. label: '批次号',
  112. align: 'center',
  113. minWidth: 110,
  114. showOverflowTooltip: true
  115. },
  116. {
  117. prop: 'quantity',
  118. slot: 'quantity',
  119. label: '数量',
  120. align: 'center',
  121. minWidth: 140,
  122. showOverflowTooltip: true
  123. },
  124. {
  125. prop: 'workOrderCode',
  126. label: '生产工单号',
  127. align: 'center',
  128. minWidth: 110,
  129. showOverflowTooltip: true
  130. },
  131. {
  132. prop: 'receiveQuantity',
  133. slot: 'receiveQuantity',
  134. label: '接收数量',
  135. align: 'center',
  136. minWidth: 150,
  137. showOverflowTooltip: true,
  138. show: this.type == 'receipt' ? true : false
  139. },
  140. {
  141. prop: 'specification',
  142. label: '规格',
  143. align: 'center',
  144. minWidth: 110,
  145. showOverflowTooltip: true
  146. },
  147. {
  148. prop: 'modelType',
  149. label: '型号',
  150. align: 'center',
  151. minWidth: 110,
  152. showOverflowTooltip: true
  153. },
  154. // {
  155. // prop: 'taskName',
  156. // label: '工序',
  157. // align: 'center',
  158. // minWidth: 150,
  159. // showOverflowTooltip: true
  160. // },
  161. {
  162. prop: 'categoryCode',
  163. label: '编码',
  164. align: 'center',
  165. showOverflowTooltip: true
  166. },
  167. {
  168. prop: 'weight',
  169. slot: 'weight',
  170. label: '重量',
  171. align: 'center',
  172. showOverflowTooltip: true
  173. },
  174. {
  175. prop: 'rootCategoryLevelId',
  176. slot: 'rootCategoryLevelId',
  177. label: '类型',
  178. align: 'center',
  179. showOverflowTooltip: true
  180. }
  181. ];
  182. }
  183. },
  184. methods: {
  185. open(item, type) {
  186. this.visible = true;
  187. this.type = type;
  188. this.title = this.type != 'receipt' ? '发货单' : '收货单';
  189. this.itemData = item;
  190. this.id = item.id;
  191. this.getDetail(item.id);
  192. },
  193. async getDetail(id) {
  194. const detailType = this.type == 'receipt' ? 2 : 1;
  195. await pleaseEntrustGoodsDetail({
  196. id,
  197. detailType
  198. }).then((res) => {
  199. this.goodsList = [];
  200. res.data.forEach((item) => {
  201. if (this.type == 'receipt' && this.itemData.sendStatus != 4) {
  202. item.receiveQuantity = item.quantity;
  203. }
  204. this.goodsList.push(this.deepCopy(item));
  205. });
  206. });
  207. },
  208. save() {
  209. if (this.type != 'receipt') {
  210. if (this.goodsList.length == 0) {
  211. return this.$message.warning('请先新增一条在制品数据!');
  212. }
  213. this.loading = this.$loading({
  214. lock: true,
  215. text: '加载中',
  216. background: 'rgba(0, 0, 0, 0.7)'
  217. });
  218. pleaseEntrustSaveDetail(this.goodsList)
  219. .then((res) => {
  220. this.loading.close();
  221. this.$message.success('发货成功');
  222. this.$emit('done');
  223. this.visible = false;
  224. })
  225. .catch(() => {
  226. this.loading.close();
  227. });
  228. } else if (this.type == 'receipt') {
  229. this.loading = this.$loading({
  230. lock: true,
  231. text: '加载中',
  232. background: 'rgba(0, 0, 0, 0.7)'
  233. });
  234. pleaseTReceiveGoods(this.goodsList)
  235. .then((res) => {
  236. this.loading.close();
  237. this.$message.success('收货成功');
  238. this.$emit('done');
  239. this.visible = false;
  240. })
  241. .catch(() => {
  242. this.loading.close();
  243. });
  244. }
  245. },
  246. cancel() {
  247. this.visible = false;
  248. },
  249. chooseData(dataList) {
  250. this.goodsList = [];
  251. dataList.forEach((item) => {
  252. this.goodsList.push(this.deepCopy(item));
  253. });
  254. },
  255. deepCopy(obj, hash = new WeakMap()) {
  256. if (obj === null) return null;
  257. if (obj instanceof Date) return new Date(obj);
  258. if (obj instanceof RegExp) return new RegExp(obj);
  259. if (typeof obj !== 'object' && typeof obj !== 'function') return obj;
  260. if (hash.has(obj)) return hash.get(obj);
  261. const result = Array.isArray(obj) ? [] : {};
  262. hash.set(obj, result);
  263. return Object.keys(obj).reduce((acc, key) => {
  264. acc[key] = this.deepCopy(obj[key], hash);
  265. return acc;
  266. }, result);
  267. },
  268. addGoods() {
  269. this.$refs.addInvoiceRef.open(this.id, this.goodsList);
  270. }
  271. }
  272. };
  273. </script>
  274. <style></style>