taskSubmit.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="">
  3. <u--form
  4. style="margin: 0 20px"
  5. labelPosition="left"
  6. :model="form"
  7. :rules="rules"
  8. ref="uForm"
  9. labelWidth="140rpx"
  10. >
  11. <u-form-item label="审批建议" prop="reason" required>
  12. <u--textarea
  13. style="width: 100%"
  14. height="120"
  15. border="surround"
  16. placeholder="请输入审批建议"
  17. v-model="form.reason"
  18. ></u--textarea>
  19. </u-form-item>
  20. </u--form>
  21. <view class="btnList">
  22. <u-button
  23. style="width: 45%; margin-bottom: 10rpx"
  24. :loading="loading"
  25. type="success"
  26. text="通过"
  27. @click="handleAudit(1)"
  28. >
  29. </u-button>
  30. <u-button
  31. style="width: 45%"
  32. :loading="loading"
  33. type="error"
  34. text="驳回"
  35. @click="handleAudit(0)"
  36. ></u-button>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. approveTaskWithVariables,
  43. rejectTask,
  44. } from "@/api/wt/index.js";
  45. export default {
  46. name: "taskSubmit",
  47. props: {
  48. businessId: {
  49. default: "",
  50. },
  51. taskId: {
  52. default: "",
  53. },
  54. id: {
  55. default: "",
  56. },
  57. taskDefinitionKey: {
  58. default: "",
  59. },
  60. },
  61. data() {
  62. return {
  63. loading: false,
  64. form: {
  65. reason: "同意",
  66. },
  67. rules: {
  68. reason: {
  69. type: "string",
  70. required: true,
  71. message: "请输入审批建议",
  72. trigger: "blur",
  73. },
  74. },
  75. };
  76. },
  77. mounted() {
  78. this.$refs.uForm.setRules(this.rules);
  79. },
  80. methods: {
  81. async handleAudit(status) {
  82. try {
  83. await this.$refs.uForm.validate();
  84. } catch (e) {
  85. return;
  86. }
  87. await this._approveTaskWithVariables(status);
  88. },
  89. async _approveTaskWithVariables(status) {
  90. this.loading = true;
  91. try {
  92. let variables = {
  93. pass: !!status,
  94. };
  95. const API = !!status ? approveTaskWithVariables : rejectTask;
  96. const res = await API({
  97. id: this.taskId,
  98. reason: this.form.reason,
  99. variables,
  100. });
  101. if (res && res.code !== "-1") {
  102. this.$emit("handleAudit", {
  103. status,
  104. title: status === 0 ? "驳回" : "",
  105. });
  106. }
  107. } catch (error) {
  108. console.error("审批操作失败", error);
  109. uni.showToast({
  110. title: status === 1 ? "审批失败" : "驳回失败",
  111. icon: "none",
  112. });
  113. } finally {
  114. this.loading = false;
  115. }
  116. },
  117. getTableValue() {
  118. return new Promise((resolve, reject) => {
  119. this.$emit("getTableValue", async (data) => {
  120. resolve(await data);
  121. });
  122. });
  123. },
  124. },
  125. };
  126. </script>
  127. <style scoped>
  128. .btnList {
  129. display: flex;
  130. }
  131. </style>