ZBLOG

关联客户 ...

要实现当查询返回特定信息(如”身份证号未匹配到客户信息请排查”)时,使得产品名称和借据号可以手动输入,可以通过添加一个状态来控制输入模式,并在相应的条件下更新这个状态。

你可以按以下步骤进行修改:

  1. 添加一个状态变量:用于控制是否允许手动输入。
  2. 根据条件更新这个变量:在 handleAssociateCustomer 函数中,判断返回的信息并更新该状态变量。
  3. 使用该变量来控制输入组件的类型:根据状态变量选择 a-select 组件或 a-input 组件。

以下是修改后的代码示例:

  1. <template>
  2. <a-button
  3. class="margin-right-10 button-light-blue"
  4. type="primary"
  5. @click="handleAssociateCustomer"
  6. >
  7. 关联客户
  8. </a-button>
  9. <a-form-item>
  10. <a-row>
  11. <a-col :span="12" v-if="isCustomerAssociated">
  12. <a-form-item label="产品名称" style="width: 250%; margin-left: -130px">
  13. <!-- 根据 isManualInput 控制显示 a-select 或 a-input -->
  14. <template v-if="isManualInput">
  15. <a-input
  16. v-model:value="formModal.productName"
  17. placeholder="请输入产品名称"
  18. />
  19. </template>
  20. <template v-else>
  21. <a-select
  22. v-model:value="formModal.productName"
  23. mode="multiple"
  24. placeholder="请选择产品名称"
  25. :options="productOptions"
  26. :disabled="isEditing || isManualInput"
  27. />
  28. </template>
  29. </a-form-item>
  30. </a-col>
  31. </a-row>
  32. <a-row>
  33. <a-col :span="12" v-if="isCustomerAssociated">
  34. <a-form-item label="借据号" style="width: 250%; margin-left: -130px">
  35. <!-- 根据 isManualInput 控制显示 a-select 或 a-input -->
  36. <template v-if="isManualInput">
  37. <a-input
  38. v-model:value="formModal.loanInfoCode"
  39. placeholder="请输入借据号"
  40. />
  41. </template>
  42. <template v-else>
  43. <a-select
  44. v-model:value="formModal.loanInfoCode"
  45. mode="multiple"
  46. placeholder="请选择借据号"
  47. :options="loanOptions"
  48. :disabled="!formModal.productName.length || isEditing || isManualInput"
  49. />
  50. </template>
  51. </a-form-item>
  52. </a-col>
  53. </a-row>
  54. </template>
  55. <script setup>
  56. import { ref, computed } from 'vue';
  57. import { message } from 'ant-design-vue';
  58. import { getCustomerByIdent } from './api';
  59. const isCustomerAssociated = ref(false);
  60. const isEditing = ref(false);
  61. const formModal = ref({
  62. ident: '',
  63. customerName: '',
  64. phoneNumber: '',
  65. productName: [],
  66. loanInfoCode: ''
  67. });
  68. const workOrderLoans = ref([]);
  69. const isManualInput = ref(false); // 新增手动输入标志
  70. // Computed for product options
  71. const productOptions = computed(() => {
  72. const uniqueProducts = new Set();
  73. workOrderLoans.value.forEach((loan) => uniqueProducts.add(loan.productName));
  74. return Array.from(uniqueProducts).map((product) => ({
  75. value: product,
  76. label: product,
  77. }));
  78. });
  79. // Computed for loan options
  80. const loanOptions = computed(() => {
  81. if (!formModal.value.productName || formModal.value.productName.length === 0) {
  82. return [];
  83. }
  84. const filteredLoans = workOrderLoans.value.filter((loan) =>
  85. formModal.value.productName.includes(loan.productName)
  86. );
  87. return filteredLoans.map((loan) => ({
  88. value: loan.loanInfoCode,
  89. label: loan.loanInfoCode,
  90. }));
  91. });
  92. // Associate customer handler
  93. const handleAssociateCustomer = () => {
  94. getCustomerByIdent({ ident: formModal.value.ident }).then((response) => {
  95. if (response.success) {
  96. isCustomerAssociated.value = true;
  97. formModal.value.customerName = response.data.customerName;
  98. formModal.value.phoneNumber = response.data.phoneNumber;
  99. workOrderLoans.value = response.data.workOrderLoans;
  100. // Reset manual input flag in case of successful association
  101. isManualInput.value = false;
  102. } else if (response.message === '身份证号未匹配到客户信息请排查') {
  103. message.error('身份证号未匹配到客户信息请手动输入');
  104. isCustomerAssociated.value = true;
  105. // 设置手动输入为真以启用文本框
  106. isManualInput.value = true;
  107. } else {
  108. message.error(response.message);
  109. }
  110. });
  111. };
  112. </script>

修改说明:

  1. 引入新的 ref 状态 isManualInput:此状态用于控制是否允许用户手动输入。
  2. handleAssociateCustomer 函数中设置 isManualInput 的值:当收到 “身份证号未匹配到客户信息请排查” 时,将其设为 true,否则设为 false
  3. 使用条件渲染切换输入框与选择框:使用 <template> 标签,根据 isManualInput 的值渲染不同的输入方式。


    内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=22846

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?