submit.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <el-col :span="16" :offset="6">
  3. <el-form label-width="100px" ref="formRef" :model="form">
  4. <el-form-item
  5. v-if="taskDefinitionKey === 'deptLeaderAssign'"
  6. label="采购部门"
  7. prop="userId"
  8. style="margin-bottom: 20px"
  9. >
  10. <deptSelect
  11. v-model="form.useDeptId"
  12. @changeGroup="searchDeptNodeClick"
  13. />
  14. </el-form-item>
  15. <el-form-item
  16. v-if="taskDefinitionKey === 'deptLeaderAssign'"
  17. label="采购员"
  18. prop="userId"
  19. style="margin-bottom: 20px"
  20. :rules="{
  21. required: true,
  22. message: '请选择',
  23. trigger: 'change'
  24. }"
  25. >
  26. <el-select
  27. v-model="selectId"
  28. clearable
  29. multiple
  30. style="width: 100%"
  31. :filterable="true"
  32. @change="handleUserChange"
  33. >
  34. <el-option
  35. v-for="item in userOptions"
  36. :key="item.id"
  37. :label="item.name"
  38. :value="item.id"
  39. />
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item
  43. label="审批意见"
  44. style="margin-bottom: 20px"
  45. :rules="{
  46. required: true,
  47. message: '请选择',
  48. trigger: 'change'
  49. }"
  50. >
  51. <ApprovalOpinion ref="approvalOpinion" v-model="form.reason" />
  52. </el-form-item>
  53. </el-form>
  54. <div style="margin-left: 10%; margin-bottom: 20px; font-size: 14px">
  55. <el-button
  56. icon="el-icon-edit-outline"
  57. type="success"
  58. size="mini"
  59. v-click-once
  60. @click="$refs.approvalOpinion.validate(1) && handleAudit(1)"
  61. v-if="!['storeManagerApprove'].includes(taskDefinitionKey)"
  62. >通过
  63. </el-button>
  64. <el-button
  65. icon="el-icon-edit-outline"
  66. type="success"
  67. size="mini"
  68. v-click-once
  69. :loading="isSaveLoading"
  70. @click="$refs.approvalOpinion.validate(1) && storeManagerApprove()"
  71. v-if="['storeManagerApprove'].includes(taskDefinitionKey)"
  72. >申请入库
  73. </el-button>
  74. <el-button
  75. icon="el-icon-circle-close"
  76. type="danger"
  77. size="mini"
  78. v-click-once
  79. @click="$refs.approvalOpinion.validate(0) && rejectTask(0)"
  80. >驳回
  81. </el-button>
  82. <!-- <el-button
  83. icon="el-icon-circle-close"
  84. type="danger"
  85. size="mini"
  86. @click="handleBackList"
  87. >退回
  88. </el-button> -->
  89. <!-- <el-button
  90. icon="el-icon-circle-close"
  91. type="danger"
  92. size="mini"
  93. @click="handleAudit(0)"
  94. v-if="taskDefinitionKey != 'productionSupervisorApprove1'"
  95. >不通过
  96. </el-button>
  97. <el-button
  98. icon="el-icon-edit-outline"
  99. type="primary"
  100. size="mini"
  101. v-if="taskDefinitionKey != 'productionSupervisorApprove1'"
  102. @click="handleUpdateAssignee"
  103. >转办
  104. </el-button> -->
  105. <el-dropdown
  106. @command="(command) => handleCommand(command)"
  107. style="margin-left: 30px"
  108. >
  109. <span class="el-dropdown-link">
  110. 更多<i class="el-icon-arrow-down el-icon--right"></i>
  111. </span>
  112. <el-dropdown-menu slot="dropdown">
  113. <el-dropdown-item command="cancel">作废</el-dropdown-item>
  114. </el-dropdown-menu>
  115. </el-dropdown>
  116. </div>
  117. </el-col>
  118. </template>
  119. <script>
  120. import { approveTaskWithVariables, rejectTask,cancelTask } from '@/api/bpm/task';
  121. import { listAllUserBind } from '@/api/system/organization';
  122. import {
  123. assign,
  124. cancel,
  125. UpdateInformation
  126. } from '@/api/bpm/components/purchasingManage/purchasePlanManage';
  127. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  128. import { getUserPage } from '@/api/system/organization';
  129. import storageApi from '@/api/warehouseManagement';
  130. // 流程实例的详情页,可用于审批
  131. export default {
  132. name: '',
  133. components: {
  134. deptSelect
  135. },
  136. props: {
  137. businessId: {
  138. default: ''
  139. },
  140. taskId: {
  141. default: ''
  142. },
  143. id: {
  144. default: ''
  145. },
  146. taskDefinitionKey: {
  147. default: ''
  148. }
  149. },
  150. data() {
  151. return {
  152. form: {
  153. userId: '',
  154. userName: '',
  155. reason: '同意',
  156. useDeptId: '',
  157. assignList: []
  158. },
  159. userOptions: [],
  160. selectId: [],
  161. isSaveLoading:false
  162. };
  163. },
  164. created() {
  165. this.getAllUsers()
  166. },
  167. methods: {
  168. getAllUsers() {
  169. this.userOptions = [];
  170. listAllUserBind().then((data) => {
  171. this.userOptions.push(...data);
  172. });
  173. },
  174. handleUserChange(val, option){
  175. console.log(val, option, 'val');
  176. // 通过选中的采购员Id数组,获取对应的name数组
  177. if (val && val.length > 0) {
  178. const userNameArray = val.map(userId => {
  179. const user = this.userOptions.find(item => item.id === userId);
  180. return user ? {userId: user.id, userName: user.name} : '';
  181. }).filter(name => name);
  182. // assignList数组
  183. this.form.assignList = [...userNameArray];
  184. this.form.userId = this.form.assignList[0]?.userId || '';
  185. this.form.userName = this.form.assignList[0]?.userName || '';
  186. } else {
  187. this.form.userId = '';
  188. this.form.userName = '';
  189. this.form.assignList = [];
  190. }
  191. console.log('assignList数组:', this.form.assignList);
  192. },
  193. /** 处理转办审批人 */
  194. handleUpdateAssignee() {
  195. this.$emit('handleUpdateAssignee');
  196. },
  197. /** 退回 */
  198. handleBackList() {
  199. this.$emit('handleBackList');
  200. },
  201. searchDeptNodeClick(val) {
  202. console.log(val, 'val');
  203. if(!val) {
  204. this.getAllUsers();
  205. return;
  206. }
  207. getUserPage({
  208. groupId: val,
  209. size: 999
  210. }).then((data) => {
  211. this.userOptions = data.list;
  212. });
  213. },
  214. async storeManagerApprove() {
  215. let res = await this.getTableValue();
  216. let storageData = res.returnStorageData;
  217. if(!storageData){
  218. return
  219. }
  220. storageData.isSkip = 1;
  221. try {
  222. this.isSaveLoading = true;
  223. await storageApi.storage(storageData);
  224. approveTaskWithVariables({
  225. id: this.taskId,
  226. reason: this.form.reason,
  227. variables: {
  228. pass: true
  229. }
  230. }).then((res) => {
  231. if (res.code != '-1') {
  232. this.$emit('handleAudit', {
  233. status: 1,
  234. title: '入库'
  235. });
  236. }
  237. this.isSaveLoading = false;
  238. });
  239. } catch (error) {
  240. this.isSaveLoading = false;
  241. this.$message.error('保存失败');
  242. }
  243. },
  244. async handleAudit(status) {
  245. // let userInfo = this.userOptions.find(
  246. // (item) => item.id == this.form.userId
  247. // );
  248. console.log(this.form)
  249. //主管指派采购员
  250. if (this.taskDefinitionKey === 'deptLeaderAssign') {
  251. if (!this.form.userId) {
  252. this.$message.warning(`请选择采购员!`);
  253. return;
  254. }
  255. await assign({
  256. userId: this.form.userId,
  257. userName: this.form.userName,
  258. assignList: this.form.assignList,
  259. id: this.taskId,
  260. reason: this.form.reason,
  261. businessId: this.businessId
  262. });
  263. }
  264. // //采购员核对
  265. // if (this.taskDefinitionKey === 'purchaserCheck') {
  266. // let arr = await this.getTableValue();
  267. // if (!arr) {
  268. // return;
  269. // }
  270. // await UpdateInformation(arr);
  271. // }
  272. console.log(this.selectId, this.form.userId, 'this.selectId');
  273. let API = !!status ? approveTaskWithVariables : rejectTask;
  274. let variables = {
  275. pass: !!status
  276. }
  277. if(this.taskDefinitionKey === 'deptLeaderAssign') {
  278. variables.userId = this.selectId.join(',');
  279. }
  280. await API({
  281. id: this.taskId,
  282. reason: this.form.reason,
  283. variables: variables
  284. });
  285. this.$emit('handleAudit', {
  286. status,
  287. title: status === 0 ? '驳回' : ''
  288. });
  289. },
  290. async rejectTask(status) {
  291. await rejectTask({
  292. id: this.taskId,
  293. reason: this.form.reason,
  294. variables: {
  295. pass: !!status
  296. }
  297. });
  298. this.$emit('handleAudit', {
  299. status,
  300. title: status === 0 ? '驳回' : ''
  301. });
  302. },
  303. getTableValue() {
  304. return new Promise((resolve, reject) => {
  305. this.$emit('getTableValue', async (data) => {
  306. resolve(await data);
  307. });
  308. });
  309. },
  310. //更多
  311. handleCommand(command) {
  312. if (command === 'cancel') {
  313. this.$confirm('是否确认作废?', {
  314. type: 'warning',
  315. cancelButtonText: '取消',
  316. confirmButtonText: '确定'
  317. })
  318. .then(() => {
  319. cancelTask({
  320. id: this.id,
  321. taskId: this.taskId,
  322. reason: this.form.reason,
  323. businessId: this.businessId
  324. })
  325. .then(() => {
  326. this.$emit('handleClose');
  327. })
  328. .catch(() => {
  329. this.$message.error('流程作废失败');
  330. });
  331. })
  332. .catch(() => {});
  333. }
  334. }
  335. }
  336. };
  337. </script>
  338. <style lang="scss"></style>