edit.vue 18 KB

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