taskSubmit.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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="['QCLeaderApprove'].includes(taskDefinitionKey)" label="质检员" prop="qualityInspectorName"
  6. required>
  7. <u--input clearable placeholder="请选择" border="surround" v-model="form.qualityInspectorName"
  8. @click.native="showTechnicianPicker"></u--input>
  9. </u-form-item>
  10. <u-form-item label="审批建议" prop="reason" required>
  11. <u--textarea style="width: 100%;" height='120' border='surround' placeholder="请输入审批建议"
  12. v-model="form.reason"></u--textarea>
  13. </u-form-item>
  14. </u--form>
  15. <view>
  16. <u-button style="width: 100%;margin-bottom: 10rpx;" icon="edit-pen" :loading='loading' type="success"
  17. text="通过" @click="handleAudit(1)">
  18. </u-button>
  19. <u-button style="width: 100%;" :loading='loading' type="error" icon="close" text="驳回"
  20. @click="handleAudit(0)" v-if="!['starter'].includes(taskDefinitionKey)"></u-button>
  21. </view>
  22. <u-picker itemHeight='60' :show="technicianShow" visibleItemCount='10' :columns="userOptions" keyName="name"
  23. @confirm='selectTechnicianInfo' @cancel='technicianShow = false' title='选择质检员'></u-picker>
  24. </view>
  25. </template>
  26. <script>
  27. import {
  28. approveTaskWithVariables,
  29. getWarehouseListByIdsAPI
  30. } from '@/api/wt/index.js'
  31. import {
  32. listAllUserBind
  33. } from '@/api/common.js'
  34. export default {
  35. name: 'taskSubmit',
  36. props: {
  37. businessId: {
  38. default: ''
  39. },
  40. taskId: {
  41. default: ''
  42. },
  43. id: {
  44. default: ''
  45. },
  46. taskDefinitionKey: {
  47. default: ''
  48. }
  49. },
  50. data() {
  51. return {
  52. loading: false,
  53. technicianShow: false,
  54. userOptions: [],
  55. form: {
  56. qualityInspectorName: '',
  57. qualityInspector: '',
  58. reason: '',
  59. },
  60. rules: {
  61. reason: {
  62. type: 'string',
  63. required: true,
  64. message: '请输入审批建议',
  65. trigger: 'blur'
  66. },
  67. qualityInspectorName: {
  68. type: 'string',
  69. required: true,
  70. message: '请选择质检员',
  71. trigger: ['blur', 'change']
  72. },
  73. }
  74. }
  75. },
  76. mounted() {
  77. this.$refs.uForm.setRules(this.rules)
  78. this.getUserOptions()
  79. },
  80. methods: {
  81. async getUserOptions() {
  82. const data = await listAllUserBind()
  83. this.userOptions.push(data)
  84. },
  85. showTechnicianPicker(val) {
  86. if (val.target.nodeName == 'I') {
  87. this.form.qualityInspector = ''
  88. this.form.qualityInspectorName = ''
  89. return
  90. }
  91. this.technicianShow = true
  92. },
  93. selectTechnicianInfo(e) {
  94. this.form.qualityInspector = e.value[0]?.id
  95. this.form.qualityInspectorName = e.value[0]?.name
  96. this.technicianShow = false
  97. },
  98. async handleAudit(status) {
  99. if (!!status) await this.$refs.uForm.validate()
  100. let storemanIds = []
  101. if (this.taskDefinitionKey === 'deptLeaderApprove') {
  102. let form = await this.getTableValue();
  103. let ids = form.productList.map((item) => item.warehouseId);
  104. let data = await getWarehouseListByIdsAPI(ids || []);
  105. storemanIds = data.map((item) => item.ownerId) || [];
  106. if (!storemanIds.length) return uni.$u.toast('未配置仓管人员,请检查')
  107. }
  108. this.loading = true
  109. await this._approveTaskWithVariables(status, Array.from(new Set(storemanIds)).toString());
  110. },
  111. async _approveTaskWithVariables(status, storemanIds) {
  112. let variables = {
  113. pass: !!status,
  114. storemanIds
  115. };
  116. if (this.form.qualityInspector) {
  117. variables['qualityInspector'] = this.form.qualityInspector;
  118. }
  119. let res = await approveTaskWithVariables({
  120. id: this.taskId,
  121. reason: this.form.reason,
  122. variables
  123. })
  124. if (res.code != '-1') {
  125. this.$emit('handleAudit', {
  126. status,
  127. title: status === 0 ? '驳回' : ''
  128. });
  129. }
  130. this.loading = false
  131. },
  132. getTableValue() {
  133. return new Promise((resolve, reject) => {
  134. this.$emit('getTableValue', async (data) => {
  135. resolve(await data);
  136. });
  137. });
  138. }
  139. }
  140. }
  141. </script>
  142. <style>
  143. </style>