form.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <template>
  2. <m-dialog title="分润认领" ref="dialog" @sure="onSure">
  3. <m-form ref="form" :items="formItems" v-model="formValues" v-loading="loading">
  4. <template #customerId>
  5. <el-tag>{{ itemData.customerId }}</el-tag>
  6. </template>
  7. <template #employeeProfitSharingRatio>
  8. <el-tag>{{ itemData.employeeProfitSharingRatio * 100 }}</el-tag>
  9. </template>
  10. <template #[`employeeProfitSharingRatio.append`]>
  11. %
  12. </template>
  13. </m-form>
  14. </m-dialog>
  15. </template>
  16. <script>
  17. import { mapGetters } from 'vuex'
  18. import { getRosterList } from '@/api/system'
  19. export default {
  20. name: 'ClaimForm',
  21. data () {
  22. return {
  23. isStaff: false,
  24. formValues: {
  25. serialNumber: null,
  26. unifiedCertificationNumber: null,
  27. organizationNo: null,
  28. employeeProfitSharingRatio: null
  29. },
  30. itemData: {},
  31. filterLoading: false,
  32. loading: false,
  33. empList: [],
  34. items: [],
  35. submitApi: null
  36. }
  37. },
  38. computed: {
  39. ...mapGetters(['organizationTree']),
  40. organizationItems () {
  41. if (this.organizationTree.length > 0) {
  42. return this.organizationTree[0].child
  43. }
  44. return []
  45. },
  46. formItems () {
  47. return [
  48. {
  49. label: '客户编号',
  50. prop: 'customerId'
  51. }, {
  52. label: '员工分润比例',
  53. prop: 'employeeProfitSharingRatio'
  54. },
  55. {
  56. label: '所属机构',
  57. prop: 'organizationNo',
  58. hidden: !this.isStaff,
  59. type: 'cascader',
  60. rules: [
  61. { required: true, message: '请选择所属机构', trigger: 'change' }
  62. ],
  63. options: {
  64. ref: 'organizationNo',
  65. filterable: true,
  66. clearable: true,
  67. placeholder: '请选择所属机构',
  68. options: this.organizationItems,
  69. showAllLevels: false,
  70. props: {
  71. emitPath: false,
  72. checkStrictly: true,
  73. value: 'organizationNo',
  74. label: 'organizationName',
  75. children: 'child'
  76. }
  77. },
  78. handles: {
  79. change: (v) => {
  80. const nodes = this.$refs.form.$refs.organizationNo.getCheckedNodes()
  81. this.getEmpData(nodes[0]?.data?.organizationNo)
  82. }
  83. }
  84. },
  85. {
  86. label: '分润员工',
  87. prop: 'unifiedCertificationNumber',
  88. type: 'select',
  89. options: {
  90. placeholder: '请输入员工姓名',
  91. filterable: true,
  92. remote: true,
  93. labelText: 'employeeName',
  94. labelValue: 'personnelCode',
  95. valueKey: 'personnelCode',
  96. defaultFirstOption: true,
  97. loading: this.filterLoading,
  98. items: this.empList
  99. },
  100. rules: [
  101. { required: true, message: '请选择分润员工', trigger: 'change' }
  102. ]
  103. },
  104. {
  105. label: '分润比例(%)',
  106. prop: 'employeeProfitSharingRatio',
  107. type: 'input',
  108. slots: ['append'],
  109. required: true,
  110. options: {
  111. placeholder: '请输入分润比例'
  112. },
  113. rules: [
  114. {
  115. validator: (rule, value, callback) => {
  116. if (!value) {
  117. return callback(new Error('请输入分润比例'))
  118. }
  119. if (isNaN(value) || isNaN(parseFloat(value))) {
  120. callback(new Error('请输入数字值'))
  121. } else {
  122. if (value > 100 || value < 0) {
  123. callback(new Error('请输入0-100的数字值'))
  124. } else {
  125. callback()
  126. }
  127. }
  128. },
  129. trigger: ['blur', 'change']
  130. }
  131. ]
  132. }
  133. ]
  134. }
  135. },
  136. methods: {
  137. async getEmpData (organizationNo) {
  138. if (!organizationNo) {
  139. this.empList = []
  140. return
  141. }
  142. try {
  143. this.filterLoading = true
  144. const params = {
  145. organizationNo,
  146. page: { current: 1, size: 9999 }
  147. }
  148. const { data } = await getRosterList(params)
  149. this.empList = data.records
  150. } catch (error) {
  151. this.empList = []
  152. this.$message.error(error)
  153. } finally {
  154. this.filterLoading = false
  155. }
  156. },
  157. async open (item, isStaff, api) {
  158. this.submitApi = api
  159. this.isStaff = isStaff
  160. this.loading = true
  161. this.itemData = item || {}
  162. this.$refs.dialog.open()
  163. this.formValues = {
  164. serialNumber: item.serialNumber,
  165. customerId: item.customerId,
  166. organizationNo: item.organizationNo,
  167. unifiedCertificationNumber: null,
  168. employeeProfitSharingRatio: null
  169. }
  170. await this.getEmpData(item.organizationNo)
  171. this.$nextTick(() => {
  172. this.$refs.form.clearValidate()
  173. this.loading = false
  174. })
  175. },
  176. close () {
  177. this.$refs.dialog.close()
  178. },
  179. setLoading (val) {
  180. this.loading = val
  181. },
  182. onSure () {
  183. this.$refs.form.validate(async valid => {
  184. if (!valid) {
  185. return
  186. }
  187. const { employeeProfitSharingRatio, ...query } = this.formValues
  188. this.$emit('submit', {
  189. ...query,
  190. employeeProfitSharingRatio: employeeProfitSharingRatio / 100
  191. })
  192. })
  193. }
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. </style>