edit.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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="1000px"
  11. >
  12. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  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" style="margin-bottom: 22px">
  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" style="margin-bottom: 22px">
  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
  41. label="车间:"
  42. prop="workshopId"
  43. style="margin-bottom: 22px"
  44. >
  45. <el-select
  46. v-model="form.workshopId"
  47. @change="change_workshopId"
  48. placeholder="请选择"
  49. style="width: 100%"
  50. >
  51. <el-option
  52. v-for="item in options.workshopId"
  53. :key="item.value"
  54. :label="item.label"
  55. :value="item.value"
  56. >
  57. </el-option>
  58. </el-select>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="8" style="margin-bottom: 22px">
  62. <el-form-item label="产线:" prop="productionLineId">
  63. <el-select
  64. v-model="form.productionLineId"
  65. @change="change_productionLineId"
  66. placeholder="请选择"
  67. style="width: 100%"
  68. >
  69. <el-option
  70. v-for="item in options.productionLineId"
  71. :key="item.value"
  72. :label="item.label"
  73. :value="item.value"
  74. >
  75. </el-option>
  76. </el-select>
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="8" style="margin-bottom: 22px">
  80. <el-form-item label="工站:" prop="workStationIds">
  81. <div class="location-warp">
  82. <el-select
  83. v-model="form.workStationIds"
  84. multiple
  85. placeholder="请选择"
  86. style="width: 100%"
  87. >
  88. <el-option
  89. v-for="item in options.workStationIds"
  90. :key="item.value"
  91. :label="item.label"
  92. :value="item.value"
  93. >
  94. </el-option>
  95. </el-select>
  96. </div>
  97. </el-form-item>
  98. </el-col>
  99. </el-row>
  100. </el-card>
  101. <el-card
  102. shadow="never"
  103. header="员工配置"
  104. body-style="padding: 22px 22px 0 22px;"
  105. >
  106. <userTable ref="userTable"></userTable>
  107. </el-card>
  108. </el-form>
  109. <template v-slot:footer>
  110. <el-button @click="handleClose">取消</el-button>
  111. <el-button type="primary" :loading="loading" @click="save">
  112. 保存
  113. </el-button>
  114. </template>
  115. </el-dialog>
  116. </template>
  117. <script>
  118. import {
  119. listWorkshopByParentId,
  120. listFactoryLineByParentId,
  121. listByProductionLineId,
  122. saveteam
  123. } from '@/api/workforceManagement/team';
  124. import userTable from './userTable.vue';
  125. export default {
  126. components: {
  127. userTable
  128. },
  129. data() {
  130. const defaultForm = {
  131. id: '',
  132. code: '',
  133. leaderUserId: '',
  134. name: '',
  135. productionLineId: '',
  136. userIds: '',
  137. userNumber: '',
  138. workStationIds: [],
  139. workshopId: ''
  140. };
  141. return {
  142. defaultForm,
  143. // 表单数据
  144. form: { ...defaultForm },
  145. // 表单验证规则
  146. rules: {
  147. code: [{ required: true, message: '请输入', trigger: 'blur' }],
  148. name: [{ required: true, message: '请输入', trigger: 'blur' }],
  149. workshopId: [{ required: true, message: '请输入', trigger: 'change' }],
  150. productionLineId: [
  151. { required: true, message: '请输入', trigger: 'change' }
  152. ]
  153. },
  154. visible: false,
  155. type: '', // add/edit
  156. loading: false,
  157. options: {
  158. workshopId: [],
  159. productionLineId: [],
  160. workStationIds: []
  161. }
  162. };
  163. },
  164. computed: {
  165. title() {
  166. switch (this.type) {
  167. case 'add':
  168. return '新增班组';
  169. break;
  170. case 'edit':
  171. return '编辑班组';
  172. break;
  173. default:
  174. break;
  175. }
  176. }
  177. },
  178. created() {
  179. this.getlistWorkshopByParentId();
  180. },
  181. methods: {
  182. async open(type, row) {
  183. this.type = type;
  184. this.visible = true;
  185. if (type == 'edit') {
  186. for (const key of Object.keys(this.form)) {
  187. if (row[key]) {
  188. this.form[key] = row[key];
  189. }
  190. }
  191. // 工位反显
  192. if (row.workStationList.length > 0) {
  193. this.form.workStationIds = row.workStationList.map(
  194. (n) => n.workstationId
  195. );
  196. }
  197. // 人员反显
  198. this.$nextTick(() => {
  199. if (row.userVOList) {
  200. this.$refs.userTable.confirmStaffSelection(
  201. JSON.parse(JSON.stringify(row.userVOList))
  202. );
  203. }
  204. // 班组长
  205. this.$refs.userTable.setLeaderId(row.leaderUserId);
  206. });
  207. // 获取下拉列表
  208. await this.getlistWorkshopByParentId();
  209. await this.getlistFactoryLineByParentId();
  210. this.getlistByProductionLineId();
  211. }
  212. },
  213. /* 保存编辑 */
  214. save() {
  215. this.$refs.form.validate((valid) => {
  216. if (!valid) {
  217. return false;
  218. }
  219. this.loading = true;
  220. let userIds = this.$refs.userTable.datasource.map((n) => n.id);
  221. if (userIds.length <= 0) {
  222. this.$message.error('请选择员工');
  223. return false;
  224. }
  225. let par = this.form;
  226. par.userIds = userIds;
  227. par.leaderUserId = this.$refs.userTable.getTwi();
  228. par.userNumber = par.userIds.length;
  229. if (this.type == 'add') {
  230. delete par.id;
  231. }
  232. saveteam(par)
  233. .then((msg) => {
  234. this.$message.success(msg);
  235. this.handleClose();
  236. this.$emit('done');
  237. })
  238. .catch((e) => {
  239. this.$message.error(e.message);
  240. })
  241. .finally(() => {
  242. this.loading = false;
  243. });
  244. });
  245. },
  246. // 重置表单
  247. restForm() {
  248. this.$refs.form.clearValidate();
  249. this.form = { ...this.defaultForm };
  250. },
  251. handleClose() {
  252. this.restForm();
  253. this.$refs.userTable.restTable();
  254. this.visible = false;
  255. },
  256. // 获取车间
  257. getlistWorkshopByParentId() {
  258. let par = this.$store.state.user.info.factoryId;
  259. return listWorkshopByParentId(par).then((res) => {
  260. this.options.workshopId = res.map((n) => {
  261. return {
  262. value: n.id,
  263. label: n.name
  264. };
  265. });
  266. });
  267. },
  268. // 获取产线
  269. getlistFactoryLineByParentId() {
  270. let par = this.form.workshopId;
  271. return listFactoryLineByParentId(par).then((res) => {
  272. this.options.productionLineId = res.map((n) => {
  273. return {
  274. value: n.id,
  275. label: n.name
  276. };
  277. });
  278. });
  279. },
  280. // 获取工位
  281. getlistByProductionLineId() {
  282. let par = this.form.productionLineId;
  283. return listByProductionLineId(par).then((res) => {
  284. this.options.workStationIds = res.map((n) => {
  285. return {
  286. value: n.id,
  287. label: n.name
  288. };
  289. });
  290. });
  291. },
  292. // 选择车间
  293. change_workshopId() {
  294. this.form.productionLineId = '';
  295. this.form.workStationIds = '';
  296. this.options.productionLineId = [];
  297. this.options.workStationIds = [];
  298. this.getlistFactoryLineByParentId();
  299. },
  300. // 选择产线
  301. change_productionLineId() {
  302. this.form.workStationIds = '';
  303. this.options.workStationIds = [];
  304. this.getlistByProductionLineId();
  305. }
  306. }
  307. };
  308. </script>
  309. <style lang="scss" scoped>
  310. .location-warp {
  311. display: flex;
  312. .detail {
  313. margin-left: 10px;
  314. }
  315. }
  316. </style>