edit.vue 9.2 KB

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