edit.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 = function () {
  131. return {
  132. id: '',
  133. code: '',
  134. leaderUserId: '',
  135. name: '',
  136. productionLineId: '',
  137. userIds: '',
  138. userNumber: '',
  139. workStationIds: [],
  140. workshopId: ''
  141. };
  142. };
  143. return {
  144. defaultForm,
  145. // 表单数据
  146. form: { ...defaultForm() },
  147. // 表单验证规则
  148. rules: {
  149. code: [{ required: true, message: '请输入', trigger: 'blur' }],
  150. name: [{ required: true, message: '请输入', trigger: 'blur' }],
  151. workshopId: [{ required: true, message: '请输入', trigger: 'change' }],
  152. productionLineId: [
  153. { required: true, message: '请输入', trigger: 'change' }
  154. ]
  155. },
  156. visible: false,
  157. type: '', // add/edit
  158. loading: false,
  159. options: {
  160. workshopId: [],
  161. productionLineId: [],
  162. workStationIds: []
  163. }
  164. };
  165. },
  166. computed: {
  167. title() {
  168. switch (this.type) {
  169. case 'add':
  170. return '新增班组';
  171. break;
  172. case 'edit':
  173. return '编辑班组';
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179. },
  180. created() {
  181. this.getlistWorkshopByParentId();
  182. },
  183. methods: {
  184. async open(type, row) {
  185. this.type = type;
  186. this.visible = true;
  187. if (type == 'edit') {
  188. for (const key of Object.keys(this.form)) {
  189. if (row[key]) {
  190. this.form[key] = row[key];
  191. }
  192. }
  193. // 工位反显
  194. if (row.workStationList.length > 0) {
  195. this.form.workStationIds = row.workStationList.map(
  196. (n) => n.workstationId
  197. );
  198. }
  199. // 人员反显
  200. this.$nextTick(() => {
  201. if (row.userVOList) {
  202. this.$refs.userTable.confirmStaffSelection(
  203. JSON.parse(JSON.stringify(row.userVOList))
  204. );
  205. }
  206. // 班组长
  207. this.$refs.userTable.setLeaderId(row.leaderUserId);
  208. });
  209. // 获取下拉列表
  210. await this.getlistWorkshopByParentId();
  211. await this.getlistFactoryLineByParentId();
  212. this.getlistByProductionLineId();
  213. }
  214. },
  215. /* 保存编辑 */
  216. save() {
  217. this.$refs.form.validate((valid) => {
  218. if (!valid) {
  219. return false;
  220. }
  221. this.loading = true;
  222. let userIds = this.$refs.userTable.datasource.map((n) => n.id);
  223. if (userIds.length <= 0) {
  224. this.$message.error('请选择员工');
  225. this.loading = false;
  226. return false;
  227. }
  228. let par = this.form;
  229. par.userIds = userIds;
  230. par.leaderUserId = this.$refs.userTable.getTwi();
  231. par.userNumber = par.userIds.length;
  232. if (this.type == 'add') {
  233. delete par.id;
  234. }
  235. saveteam(par)
  236. .then((msg) => {
  237. this.loading = false;
  238. this.$message.success(msg);
  239. this.handleClose();
  240. this.$emit('done');
  241. })
  242. .catch((e) => {
  243. this.loading = false;
  244. // this.$message.error(e.message);
  245. });
  246. });
  247. },
  248. // 重置表单
  249. restForm() {
  250. this.form = { ...this.defaultForm() };
  251. this.$nextTick(() => {
  252. this.$refs.form.clearValidate();
  253. });
  254. },
  255. handleClose() {
  256. this.restForm();
  257. this.$refs.userTable.restTable();
  258. this.visible = false;
  259. this.loading = false;
  260. },
  261. // 获取车间
  262. getlistWorkshopByParentId() {
  263. let par = this.$store.state.user.info.factoryId;
  264. return listWorkshopByParentId(par).then((res) => {
  265. this.options.workshopId = res.map((n) => {
  266. return {
  267. value: n.id,
  268. label: n.name
  269. };
  270. });
  271. });
  272. },
  273. // 获取产线
  274. getlistFactoryLineByParentId() {
  275. let par = this.form.workshopId;
  276. return listFactoryLineByParentId(par).then((res) => {
  277. this.options.productionLineId = res.map((n) => {
  278. return {
  279. value: n.id,
  280. label: n.name
  281. };
  282. });
  283. });
  284. },
  285. // 获取工位
  286. getlistByProductionLineId() {
  287. let par = this.form.productionLineId;
  288. return listByProductionLineId(par).then((res) => {
  289. this.options.workStationIds = res.map((n) => {
  290. return {
  291. value: n.id,
  292. label: n.name
  293. };
  294. });
  295. });
  296. },
  297. // 选择车间
  298. change_workshopId() {
  299. this.form.productionLineId = '';
  300. this.form.workStationIds = [];
  301. this.options.productionLineId = [];
  302. this.options.workStationIds = [];
  303. this.getlistFactoryLineByParentId();
  304. },
  305. // 选择产线
  306. change_productionLineId() {
  307. this.form.workStationIds = [];
  308. this.options.workStationIds = [];
  309. this.getlistByProductionLineId();
  310. }
  311. }
  312. };
  313. </script>
  314. <style lang="scss" scoped>
  315. .location-warp {
  316. display: flex;
  317. .detail {
  318. margin-left: 10px;
  319. }
  320. }
  321. </style>