unpackDialog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <template>
  2. <ele-modal
  3. width="60vw"
  4. :visible.sync="visible"
  5. :close-on-click-modal="false"
  6. custom-class="ele-dialog-form"
  7. :title="'拆分工单'"
  8. >
  9. <div class="form-wrapper">
  10. <el-form :model="requestData" label-width="0" :show-message="false">
  11. <el-descriptions title="" :column="2" border>
  12. <el-descriptions-item label="工单号">
  13. {{ formData.code }}</el-descriptions-item
  14. >
  15. <el-descriptions-item label="物料编码">
  16. {{ formData.productCode }}</el-descriptions-item
  17. >
  18. <el-descriptions-item label="产品名称">{{
  19. formData.productName
  20. }}</el-descriptions-item>
  21. <el-descriptions-item label="牌号|型号">
  22. {{ formData.brandNo }}|{{ formData.model }}</el-descriptions-item
  23. >
  24. <el-descriptions-item label="要求生产数量">{{
  25. formData.formingNum
  26. }}</el-descriptions-item>
  27. <el-descriptions-item label="计划开始时间">{{
  28. formData.planStartTime
  29. }}</el-descriptions-item>
  30. </el-descriptions>
  31. </el-form>
  32. <headerTitle title="剩余拆单" class="mt20"> </headerTitle>
  33. <el-form ref="form" :model="form" :rules="rules">
  34. <ele-pro-table
  35. ref="table"
  36. :needPage="false"
  37. :columns="columns"
  38. :datasource="form.surplusUnpack"
  39. >
  40. <template v-slot:toolbar>
  41. <el-button
  42. size="small"
  43. type="primary"
  44. icon="el-icon-plus"
  45. class="ele-btn-icon"
  46. :disabled="formingNum == 0 ? true : false"
  47. @click="openUnpack"
  48. >
  49. 拆单
  50. </el-button>
  51. </template>
  52. <template v-slot:formingNum="scope">
  53. <el-form-item
  54. v-if="formingNum != 0"
  55. :prop="'surplusUnpack.' + scope.$index + '.formingNum'"
  56. :rules="[
  57. {
  58. required: true,
  59. message: '请输入要求生产数量',
  60. trigger: 'change'
  61. },
  62. {
  63. pattern: /^\d+(\.{0,1}\d+){0,1}$/,
  64. message: '拆单数超过生产数量',
  65. trigger: ['blur', 'change']
  66. }
  67. ]"
  68. >
  69. <el-input
  70. disabled
  71. v-model="formingNum"
  72. placeholder="请输入"
  73. ></el-input>
  74. </el-form-item>
  75. <el-form-item v-else> 工单已全部拆完 </el-form-item>
  76. </template>
  77. <template v-slot:planStartTime="scope">
  78. <el-form-item
  79. v-if="formingNum != 0"
  80. :prop="'surplusUnpack.' + scope.$index + '.planStartTime'"
  81. :rules="{
  82. required: true,
  83. message: '请选择开始计划时间',
  84. trigger: 'change'
  85. }"
  86. >
  87. <el-date-picker
  88. class="w100"
  89. v-model="scope.row.planStartTime"
  90. type="date"
  91. value-format="yyyy-MM-dd"
  92. ></el-date-picker>
  93. </el-form-item>
  94. </template>
  95. <template v-slot:classeId="scope">
  96. <el-form-item
  97. v-if="formingNum != 0"
  98. :prop="'surplusUnpack.' + scope.$index + '.classeId'"
  99. :rules="{
  100. required: true,
  101. message: '请选择排班',
  102. trigger: 'change'
  103. }"
  104. >
  105. <el-input
  106. readonly
  107. v-model="scope.row.classeName"
  108. @click.native="openClasse(scope.row, 1, scope.$index)"
  109. ></el-input>
  110. </el-form-item>
  111. </template>
  112. </ele-pro-table>
  113. <headerTitle title="拆单" class="mt20"> </headerTitle>
  114. <ele-pro-table
  115. ref="table"
  116. :needPage="false"
  117. :columns="columns2"
  118. :datasource="form.unpackList"
  119. >
  120. <template v-slot:formingNum="scope">
  121. <el-form-item
  122. :prop="'unpackList.' + scope.$index + '.formingNum'"
  123. :rules="{
  124. required: true,
  125. message: '请输入要求生产数量',
  126. trigger: 'change'
  127. }"
  128. >
  129. <el-input-number
  130. type="number"
  131. @change="changeNum(scope.$index)"
  132. :min="0"
  133. v-model="scope.row.formingNum"
  134. placeholder="请输入"
  135. ></el-input-number>
  136. </el-form-item>
  137. </template>
  138. <template v-slot:planStartTime="scope">
  139. <el-form-item
  140. :prop="'unpackList.' + scope.$index + '.planStartTime'"
  141. :rules="{
  142. required: true,
  143. message: '请选择开始计划时间',
  144. trigger: 'change'
  145. }"
  146. >
  147. <el-date-picker
  148. class="w100"
  149. v-model="scope.row.planStartTime"
  150. type="date"
  151. value-format="yyyy-MM-dd"
  152. ></el-date-picker>
  153. </el-form-item>
  154. </template>
  155. <template v-slot:action="{ $index }">
  156. <el-popconfirm
  157. class="ele-action"
  158. title="确定要删除此子单吗?"
  159. @confirm="remove($index)"
  160. >
  161. <template v-slot:reference>
  162. <el-link type="danger" :underline="false" icon="el-icon-delete">
  163. 删除
  164. </el-link>
  165. </template>
  166. </el-popconfirm>
  167. </template>
  168. </ele-pro-table>
  169. </el-form>
  170. </div>
  171. <div slot="footer">
  172. <el-button plain @click="cancel">取消</el-button>
  173. <el-button type="primary" @click="confirm">确定</el-button>
  174. </div>
  175. </ele-modal>
  176. </template>
  177. <script>
  178. import { deepClone } from '@/utils';
  179. export default {
  180. components: {},
  181. data() {
  182. return {
  183. visible: false,
  184. formData: {},
  185. requestData: {
  186. deviceCode: '',
  187. deviceName: '',
  188. deviceId: ''
  189. },
  190. formingNum: 0,
  191. form: {
  192. surplusUnpack: [],
  193. unpackList: []
  194. },
  195. rules: {},
  196. columns: [
  197. {
  198. prop: 'originalCode',
  199. label: '工单号',
  200. align: 'center',
  201. minWidth: 200
  202. },
  203. {
  204. prop: 'formingNum',
  205. label: '要求生产数量',
  206. align: 'center',
  207. slot: 'formingNum',
  208. minWidth: 200
  209. },
  210. {
  211. prop: 'planStartTime',
  212. label: '计划开始时间',
  213. align: 'center',
  214. slot: 'planStartTime',
  215. minWidth: 200
  216. },
  217. {
  218. prop: 'classeId',
  219. label: '排班',
  220. align: 'center',
  221. slot: 'classeId',
  222. minWidth: 200
  223. }
  224. ],
  225. columns2: [
  226. {
  227. prop: 'originalCode',
  228. label: '工单号',
  229. align: 'center',
  230. minWidth: 200
  231. },
  232. {
  233. prop: 'formingNum',
  234. label: '要求生产数量',
  235. align: 'center',
  236. slot: 'formingNum',
  237. minWidth: 200
  238. },
  239. {
  240. prop: 'planStartTime',
  241. label: '计划开始时间',
  242. align: 'center',
  243. slot: 'planStartTime',
  244. minWidth: 200
  245. },
  246. {
  247. prop: 'classeId',
  248. label: '排班',
  249. align: 'center',
  250. slot: 'classeId',
  251. minWidth: 200
  252. },
  253. {
  254. columnKey: 'action',
  255. label: '操作',
  256. width: 160,
  257. align: 'center',
  258. resizable: false,
  259. fixed: 'right',
  260. slot: 'action',
  261. showOverflowTooltip: true
  262. }
  263. ]
  264. };
  265. },
  266. methods: {
  267. open(row) {
  268. this.visible = true;
  269. this.formData = deepClone(row);
  270. this.formingNum = this.formData.formingNum;
  271. this.form.surplusUnpack = [];
  272. this.form.unpackList = [];
  273. this.setSurplus();
  274. },
  275. setSurplus() {
  276. this.form.surplusUnpack.push({
  277. originalCode: this.formData.code,
  278. formingNum: this.formData.formingNum,
  279. planStartTime: '',
  280. classeId: '',
  281. isCopy: 1
  282. });
  283. },
  284. openUnpack() {
  285. this.form.unpackList.push({
  286. originalCode: this.formData.code,
  287. formingNum: '',
  288. planStartTime: '',
  289. classeId: ''
  290. });
  291. },
  292. changeNum(index) {
  293. let num = this.formData.formingNum;
  294. this.form.unpackList.forEach((e) => {
  295. if (e.formingNum != null && e.formingNum != undefined) {
  296. num = num - Number(e.formingNum);
  297. if (num >= 0) {
  298. this.formingNum = num;
  299. } else {
  300. this.$nextTick(() => {
  301. this.$set(this.form.unpackList[index], 'formingNum', 0);
  302. });
  303. this.$message.error('拆单数超过生产数量');
  304. return;
  305. }
  306. }
  307. });
  308. },
  309. remove(index) {
  310. this.form.unpackList.splice(index, 1);
  311. if (this.form.unpackList.length == 0) {
  312. this.formingNum = this.formData.formingNum;
  313. } else {
  314. this.changeNum(index);
  315. }
  316. },
  317. cancel() {
  318. this.formData = {};
  319. this.visible = false;
  320. this.$refs.form.resetFields();
  321. },
  322. confirm() {
  323. this.$refs.form.validate(async (value) => {
  324. if (value) {
  325. if (
  326. this.form.unpackList.length == 1 &&
  327. this.form.unpackList[0].formingNum == this.formData.formingNum
  328. ) {
  329. this.$message.info('拆单数要大于1');
  330. return false;
  331. }
  332. if (
  333. this.form.surplusUnpack.length == 1 &&
  334. this.form.unpackList.length == 0
  335. ) {
  336. this.$message.info('拆单数要大于1');
  337. return false;
  338. }
  339. let params = [];
  340. if (this.formingNum != 0) {
  341. this.form.surplusUnpack[0].formingNum = this.formingNum;
  342. params = [...this.form.unpackList, ...this.form.surplusUnpack];
  343. } else {
  344. params = this.form.unpackList;
  345. }
  346. // const res = await splitWork(params);
  347. // if (res) {
  348. // this.$message.success('拆分成功!');
  349. // this.$emit('success');
  350. // this.cancel();
  351. // }
  352. }
  353. });
  354. }
  355. }
  356. };
  357. </script>
  358. <style lang="scss" scoped>
  359. .mt20 {
  360. margin-top: 20px;
  361. }
  362. .el-form-item {
  363. margin-bottom: 0 !important;
  364. }
  365. </style>