edit.vue 17 KB

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