taskSubmit.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 v-if="taskDefinitionKey === 'deptLeaderAssign'" label="采购部门" prop="useDeptId">
  6. <u--input clearable placeholder="请选择" border="surround" v-model="form.useDeptName"
  7. @click.native="openDepartmentPicker"></u--input>
  8. </u-form-item>
  9. <u-form-item v-if="taskDefinitionKey === 'deptLeaderAssign'" label="采购员" prop="assignList" required>
  10. <u--input clearable placeholder="请选择" border="surround" v-model="form.assignListName"
  11. @click.native="openPicker"></u--input>
  12. </u-form-item>
  13. <u-form-item label="审批建议" prop="reason" required>
  14. <u--textarea style="width: 100%;" height='120' border='surround' placeholder="请输入审批建议"
  15. v-model="form.reason"></u--textarea>
  16. </u-form-item>
  17. </u--form>
  18. <view>
  19. <u-button v-if="!['storeManagerApprove'].includes(taskDefinitionKey)" style="width: 100%;margin-bottom: 10rpx;" icon="edit-pen" :loading='loading' type="success"
  20. text="通过" @click="handleAudit(1)">
  21. </u-button>
  22. <u-button v-if="['storeManagerApprove'].includes(taskDefinitionKey)" style="width: 100%;margin-bottom: 10rpx;" icon="edit-pen" :loading='loading' type="success"
  23. text="申请入库" @click="handleAudit(1)">
  24. </u-button>
  25. <u-button style="width: 100%;" :loading='loading' type="error" icon="close" text="驳回"
  26. @click="rejectTask" v-if="!['starter'].includes(taskDefinitionKey)"></u-button>
  27. </view>
  28. <view class="btnConcel">
  29. <u-button @click="showAction = true">更多</u-button>
  30. </view>
  31. <u-action-sheet :actions="actionList" :closeOnClickOverlay="true" :closeOnClickAction="true" title="更多操作" :show="showAction" @close="showAction = false" @select="selectActionClick"></u-action-sheet>
  32. <u-picker itemHeight='60' :show="technicianShow" visibleItemCount='10' :columns="userOptions" keyName="name"
  33. @confirm='selectTechnicianInfo' @cancel='technicianShow = false' title='选择采购员'></u-picker>
  34. <ba-tree-picker ref="departmentPicker" :multiple="false" @select-change="departmentConfirm" title="选择采购部门"
  35. :localdata="departmentOption" valueKey="id" textKey="name" childrenKey="children" />
  36. <ba-tree-picker ref="treePicker" :multiple="true" @select-change="confirm" title="选择采购员"
  37. :localdata="userOptions" valueKey="id" textKey="name" childrenKey="child" />
  38. </view>
  39. </template>
  40. <script>
  41. import {
  42. approveTaskWithVariables,
  43. AssignPurchasePlanUserAPI,
  44. cancelTask,
  45. rejectTask,
  46. } from '@/api/wt/index.js'
  47. import {
  48. listOrganizations,
  49. getUserPage,
  50. listAllUserBind
  51. } from '@/api/common'
  52. import {
  53. toTreeData
  54. } from '@/utils/utils.js'
  55. export default {
  56. name: 'taskSubmit',
  57. props: {
  58. businessId: {
  59. default: ''
  60. },
  61. taskId: {
  62. default: ''
  63. },
  64. id: {
  65. default: ''
  66. },
  67. taskDefinitionKey: {
  68. default: ''
  69. }
  70. },
  71. data() {
  72. return {
  73. departmentOption: [],
  74. showAction: false,
  75. loading: false,
  76. actionList: [{
  77. name: '作废',
  78. fontSize: '28',
  79. color: '#ffaa7f'
  80. }],
  81. technicianShow: false,
  82. userOptions: [],
  83. form: {
  84. userId: '',
  85. useDeptId: '',
  86. useDeptName: '',
  87. userName: '',
  88. assignListName: '',
  89. assignList: [],
  90. reason: '',
  91. },
  92. rules: {
  93. reason: {
  94. type: 'string',
  95. required: true,
  96. message: '请输入审批建议',
  97. trigger: 'blur'
  98. },
  99. // useDeptId: {
  100. // type: 'string',
  101. // required: false,
  102. // message: '请选择采购部门',
  103. // trigger: ['blur','change']
  104. // },
  105. assignList: {
  106. type: 'array',
  107. required: true,
  108. message: '请选择采购员',
  109. trigger: ['blur','change']
  110. },
  111. }
  112. }
  113. },
  114. created() {
  115. this.initDeptData()
  116. this.getUserOptions()
  117. },
  118. mounted() {
  119. this.$refs.uForm.setRules(this.rules)
  120. },
  121. methods: {
  122. openPicker() {
  123. this.$refs.treePicker._show()
  124. },
  125. confirm(data, name, allList) {
  126. console.log('name-------', data,name, allList)
  127. this.form.assignListName = name
  128. this.form.assignList = allList
  129. this.form.userId = allList.map(item => item.id)?.[0] || ''
  130. this.form.userName = allList.map(item => item.name)?.[0] || ''
  131. },
  132. openDepartmentPicker() {
  133. this.$refs.departmentPicker._show()
  134. },
  135. departmentConfirm(data, name, allList) {
  136. console.log(data, name, allList)
  137. this.form.useDeptId = data
  138. this.form.useDeptName = name
  139. this.form.userName = ''
  140. this.form.userId = ''
  141. this.form.assignListName = ''
  142. this.form.assignList = []
  143. if(!data) {
  144. this.getUserOptions()
  145. return;
  146. }
  147. getUserPage({
  148. groupId: data,
  149. size: 999
  150. }).then((data) => {
  151. this.userOptions = data.list;
  152. });
  153. },
  154. async initDeptData() {
  155. let deptTreeList = await listOrganizations()
  156. this.departmentOption = toTreeData({
  157. data: deptTreeList,
  158. idField: 'id',
  159. parentIdField: 'parentId'
  160. })
  161. },
  162. selectActionClick(item) {
  163. console.log('selectActionClick', item)
  164. if (item.name == '作废') {
  165. uni.showModal({
  166. title: '提示',
  167. content: '是否确认作废?',
  168. success: (res) => {
  169. if (res.confirm) {
  170. this.loading = true
  171. cancelTask({
  172. taskId: this.taskId,
  173. id: this.id,
  174. reason: this.form.reason,
  175. businessId: this.businessId,
  176. }).then(() => {
  177. if (res.code != '-1') {
  178. this.loading = false
  179. this.$emit('handleAudit', {
  180. title: '作废'
  181. });
  182. }
  183. }).catch(() => {
  184. this.loading = false
  185. this.$message.error("流程作废失败");
  186. });
  187. } else if (res.cancel) {
  188. console.log('用户点击取消');
  189. }
  190. }
  191. });
  192. }
  193. },
  194. async getUserOptions() {
  195. const data = await listAllUserBind()
  196. this.userOptions = data
  197. console.log('userOptions~~~', this.userOptions)
  198. },
  199. showTechnicianPicker(val) {
  200. if (val.target.nodeName == 'I') {
  201. this.form.userId = ''
  202. this.form.userName = ''
  203. return
  204. }
  205. this.technicianShow = true
  206. },
  207. selectTechnicianInfo(e) {
  208. this.form.userId = e.value[0]?.id
  209. this.form.userName = e.value[0]?.name
  210. this.technicianShow = false
  211. },
  212. // async handleAudit(status) {
  213. // if (!!status) await this.$refs.uForm.validate()
  214. // await AssignPurchasePlanUserAPI({
  215. // userId: this.form.userId,
  216. // userName: this.form.userName,
  217. // id: this.taskId,
  218. // reason: this.form.reason,
  219. // businessId: this.businessId
  220. // })
  221. // this.loading = true
  222. // await this._approveTaskWithVariables(status);
  223. // },
  224. async handleAudit(status) {
  225. console.log(this.form)
  226. if (!!status) await this.$refs.uForm.validate()
  227. //主管指派采购员
  228. if (this.taskDefinitionKey === 'deptLeaderAssign') {
  229. await AssignPurchasePlanUserAPI({
  230. userId: this.form.userId,
  231. userName: this.form.userName,
  232. assignList: this.form.assignList,
  233. id: this.taskId,
  234. reason: this.form.reason,
  235. businessId: this.businessId
  236. });
  237. }
  238. let API = !!status ? approveTaskWithVariables : rejectTask;
  239. await API({
  240. id: this.taskId,
  241. reason: this.form.reason,
  242. variables: {
  243. // userId: this.form.userId,
  244. userId: this.form.assignList.map(item => item.id).join(','),
  245. pass: !!status
  246. }
  247. });
  248. this.$emit('handleAudit', {
  249. status,
  250. title: status === 0 ? '驳回' : ''
  251. });
  252. },
  253. async rejectTask(status) {
  254. await rejectTask({
  255. id: this.taskId,
  256. reason: this.form.reason,
  257. variables: {
  258. pass: !!status
  259. }
  260. });
  261. this.$emit('handleAudit', {
  262. status,
  263. title: status === 0 ? '驳回' : ''
  264. });
  265. },
  266. async _approveTaskWithVariables(status) {
  267. let variables = {
  268. pass: !!status
  269. };
  270. let res = await approveTaskWithVariables({
  271. id: this.taskId,
  272. reason: this.form.reason,
  273. variables
  274. })
  275. if (res.code != '-1') {
  276. this.$emit('handleAudit', {
  277. status,
  278. title: status === 0 ? '驳回' : ''
  279. });
  280. }
  281. this.loading = false
  282. },
  283. getTableValue() {
  284. return new Promise((resolve, reject) => {
  285. this.$emit('getTableValue', async (data) => {
  286. resolve(await data);
  287. });
  288. });
  289. }
  290. }
  291. }
  292. </script>
  293. <style scoped>
  294. .btnConcel {
  295. margin-top: 20rpx;
  296. }
  297. </style>