edit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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="100px">
  13. <el-row>
  14. <el-col :span="8">
  15. <el-form-item
  16. label="产线编码:"
  17. prop="code"
  18. style="margin-bottom: 22px"
  19. >
  20. <el-input
  21. clearable
  22. :maxlength="20"
  23. v-model="form.code"
  24. placeholder="请输入"
  25. />
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="8">
  29. <el-form-item
  30. label="产线名称:"
  31. prop="name"
  32. style="margin-bottom: 22px"
  33. >
  34. <el-input
  35. clearable
  36. :maxlength="20"
  37. v-model="form.name"
  38. placeholder="请输入"
  39. />
  40. </el-form-item>
  41. </el-col>
  42. <el-col :span="8" style="margin-bottom: 22px">
  43. <el-form-item label="所属工厂:" prop="extInfo.factoryId">
  44. <el-select
  45. v-model="form.extInfo.factoryId"
  46. placeholder="请选择"
  47. @change="change_factoryId"
  48. style="width: 100%"
  49. >
  50. <el-option
  51. v-for="item in options_factory"
  52. :key="item.id"
  53. :label="item.name"
  54. :value="item.id"
  55. >
  56. </el-option>
  57. </el-select>
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="8" style="margin-bottom: 22px">
  61. <el-form-item label="所属车间:" prop="parentId">
  62. <el-select
  63. v-model="form.parentId"
  64. placeholder="请选择"
  65. style="width: 100%"
  66. @change="change_workshop"
  67. >
  68. <el-option
  69. v-for="item in options.workshop"
  70. :key="item.id"
  71. :label="item.name"
  72. :value="item.id"
  73. >
  74. </el-option>
  75. </el-select>
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="8">
  79. <el-form-item
  80. label="负责人部门:"
  81. prop="extInfo.principalDep"
  82. style="margin-bottom: 22px"
  83. >
  84. <ele-tree-select
  85. clearable
  86. :data="options.principalDep"
  87. v-model="form.extInfo.principalDep"
  88. valueKey="id"
  89. labelKey="name"
  90. placeholder="请选择"
  91. @change="change_principalDep"
  92. default-expand-all
  93. />
  94. </el-form-item>
  95. </el-col>
  96. <el-col :span="8" style="margin-bottom: 22px">
  97. <el-form-item label="负责人:" prop="extInfo.principal">
  98. <el-select
  99. v-model="form.extInfo.principal"
  100. placeholder="请选择"
  101. @change="change_principal"
  102. style="width: 100%"
  103. >
  104. <el-option
  105. v-for="item in options.principal"
  106. :key="item.id"
  107. :label="item.name"
  108. :value="item.id"
  109. >
  110. </el-option>
  111. </el-select>
  112. </el-form-item>
  113. </el-col>
  114. <el-col :span="8" style="margin-bottom: 22px">
  115. <el-form-item label="联系方式:" prop="extInfo.phone">
  116. <el-input
  117. clearable
  118. :maxlength="20"
  119. v-model="form.extInfo.phone"
  120. οninput="value=value.replace(/[^\d]/g,'');if(value.length > 11)value = value.slice(0, 11)"
  121. placeholder="请输入"
  122. />
  123. </el-form-item>
  124. </el-col>
  125. <el-col :span="8" style="margin-bottom: 22px">
  126. <el-form-item label="工作节拍:" prop="extInfo.workMeter">
  127. <el-input
  128. clearable
  129. :maxlength="20"
  130. v-model="form.extInfo.workMeter"
  131. placeholder="请输入"
  132. />
  133. </el-form-item>
  134. </el-col>
  135. <el-col :span="8" style="margin-bottom: 22px">
  136. <el-form-item label="加工能力:" prop="extInfo.workingAbility">
  137. <el-input
  138. clearable
  139. :maxlength="20"
  140. v-model="form.extInfo.workingAbility"
  141. placeholder="请输入"
  142. />
  143. </el-form-item>
  144. </el-col>
  145. <el-col :span="8" style="margin-bottom: 22px">
  146. <el-form-item label="状态:" prop="enabled">
  147. <el-select
  148. v-model="form.enabled"
  149. placeholder="请选择"
  150. style="width: 100%"
  151. >
  152. <el-option
  153. v-for="item in options.enabled"
  154. :key="item.value"
  155. :label="item.label"
  156. :value="item.value"
  157. >
  158. </el-option>
  159. </el-select>
  160. </el-form-item>
  161. </el-col>
  162. <el-col :span="24" style="margin-bottom: 22px">
  163. <el-form-item label="地址:" prop="extInfo.location">
  164. <div class="location-warp">
  165. <el-cascader
  166. clearable
  167. style="width: 400px"
  168. v-model="form.extInfo.location"
  169. :options="options.cityDataLabel"
  170. ></el-cascader>
  171. <el-input
  172. class="detail"
  173. clearable
  174. :maxlength="20"
  175. v-model="form.extInfo.locationDetail"
  176. placeholder="请输入详细地址"
  177. />
  178. </div>
  179. </el-form-item>
  180. </el-col>
  181. <el-col :span="24" style="margin-bottom: 22px">
  182. <el-form-item label="备注:" prop="remark">
  183. <el-input
  184. clearable
  185. :maxlength="100"
  186. type="textarea"
  187. v-model="form.remark"
  188. placeholder="请输入"
  189. />
  190. </el-form-item>
  191. </el-col>
  192. </el-row>
  193. </el-form>
  194. <template v-slot:footer>
  195. <el-button @click="handleClose">取消</el-button>
  196. <el-button type="primary" :loading="loading" @click="save">
  197. 保存
  198. </el-button>
  199. </template>
  200. </el-dialog>
  201. </template>
  202. <script>
  203. import { saveOrUpdate, listWorkshopByParentId } from '@/api/factoryModel';
  204. import { getUserPage } from '@/api/system/organization';
  205. import { cityDataLabel } from 'ele-admin/packages/utils/regions';
  206. export default {
  207. props: {
  208. options_groupId: {
  209. type: Array,
  210. default() {
  211. return [];
  212. }
  213. },
  214. options_factory: {
  215. type: Array,
  216. default() {
  217. return [];
  218. }
  219. }
  220. },
  221. watch: {
  222. options_groupId(nval) {
  223. this.toTreeData(nval);
  224. }
  225. },
  226. data() {
  227. const defaultForm = {
  228. id: '',
  229. code: '',
  230. name: '',
  231. extInfo: {
  232. factoryId: '',
  233. principal: '', // 负责人
  234. principalDep: '', // 负责人部门
  235. phone: '', // 手机号
  236. workMeter: '', // 工作节拍
  237. workingAbility: '', // 加工能力
  238. locationDetail: '', // 详细地址
  239. location: [] // 省市区
  240. },
  241. groupId: '',
  242. enabled: 1,
  243. parentId: '',
  244. remark: '',
  245. type: 4 // FACTORY(1, "工厂"), WORKSHOP_PLAN(2, "厂房"), WORKSHOP(3, "车间"), LINE(4, "厂线");
  246. };
  247. return {
  248. defaultForm,
  249. // 表单数据
  250. form: { ...defaultForm },
  251. // 表单验证规则
  252. rules: {
  253. code: [{ required: true, message: '请输入', trigger: 'blur' }],
  254. name: [{ required: true, message: '请输入', trigger: 'blur' }],
  255. 'extInfo.factoryId': [
  256. { required: true, message: '请输入', trigger: 'change' }
  257. ],
  258. parentId: { required: true, message: '请输入', trigger: 'change' },
  259. 'extInfo.principalDep': [
  260. { required: true, message: '请输入', trigger: 'change' }
  261. ],
  262. 'extInfo.principal': [
  263. { required: true, message: '请输入', trigger: 'change' }
  264. ],
  265. 'extInfo.phone': [
  266. { min: 11, message: '手机号格式不正确', trigger: 'blur' }
  267. ]
  268. },
  269. visible: false,
  270. type: '', // add/edit
  271. loading: false,
  272. options: {
  273. principalDep: [],
  274. principal: [],
  275. workshop: [],
  276. enabled: [
  277. {
  278. label: '生效',
  279. value: 1
  280. },
  281. {
  282. label: '未生效',
  283. value: 0
  284. }
  285. ],
  286. cityDataLabel
  287. }
  288. };
  289. },
  290. computed: {
  291. title() {
  292. switch (this.type) {
  293. case 'add':
  294. return '新增产线';
  295. break;
  296. case 'edit':
  297. return '编辑产线';
  298. break;
  299. default:
  300. break;
  301. }
  302. }
  303. },
  304. methods: {
  305. open(type, row) {
  306. this.type = type;
  307. this.visible = true;
  308. if (type == 'edit') {
  309. for (const key of Object.keys(this.form)) {
  310. if (key !== 'extInfo') {
  311. this.form[key] = row[key];
  312. } else {
  313. for (const el of Object.keys(this.form.extInfo)) {
  314. this.form.extInfo[el] = row.extInfo[el];
  315. }
  316. }
  317. }
  318. // 请求下拉数据
  319. if (this.form.extInfo.factoryId) {
  320. this.getListWorkshopByParentId();
  321. }
  322. if (this.form.extInfo.principalDep) {
  323. this.getUserPage();
  324. }
  325. }
  326. },
  327. /* 保存编辑 */
  328. save() {
  329. this.$refs.form.validate((valid) => {
  330. if (!valid) {
  331. return false;
  332. }
  333. this.loading = true;
  334. if (this.type == 'add') {
  335. delete this.form.id;
  336. }
  337. saveOrUpdate(this.form)
  338. .then((msg) => {
  339. this.loading = false;
  340. this.$message.success(msg);
  341. this.handleClose();
  342. this.$emit('done');
  343. })
  344. .catch((e) => {
  345. this.loading = false;
  346. this.$message.error(e.message);
  347. });
  348. });
  349. },
  350. restForm() {
  351. this.$refs.form.clearValidate();
  352. this.form = { ...this.defaultForm };
  353. },
  354. handleClose() {
  355. this.restForm();
  356. this.visible = false;
  357. },
  358. // 格式化公司数据
  359. toTreeData(val) {
  360. this.options.principalDep = this.$util.toTreeData({
  361. data: val,
  362. idField: 'id',
  363. parentIdField: 'parentId'
  364. });
  365. },
  366. // 获取车间
  367. getListWorkshopByParentId() {
  368. listWorkshopByParentId(this.form.extInfo.factoryId).then((res) => {
  369. this.options.workshop = res;
  370. });
  371. },
  372. // 获取人员
  373. getUserPage() {
  374. let par = {
  375. groupId: this.form.extInfo.principalDep,
  376. size: 999
  377. };
  378. getUserPage(par).then((res) => {
  379. this.options.principal = res.list;
  380. });
  381. },
  382. // 选择工厂
  383. change_factoryId() {
  384. this.form.parentId = '';
  385. this.form.groupId = '';
  386. this.options.workshop = [];
  387. this.getListWorkshopByParentId();
  388. },
  389. // 选择负责人部门
  390. change_principalDep() {
  391. this.form.extInfo.principal = '';
  392. this.options.principal = [];
  393. this.getUserPage();
  394. },
  395. // 选择车间
  396. change_workshop() {
  397. let result = this.options.workshop.find(
  398. (n) => n.id == this.form.parentId
  399. );
  400. this.form.groupId = result.groupId;
  401. },
  402. // 选择负责人
  403. change_principal() {
  404. let result = this.options.principal.find(
  405. (n) => n.id == this.form.extInfo.principal
  406. );
  407. this.form.extInfo.phone = result.phone;
  408. }
  409. }
  410. };
  411. </script>
  412. <style lang="scss" scoped>
  413. .location-warp {
  414. display: flex;
  415. .detail {
  416. margin-left: 10px;
  417. }
  418. }
  419. </style>