edit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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="workStationIds">
  39. <div class="location-warp">
  40. <el-select v-model="form.workStationIds" multiple filterable placeholder="请选择" style="width: 100%">
  41. <el-option v-for="item in options.workStationIds" :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. workStationIds: [],
  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. workStationIds: []
  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. if (row.workStationList.length > 0) {
  141. this.form.workStationIds = row.workStationList.map(
  142. (n) => n.workstationId
  143. );
  144. }
  145. // 人员反显
  146. this.$nextTick(() => {
  147. if (row.userVOList) {
  148. this.$refs.userTable.confirmStaffSelection(
  149. JSON.parse(JSON.stringify(row.userVOList))
  150. );
  151. }
  152. // 班组长
  153. this.$refs.userTable.setLeaderId(row.leaderUserId);
  154. });
  155. // 获取下拉列表
  156. await this.getlistWorkshopByParentId();
  157. await this.getlistFactoryLineByParentId();
  158. }
  159. this.getlistByProductionLineId();
  160. },
  161. /* 保存编辑 */
  162. save() {
  163. this.$refs.form.validate((valid) => {
  164. if (!valid) {
  165. return false;
  166. }
  167. this.loading = true;
  168. let userIds = this.$refs.userTable.datasource.map((n) => n.id);
  169. if (userIds.length <= 0) {
  170. this.$message.error('请选择员工');
  171. this.loading = false;
  172. return false;
  173. }
  174. let par = this.form;
  175. par.userIds = userIds;
  176. par.leaderUserId = this.$refs.userTable.getTwi();
  177. par.userNumber = par.userIds.length;
  178. if (this.type == 'add') {
  179. delete par.id;
  180. }
  181. const saveOrUpdate = this.type == 'add' ? saveteam : updateteam
  182. saveOrUpdate(par)
  183. .then((msg) => {
  184. this.loading = false;
  185. this.$message.success(msg);
  186. this.handleClose();
  187. this.$emit('done');
  188. })
  189. .catch((e) => {
  190. this.loading = false;
  191. // this.$message.error(e.message);
  192. });
  193. });
  194. },
  195. // 重置表单
  196. restForm() {
  197. this.form = { ...this.defaultForm() };
  198. this.$nextTick(() => {
  199. this.$refs.form.clearValidate();
  200. });
  201. },
  202. handleClose() {
  203. this.restForm();
  204. this.$refs.userTable.restTable();
  205. this.visible = false;
  206. this.loading = false;
  207. },
  208. // 获取车间
  209. getlistWorkshopByParentId() {
  210. let par = this.$store.state.user.info.factoryId;
  211. return listWorkshopByParentId(par).then((res) => {
  212. this.options.workshopId = res.map((n) => {
  213. return {
  214. value: n.id,
  215. label: n.name
  216. };
  217. });
  218. });
  219. },
  220. // 获取产线
  221. getlistFactoryLineByParentId() {
  222. return listFactoryLine().then((res) => {
  223. this.options.productionLineId = res.map((n) => {
  224. return {
  225. value: n.id,
  226. label: n.name
  227. };
  228. });
  229. });
  230. },
  231. // 获取工位
  232. getlistByProductionLineId() {
  233. return work.list({pageNum: 1, size: -1}).then((res) => {
  234. this.options.workStationIds = res.list.map((n) => {
  235. return {
  236. value: n.id,
  237. label: n.name
  238. };
  239. });
  240. });
  241. },
  242. // 选择车间
  243. change_workshopId() {
  244. this.form.productionLineId = '';
  245. this.options.productionLineId = [];
  246. this.getlistFactoryLineByParentId();
  247. },
  248. }
  249. };
  250. </script>
  251. <style lang="scss" scoped>
  252. .location-warp {
  253. display: flex;
  254. .detail {
  255. margin-left: 10px;
  256. }
  257. }
  258. </style>