edit.vue 11 KB

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