taskSubmit.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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="taskDefinitionKey === 'storeman' ? '申请出库' : '通过'"
  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="rejectTask(0)"
  36. ></u-button>
  37. </view>
  38. <view class="btnConcel" v-if="taskDefinitionKey !== 'deptLeaderApprove'">
  39. <u-button @click="showAction = true">更多</u-button>
  40. </view>
  41. <u-action-sheet
  42. :actions="actionList"
  43. :closeOnClickOverlay="true"
  44. :closeOnClickAction="true"
  45. title="更多操作"
  46. :show="showAction"
  47. @close="showAction = false"
  48. @select="selectActionClick"
  49. ></u-action-sheet>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. approveTaskWithVariables,
  55. rejectTask,
  56. cancelTask,
  57. } from "@/api/wt/index.js";
  58. import { outStorage } from "@/api/warehouseManagement/index.js";
  59. export default {
  60. name: "taskSubmit",
  61. props: {
  62. businessId: {
  63. default: "",
  64. },
  65. taskId: {
  66. default: "",
  67. },
  68. id: {
  69. default: "",
  70. },
  71. taskDefinitionKey: {
  72. default: "",
  73. },
  74. },
  75. data() {
  76. return {
  77. showAction: false,
  78. loading: false,
  79. taskFormData: {},
  80. actionList: [
  81. {
  82. name: "作废",
  83. fontSize: "28",
  84. color: "#ffaa7f",
  85. },
  86. ],
  87. form: {
  88. technicianId: "",
  89. reason: "",
  90. },
  91. rules: {
  92. reason: {
  93. type: "string",
  94. required: true,
  95. message: "请输入审批建议",
  96. trigger: "blur",
  97. },
  98. },
  99. };
  100. },
  101. mounted() {
  102. this.$refs.uForm.setRules(this.rules);
  103. },
  104. methods: {
  105. async syncTaskFormData() {
  106. try {
  107. const data = await this.getTableValue();
  108. this.taskFormData = data || {};
  109. } catch (e) {
  110. console.warn("获取 taskForm 数据失败", e);
  111. this.taskFormData = {};
  112. }
  113. return this.taskFormData;
  114. },
  115. selectActionClick(item) {
  116. if (item.name == "作废") {
  117. uni.showModal({
  118. title: "提示",
  119. content: "是否确认作废?",
  120. success: async (modalRes) => {
  121. if (modalRes.confirm) {
  122. if (!this.form.reason) {
  123. return uni.showToast({
  124. title: "审批建议不能为空",
  125. icon: "none",
  126. });
  127. }
  128. this.loading = true;
  129. await this.syncTaskFormData();
  130. cancelTask({
  131. taskId: this.taskId,
  132. id: this.id,
  133. reason: this.form.reason,
  134. businessId: this.businessId,
  135. variables: {
  136. taskFormData: this.taskFormData,
  137. },
  138. })
  139. .then(() => {
  140. this.loading = false;
  141. this.$emit("handleAudit", {
  142. title: "作废",
  143. });
  144. })
  145. .catch(() => {
  146. this.loading = false;
  147. uni.showToast({ title: "流程作废失败", icon: "none" });
  148. });
  149. }
  150. },
  151. });
  152. }
  153. },
  154. async handleAudit(status) {
  155. if (!!status) {
  156. try {
  157. await this.$refs.uForm.validate();
  158. } catch (e) {
  159. return;
  160. }
  161. }
  162. await this.syncTaskFormData();
  163. let storageData = this.taskFormData.returnStorageData;
  164. if (!!status) {
  165. if (!storageData?.extInfo?.verifyDeptCode) {
  166. return uni.showToast({ title: "请选择部门", icon: "none" });
  167. }
  168. if (!storageData?.fromUser) {
  169. return uni.showToast({ title: "请选择领料人", icon: "none" });
  170. }
  171. }
  172. if (!this.form.reason && !!status) {
  173. return uni.showToast({ title: "请输入审批意见", icon: "none" });
  174. }
  175. if (this.taskDefinitionKey === "storeman" && !!status) {
  176. storageData.isSkip = 1;
  177. try {
  178. this.loading = true;
  179. const res = await outStorage(storageData);
  180. if (res.code == 0) {
  181. await this._approveTaskWithVariables(status);
  182. }
  183. } catch (error) {
  184. this.loading = false;
  185. uni.showToast({ title: "出库失败", icon: "none" });
  186. }
  187. } else {
  188. this.loading = true;
  189. await this._approveTaskWithVariables(status);
  190. }
  191. },
  192. async _approveTaskWithVariables(status) {
  193. try {
  194. let variables = {
  195. pass: !!status,
  196. taskFormData: this.taskFormData,
  197. };
  198. let API = !!status ? approveTaskWithVariables : rejectTask;
  199. let res = await API({
  200. id: this.taskId,
  201. reason: this.form.reason,
  202. variables,
  203. });
  204. if (res.code != "-1") {
  205. this.$emit("handleAudit", {
  206. status,
  207. title: status === 0 ? "驳回" : "",
  208. });
  209. }
  210. } catch (e) {
  211. console.error("审批操作失败", e);
  212. uni.showToast({ title: "操作失败", icon: "none" });
  213. } finally {
  214. this.loading = false;
  215. }
  216. },
  217. async rejectTask(status) {
  218. await this.syncTaskFormData();
  219. try {
  220. this.loading = true;
  221. let variables = {
  222. pass: !!status,
  223. taskFormData: this.taskFormData,
  224. };
  225. let res = await rejectTask({
  226. id: this.taskId,
  227. reason: this.form.reason,
  228. variables,
  229. });
  230. if (res.code != "-1") {
  231. this.$emit("handleAudit", {
  232. status,
  233. title: status === 0 ? "驳回" : "",
  234. });
  235. }
  236. } catch (e) {
  237. console.error("驳回操作失败", e);
  238. uni.showToast({ title: "驳回失败", icon: "none" });
  239. } finally {
  240. this.loading = false;
  241. }
  242. },
  243. getTableValue() {
  244. return new Promise((resolve, reject) => {
  245. this.$emit("getTableValue", async (data) => {
  246. resolve(await data);
  247. });
  248. });
  249. },
  250. },
  251. };
  252. </script>
  253. <style scoped>
  254. .btnList {
  255. display: flex;
  256. }
  257. .btnConcel {
  258. margin-top: 20rpx;
  259. }
  260. </style>