taskSubmit.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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="['productionSupervisorApprove1'].includes(taskDefinitionKey)" label="技术员"
  6. prop="technicalAnswerName" required>
  7. <u--input clearable placeholder="请选择" border="surround" v-model="form.technicalAnswerName"
  8. @click.native="showTechnicianPicker"></u--input>
  9. </u-form-item>
  10. <u-form-item label="审批建议" prop="reason" required style="margin: 20rpx 0;">
  11. <u--textarea height='120' 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. businessOpportunityUpdateAPI
  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. technicalAnswerId: '',
  57. technicalAnswerName: '',
  58. reason: '',
  59. },
  60. rules: {
  61. reason: {
  62. type: 'string',
  63. required: true,
  64. message: '请输入审批建议',
  65. trigger: 'blur'
  66. },
  67. technicalAnswerName: {
  68. type: 'string',
  69. required: true,
  70. message: '请选择技术员',
  71. trigger: ['blur', 'change']
  72. },
  73. },
  74. tabOptions: [{
  75. key: 'productionSupervisorApprove1',
  76. permissionType: 'update',
  77. name: '生产主管审批',
  78. }, {
  79. key: 'techLeaderApprove',
  80. permissionType: 'view',
  81. name: '技术部主管审批',
  82. }, {
  83. key: 'productionSupervisorApprove2',
  84. permissionType: 'view',
  85. name: '生产主管审批',
  86. }, {
  87. key: 'salesManagerApprove',
  88. permissionType: 'view',
  89. name: '销售主管审批',
  90. }],
  91. }
  92. },
  93. mounted() {
  94. this.$refs.uForm.setRules(this.rules)
  95. this.getUserOptions()
  96. },
  97. methods: {
  98. async getUserOptions() {
  99. const data = await listAllUserBind()
  100. this.userOptions.push(data)
  101. },
  102. showTechnicianPicker(val) {
  103. if (val.target.nodeName == 'I') {
  104. this.form.technicalAnswerId = ''
  105. this.form.technicalAnswerName = ''
  106. return
  107. }
  108. this.technicianShow = true
  109. },
  110. selectTechnicianInfo(e) {
  111. this.form.technicalAnswerId = e.value[0]?.id
  112. this.form.technicalAnswerName = e.value[0]?.name
  113. this.technicianShow = false
  114. },
  115. async handleAudit(status) {
  116. if (!!status) await this.$refs.uForm.validate()
  117. let permissionType = this.tabOptions.find(item => item.key == this.taskDefinitionKey)?.permissionType
  118. if (!!status && permissionType === 'update') {
  119. let date = await this.getTableValue();
  120. let arr = []
  121. if (this.taskDefinitionKey == 'productionSupervisorApprove1') {
  122. arr = date.productList.map(item => {
  123. return {
  124. ...item,
  125. technicalAnswerId: this.form.technicalAnswerId,
  126. technicalAnswerName: this.form.technicalAnswerName
  127. }
  128. })
  129. }
  130. if (this.taskDefinitionKey == 'productionSupervisorApprove2') {
  131. arr = date.productList.map(item => {
  132. return {
  133. ...item
  134. }
  135. })
  136. }
  137. await businessOpportunityUpdateAPI(arr)
  138. }
  139. this.loading = true
  140. await this._approveTaskWithVariables(status);
  141. },
  142. async _approveTaskWithVariables(status) {
  143. let variables = {
  144. pass: !!status,
  145. };
  146. if (!!status) {
  147. variables.technicianId = this.form.technicalAnswerId
  148. }
  149. let res = await approveTaskWithVariables({
  150. id: this.taskId,
  151. reason: this.form.reason,
  152. variables
  153. })
  154. if (res.code != '-1') {
  155. this.$emit('handleAudit', {
  156. status,
  157. title: status === 0 ? '驳回' : ''
  158. });
  159. }
  160. this.loading = false
  161. },
  162. getTableValue() {
  163. return new Promise((resolve, reject) => {
  164. this.$emit('getTableValue', async (data) => {
  165. resolve(await data);
  166. });
  167. });
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss">
  173. ::v-deep .u-textarea{
  174. // margin: 20rpx 0;
  175. padding: 0;
  176. border: 1rpx solid #666;
  177. }
  178. </style>