taskSubmit.vue 8.2 KB

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