CandidateForm.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view class="candidateForm-v">
  3. <u-popup mode="left" :popup="false" v-model="showPopup" length="auto" @close="close" width="100%">
  4. <view class="jnpf-wrap jnpf-wrap-form">
  5. <u-form :model="candidateForm" ref="candidateForm" :errorType="['toast']" label-position="left"
  6. label-width="150" label-align="left">
  7. <u-form-item label="分支选择" prop="branch" v-if="candidateType == 1" required>
  8. <JnpfSelect v-model="candidateForm.branchList" @change="branchChange" placeholder="请选择审批分支"
  9. :options="branchList" :multiple="true" :props='props' />
  10. </u-form-item>
  11. <u-form-item label-width="250" v-for="(item,index) in candidateForm.list" :key="index"
  12. :label="item.label">
  13. <u-input type="select" :select-open="item.selectShow" v-model="item.value"
  14. @click="openSelect(item)" placeholder="请选择审批候选人">
  15. </u-input>
  16. </u-form-item>
  17. </u-form>
  18. <view class="buttom-actions">
  19. <u-button class="buttom-btn" @click="cancel">取消</u-button>
  20. <u-button class="buttom-btn" type="primary" @click="submit">确定</u-button>
  21. </view>
  22. </view>
  23. </u-popup>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. props: {
  29. modelValue: {
  30. type: Boolean,
  31. default: false
  32. },
  33. formData: {
  34. type: Object,
  35. default: () => ({})
  36. },
  37. taskId: {
  38. type: String,
  39. default: ""
  40. }
  41. },
  42. data() {
  43. return {
  44. showPopup: false,
  45. candidateForm: {
  46. list: [],
  47. branchList: []
  48. },
  49. nodeId: '',
  50. selectId: {},
  51. rules: {},
  52. selectList: [],
  53. selectVal: {},
  54. isCandidate: false,
  55. props: {
  56. label: 'nodeName',
  57. value: 'nodeId'
  58. },
  59. candidateType: 1,
  60. branchList: [],
  61. candidateList: []
  62. };
  63. },
  64. watch: {
  65. modelValue: {
  66. immediate: true,
  67. handler(val) {
  68. this.showPopup = val
  69. }
  70. },
  71. },
  72. created() {
  73. uni.$on('confirm', (data, id) => {
  74. this.selectConfirm(data, id)
  75. })
  76. },
  77. onUnload() {
  78. uni.$off('confirm')
  79. },
  80. methods: {
  81. branchChange(e) {
  82. this.candidateForm.branchList = e;
  83. this.init()
  84. },
  85. init(candidateType, branchList, candidateList) {
  86. this.candidateType = candidateType;
  87. this.branchList = branchList;
  88. this.candidateList = candidateList
  89. if (this.candidateType == 1) {
  90. let list = [];
  91. for (let i = 0; i < this.candidateForm.branchList.length; i++) {
  92. inner: for (let j = 0; j < this.branchList.length; j++) {
  93. let o = this.branchList[j]
  94. if (o.isCandidates) this.isCandidate = o.isCandidates
  95. if (this.candidateForm.branchList[i] === o.nodeId && o.isCandidates) {
  96. list.push({
  97. ...o,
  98. label: o.nodeName + '审批人',
  99. value: '',
  100. selectShow: false
  101. })
  102. break inner
  103. }
  104. }
  105. this.candidateForm.list = list
  106. }
  107. } else {
  108. if (Array.isArray(this.candidateList) && this.candidateList.length) {
  109. this.isCandidate = true
  110. this.candidateForm.list = this.candidateList.map(o => ({
  111. ...o,
  112. label: o.nodeName + '审批人',
  113. value: '',
  114. selectShow: false
  115. }))
  116. }
  117. }
  118. },
  119. openSelect(item) {
  120. this.selectList = []
  121. for (let o in this.selectVal) {
  122. if (o === item.nodeId) this.selectList = this.selectVal[o]
  123. }
  124. item.formData = this.formData
  125. item.taskId = this.taskId
  126. item.selectList = !item.value ? [] : this.selectList
  127. uni.navigateTo({
  128. url: '/pages/workFlow/candiDateUserSelect/index?data=' + encodeURIComponent(JSON.stringify(
  129. item))
  130. })
  131. },
  132. selectConfirm(e, id) {
  133. let selectData = e;
  134. let selectVal = [];
  135. let val = [];
  136. let selectId = [];
  137. let nodeId = '';
  138. if (!selectData.length) {
  139. delete this.selectVal[id]
  140. delete this.selectId[id]
  141. for (let i = 0; i < this.candidateForm.list.length; i++) {
  142. if (id === this.candidateForm.list[i].nodeId) {
  143. this.candidateForm.list[i].value = ""
  144. }
  145. }
  146. }
  147. for (let i = 0; i < this.candidateForm.list.length; i++) {
  148. for (let o = 0; o < selectData.length; o++) {
  149. if (selectData[o].nodeId === this.candidateForm.list[i].nodeId) {
  150. nodeId = selectData[o].nodeId
  151. val.push(selectData[o].userName)
  152. selectVal.push(selectData[o])
  153. this.candidateForm.list[i].value = val.join(',')
  154. selectId.push(selectData[o].userId)
  155. this.$set(this.selectId, selectData[o].nodeId, selectId)
  156. }
  157. }
  158. }
  159. this.$set(this.selectVal, nodeId, selectVal)
  160. },
  161. submit() {
  162. const query = {
  163. candidateType: this.candidateType,
  164. branchList: this.candidateForm.branchList
  165. }
  166. if (this.isCandidate) {
  167. query.candidateList = this.selectId
  168. for (let rules of this.candidateForm.list) {
  169. if (!rules.value) return this.$u.toast(
  170. `${rules.nodeName}不能为空`
  171. )
  172. }
  173. }
  174. this.$emit('submitCandidate', query);
  175. },
  176. cancel() {
  177. this.close()
  178. },
  179. close() {
  180. this.$emit('input', false);
  181. }
  182. }
  183. };
  184. </script>
  185. <style lang="scss" scoped>
  186. .candidateForm-v {
  187. .jnpf-wrap,
  188. .jnpf-wrap-form {
  189. padding: 0;
  190. }
  191. }
  192. </style>