editForm.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <el-row :gutter="10" :loading="loading">
  3. <el-col :span="24">
  4. <el-form
  5. ref="ruleForm"
  6. :model="ruleForm"
  7. status-icon
  8. :rules="rules"
  9. label-width="100px"
  10. class="demo-ruleForm"
  11. >
  12. <el-form-item label="离职人" prop="resign_name">
  13. <search-account
  14. :value="ruleForm.resign_uid"
  15. :size="searchSize"
  16. :names="ruleForm.resign_name"
  17. :is-detail="isDetail"
  18. :disabled="!isDetail"
  19. :placeholder="'离职人名称'"
  20. @searchChange="handleResignName"
  21. />
  22. </el-form-item>
  23. <el-form-item label="接受人" prop="hand_name">
  24. <search-account
  25. :value="ruleForm.hand_uid"
  26. :size="searchSize"
  27. :names="ruleForm.hand_name"
  28. :is-detail="isDetail"
  29. :disabled="!isDetail"
  30. :placeholder="'接受人名称'"
  31. @searchChange="handleHandoverName"
  32. />
  33. </el-form-item>
  34. 12{{ edit_form }}
  35. </el-form>
  36. </el-col>
  37. <el-col :span="24" style="text-align: right">
  38. <el-button v-if="isDetail" type="primary" @click="submitForm"
  39. >保 存
  40. </el-button>
  41. <el-button v-if="isDetail" type="primary" @click="submitForm12"
  42. >保 存 并 发 起 流 程
  43. </el-button>
  44. <el-button @click="closeAddEdit" v-if="isDetail">{{
  45. isDetail ? "关 闭" : "取 消"
  46. }}</el-button>
  47. </el-col>
  48. </el-row>
  49. </template>
  50. <script>
  51. import asyncRequest from "@/apis/service/interest/handover";
  52. import resToken from "@/mixins/resToken";
  53. export default {
  54. name: "handover",
  55. props: ["id", "isDetail", "showModelThis", "edit_form"],
  56. mixins: [resToken],
  57. data() {
  58. return {
  59. parmValue: "parmValue",
  60. roleList: [],
  61. loading: false,
  62. showModelThis: this.showModel,
  63. resign_name: "", //离职人
  64. hand_name: "", //交接人
  65. ruleForm: {
  66. hand_uid: [],
  67. resign_uid: [],
  68. },
  69. rulesThis: this.rules,
  70. rules: {
  71. resign_uid: [
  72. {
  73. type: "array",
  74. required: true,
  75. message: "请选择离职人",
  76. trigger: "change",
  77. },
  78. ],
  79. hand_uid: [
  80. {
  81. type: "array",
  82. required: true,
  83. message: "请选择接受人",
  84. trigger: "change",
  85. },
  86. ],
  87. },
  88. };
  89. },
  90. mounted() {
  91. this.initForm();
  92. console.log(this.ruleForm);
  93. console.log(this.parmValue1);
  94. },
  95. // watch: {
  96. // parmValue: function (newV, oldV) {
  97. // console.log(newV);
  98. // console.log(oldV);
  99. // },
  100. // },
  101. methods: {
  102. // 关闭弹窗,直接隐藏表单
  103. closeAddEdit() {
  104. this.isShowForm = false;
  105. this.$emit("closeModel", false); //抛出一个事件,关闭弹窗
  106. },
  107. async initForm() {
  108. this.loading = true;
  109. // if (this.id === "add") {
  110. // // this.title = "添加离职交接";
  111. // this.rulesThis = this.rules;
  112. // await this.resetForm();
  113. // } else {
  114. // if (this.isDetail) {
  115. // this.rulesThis = {};
  116. // }
  117. // await this.resetForm();
  118. // await this.initData();
  119. // }
  120. console.log("initform");
  121. if (this.isDetail) {
  122. this.rulesThis = {};
  123. }
  124. await this.resetForm();
  125. await this.initData();
  126. this.loading = false;
  127. },
  128. async initData() {
  129. console.log(this.parmValue1);
  130. const res = await asyncRequest.detail({ id: this.edit_form.id });
  131. if (res && res.code === 0 && res.data) {
  132. console.log(res);
  133. let { hand_name, resign_name, hand_uid, resign_uid } = res.data;
  134. this.ruleForm = {
  135. resign_name,
  136. hand_name,
  137. hand_uid: hand_uid.split(","),
  138. resign_uid: resign_uid.split(","),
  139. };
  140. console.log(this.ruleForm);
  141. this.$emit("refreshList");
  142. } else if (res && res.code >= 100 && res.code <= 104) {
  143. await this.logout();
  144. } else {
  145. this.$message.warning(res.message);
  146. }
  147. },
  148. async resetForm() {
  149. // 重置
  150. await this.$nextTick(() => {
  151. if (this.$refs.ruleForm) {
  152. this.$refs.ruleForm.resetFields();
  153. this.$refs.ruleForm.clearValidate();
  154. this.ruleForm = {
  155. resign_name: "", //离职人
  156. hand_name: "", //交接人
  157. hand_uid: [],
  158. resign_uid: [],
  159. };
  160. }
  161. });
  162. },
  163. async submitForm() {
  164. await this.$refs.ruleForm.validate(async (valid) => {
  165. console.log(valid);
  166. if (valid) {
  167. let resign_name1 = this.ruleForm.resign_uid;
  168. let hand_name1 = this.ruleForm.hand_uid;
  169. if (resign_name1.toString() !== hand_name1.toString()) {
  170. this.loading = true;
  171. const model = {
  172. id: this.id,
  173. resign_uid: resign_name1.toString(),
  174. hand_uid: hand_name1.toString(),
  175. };
  176. let res = {};
  177. // if (this.id === "add") {
  178. // delete model["id"];
  179. // res = await asyncRequest.add(model);
  180. // console.log(res);
  181. // } else {
  182. res = await asyncRequest.update(model);
  183. // }
  184. console.log(res);
  185. this.loading = false;
  186. if (res && res.code === 0) {
  187. const title = this.id === "add" ? "添加成功!" : "修改成功!";
  188. this.$notify.success({
  189. title,
  190. message: "",
  191. });
  192. this.showModelThis = false;
  193. // 刷新
  194. this.$emit("refresh", false);
  195. } else if (res && res.code >= 100 && res.code <= 104) {
  196. await this.logout();
  197. } else {
  198. this.$message.warning(res.message);
  199. }
  200. } else {
  201. console.log("12");
  202. this.$message.error("离职人和接收人不能相同");
  203. }
  204. } else {
  205. console.log("error submit!!");
  206. return false;
  207. }
  208. });
  209. },
  210. handleResignName(e) {
  211. if (e && e.id) {
  212. this.ruleForm.resign_uid = [e.id];
  213. } else {
  214. this.ruleForm.resign_uid = [];
  215. }
  216. // this.$refs.ruleForm.validateField("resign_uid");
  217. },
  218. handleHandoverName(e) {
  219. console.log(e);
  220. if (e && e.id) {
  221. this.ruleForm.hand_uid = [e.id];
  222. } else {
  223. this.ruleForm.hand_uid = [];
  224. }
  225. // this.$refs.ruleForm.validateField("hand_uid");
  226. },
  227. },
  228. };
  229. </script>
  230. <style lang="scss" scoped>
  231. .account {
  232. }
  233. </style>