addEditForm.vue 7.7 KB

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