create.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <ele-modal :visible.sync="visible" :title="title" width="80vw" append-to-body @close="cancel">
  3. <el-form
  4. ref="form"
  5. :model="form"
  6. :rules="rules"
  7. label-width="90px"
  8. class="create-form"
  9. >
  10. <el-row :gutter="15">
  11. <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
  12. <el-form-item label="编码:">
  13. <el-input :maxlength="20" v-model="form.code" disabled />
  14. </el-form-item>
  15. </el-col>
  16. <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
  17. <el-form-item label="来源编码:">
  18. <el-input :maxlength="20" v-model="form.unqualifiedSourceCode" disabled />
  19. </el-form-item>
  20. </el-col>
  21. <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
  22. <el-form-item label="数量:">
  23. <el-input
  24. :maxlength="20"
  25. v-model="form.unqualifiedQuantity"
  26. disabled
  27. />
  28. </el-form-item>
  29. </el-col>
  30. <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
  31. <el-form-item label="工艺路线:">
  32. <el-input
  33. @click.native="openVersion"
  34. clearable
  35. v-model="form.produceRoutingName"
  36. />
  37. </el-form-item>
  38. </el-col>
  39. <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
  40. <el-form-item label="工序:">
  41. <el-select
  42. style="width: 100%"
  43. v-model="form.produceTaskId"
  44. placeholder="请选择"
  45. clearable
  46. @change="produceTaskChange"
  47. >
  48. <el-option
  49. v-for="item in produceTaskList"
  50. :key="item.id"
  51. :label="item.name"
  52. :value="item.id"
  53. >
  54. </el-option>
  55. </el-select>
  56. </el-form-item>
  57. </el-col>
  58. <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 6 }">
  59. <el-form-item label="批次号:">
  60. <el-input :maxlength="20" v-model="form.batchNo" disabled />
  61. </el-form-item>
  62. </el-col>
  63. </el-row>
  64. <el-table :data="form.poList" border height="40vh">
  65. <el-table-column label="序号" align="center" width="60">
  66. <template slot-scope="scope">
  67. <span>{{ scope.$index + 1 }}</span>
  68. </template>
  69. </el-table-column>
  70. <el-table-column label="产品名称" align="center" prop="productName">
  71. </el-table-column>
  72. <el-table-column label="产品编码" align="center" prop="productCode">
  73. </el-table-column>
  74. <el-table-column label="牌号" align="center" prop="brandNo">
  75. </el-table-column>
  76. <el-table-column label="刻码" align="center" prop="engravingCode">
  77. <template slot-scope="scope">
  78. <el-form-item
  79. label-width="0px"
  80. :prop="'poList.' + scope.$index + '.engravingCode'"
  81. >
  82. <el-input
  83. v-model="scope.row.engravingCode"
  84. size="small"
  85. style="width: 100%"
  86. placeholder="输入刻码"
  87. ></el-input>
  88. </el-form-item>
  89. </template>
  90. </el-table-column>
  91. <!-- <el-table-column label="型号" align="center" prop="model">
  92. </el-table-column> -->
  93. <el-table-column label="规格" align="center" prop="specification">
  94. </el-table-column>
  95. <el-table-column label="数量" align="center" prop="unqualifiedQuantity">
  96. <template slot-scope="scope">
  97. <el-form-item
  98. label-width="0px"
  99. :prop="'poList.' + scope.$index + '.unqualifiedQuantity'"
  100. :rules="[
  101. {
  102. required: true,
  103. message: '请输入数量',
  104. trigger: 'blur'
  105. },
  106. { validator: validatePass, trigger: 'change' }
  107. ]"
  108. >
  109. <el-input
  110. :disabled="!!scope.row.id"
  111. v-model.number="scope.row.unqualifiedQuantity"
  112. size="small"
  113. oninput="value=value.replace(/[^\d]/g,'')"
  114. style="width: 100%"
  115. placeholder="输入数量"
  116. @input="
  117. inputNumber(scope.$index, scope.row.unqualifiedQuantity)
  118. "
  119. ></el-input>
  120. </el-form-item>
  121. </template>
  122. </el-table-column>
  123. <el-table-column
  124. label="工艺路线"
  125. align="center"
  126. prop="produceRoutingName"
  127. >
  128. </el-table-column>
  129. <el-table-column label="工序" align="center" prop="produceTaskName">
  130. </el-table-column>
  131. <el-table-column label="原因" align="center" prop="unqualifiedReason">
  132. <template slot-scope="scope">
  133. <el-form-item
  134. label-width="0px"
  135. :prop="'poList.' + scope.$index + '.unqualifiedReason'"
  136. :rules="{
  137. required: true,
  138. message: '请输入原因',
  139. trigger: 'blur'
  140. }"
  141. >
  142. <el-input
  143. v-model="scope.row.unqualifiedReason"
  144. size="small"
  145. style="width: 100%"
  146. placeholder="输入原因"
  147. ></el-input>
  148. </el-form-item>
  149. </template>
  150. </el-table-column>
  151. <el-table-column label="操作" align="center" width="70">
  152. <template slot-scope="scope">
  153. <el-link
  154. type="danger"
  155. :underline="false"
  156. @click="handleDeleteItem(scope.$index, scope.row.id)"
  157. >
  158. 删除
  159. </el-link>
  160. </template>
  161. </el-table-column>
  162. </el-table>
  163. <div class="add-product" @click="addEquipment">
  164. <i class="el-icon-circle-plus-outline"></i>
  165. </div>
  166. </el-form>
  167. <template v-slot:footer>
  168. <el-button @click="cancel">取消</el-button>
  169. <el-button type="primary" @click="save" :loading="loading">
  170. 确定
  171. </el-button>
  172. </template>
  173. <!-- 选择产品 -->
  174. <EquipmentDialog ref="equipmentRefs" @choose="confirmChoose">
  175. </EquipmentDialog>
  176. <ProductionVersion
  177. ref="versionRefs"
  178. @changeProduct="changeProduct"
  179. ></ProductionVersion>
  180. </ele-modal>
  181. </template>
  182. <script>
  183. import EquipmentDialog from '../components/EquipmentDialog.vue';
  184. import ProductionVersion from '@/components/ProductionVersion/ProductionVersion.vue';
  185. import { getProduceTaskList } from '@/api/aps';
  186. import {
  187. unqualifiedProductsAdd,
  188. getDetail,
  189. deleteUnacceptedProductDetail
  190. } from '@/api/unacceptedProduct/index';
  191. export default {
  192. components: {
  193. EquipmentDialog,
  194. ProductionVersion
  195. },
  196. data() {
  197. return {
  198. validatePass: (rule, value, callback) => {
  199. if (!value) {
  200. callback(new Error('数量不能为0'));
  201. } else {
  202. callback();
  203. }
  204. },
  205. visible: false,
  206. loading: false,
  207. produceTaskList: [],
  208. form: {
  209. poList: [],
  210. code: '',
  211. unqualifiedSourceCode: '',
  212. unqualifiedSourceId: '',
  213. unqualifiedQuantity: '',
  214. type: '',
  215. status: null,
  216. reviewerId: null,
  217. reviewerName: '',
  218. createUserName: '',
  219. brandNo: '',
  220. produceRoutingId: '',
  221. produceRoutingName: '',
  222. produceTaskId: '',
  223. produceTaskName: '',
  224. batchNo: ''
  225. },
  226. // 表单验证规则
  227. rules: {
  228. deliveryTime: [
  229. { required: true, message: '请选择交付日期', trigger: 'change' }
  230. ]
  231. },
  232. title: '创建'
  233. };
  234. },
  235. computed: {
  236. // 是否开启响应式布局
  237. styleResponsive() {
  238. return this.$store.state.theme.styleResponsive;
  239. }
  240. },
  241. created() {},
  242. methods: {
  243. open(row, type) {
  244. this.visible = true;
  245. if (type == 'add') {
  246. this.title = '创建';
  247. this.form = row;
  248. this.getProduceTaskList();
  249. return;
  250. }
  251. if (row) {
  252. this.title = '修改';
  253. this.detail(row);
  254. } else {
  255. this.title = '创建';
  256. }
  257. },
  258. //选择工艺路线
  259. openVersion() {
  260. this.$refs.versionRefs.open();
  261. },
  262. //工艺路线回调
  263. changeProduct(data) {
  264. this.form.produceRoutingId = data.id;
  265. this.form.produceRoutingName = data.name;
  266. this.form.produceTaskId = '';
  267. this.form.produceTaskName = '';
  268. this.getProduceTaskList();
  269. },
  270. async getProduceTaskList() {
  271. const res = await getProduceTaskList({
  272. isDetail: true,
  273. pageNum: 1,
  274. routingId: this.form.produceRoutingId,
  275. size: -1
  276. });
  277. this.produceTaskList = res.list;
  278. },
  279. produceTaskChange() {
  280. if (!this.form.produceTaskId) {
  281. return;
  282. }
  283. this.form.produceTaskName = this.produceTaskList.find(
  284. (item) => item.id == this.form.produceTaskId
  285. ).name;
  286. this.form.poList.forEach((item, index) => {
  287. this.$set(
  288. this.form.poList[index],
  289. 'produceRoutingId',
  290. this.form.produceRoutingId
  291. );
  292. this.$set(
  293. this.form.poList[index],
  294. 'produceRoutingName',
  295. this.form.produceRoutingName
  296. );
  297. this.$set(
  298. this.form.poList[index],
  299. 'produceTaskId',
  300. this.form.produceTaskId
  301. );
  302. this.$set(
  303. this.form.poList[index],
  304. 'produceTaskName',
  305. this.form.produceTaskName
  306. );
  307. });
  308. },
  309. detail(row) {
  310. getDetail(row.id).then((res) => {
  311. this.form = row;
  312. this.getProduceTaskList();
  313. this.form.poList = res;
  314. });
  315. },
  316. cancel() {
  317. this.form = {
  318. poList: [],
  319. code: '',
  320. workOrderId: '',
  321. productCode: '',
  322. productName: '',
  323. specifications: '',
  324. unqualifiedQuantity: '',
  325. type: '',
  326. status: null,
  327. reviewerId: null,
  328. reviewerName: '',
  329. createUserName: '',
  330. brandNo: '',
  331. produceRoutingId: '',
  332. produceRoutingName: '',
  333. produceTaskId: '',
  334. produceTaskName: '',
  335. batchNo: ''
  336. };
  337. this.$refs.form.clearValidate();
  338. this.visible = false;
  339. },
  340. // 删除产品
  341. handleDeleteItem(index, id) {
  342. this.$confirm('确认删除吗?', '提示', {
  343. confirmButtonText: '确定',
  344. cancleButtonText: '取消',
  345. type: 'warning'
  346. })
  347. .then((res) => {
  348. if (id) {
  349. deleteUnacceptedProductDetail([id]).then((res) => {
  350. this.form.poList.splice(index, 1);
  351. });
  352. } else {
  353. this.form.poList.splice(index, 1);
  354. }
  355. })
  356. .catch(() => {});
  357. this.inputNumber();
  358. },
  359. addEquipment() {
  360. this.$refs.equipmentRefs.open();
  361. },
  362. /* 保存编辑 */
  363. save() {
  364. console.log(this.form.poList);
  365. this.$refs.form.validate((valid) => {
  366. if (!valid) {
  367. return false;
  368. }
  369. if (!this.form.poList.length) {
  370. return this.$message.warning('产品列表不能为空!');
  371. }
  372. for (let key in this.form) {
  373. if (key.includes('create')) {
  374. this.form[key] = '';
  375. }
  376. }
  377. this.form.poList.forEach((item) => {
  378. for (let key in item) {
  379. if (key.includes('create')) {
  380. item[key] = '';
  381. }
  382. }
  383. });
  384. this.loading = true;
  385. unqualifiedProductsAdd(this.form)
  386. .then((res) => {
  387. this.loading = false;
  388. this.$message.success('成功');
  389. this.cancel();
  390. this.$emit('refresh');
  391. })
  392. .catch((e) => {
  393. this.loading = false;
  394. });
  395. });
  396. },
  397. // 确定选择
  398. confirmChoose(data) {
  399. let list = [];
  400. list = data.map((item, index) => {
  401. if (item.productCode) {
  402. return item;
  403. } else {
  404. return {
  405. productCode: item.code,
  406. productName: item.name,
  407. // productUnitWeight: item.netWeight,
  408. // weightUnit: item.weightUnit,
  409. specification: item.specification,
  410. brandNo: item.brandNum,
  411. unqualifiedQuantity: '',
  412. unqualifiedReason: '',
  413. produceRoutingId: '',
  414. produceRoutingName: '',
  415. produceTaskId: '',
  416. produceTaskName: ''
  417. };
  418. }
  419. });
  420. this.form.poList = this.form.poList.concat(list);
  421. this.produceTaskChange();
  422. this.inputNumber();
  423. },
  424. inputNumber() {
  425. this.form.unqualifiedQuantity = 0;
  426. this.form.poList.forEach((item) => {
  427. this.form.unqualifiedQuantity += Number(item.unqualifiedQuantity) || 0;
  428. });
  429. }
  430. }
  431. };
  432. </script>
  433. <style lang="scss" scoped>
  434. .basic-details-title {
  435. margin: 10px 0;
  436. }
  437. .add-product {
  438. width: 100%;
  439. display: flex;
  440. align-items: center;
  441. justify-content: flex-end;
  442. font-size: 30px;
  443. color: #1890ff;
  444. margin: 10px 0;
  445. cursor: pointer;
  446. }
  447. .create-form .el-form-item {
  448. margin-bottom: 15px !important;
  449. }
  450. </style>