taskSubmit.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="">
  3. <u--form style="margin: 0 20px;" labelPosition="left" :model="form" :rules="rules" ref="uForm"
  4. labelWidth='140rpx'>
  5. <u-form-item label="审批建议" prop="reason" required>
  6. <u--textarea style="width: 100%;" height='120' border='surround' placeholder="请输入审批建议"
  7. v-model="form.reason"></u--textarea>
  8. </u-form-item>
  9. </u--form>
  10. <!-- <view>
  11. <u-button style="width: 100%;margin-bottom: 10rpx;" icon="edit-pen" :loading='loading' type="success"
  12. text="通过" @click="handleAudit(1)">
  13. </u-button>
  14. <u-button style="width: 100%;" :loading='loading' type="error" icon="close" text="驳回"
  15. @click="handleAudit(0)" v-if="!['starter'].includes(taskDefinitionKey)"></u-button>
  16. </view> -->
  17. <view class="btnList">
  18. <u-button v-if="passBtnDisabled" style="width: 45%;margin-bottom: 10rpx;" :loading='loading' type="success" text="通过" @click="handleAudit(1)">
  19. </u-button>
  20. <u-button v-if="acceptBtnDisabled" style="width: 45%;margin-bottom: 10rpx;" :loading='loading' type="success" text="申请出库" @click="storemanApprove">
  21. </u-button>
  22. <u-button style="width: 45%;" :loading='loading' type="error" text="驳回" @click="rejectTask(0)"></u-button>
  23. </view>
  24. <!-- <view class="btnConcel">
  25. <u-button @click="showAction = true">更多</u-button>
  26. </view> -->
  27. <!-- <u-action-sheet :actions="actionList" :closeOnClickOverlay="true" :closeOnClickAction="true" title="更多操作" :show="showAction" @close="showAction = false" @select="selectActionClick"></u-action-sheet> -->
  28. </view>
  29. </template>
  30. <script>
  31. import {
  32. approveTaskWithVariables,
  33. getWarehouseListByIdsAPI,
  34. getSaleOrderSendRecordDetailAPI,
  35. getOutInBySourceBizNo,
  36. rejectTask
  37. } from '@/api/wt/index.js'
  38. import { outStorage, updateSendInformation } from '@/api/warehouseManagement/index.js'
  39. export default {
  40. name: 'taskSubmit',
  41. props: {
  42. businessId: {
  43. default: ''
  44. },
  45. taskId: {
  46. default: ''
  47. },
  48. id: {
  49. default: ''
  50. },
  51. taskDefinitionKey: {
  52. default: ''
  53. }
  54. },
  55. data() {
  56. return {
  57. loading: false,
  58. outInData: { verifyStatus: 0 },
  59. form: {
  60. technicianId: '',
  61. reason: '',
  62. },
  63. rules: {
  64. reason: {
  65. type: 'string',
  66. required: true,
  67. message: '请输入审批建议',
  68. trigger: 'blur'
  69. }
  70. },
  71. }
  72. },
  73. computed: {
  74. acceptBtnDisabled() {
  75. console.log('acceptBtnDisabled check:', this.taskDefinitionKey, this.outInData.verifyStatus);
  76. return ['storemanApprove'].includes(this.taskDefinitionKey) && [0, 3].includes(this.outInData.verifyStatus);
  77. },
  78. passBtnDisabled() {
  79. console.log('passBtnDisabled check:', this.taskDefinitionKey, this.outInData.verifyStatus);
  80. return this.taskDefinitionKey != 'storemanApprove' || (this.taskDefinitionKey == 'storemanApprove' && this.outInData.verifyStatus == 2)
  81. }
  82. },
  83. async mounted() {
  84. this.$nextTick(() => {
  85. this.$refs.uForm?.setRules(this.rules)
  86. })
  87. if (this.taskDefinitionKey == 'storemanApprove') {
  88. let data = await getSaleOrderSendRecordDetailAPI(this.businessId);
  89. try {
  90. console.log(data, '1111111111');
  91. data = await getOutInBySourceBizNo(data.docNo);
  92. console.log('data--------------', data);
  93. if (JSON.stringify(data) != '{}') {
  94. this.outInData = data;
  95. }
  96. console.log(this.outInData, '============');
  97. } catch (error) {
  98. console.log(22222222, '22222222222');
  99. this.outInData.verifyStatus = 0;
  100. }
  101. }
  102. },
  103. methods: {
  104. async storemanApprove() {
  105. let res = await this.getTableValue();
  106. let storageData = res.returnStorageData;
  107. console.log('storageData~~~', storageData);
  108. // return
  109. // 出库来源isSkip 0-正常 1-外部(外部跳过内部审核流程)
  110. storageData.isSkip = 1;
  111. try {
  112. this.loading = true;
  113. await outStorage(storageData);
  114. approveTaskWithVariables({
  115. id: this.taskId,
  116. reason: this.form.reason,
  117. variables: {
  118. pass: true
  119. }
  120. }).then((res) => {
  121. if (res.code != '-1') {
  122. this.$emit('handleAudit', {
  123. status: 1,
  124. title: '出库'
  125. });
  126. }
  127. this.loading = false;
  128. });
  129. } catch (error) {
  130. this.loading = false;
  131. console.error('保存失败:', error);
  132. }
  133. },
  134. rejectTask(status) {
  135. let variables = {
  136. pass: !!status
  137. };
  138. rejectTask({
  139. id: this.taskId,
  140. reason: this.form.reason,
  141. variables
  142. }).then((res) => {
  143. if (res.data.code != '-1') {
  144. this.$emit('handleAudit', {
  145. status,
  146. title: status === 0 ? '驳回' : ''
  147. });
  148. }
  149. });
  150. },
  151. async handleAudit(status) {
  152. let storemanIds = '';
  153. //发起人补充
  154. if (
  155. this.taskDefinitionKey === 'starter' ||
  156. this.taskDefinitionKey === 'salesmanUploadReceipt'
  157. ) {
  158. let arr = await this.getTableValue();
  159. console.log('arr--------', arr);
  160. if (!arr) {
  161. return;
  162. }
  163. if (
  164. this.taskDefinitionKey === 'salesmanUploadReceipt' &&
  165. arr.replied === 0
  166. ) {
  167. uni.$u.toast('回执附件不能为空');
  168. return;
  169. }
  170. // console.log(arr)
  171. // return
  172. let data = await updateSendInformation(arr);
  173. if (data.code != '0') {
  174. return;
  175. }
  176. }
  177. if (this.taskDefinitionKey === 'deptLeaderApprove') {
  178. let arr = await this.getTableValue();
  179. let ids = arr.form.productList.map((item) => item.warehouseId);
  180. let data = await getWarehouseListByIdsAPI(ids || []);
  181. storemanIds = data.map((item) => item.ownerId);
  182. }
  183. this.loading = true
  184. this._approveTaskWithVariables(
  185. status,
  186. storemanIds.length > 0
  187. ? Array.from(new Set(storemanIds)).toString()
  188. : ''
  189. );
  190. },
  191. async _approveTaskWithVariables(status, storemanIds) {
  192. let variables = {
  193. pass: !!status
  194. };
  195. if (storemanIds) {
  196. variables['storemanIds'] = storemanIds;
  197. }
  198. let API = !!status ? approveTaskWithVariables : rejectTask;
  199. API({
  200. id: this.taskId,
  201. reason: this.form.reason,
  202. variables
  203. }).then((res) => {
  204. if (res.data.code != '-1') {
  205. this.$emit('handleAudit', {
  206. status,
  207. title: status === 0 ? '驳回' : ''
  208. });
  209. }
  210. this.loading = false
  211. });
  212. },
  213. getTableValue() {
  214. return new Promise((resolve, reject) => {
  215. this.$emit('getTableValue', async (data) => {
  216. resolve(await data);
  217. });
  218. });
  219. }
  220. }
  221. }
  222. </script>
  223. <style scoped>
  224. .btnList {
  225. display: flex;
  226. }
  227. .btnConcel {
  228. margin-top: 20rpx;
  229. }
  230. </style>