index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <view class="commission-form-page">
  3. <u-navbar placeholder :autoBack="true" :title="pageTitle" @rightClick="submitForm">
  4. <view class="u-nav-slot" slot="right"> 保存 </view>
  5. </u-navbar>
  6. <!-- 表单内容 -->
  7. <view class="follow_form_wrap">
  8. <u--form labelPosition="left" labelWidth="130" :model="commissionForm" :rules="rules" ref="commissionFormRef"
  9. class="form_wrap" :errorType="'toast'">
  10. <u-form-item label="账户类型" prop="accountType" borderBottom :required="true">
  11. <ld-select :list="accountTypeOptions" label-key="label" value-key="value" placeholder="请选择账户类型"
  12. v-model="commissionForm.accountType" :border="false"></ld-select>
  13. <u-icon slot="right" name="arrow-right"></u-icon>
  14. </u-form-item>
  15. <u-form-item label="分成人" prop="userName" borderBottom :required="true" @click="handleShowCommissionUser">
  16. <u--input v-model="commissionForm.userName" disabled style='pointer-events: none !important'
  17. disabledColor="#ffffff" placeholder="点击选择" border="none"></u--input>
  18. <u-icon slot="right" name="arrow-right"></u-icon>
  19. </u-form-item>
  20. <u-form-item label="分成比例(%)" prop="commissionRate" borderBottom :required="true">
  21. <u--input v-model.number="commissionForm.commissionRate" type="number" placeholder="请输入分成比例(0-100)"
  22. border="none" @blur="validateCommissionRate"></u--input>
  23. </u-form-item>
  24. <u-form-item label="是否归属公司业绩" prop="isCompanyPerformance" borderBottom :required="true">
  25. <ld-select :list="companyPerformanceOptions" label-key="label" value-key="value" placeholder="请选择是否归属公司业绩"
  26. v-model="commissionForm.isCompanyPerformance" :border="false"></ld-select>
  27. <u-icon slot="right" name="arrow-right"></u-icon>
  28. </u-form-item>
  29. <u-form-item label="关联收单信息" prop="receiptFormId" borderBottom :required="true">
  30. <ld-select :list="receiptList" label-key="item" value-key="id" placeholder="请选择收单信息"
  31. v-model="commissionForm.receiptFormId" :border="false"></ld-select>
  32. <u-icon slot="right" name="arrow-right"></u-icon>
  33. </u-form-item>
  34. </u--form>
  35. </view>
  36. <!-- 分成人选择器 -->
  37. <ba-tree-picker :selectParent="false" v-if="commissionUserList.length > 0" ref="commissionUser" :multiple='false'
  38. @select-change="commissionUserSelectChange" border title="分成人" :localdata="commissionUserList" valueKey="id"
  39. textKey="label" childrenKey="children" :selectedValues="commissionForm.userId"
  40. :personNames="commissionForm.userName" />
  41. </view>
  42. </template>
  43. <script>
  44. import ldSelect from "@/components/ld-select/ld-select.vue";
  45. import { filterCustomerManager, handleTree } from '@/utils/util';
  46. export default {
  47. name: "CommissionForm",
  48. components: {
  49. ldSelect
  50. },
  51. data() {
  52. return {
  53. loading: false,
  54. commissionForm: {
  55. id: undefined,
  56. sendFormId: '',
  57. clueId: '',
  58. receiptFormId: '',
  59. accountType: '1',
  60. userName: '',
  61. userId: '',
  62. commissionRate: undefined,
  63. isCompanyPerformance: '1'
  64. },
  65. receiptList: [],
  66. commissionUserList: [],
  67. accountTypeOptions: [
  68. { label: "前端", value: "1" },
  69. { label: "后端", value: "2" }
  70. ],
  71. companyPerformanceOptions: [
  72. { label: "是", value: "1" },
  73. { label: "否", value: "2" }
  74. ],
  75. // 表单验证规则
  76. rules: {
  77. accountType: [{ required: true, message: "请选择账户类型", trigger: "change" }],
  78. userName: [{ required: true, message: "请选择分成人", trigger: "blur" }],
  79. commissionRate: [
  80. {
  81. validator: (rule, value, callback) => {
  82. if (value === undefined || value === null || value === '') {
  83. callback(new Error("请输入分成比例"));
  84. } else {
  85. callback();
  86. }
  87. },
  88. trigger: "blur"
  89. },
  90. { type: 'number', min: 0, max: 100, message: '分成比例必须在0-100之间', trigger: "blur" }
  91. ],
  92. isCompanyPerformance: [{ required: true, message: "请选择是否归属公司业绩", trigger: "change" }],
  93. receiptFormId: [{ required: true, message: "请选择关联收单信息", trigger: "change" }]
  94. },
  95. };
  96. },
  97. computed: {
  98. pageTitle() {
  99. return this.commissionForm.id ? "编辑分成" : "新增分成";
  100. },
  101. },
  102. onLoad(options) {
  103. // 从路由参数获取sendFormId和clueId
  104. this.commissionForm.sendFormId = options.sendFormId;
  105. this.commissionForm.clueId = options.clueId;
  106. this.commissionForm.id = options.id;
  107. // 获取分成人列表
  108. this.getCommissionUserList();
  109. this.fetchReceiptList().then(() => {
  110. if (options.id) {
  111. this.initForm(options.id);
  112. }
  113. });
  114. },
  115. methods: {
  116. // 获取分成人列表
  117. getCommissionUserList() {
  118. // 获取人员列表
  119. uni.$u.api.getCustomerManagerAllList().then(res => {
  120. this.commissionUserList = filterCustomerManager(res.data);
  121. });
  122. },
  123. // 显示分成人选择器
  124. handleShowCommissionUser() {
  125. this.$refs.commissionUser._show();
  126. },
  127. // 分成人选择变化
  128. commissionUserSelectChange(ids, names) {
  129. this.commissionForm.userId = ids[0];
  130. this.commissionForm.userName = names[0];
  131. },
  132. // 获取收单列表
  133. async fetchReceiptList() {
  134. try {
  135. const res = await uni.$u.api.clueReceiptFormListByOrderId(this.commissionForm.sendFormId);
  136. this.receiptList = res.data || [];
  137. } catch (error) {
  138. console.error("获取收单列表失败:", error);
  139. uni.$u.toast("获取收单列表失败");
  140. }
  141. },
  142. // 初始化表单数据
  143. async initForm(id) {
  144. try {
  145. const res = await uni.$u.api.clueCommissionById(id);
  146. this.commissionForm = res.data;
  147. } catch (error) {
  148. console.error("获取分成详情失败:", error);
  149. uni.$u.toast("获取分成详情失败");
  150. }
  151. },
  152. // 分成比例验证
  153. validateCommissionRate() {
  154. const { commissionRate } = this.commissionForm;
  155. if (!commissionRate && commissionRate !== 0) return;
  156. const rate = Number(commissionRate);
  157. if (rate < 0) {
  158. uni.$u.toast("分成比例不能小于0");
  159. this.commissionForm.commissionRate = 0;
  160. } else if (rate > 100) {
  161. uni.$u.toast("分成比例不能大于100");
  162. this.commissionForm.commissionRate = 100;
  163. }
  164. },
  165. // 提交表单
  166. submitForm() {
  167. this.$refs.commissionFormRef.validate().then(async (valid) => {
  168. if (valid) {
  169. await this.handleUpdate();
  170. } else {
  171. uni.$u.toast("请检查表单填写是否正确");
  172. }
  173. });
  174. },
  175. // 更新表单
  176. async handleUpdate() {
  177. try {
  178. this.loading = true;
  179. // 根据是否有id判断是新增还是修改
  180. if (this.commissionForm.id) {
  181. // 修改
  182. await uni.$u.api.clueCommissionUpdate(this.commissionForm);
  183. uni.$emit('addCommissionSuccess');
  184. uni.$u.toast("修改成功");
  185. } else {
  186. // 新增
  187. await uni.$u.api.clueCommissionAdd(this.commissionForm);
  188. uni.$emit('addCommissionSuccess');
  189. uni.$u.toast("新增成功");
  190. }
  191. // 延迟返回上一页
  192. setTimeout(() => {
  193. uni.navigateBack();
  194. }, 1500);
  195. } catch (error) {
  196. uni.$u.toast(error);
  197. } finally {
  198. this.loading = false;
  199. }
  200. },
  201. },
  202. };
  203. </script>
  204. <style lang="scss">
  205. .commission-form-page {
  206. background-color: #fff;
  207. }
  208. @import "@/static/follow/index.scss";
  209. </style>