edit.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <el-dialog
  4. class="ele-dialog-form"
  5. :title="title"
  6. :visible.sync="visible"
  7. :before-close="handleClose"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. width="1200px"
  11. >
  12. <el-form ref="form" :model="form" :rules="rules" label-width="110px">
  13. <el-card
  14. shadow="never"
  15. header="基本信息"
  16. body-style="padding: 22px 22px 0 22px;"
  17. >
  18. <el-row>
  19. <el-col :span="8">
  20. <el-form-item label="工位编码:" prop="code">
  21. <el-input
  22. clearable
  23. :maxlength="20"
  24. v-model="form.code"
  25. placeholder="请输入"
  26. />
  27. </el-form-item>
  28. </el-col>
  29. <el-col :span="8">
  30. <el-form-item label="工位名称:" prop="name">
  31. <el-input
  32. clearable
  33. :maxlength="20"
  34. v-model="form.name"
  35. placeholder="请输入"
  36. />
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8">
  40. <el-form-item label="所属工厂:" prop="extInfo.factoryId">
  41. <el-select
  42. v-model="form.extInfo.factoryId"
  43. placeholder="请选择"
  44. @change="change_factoryId"
  45. style="width: 100%"
  46. >
  47. <el-option
  48. v-for="item in options_factory"
  49. :key="item.id"
  50. :label="item.name"
  51. :value="item.id"
  52. >
  53. </el-option>
  54. </el-select>
  55. </el-form-item>
  56. </el-col>
  57. <el-col :span="8">
  58. <el-form-item label="设备编码:" prop="extInfo.assetCode">
  59. <el-input
  60. v-model="form.extInfo.assetCode"
  61. readonly
  62. @click.native="chooseAsset"
  63. />
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="8">
  67. <el-form-item label="设备名称:" prop="extInfo.assetName">
  68. <el-input disabled v-model="form.extInfo.assetName" />
  69. </el-form-item>
  70. </el-col>
  71. <el-col :span="8">
  72. <el-form-item label="所属车间:" prop="extInfo.workshopId">
  73. <el-select
  74. v-model="form.extInfo.workshopId"
  75. placeholder="请选择"
  76. style="width: 100%"
  77. @change="change_workshop"
  78. >
  79. <el-option
  80. v-for="item in options.workshopId"
  81. :key="item.id"
  82. :label="item.name"
  83. :value="item.id"
  84. >
  85. </el-option>
  86. </el-select>
  87. </el-form-item>
  88. </el-col>
  89. <el-col :span="8">
  90. <el-form-item label="所属产线:" prop="productionLineId">
  91. <el-select
  92. v-model="form.productionLineId"
  93. placeholder="请选择"
  94. style="width: 100%"
  95. @change="change_productionLineId"
  96. >
  97. <el-option
  98. v-for="item in options.productionLineId"
  99. :key="item.id"
  100. :label="item.name"
  101. :value="item.id"
  102. >
  103. </el-option>
  104. </el-select>
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="8">
  108. <el-form-item label="负责人部门:" prop="extInfo.principalDep">
  109. <ele-tree-select
  110. clearable
  111. :data="options_groupId"
  112. v-model="form.extInfo.principalDep"
  113. valueKey="id"
  114. labelKey="name"
  115. placeholder="请选择"
  116. @change="change_principalDep"
  117. default-expand-all
  118. />
  119. </el-form-item>
  120. </el-col>
  121. <el-col :span="8">
  122. <el-form-item label="负责人:" prop="leaderId">
  123. <el-select
  124. v-model="form.leaderId"
  125. placeholder="请选择"
  126. style="width: 100%"
  127. >
  128. <el-option
  129. v-for="item in options.leaderId"
  130. :key="item.id"
  131. :label="item.name"
  132. :value="item.id"
  133. >
  134. </el-option>
  135. </el-select>
  136. </el-form-item>
  137. </el-col>
  138. <el-col :span="8">
  139. <el-form-item label="所属工作中心:" prop="extInfo.workCenterId">
  140. <el-select
  141. v-model="form.extInfo.workCenterId"
  142. placeholder="请选择"
  143. style="width: 100%"
  144. >
  145. <el-option
  146. v-for="item in options.workCenterList"
  147. :key="item.id"
  148. :label="item.name"
  149. :value="item.id"
  150. >
  151. </el-option>
  152. </el-select>
  153. </el-form-item>
  154. </el-col>
  155. <el-col :span="16">
  156. <el-form-item label="可执行工序:" prop="taskNames">
  157. <el-input :value="form.taskNames && form.taskNames.join(',')" placeholder="请选择" @click.native="handleProduce"></el-input>
  158. <!-- <el-select
  159. v-model="form.extInfo.produceId"
  160. placeholder="请选择"
  161. style="width: 100%"
  162. >
  163. <el-option
  164. v-for="item in options.produceList"
  165. :key="item.id"
  166. :label="item.name"
  167. :value="item.id"
  168. >
  169. </el-option> -->
  170. </el-select>
  171. </el-form-item>
  172. </el-col>
  173. <el-col :span="8">
  174. <el-form-item label="状态:" prop="enabled">
  175. <el-select
  176. v-model="form.enabled"
  177. placeholder="请选择"
  178. style="width: 100%"
  179. >
  180. <el-option
  181. v-for="item in options.enabled"
  182. :key="item.value"
  183. :label="item.label"
  184. :value="item.value"
  185. >
  186. </el-option>
  187. </el-select>
  188. </el-form-item>
  189. </el-col>
  190. <el-col :span="14">
  191. <el-form-item label="节拍时间:" prop="extInfo.meterTime">
  192. <div class="workMeter-warp">
  193. <el-input
  194. class="s1"
  195. clearable
  196. :maxlength="20"
  197. v-model="form.extInfo.meterTime"
  198. placeholder="请输入"
  199. />
  200. <DictSelection
  201. style="width: 30%"
  202. dictName="计量单位"
  203. clearable
  204. v-model="form.extInfo.meterMeasuringUnit"
  205. >
  206. </DictSelection>
  207. <span class="s3">/</span>
  208. <el-select
  209. class="s2"
  210. v-model="form.extInfo.meterTimeUnit"
  211. placeholder="请选择"
  212. >
  213. <el-option
  214. v-for="item in options.meterTimeUnit"
  215. :key="item.value"
  216. :label="item.label"
  217. :value="item.value"
  218. >
  219. </el-option>
  220. </el-select>
  221. </div>
  222. </el-form-item>
  223. </el-col>
  224. <el-col :span="24">
  225. <el-form-item label="备注:" prop="remark">
  226. <el-input
  227. clearable
  228. :maxlength="100"
  229. type="textarea"
  230. v-model="form.remark"
  231. placeholder="请输入"
  232. />
  233. </el-form-item>
  234. </el-col>
  235. </el-row>
  236. </el-card>
  237. <!-- <el-card
  238. shadow="never"
  239. header="关联设备"
  240. body-style="padding: 22px 22px 0 22px;"
  241. >
  242. <equipmentTable ref="equipmentTable"></equipmentTable>
  243. </el-card> -->
  244. </el-form>
  245. <template v-slot:footer>
  246. <el-button @click="handleClose">取消</el-button>
  247. <el-button type="primary" :loading="loading" @click="save">
  248. 保存
  249. </el-button>
  250. </template>
  251. <!-- 选择设备 -->
  252. <AssetSelection
  253. ref="equipmentTable"
  254. @confirm="assetConfirm"
  255. ></AssetSelection>
  256. <ProduceDialog ref="produceRef" @success="produceConfirm"/>
  257. </el-dialog>
  258. </template>
  259. <script>
  260. import {
  261. listWorkshopByParentId,
  262. saveOrUpdate_gw,
  263. listFactoryLineByParentId,
  264. getById
  265. } from '@/api/factoryModel';
  266. import { getUserPage } from '@/api/system/organization';
  267. import AssetSelection from './AssetSelection.vue';
  268. import producetask from '@/api/technology/production';
  269. import work from '@/api/technology/work';
  270. import ProduceDialog from './ProduceDialog'
  271. export default {
  272. components: {
  273. AssetSelection,
  274. ProduceDialog
  275. },
  276. props: {
  277. options_groupId: {
  278. type: Array,
  279. default () {
  280. return [];
  281. }
  282. },
  283. options_factory: {
  284. type: Array,
  285. default () {
  286. return [];
  287. }
  288. }
  289. },
  290. watch: {
  291. options_groupId (nval) {
  292. this.toTreeData(nval);
  293. }
  294. },
  295. data () {
  296. const defaultForm = function () {
  297. return {
  298. code: '',
  299. enabled: 1,
  300. extInfo: {
  301. factoryId: '', // 工厂
  302. workshopId: '', // 车间
  303. principalDep: '', // 负责人部门
  304. meterTimeUnit: '时', // 节拍时间单位
  305. meterTime: '', // 节拍时间
  306. assetCode: '', //设备编码
  307. assetName: '', //设备名称
  308. meterMeasuringUnit: '', // 节拍计量单位
  309. workCenterId: null, //所属工作中心
  310. produceId: null //可执行工序
  311. },
  312. id: '',
  313. leaderId: '', // 负责人
  314. name: '',
  315. productionLineId: '',
  316. remark: '',
  317. taskIds:[],
  318. taskNames:[],
  319. workstationSubstanceList: []
  320. };
  321. };
  322. return {
  323. defaultForm,
  324. // 表单数据
  325. form: defaultForm(),
  326. // 表单验证规则
  327. rules: {
  328. code: [{ required: true, message: '请输入', trigger: 'blur' }],
  329. name: [{ required: true, message: '请输入', trigger: 'blur' }],
  330. workCenterId: [
  331. { required: true, message: '请选择', trigger: 'change' }
  332. ],
  333. processId: [{ required: true, message: '请选择', trigger: 'change' }],
  334. 'extInfo.factoryId': [
  335. { required: true, message: '请输入', trigger: 'change' }
  336. ],
  337. 'extInfo.principalDep': [
  338. { required: true, message: '请输入', trigger: 'change' }
  339. ],
  340. 'extInfo.assetCode': [
  341. { required: true, message: '请选择', trigger: 'change' }
  342. ],
  343. 'extInfo.assetName': [
  344. { required: true, message: '请选择', trigger: 'change' }
  345. ],
  346. 'extInfo.workshopId': {
  347. required: true,
  348. message: '请输入',
  349. trigger: 'change'
  350. },
  351. 'extInfo.workCenterId': {
  352. required: true,
  353. message: '请输入',
  354. trigger: 'change'
  355. },
  356. 'extInfo.taskNames': {
  357. required: true,
  358. message: '请输入',
  359. trigger: 'change'
  360. },
  361. productionLineId: {
  362. required: true,
  363. message: '请输入',
  364. trigger: 'change'
  365. },
  366. leaderId: {
  367. required: true,
  368. message: '请输入',
  369. trigger: 'change'
  370. }
  371. },
  372. visible: false,
  373. type: '', // add/edit
  374. loading: false,
  375. options: {
  376. leaderId: [],
  377. workshopId: [],
  378. workCenterList: [],
  379. produceList: [],
  380. enabled: [
  381. {
  382. label: '生效',
  383. value: 1
  384. },
  385. {
  386. label: '未生效',
  387. value: 0
  388. }
  389. ],
  390. meterTimeUnit: [
  391. {
  392. value: '时',
  393. label: '时'
  394. },
  395. {
  396. value: '分',
  397. label: '分'
  398. },
  399. {
  400. value: '秒',
  401. label: '秒'
  402. },
  403. {
  404. value: '日',
  405. label: '日'
  406. }
  407. ],
  408. productionLineId: []
  409. }
  410. };
  411. },
  412. computed: {
  413. title () {
  414. switch (this.type) {
  415. case 'add':
  416. return '新增工位';
  417. case 'edit':
  418. return '编辑工位';
  419. default:
  420. break;
  421. }
  422. }
  423. },
  424. methods: {
  425. chooseAsset () {
  426. this.$refs.equipmentTable.open(this.form.extInfo);
  427. },
  428. // 选择可执行工序
  429. handleProduce(){
  430. this.$refs.produceRef.open(this.form.taskIds)
  431. },
  432. produceConfirm(list){
  433. this.form.taskIds = list.map(i => i.id)
  434. this.form.taskNames = list.map(i => i.taskInstanceName)
  435. console.log(list);
  436. console.log(this.form);
  437. },
  438. assetConfirm (data) {
  439. this.form.extInfo.assetCode = data.code;
  440. this.form.extInfo.assetName = data.name;
  441. this.form.extInfo.assetId = data.id;
  442. },
  443. open (type, row) {
  444. this.type = type;
  445. this.visible = true;
  446. if (type == 'edit') {
  447. for (const key of Object.keys(this.form)) {
  448. if (key !== 'extInfo') {
  449. this.form[key] = row[key];
  450. } else {
  451. for (const el of Object.keys(this.form.extInfo)) {
  452. this.form.extInfo[el] = row.extInfo[el];
  453. }
  454. }
  455. }
  456. this.getData(row.id);
  457. // 请求下拉数据
  458. if (this.form.extInfo.factoryId) {
  459. this.getListWorkshopByParentId();
  460. }
  461. if (this.form.extInfo.workshopId) {
  462. this.getlistFactoryLineByParentId();
  463. }
  464. if (this.form.extInfo.principalDep) {
  465. this.getUserPage();
  466. }
  467. }
  468. this.getListWorkCenter();
  469. this.getListProduce();
  470. },
  471. /* 保存编辑 */
  472. save () {
  473. this.$refs.form.validate((valid) => {
  474. if (!valid) {
  475. return false;
  476. }
  477. this.loading = true;
  478. if (this.type == 'add') {
  479. delete this.form.id;
  480. }
  481. // this.form.workstationSubstanceList =
  482. // this.$refs.equipmentTable.datasource.map((n) => {
  483. // return {
  484. // type: 1,
  485. // substanceId: n.id
  486. // };
  487. // });
  488. this.form.workstationSubstanceList = [
  489. {
  490. type: 1,
  491. substanceId: this.form.extInfo.assetId
  492. }
  493. ];
  494. saveOrUpdate_gw(this.form)
  495. .then((msg) => {
  496. this.loading = false;
  497. this.$message.success(msg);
  498. this.handleClose();
  499. this.$emit('done');
  500. })
  501. .catch((e) => {
  502. this.loading = false;
  503. this.$message.error(e.message);
  504. });
  505. });
  506. },
  507. restForm () {
  508. this.form = { ...this.defaultForm() };
  509. this.$nextTick(() => {
  510. this.$refs.form.clearValidate();
  511. });
  512. },
  513. handleClose () {
  514. this.restForm();
  515. this.loading = false;
  516. this.visible = false;
  517. },
  518. // 格式化公司数据
  519. toTreeData (val) {
  520. this.options.principalDep = this.$util.toTreeData({
  521. data: val,
  522. idField: 'id',
  523. parentIdField: 'parentId'
  524. });
  525. },
  526. // 获取工作中心
  527. getListWorkCenter () {
  528. work.list({ pageNum: 1, size: -1 }).then((res) => {
  529. this.options.workCenterList = res.list;
  530. });
  531. },
  532. // 获取工序
  533. getListProduce () {
  534. producetask.list({ pageNum: 1, size: -1 }).then((res) => {
  535. this.options.produceList = res.list;
  536. });
  537. },
  538. // 获取车间
  539. getListWorkshopByParentId () {
  540. listWorkshopByParentId(this.form.extInfo.factoryId).then((res) => {
  541. this.options.workshopId = res;
  542. });
  543. },
  544. // 获取产线
  545. getlistFactoryLineByParentId () {
  546. console.log(this.form.extInfo.workshopId);
  547. listFactoryLineByParentId(this.form.extInfo.workshopId).then((res) => {
  548. console.log(res);
  549. this.options.productionLineId = res;
  550. });
  551. },
  552. // 获取人员
  553. getUserPage () {
  554. let par = {
  555. groupId: this.form.extInfo.principalDep,
  556. size: 999
  557. };
  558. getUserPage(par).then((res) => {
  559. this.options.leaderId = res.list;
  560. });
  561. },
  562. // 选择工厂
  563. change_factoryId () {
  564. this.form.extInfo.workshopId = '';
  565. this.form.leaderId = '';
  566. this.options.workshopId = [];
  567. this.options.leaderId = [];
  568. this.getListWorkshopByParentId();
  569. },
  570. // 选择负责人部门
  571. change_principalDep () {
  572. this.form.leaderId = '';
  573. this.getUserPage();
  574. },
  575. // 选择车间
  576. change_workshop () {
  577. this.form.leaderId = '';
  578. this.options.leaderId = [];
  579. this.getlistFactoryLineByParentId();
  580. },
  581. // 选择产线
  582. change_productionLineId () {},
  583. // 请求详情
  584. getData (id) {
  585. getById(id).then((res) => {
  586. if (
  587. res.workstationSubstanceList &&
  588. res.workstationSubstanceList.length > 0
  589. ) {
  590. let list = res.workstationSubstanceList.map((n) => {
  591. return n.substance;
  592. });
  593. if (list.length > 0) {
  594. this.$refs.equipmentTable.datasource = list;
  595. }
  596. }
  597. this.form = Object.assign({}, this.form, res)
  598. if(res.taskInstanceList?.length){
  599. this.form.taskNames = res.taskInstanceList.map(i => i.name)
  600. }
  601. });
  602. }
  603. }
  604. };
  605. </script>
  606. <style lang="scss" scoped>
  607. .location-warp {
  608. display: flex;
  609. .detail {
  610. margin-left: 10px;
  611. }
  612. }
  613. .workMeter-warp {
  614. .s1 {
  615. width: 30%;
  616. margin-right: 10px;
  617. }
  618. .s2 {
  619. width: 20%;
  620. margin-left: 10px;
  621. }
  622. .s3 {
  623. margin-left: 10px;
  624. }
  625. }
  626. :deep(.el-dialog:not(.ele-dialog-form)
  627. .el-dialog__body
  628. .el-form
  629. .el-form-item:last-child) {
  630. margin-bottom: 22px;
  631. }
  632. </style>