submit.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <el-col :span="16" :offset="6">
  3. <el-form label-width="100px" ref="formRef" :model="form">
  4. <!-- <el-form-item
  5. label="采购员"
  6. prop="technicianId"
  7. style="margin-bottom: 20px"
  8. :rules="{
  9. required: true,
  10. message: '请选择',
  11. trigger: 'change'
  12. }"
  13. >
  14. <el-select
  15. v-model="form.technicianId"
  16. clearable
  17. style="width: 100%"
  18. :filterable="true"
  19. >
  20. <el-option
  21. v-for="item in userOptions"
  22. @click.native="form.userName = item.name"
  23. :key="item.id"
  24. :label="item.name"
  25. :value="item.id"
  26. />
  27. </el-select>
  28. </el-form-item> -->
  29. <el-form-item
  30. label="审批意见"
  31. style="margin-bottom: 20px"
  32. :rules="{
  33. required: true,
  34. message: '请选择',
  35. trigger: 'change'
  36. }"
  37. >
  38. <ApprovalOpinion ref="approvalOpinion" v-model="form.reason" />
  39. </el-form-item>
  40. </el-form>
  41. <div style="margin-left: 10%; margin-bottom: 20px; font-size: 14px">
  42. <el-button
  43. icon="el-icon-edit-outline"
  44. type="success"
  45. size="mini"
  46. @click="$refs.approvalOpinion.validate(1) && handleAudit(1)"
  47. v-click-once
  48. v-if="taskDefinitionKey != 'apsStoreman'"
  49. >通过
  50. </el-button>
  51. <el-button
  52. icon="el-icon-edit-outline"
  53. type="success"
  54. size="mini"
  55. :loading="isLoading"
  56. v-click-once
  57. @click="$refs.approvalOpinion.validate(1) && handleAudit(1)"
  58. v-if="taskDefinitionKey == 'apsStoreman'"
  59. >申请出库
  60. </el-button>
  61. <el-button
  62. icon="el-icon-circle-close"
  63. type="danger"
  64. size="mini"
  65. v-click-once
  66. @click="$refs.approvalOpinion.validate(0) && rejectTask(0)"
  67. >驳回
  68. </el-button>
  69. <el-dropdown
  70. @command="(command) => handleCommand(command)"
  71. style="margin-left: 30px"
  72. >
  73. <span class="el-dropdown-link"
  74. >更多<i class="el-icon-arrow-down el-icon--right"></i
  75. ></span>
  76. <el-dropdown-menu slot="dropdown">
  77. <el-dropdown-item command="cancel">作废</el-dropdown-item>
  78. </el-dropdown-menu>
  79. </el-dropdown>
  80. </div>
  81. </el-col>
  82. </template>
  83. <script>
  84. import {
  85. apspurchaseplan,
  86. cancel
  87. } from '@/api/bpm/components/apsMeterialPlan';
  88. import {
  89. approveTaskWithVariables,
  90. rejectTask,
  91. cancelTask
  92. } from '@/api/bpm/task';
  93. import { listAllUserBind } from '@/api/system/organization';
  94. import storageApi from '@/api/warehouseManagement';
  95. // 流程实例的详情页,可用于审批
  96. export default {
  97. name: '',
  98. components: {},
  99. props: {
  100. businessId: {
  101. default: ''
  102. },
  103. taskId: {
  104. default: ''
  105. },
  106. id: {
  107. default: ''
  108. },
  109. taskDefinitionKey: {
  110. default: ''
  111. }
  112. },
  113. data() {
  114. return {
  115. form: {
  116. // technicianId: '',
  117. reason: '同意'
  118. },
  119. userOptions: [],
  120. isLoading: false
  121. };
  122. },
  123. created() {
  124. this.userOptions = [];
  125. listAllUserBind().then((data) => {
  126. this.userOptions.push(...data);
  127. });
  128. },
  129. methods: {
  130. async handleAudit(status) {
  131. let data = await this.getTableValue();
  132. let storageData = data.returnStorageData;
  133. if (!!status) {
  134. if (!storageData?.extInfo?.verifyDeptCode) {
  135. this.$message.error('请选择部门');
  136. return false;
  137. }
  138. if (!storageData?.fromUser) {
  139. this.$message.error('请选择领料人');
  140. return false;
  141. }
  142. }
  143. if (!this.form.reason && !!status) {
  144. this.$message.error('请输入审批意见');
  145. return false;
  146. }
  147. if (this.taskDefinitionKey === 'apsStoreman' && !!status) {
  148. // 入库来源isSkip 0-正常 1-外部(外部跳过内部审核流程)
  149. storageData.isSkip = 1;
  150. console.log('storageData~~~', storageData);
  151. try {
  152. this.isLoading = true;
  153. const res = await storageApi.outStorage(storageData);
  154. if (res.code == 0) {
  155. let API = !!status ? approveTaskWithVariables : rejectTask;
  156. API({
  157. id: this.taskId,
  158. reason: this.form.reason,
  159. variables: {
  160. pass: !!status
  161. }
  162. }).then((res) => {
  163. if (res.code != '-1') {
  164. this.$emit('handleAudit', {
  165. status: status,
  166. title: !status ? '驳回' : ''
  167. });
  168. }
  169. this.isLoading = false;
  170. });
  171. }
  172. } catch (error) {
  173. this.isLoading = false;
  174. console.error('保存失败:', error);
  175. }
  176. } else {
  177. // await this._approveTaskWithVariables(status, storemanIds);
  178. await this._approveTaskWithVariables(status);
  179. }
  180. },
  181. // async handleAudit(status, type) {
  182. // //生产主管审批选择技术员
  183. // // if (!this.form.technicianId && status == 1) {
  184. // // this.$message.warning(`请选择采购员!`);
  185. // // return;
  186. // // }
  187. // this._approveTaskWithVariables(status);
  188. // },
  189. rejectTask(status) {
  190. rejectTask({
  191. id: this.taskId,
  192. reason: this.form.reason,
  193. pass: false
  194. }).then((res) => {
  195. if (res.data.code != '-1') {
  196. this.$emit('handleAudit', {
  197. status,
  198. title: '驳回'
  199. });
  200. }
  201. });
  202. },
  203. async _approveTaskWithVariables(status) {
  204. if (status == 1) {
  205. apspurchaseplan({
  206. businessId: this.businessId,
  207. id: this.taskId,
  208. userId: this.form.technicianId,
  209. userName: this.form.userName,
  210. reason: this.form.reason,
  211. pass: true
  212. }).then((res) => {
  213. if (res.data.code != '-1') {
  214. this.$emit('handleAudit', {
  215. status,
  216. title: ''
  217. });
  218. }
  219. });
  220. } else if (status == 0) {
  221. let API = rejectTask;
  222. API({
  223. id: this.taskId,
  224. reason: this.form.reason,
  225. pass: false
  226. }).then((res) => {
  227. if (res.data.code != '-1') {
  228. this.$emit('handleAudit', {
  229. status,
  230. title: '驳回'
  231. });
  232. }
  233. });
  234. }
  235. },
  236. getTableValue() {
  237. return new Promise((resolve, reject) => {
  238. this.$emit('getTableValue', async (data) => {
  239. resolve(await data);
  240. });
  241. });
  242. },
  243. //更多
  244. handleCommand(command) {
  245. if (command === 'cancel') {
  246. this.$confirm('是否确认作废?', {
  247. type: 'warning',
  248. cancelButtonText: '取消',
  249. confirmButtonText: '确定'
  250. })
  251. .then(() => {
  252. cancelTask({
  253. taskId: this.taskId,
  254. id: this.id,
  255. reason: this.form.reason,
  256. businessId: this.businessId
  257. })
  258. .then(() => {
  259. this.$emit('handleClose');
  260. })
  261. .catch(() => {
  262. this.$message.error('流程作废失败');
  263. });
  264. })
  265. .catch(() => {});
  266. }
  267. }
  268. }
  269. };
  270. </script>
  271. <style lang="scss"></style>