edit.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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="1200px"
  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. :disabled="type == 'edit'"
  27. />
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="8">
  31. <el-form-item
  32. label="班次名称:"
  33. prop="name"
  34. style="margin-bottom: 22px"
  35. >
  36. <el-input
  37. clearable
  38. :maxlength="20"
  39. v-model="form.name"
  40. placeholder="请输入"
  41. />
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="8">
  45. <el-form-item
  46. label="日工作时长:"
  47. prop="totalWorkHour"
  48. style="margin-bottom: 22px"
  49. >
  50. {{ form.totalWorkHour }} 时
  51. </el-form-item>
  52. </el-col>
  53. </el-row>
  54. </el-card>
  55. <el-card
  56. shadow="never"
  57. header="工作时间段"
  58. body-style="padding: 22px 22px 0 22px;"
  59. >
  60. <timeTable
  61. ref="timeTable"
  62. @timeAll="gettimeAll"
  63. :delDetailIds="delDetailIds"
  64. ></timeTable>
  65. </el-card>
  66. </el-form>
  67. <template v-slot:footer>
  68. <el-button @click="handleClose">取消</el-button>
  69. <el-button type="primary" :loading="loading" @click="save">
  70. 保存
  71. </el-button>
  72. </template>
  73. </el-dialog>
  74. </template>
  75. <script>
  76. import {
  77. saveteamtime,
  78. updateteamtime
  79. } from '@/api/workforceManagement/classes';
  80. import timeTable from './timeTable.vue';
  81. export default {
  82. components: {
  83. timeTable
  84. },
  85. data () {
  86. const defaultForm = {
  87. id: '',
  88. code: '',
  89. name: '',
  90. totalWorkHour: '',
  91. details: []
  92. };
  93. return {
  94. defaultForm,
  95. // 表单数据
  96. form: { ...defaultForm },
  97. // 表单验证规则
  98. rules: {
  99. code: [{ required: true, message: '请输入', trigger: 'blur' }],
  100. name: [{ required: true, message: '请输入', trigger: 'blur' }]
  101. },
  102. visible: false,
  103. type: '', // add/edit
  104. loading: false,
  105. options: {
  106. workshopId: [],
  107. productionLineId: [],
  108. workStationId: []
  109. },
  110. delDetailIds: []
  111. };
  112. },
  113. computed: {
  114. title () {
  115. switch (this.type) {
  116. case 'add':
  117. return '新增班次';
  118. break;
  119. case 'edit':
  120. return '修改班次';
  121. break;
  122. default:
  123. break;
  124. }
  125. }
  126. },
  127. created () {},
  128. methods: {
  129. open (type, row) {
  130. this.type = type;
  131. this.visible = true;
  132. if (type == 'edit') {
  133. for (const key of Object.keys(this.form)) {
  134. if (row[key]) {
  135. this.form[key] = row[key];
  136. }
  137. }
  138. this.$nextTick(() => {
  139. // 反显时间段
  140. if (row.details) {
  141. this.$refs.timeTable.form.datasource = row.details;
  142. }
  143. });
  144. }
  145. },
  146. /* 保存编辑 */
  147. save () {
  148. this.$refs.form.validate((valid) => {
  149. if (!valid) {
  150. return false;
  151. }
  152. if (this.type == 'add') {
  153. delete this.form.id;
  154. }
  155. this.$refs.timeTable.verification().then((res) => {
  156. this.loading = true;
  157. this.form.details = this.$refs.timeTable.form.datasource;
  158. let fn;
  159. switch (this.type) {
  160. case 'add':
  161. fn = saveteamtime;
  162. break;
  163. case 'edit':
  164. fn = updateteamtime;
  165. this.form.delDetailIds = this.delDetailIds;
  166. break;
  167. default:
  168. break;
  169. }
  170. fn(this.form)
  171. .then((msg) => {
  172. this.loading = false;
  173. this.$message.success(msg);
  174. this.handleClose();
  175. this.$emit('done');
  176. })
  177. .catch((e) => {
  178. this.loading = false;
  179. this.$message.error(e.message);
  180. });
  181. });
  182. });
  183. },
  184. // 重置表单
  185. restForm () {
  186. this.$refs.form.clearValidate();
  187. this.form = { ...this.defaultForm };
  188. },
  189. handleClose () {
  190. this.delDetailIds = [];
  191. this.restForm();
  192. this.$refs.timeTable.restTable();
  193. this.visible = false;
  194. },
  195. gettimeAll (val) {
  196. this.form.totalWorkHour = val;
  197. }
  198. }
  199. };
  200. </script>
  201. <style lang="scss" scoped>
  202. .location-warp {
  203. display: flex;
  204. .detail {
  205. margin-left: 10px;
  206. }
  207. }
  208. </style>