taskSubmit.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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?.map(item => {
  129. return {
  130. userId: item.id,
  131. userName: item.name,
  132. }
  133. })
  134. this.form.userId = allList.map(item => item.id)?.[0] || ''
  135. this.form.userName = allList.map(item => item.name)?.[0] || ''
  136. },
  137. openDepartmentPicker() {
  138. this.$refs.departmentPicker._show()
  139. },
  140. departmentConfirm(data, name, allList) {
  141. console.log(data, name, allList)
  142. this.form.useDeptId = data
  143. this.form.useDeptName = name
  144. this.form.userName = ''
  145. this.form.userId = ''
  146. this.form.assignListName = ''
  147. this.form.assignList = []
  148. if(!data) {
  149. this.getUserOptions()
  150. return;
  151. }
  152. getUserPage({
  153. groupId: data,
  154. size: 999
  155. }).then((data) => {
  156. this.userOptions = data.list;
  157. });
  158. },
  159. async initDeptData() {
  160. let deptTreeList = await listOrganizations()
  161. this.departmentOption = toTreeData({
  162. data: deptTreeList,
  163. idField: 'id',
  164. parentIdField: 'parentId'
  165. })
  166. },
  167. selectActionClick(item) {
  168. console.log('selectActionClick', item)
  169. if (item.name == '作废') {
  170. uni.showModal({
  171. title: '提示',
  172. content: '是否确认作废?',
  173. success: (res) => {
  174. if (res.confirm) {
  175. this.loading = true
  176. cancelTask({
  177. taskId: this.taskId,
  178. id: this.id,
  179. reason: this.form.reason,
  180. businessId: this.businessId,
  181. }).then(() => {
  182. if (res.code != '-1') {
  183. this.loading = false
  184. this.$emit('handleAudit', {
  185. title: '作废'
  186. });
  187. }
  188. }).catch(() => {
  189. this.loading = false
  190. this.$message.error("流程作废失败");
  191. });
  192. } else if (res.cancel) {
  193. console.log('用户点击取消');
  194. }
  195. }
  196. });
  197. }
  198. },
  199. async getUserOptions() {
  200. const data = await listAllUserBind()
  201. this.userOptions = data
  202. console.log('userOptions~~~', this.userOptions)
  203. },
  204. showTechnicianPicker(val) {
  205. if (val.target.nodeName == 'I') {
  206. this.form.userId = ''
  207. this.form.userName = ''
  208. return
  209. }
  210. this.technicianShow = true
  211. },
  212. selectTechnicianInfo(e) {
  213. this.form.userId = e.value[0]?.id
  214. this.form.userName = e.value[0]?.name
  215. this.technicianShow = false
  216. },
  217. // async handleAudit(status) {
  218. // if (!!status) await this.$refs.uForm.validate()
  219. // await AssignPurchasePlanUserAPI({
  220. // userId: this.form.userId,
  221. // userName: this.form.userName,
  222. // id: this.taskId,
  223. // reason: this.form.reason,
  224. // businessId: this.businessId
  225. // })
  226. // this.loading = true
  227. // await this._approveTaskWithVariables(status);
  228. // },
  229. async handleAudit(status) {
  230. console.log(this.form)
  231. if (!!status) await this.$refs.uForm.validate()
  232. //主管指派采购员
  233. if (this.taskDefinitionKey === 'deptLeaderAssign') {
  234. await AssignPurchasePlanUserAPI({
  235. userId: this.form.userId,
  236. userName: this.form.userName,
  237. assignList: this.form.assignList,
  238. id: this.taskId,
  239. reason: this.form.reason,
  240. businessId: this.businessId
  241. });
  242. }
  243. let API = !!status ? approveTaskWithVariables : rejectTask;
  244. await API({
  245. id: this.taskId,
  246. reason: this.form.reason,
  247. variables: {
  248. // userId: this.form.userId,
  249. userId: this.form.assignList.map(item => item.userId).join(','),
  250. pass: !!status
  251. }
  252. });
  253. this.$emit('handleAudit', {
  254. status,
  255. title: status === 0 ? '驳回' : ''
  256. });
  257. },
  258. async rejectTask(status) {
  259. await rejectTask({
  260. id: this.taskId,
  261. reason: this.form.reason,
  262. variables: {
  263. pass: !!status
  264. }
  265. });
  266. this.$emit('handleAudit', {
  267. status,
  268. title: status === 0 ? '驳回' : ''
  269. });
  270. },
  271. async _approveTaskWithVariables(status) {
  272. let variables = {
  273. pass: !!status
  274. };
  275. let res = await approveTaskWithVariables({
  276. id: this.taskId,
  277. reason: this.form.reason,
  278. variables
  279. })
  280. if (res.code != '-1') {
  281. this.$emit('handleAudit', {
  282. status,
  283. title: status === 0 ? '驳回' : ''
  284. });
  285. }
  286. this.loading = false
  287. },
  288. getTableValue() {
  289. return new Promise((resolve, reject) => {
  290. this.$emit('getTableValue', async (data) => {
  291. resolve(await data);
  292. });
  293. });
  294. }
  295. }
  296. }
  297. </script>
  298. <style scoped>
  299. .btnConcel {
  300. margin-top: 20rpx;
  301. }
  302. </style>