Commit db154520 by liangjianmin

feat(apply): add order number validation and auto-fetch customer name

- Add debounced handleOrderNoInput method to fetch customer name based on order number
- Integrate getCustomerName API endpoint to retrieve customer information
- Update customer name field to display fetched value or placeholder text
- Add customer_name validation in form submission to ensure valid order number
- Replace standalone request import with debounce from lodash for input optimization
- Update API submission to use instance method instead of standalone function
- Remove unnecessary catch block from form submission promise chain
- Improves user experience by automatically populating customer name when valid order number is entered
parent 9d6d606e
Showing with 40 additions and 8 deletions
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
<u-icon slot="right" name="arrow-down" color="#c0c4cc"></u-icon> <u-icon slot="right" name="arrow-down" color="#c0c4cc"></u-icon>
</u-form-item> </u-form-item>
<u-form-item label="订单号" prop="order_no" required borderBottom> <u-form-item label="订单号" prop="order_no" required borderBottom>
<u--input v-model="form.order_no" placeholder="请输入" border="none" inputAlign="right"></u--input> <u--input v-model="form.order_no" placeholder="请输入" border="none" inputAlign="right" @input="handleOrderNoInput"></u--input>
</u-form-item> </u-form-item>
<u-form-item label="客户名称" prop="customer_name" required> <u-form-item label="客户名称" prop="customer_name" required>
<view class="row verCenter boxFlex" style="justify-content: flex-end;"> <view class="row verCenter boxFlex" style="justify-content: flex-end;">
<text class="link-text">关联订单号显示</text> <text class="link-text">{{ form.customer_name || '关联订单号显示' }}</text>
</view> </view>
</u-form-item> </u-form-item>
</view> </view>
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
<script> <script>
import { API } from '@/util/api.js'; import { API } from '@/util/api.js';
import { request } from '@/util/util.js'; import debounce from 'lodash/debounce';
export default { export default {
data() { data() {
...@@ -102,11 +102,36 @@ ...@@ -102,11 +102,36 @@
}, },
/** /**
* 订单号输入事件,防抖获取客户名称
* @return {void}
*/
handleOrderNoInput: debounce(function() {
var orderNo = this.form.order_no.trim();
if (!orderNo) {
this.form.customer_name = '';
return;
}
this.request(API.getCustomerName, 'GET', { order_sn: orderNo }).then(res => {
if (res.code === 0) {
this.form.customer_name = res.data;
} else {
this.form.customer_name = '';
uni.showToast({
title: res.msg || '获取客户名称失败',
icon: 'none'
});
}
});
}, 500),
/**
* 表单校验 * 表单校验
* @return {boolean} 校验是否通过 * @return {boolean} 校验是否通过
*/ */
validateForm() { validateForm() {
var { apply_type, order_no, apply_fee_amount, relief_detail, relief_reason } = this.form; var { apply_type, order_no, customer_name, apply_fee_amount, relief_detail, relief_reason } = this.form;
if (!apply_type) { if (!apply_type) {
this.errorMsg = '请选择申请类型'; this.errorMsg = '请选择申请类型';
...@@ -118,6 +143,11 @@ ...@@ -118,6 +143,11 @@
return false; return false;
} }
if (!customer_name) {
this.errorMsg = '请输入有效的订单号以获取客户名称';
return false;
}
if (!apply_fee_amount) { if (!apply_fee_amount) {
this.errorMsg = '请输入申请免收金额'; this.errorMsg = '请输入申请免收金额';
return false; return false;
...@@ -146,7 +176,7 @@ ...@@ -146,7 +176,7 @@
return; return;
} }
request(API.addFeeApprove, 'POST', this.form, true).then(res => { this.request(API.addFeeApprove, 'POST', this.form, true).then(res => {
if (res.code === 0) { if (res.code === 0) {
uni.showToast({ uni.showToast({
title: '提交成功', title: '提交成功',
...@@ -159,8 +189,6 @@ ...@@ -159,8 +189,6 @@
} else { } else {
this.errorMsg = res.msg || '提交失败'; this.errorMsg = res.msg || '提交失败';
} }
}).catch(() => {
this.errorMsg = '网络异常,请稍后重试';
}); });
} }
} }
......
...@@ -50,7 +50,11 @@ const API = { ...@@ -50,7 +50,11 @@ const API = {
/** /**
* 新增费用减免申请 * 新增费用减免申请
*/ */
addFeeApprove: API_BASE + '/api/approve/addFeeApprove' addFeeApprove: API_BASE + '/api/approve/addFeeApprove',
/**
* 根据订单号获取客户名称
*/
getCustomerName: API_BASE + '/ajax/customerNameOption'
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment