edit.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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="1000px">
  5. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  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" style="margin-bottom: 22px">
  10. <el-input clearable :maxlength="20" v-model="form.code" placeholder="请输入" />
  11. </el-form-item>
  12. </el-col>
  13. <el-col :span="8">
  14. <el-form-item label="名称:" prop="name" style="margin-bottom: 22px">
  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="workshopId" style="margin-bottom: 22px">
  20. <el-select v-model="form.workshopId" @change="change_workshopId" multiple placeholder="请选择"
  21. style="width: 100%">
  22. <el-option v-for="item in options.workshopId" :key="item.value" :label="item.label" :value="item.value">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="8" style="margin-bottom: 22px">
  28. <el-form-item label="产线:" prop="productionLineId">
  29. <el-select v-model="form.productionLineId" multiple placeholder="请选择"
  30. style="width: 100%">
  31. <el-option v-for="item in options.productionLineId" :key="item.value" :label="item.label"
  32. :value="item.value">
  33. </el-option>
  34. </el-select>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="8" style="margin-bottom: 22px">
  38. <el-form-item label="工作中心:" prop="workCenterIds">
  39. <div class="location-warp">
  40. <el-select v-model="form.workCenterIds" multiple filterable placeholder="请选择" style="width: 100%">
  41. <el-option v-for="item in options.workCenterIds" :key="item.value" :label="item.label"
  42. :value="item.value">
  43. </el-option>
  44. </el-select>
  45. </div>
  46. </el-form-item>
  47. </el-col>
  48. </el-row>
  49. </el-card>
  50. <el-card shadow="never" header="员工配置" body-style="padding: 22px 22px 0 22px;">
  51. <userTable ref="userTable"></userTable>
  52. </el-card>
  53. </el-form>
  54. <template v-slot:footer>
  55. <el-button @click="handleClose">取消</el-button>
  56. <el-button type="primary" :loading="loading" @click="save">
  57. 保存
  58. </el-button>
  59. </template>
  60. </el-dialog>
  61. </template>
  62. <script>
  63. import {
  64. listWorkshopByParentId,
  65. listFactoryLine,
  66. saveteam,
  67. updateteam
  68. } from '@/api/workforceManagement/team';
  69. import work from '@/api/technology/work';
  70. import userTable from './userTable.vue';
  71. export default {
  72. components: {
  73. userTable
  74. },
  75. data() {
  76. const defaultForm = function () {
  77. return {
  78. id: '',
  79. code: '',
  80. leaderUserId: '',
  81. name: '',
  82. productionLineId: [],
  83. userIds: '',
  84. userNumber: '',
  85. workCenterIds: [],
  86. workshopId: []
  87. };
  88. };
  89. return {
  90. defaultForm,
  91. // 表单数据
  92. form: { ...defaultForm() },
  93. // 表单验证规则
  94. rules: {
  95. code: [{ required: true, message: '请输入', trigger: 'blur' }],
  96. name: [{ required: true, message: '请输入', trigger: 'blur' }],
  97. workshopId: [{ required: true, message: '请输入', trigger: 'change' }],
  98. productionLineId: [
  99. { required: true, message: '请输入', trigger: 'change' }
  100. ]
  101. },
  102. visible: false,
  103. type: '', // add/edit
  104. loading: false,
  105. options: {
  106. workshopId: [],
  107. productionLineId: [],
  108. workCenterIds: []
  109. }
  110. };
  111. },
  112. computed: {
  113. title() {
  114. switch (this.type) {
  115. case 'add':
  116. return '新增班组';
  117. break;
  118. case 'edit':
  119. return '编辑班组';
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. },
  126. created() {
  127. this.getlistWorkshopByParentId();
  128. },
  129. methods: {
  130. async open(type, row) {
  131. this.type = type;
  132. this.visible = true;
  133. if (type == 'edit') {
  134. for (const key of Object.keys(this.form)) {
  135. if (row[key]) {
  136. this.form[key] = row[key];
  137. }
  138. }
  139. // 人员反显
  140. this.$nextTick(() => {
  141. if (row.userVOList) {
  142. this.$refs.userTable.confirmStaffSelection(
  143. JSON.parse(JSON.stringify(row.userVOList))
  144. );
  145. }
  146. // 班组长
  147. this.$refs.userTable.setLeaderId(row.leaderUserId);
  148. });
  149. // 获取下拉列表
  150. await this.getlistWorkshopByParentId();
  151. await this.getlistFactoryLineByParentId();
  152. }
  153. this.getlistByProductionLineId();
  154. },
  155. /* 保存编辑 */
  156. save() {
  157. this.$refs.form.validate((valid) => {
  158. if (!valid) {
  159. return false;
  160. }
  161. this.loading = true;
  162. let userIds = this.$refs.userTable.datasource.map((n) => n.id);
  163. if (userIds.length <= 0) {
  164. this.$message.error('请选择员工');
  165. this.loading = false;
  166. return false;
  167. }
  168. let par = this.form;
  169. par.userIds = userIds;
  170. par.leaderUserId = this.$refs.userTable.getTwi();
  171. par.userNumber = par.userIds.length;
  172. if (this.type == 'add') {
  173. delete par.id;
  174. }
  175. const saveOrUpdate = this.type == 'add' ? saveteam : updateteam
  176. saveOrUpdate(par)
  177. .then((msg) => {
  178. this.loading = false;
  179. this.$message.success(msg);
  180. this.handleClose();
  181. this.$emit('done');
  182. })
  183. .catch((e) => {
  184. this.loading = false;
  185. // this.$message.error(e.message);
  186. });
  187. });
  188. },
  189. // 重置表单
  190. restForm() {
  191. this.form = { ...this.defaultForm() };
  192. this.$nextTick(() => {
  193. this.$refs.form.clearValidate();
  194. });
  195. },
  196. handleClose() {
  197. this.restForm();
  198. this.$refs.userTable.restTable();
  199. this.visible = false;
  200. this.loading = false;
  201. },
  202. // 获取车间
  203. getlistWorkshopByParentId() {
  204. let par = this.$store.state.user.info.factoryId;
  205. return listWorkshopByParentId(par).then((res) => {
  206. this.options.workshopId = res.map((n) => {
  207. return {
  208. value: n.id,
  209. label: n.name
  210. };
  211. });
  212. });
  213. },
  214. // 获取产线
  215. getlistFactoryLineByParentId() {
  216. return listFactoryLine().then((res) => {
  217. this.options.productionLineId = res.map((n) => {
  218. return {
  219. value: n.id,
  220. label: n.name
  221. };
  222. });
  223. });
  224. },
  225. // 获取工位
  226. getlistByProductionLineId() {
  227. return work.list({pageNum: 1, size: -1}).then((res) => {
  228. this.options.workCenterIds = res.list.map((n) => {
  229. return {
  230. value: n.id,
  231. label: n.name
  232. };
  233. });
  234. });
  235. },
  236. // 选择车间
  237. change_workshopId() {
  238. this.form.productionLineId = '';
  239. this.options.productionLineId = [];
  240. this.getlistFactoryLineByParentId();
  241. },
  242. }
  243. };
  244. </script>
  245. <style lang="scss" scoped>
  246. .location-warp {
  247. display: flex;
  248. .detail {
  249. margin-left: 10px;
  250. }
  251. }
  252. </style>