Commit a0e101e8 by chenwq

feat(validReferralCount): 新增门店引荐数编辑页面及组件

添加门店引荐数编辑功能,包括:
1. 创建referraCountEdit页面用于编辑门店引荐数
2. 开发editItem组件处理具体业务场景的编辑逻辑
3. 实现图片上传、表单验证等功能
4. 在referralCountList页面添加跳转逻辑
1 parent 15edf6f8
...@@ -82,7 +82,8 @@ ...@@ -82,7 +82,8 @@
"pages/orderApprovalManage/orderApprovalDetail/orderApprovalDetail", "pages/orderApprovalManage/orderApprovalDetail/orderApprovalDetail",
"pages/performanceRating/ruleNote/ruleNote", "pages/performanceRating/ruleNote/ruleNote",
"pages/performanceRating/rateDetail/rateDetail", "pages/performanceRating/rateDetail/rateDetail",
"pages/performanceRating/batchOperation/batchOperation" "pages/performanceRating/batchOperation/batchOperation",
"pages/validReferralCount/referraCountEdit/referraCountEdit"
] ]
}, },
{ {
......
// packageWorkspace/pages/validReferralCount/components/editItem/editItem.js
import api from '~/api/api.js'
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/miniprogram/regional-assistant/'
Component({
properties: {
item: {
type: Object,
value: {},
observer(newVal) {
if (newVal) {
this.initData(newVal);
}
}
}
},
data: {
IMG_URL,
// 业务场景:1-精品升级(轻改);2-会员权益(广联权益);3-单延保;
sceneMap: {
1: '轻改',
2: '广联权益',
3: '单延保'
},
isRemarkRequired: false,
fileList: [], // For uploader
},
lifetimes: {
attached() {
if (this.data.item) {
this.checkRemarkRequired(this.data.item);
}
}
},
methods: {
initData(item) {
// Initialize fileList from imageUrls
if (item.imageUrls) {
const urls = item.imageUrls.split(',').filter(i => i);
const fileList = urls.map(url => ({
fileUrl: url,
}));
this.setData({ fileList });
} else {
this.setData({ fileList: [] });
}
},
// Check if remark is required
checkRemarkRequired(item) {
let isRequired = false;
const list = item?.effectiveReferralCountDTOS || [];
for (const dto of list) {
const referral = parseInt(dto.effectiveReferralCount || 0, 10);
const delivery = parseInt(dto.deliveryCount || 0, 10);
if (referral != delivery) {
isRequired = true;
break;
}
}
this.setData({ isRemarkRequired: isRequired });
},
// Handle Effective Referral Count Change
onCountChange(e) {
const index = e.currentTarget.dataset.index;
let value = e.detail;
// Ensure it's a string
value = String(value);
// Remove any non-digit characters (integer only)
let sanitizedValue = value.replace(/\D/g, '');
// Handle range check (0-100,000,000)
if (sanitizedValue !== '') {
let num = parseInt(sanitizedValue, 10);
if (num > 100000000) {
num = 100000000;
}
sanitizedValue = String(num);
}
const key = `item.effectiveReferralCountDTOS[${index}].effectiveReferralCount`;
this.setData({
[key]: sanitizedValue
}, () => {
// Re-check remark requirement
this.checkRemarkRequired(this.data.item);
});
},
// Handle Remark Change
onRemarkChange(e) {
this.setData({
'item.remark': e.detail.value
});
},
// Upload Images
uploadImages() {
let _this = this
let { fileList } = _this.data
wx.chooseMedia({
count: 15 - fileList.length,
sizeType: ['original'],
mediaType: ['image'],
success(res) {
wx.showLoading({ title: '上传中' })
const uploadImages = async (tempFiles) => {
try {
for (const item of tempFiles) {
const val = item.tempFilePath
const imgType = val.split('.')[1]
const type = imgType === 'unknown' ? 'jpg' : imgType
const _res = await new Promise((resolve, reject) => {
wx.getFileSystemManager().readFile({
filePath: val,
encoding: 'base64',
success: resolve,
fail: reject
})
})
const img = await api.uploadImg({
file: `${type}@${_res.data}`
})
const { code, data, message } = img
if (code == 0) {
fileList.push({ fileUrl: data })
_this.setData({
fileList
})
_this.updateImageUrls(fileList)
} else {
wx.showToast({ title: message, icon: 'none' })
}
}
} catch (error) {
wx.showToast({ title: '上传失败,请重试', icon: 'none' })
} finally {
wx.hideLoading()
}
}
uploadImages(res?.tempFiles)
}
})
},
// Preview Image
previewImage(e) {
let { url, index } = e.currentTarget.dataset
let imageUrl = url?.map(v => { return v.fileUrl})
wx.previewImage({
urls: imageUrl,
current: imageUrl[index]
})
},
// Delete File
deleteFile(e) {
let { index } = e.currentTarget.dataset
let { fileList } = this.data
fileList.splice(index, 1)
this.setData({ fileList })
this.updateImageUrls(fileList)
},
// Sync fileList to item.imageUrls
updateImageUrls(fileList) {
const urls = fileList.map(file => file.fileUrl).join(',');
this.setData({
'item.imageUrls': urls
});
},
// Validate Referral Counts
validateReferralCounts() {
const { effectiveReferralCountDTOS, remark } = this.data.item;
const { isRemarkRequired } = this.data;
if (effectiveReferralCountDTOS && effectiveReferralCountDTOS.length > 0) {
for (const dto of effectiveReferralCountDTOS) {
const val = dto.effectiveReferralCount;
if (val == null || val == undefined || val == '') {
wx.showToast({
title: `${dto.brandName}交车数有效引荐数未填`,
icon: 'none'
});
return false;
}
}
}
if (isRemarkRequired && !remark) {
wx.showToast({
title: '有效引荐数与交车数不一致,请填写备注',
icon: 'none'
});
return false;
}
return true;
},
// Save Draft
onDraft() {
if (!this.validateReferralCounts()) return;
this.triggerEvent('draft', this.data.item);
},
// Submit
onSubmit() {
if (!this.validateReferralCounts()) return;
this.triggerEvent('submit', this.data.item);
}
}
})
{
"component": true,
"usingComponents": {
"van-cell": "@vant/weapp/cell/index",
"van-cell-group": "@vant/weapp/cell-group/index",
"van-field": "@vant/weapp/field/index",
"van-uploader": "@vant/weapp/uploader/index",
"van-button": "@vant/weapp/button/index",
"van-icon": "@vant/weapp/icon/index"
}
}
\ No newline at end of file \ No newline at end of file
/* packageWorkspace/pages/validReferralCount/components/editItem/editItem.wxss */
.edit-item-container {
background-color: #fff;
border-radius: 16rpx;
}
.header {
margin-bottom: 20rpx;
}
.title-bar {
display: flex;
align-items: center;
font-weight: 500;
margin: 16rpx 0;
image {
width: 6rpx;
height: 24rpx;
margin-right: 16rpx;
}
}
.title {
font-size: 30rpx;
font-weight: bold;
color: #333;
}
.brand-item {
margin-bottom: 20rpx;
}
.ellipsis {
overflow: hidden;
display: -webkit-box !important;
-webkit-line-clamp: 1;
-webkit-box-orient: vertical;
word-break: break-all;
}
.info-row {
display: flex;
align-items: center;
margin-bottom: 12rpx;
font-size: 28rpx;
// padding: 0 32rpx;
}
.flex {
display: flex;
}
.label {
font-size: 28rpx;
color: #333;
font-weight: 600;
}
.brand-name {
display: inline-block;
max-width: 372rpx;
}
.info-row .value {
color: #1989fa;
margin-left: 8rpx;
}
.notes {
font-size: 24rpx;
color: #888888;
margin-bottom: 24rpx;
}
.section {
margin-bottom: 30rpx;
}
.section-title {
margin-bottom: 24rpx;
}
.remark-box {
background-color: #f7f8fa;
padding: 20rpx;
border-radius: 16rpx;
}
.remark-textarea {
width: 100%;
height: 160rpx;
font-size: 28rpx;
color: #333;
}
.footer {
background-color: #fff;
display: flex;
justify-content: space-between;
}
.btn-wrapper {
flex: 1;
}
.btn-wrapper:first-child {
margin-right: 24rpx;
}
.btn-draft {
background-color: #e8f0fe !important;
color: #2C66F7 !important;
border: none !important;
border-radius: 16rpx !important;
}
.btn-submit {
border-radius: 16rpx !important;
background-color: #2C66F7 !important;
color: #fff !important;
}
.field-no-padding {
padding-left: 0 !important;
padding-right: 0 !important;
}
.upload_box {
.content_box {
display: flex;
flex-wrap: wrap;
gap: 24rpx;
.image_content {
display: inline-block;
position: relative;
border-radius: 12rpx;
overflow: hidden;
.image_box {
width: 192rpx;
height: 192rpx;
display: block;
background-color: #f0f0f0;
}
.del_icon {
width: 36rpx;
height: 36rpx;
position: absolute;
top: 12rpx;
right: 12rpx;
z-index: 2;
}
}
.upload_content {
width: 192rpx;
height: 192rpx;
background: #F5F5F7;
border-radius: 8rpx;
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
image {
width: 40rpx;
height: 40rpx;
}
.text {
font-size: 24rpx;
color: #9B9B9E;
margin-top: 20rpx;
}
}
}
}
<!--packageWorkspace/pages/validReferralCount/components/editItem/editItem.wxml-->
<view class="edit-item-container">
<!-- Title -->
<view class="header">
<view class="title-bar">
<image src="{{IMG_URL}}title_icon.png" mode=""/>
<text class="title">{{sceneMap[item.sceneType] || '未知业务'}}</text>
</view>
</view>
<!-- List of Brands -->
<view class="brand-list">
<block wx:for="{{item.effectiveReferralCountDTOS}}" wx:key="brandType" wx:for-item="dto" wx:for-index="idx">
<view class="brand-item">
<!-- Delivery Count Row -->
<view class="info-row flex">
<text class="label brand-name ellipsis">{{dto.brandName}}</text>
<text class="label">交车数</text>
<text class="value">{{dto.deliveryCount}}</text>
</view>
<!-- Input Row -->
<van-cell-group border="{{false}}">
<van-field
value="{{ dto.effectiveReferralCount }}"
placeholder="请输入"
type="number"
border="{{ false }}"
bind:change="onCountChange"
data-index="{{idx}}"
input-align="right"
custom-class="field-no-padding"
>
<view slot="label">
有效引荐数<text style="color: #ee0a24; margin-left: 8rpx;">*</text>
</view>
</van-field>
</van-cell-group>
</view>
</block>
</view>
<!-- Notes -->
<view class="notes">
剔除试驾车、HW大客户、拖车、门店有痕报备无法引荐的
</view>
<!-- Uploader -->
<view class="section">
<view class="section-title label">上传凭证</view>
<view class="upload_box">
<view class="content_box">
<view class="image_content" wx:for="{{fileList}}" wx:key="index">
<image bindtap="previewImage" class="image_box" data-url="{{fileList}}" data-index="{{index}}" src="{{item.fileUrl}}"/>
<image class="del_icon" src="{{IMG_URL}}zy_paf_del_icon.png" mode="" bindtap="deleteFile" data-index="{{index}}" />
</view>
<view class="upload_content" bindtap="uploadImages" wx:if="{{fileList.length < 15}}">
<image src="{{IMG_URL}}zy-upload_icon.png"></image>
<text class="text">{{fileList.length}} / 15</text>
</view>
</view>
</view>
</view>
<!-- Remark -->
<view class="section">
<view class="section-title label">
备注<text wx:if="{{isRemarkRequired}}" style="color: #ee0a24; margin-left: 8rpx;">*</text>
</view>
<view class="remark-box">
<textarea
class="remark-textarea"
placeholder="请输入(300字以内)"
value="{{item.remark}}"
bindinput="onRemarkChange"
maxlength="300"
></textarea>
</view>
</view>
<!-- Footer Buttons -->
<view class="footer">
<view class="btn-wrapper">
<van-button type="default" block custom-class="btn-draft" bind:click="onDraft">存草稿</van-button>
</view>
<view class="btn-wrapper">
<van-button type="info" block custom-class="btn-submit" bind:click="onSubmit">提交</van-button>
</view>
</view>
</view>
// packageWorkspace/pages/validReferralCount/referraCountEdit/referraCountEdit.js
Page({
/**
* 页面的初始数据
*/
data: {
routerParams: {},
mockData: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
routerParams: options
});
this.fetchData();
},
// Simulate fetching data from backend
fetchData() {
// In a real scenario, you would make a request using this.data.routerParams
// For now, using the structure provided in the prompt
// Simulating API response
const mockData = {
merchantName: "7777",
sceneTypeEffectiveReferrals: [
{
"sceneType": 1, // 精品升级(轻改)
"effectiveReferralCountDTOS": [
{ "brandType": 0, "brandName": "问界23213123132132132132132132132132132", "deliveryCount": 10, "effectiveReferralCount": '' },
{ "brandType": 1, "brandName": "智界", "deliveryCount": 5, "effectiveReferralCount": '' }
],
"imageUrls": "",
"remark": ""
},
{
"sceneType": 2, // 会员权益(广联权益)
"effectiveReferralCountDTOS": [
{ "brandType": 0, "brandName": "问界", "deliveryCount": 20, "effectiveReferralCount": '' },
{ "brandType": 2, "brandName": "享界", "deliveryCount": 8, "effectiveReferralCount": '' }
],
"imageUrls": "",
"remark": ""
}
]
};
this.setData({
mockData: mockData
});
},
// Handle Save Draft
onDraft(e) {
const updatedItem = e.detail;
console.log('Save Draft:', updatedItem);
// Logic to save draft to backend
// You might want to update the local list with the new item data
this.updateLocalList(updatedItem);
wx.showToast({
title: '草稿已保存',
icon: 'success'
});
},
// Handle Submit
onSubmitItem(e) {
const updatedItem = e.detail;
console.log('Submit Item:', updatedItem);
// Validation Logic (Basic check if needed)
// The component might do some validation, but parent can also enforce rules.
// Logic to submit to backend
this.updateLocalList(updatedItem);
wx.showToast({
title: '提交成功',
icon: 'success'
});
},
// Helper to update the specific item in the list based on sceneType
updateLocalList(updatedItem) {
const list = this.data.mockData.sceneTypeEffectiveReferrals;
const index = list.findIndex(item => item.sceneType === updatedItem.sceneType);
if (index !== -1) {
const key = `mockData.sceneTypeEffectiveReferrals[${index}]`;
this.setData({
[key]: updatedItem
});
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
{
"navigationBarTitleText": "编辑门店引荐数",
"usingComponents": {
"edit-item": "../components/editItem/editItem"
}
}
\ No newline at end of file \ No newline at end of file
/* packageWorkspace/pages/validReferralCount/referraCountEdit/referraCountEdit.wxss */
page {
background: #F2F3F7;
}
.container {
padding: 24rpx;
min-height: 100vh;
box-sizing: border-box;
}
.edit-box {
background: #FFFFFF;
border-radius: 32rpx;
padding: 24rpx 32rpx;
margin-bottom: 24rpx;
}
.merchant-name {
color: #222222;
font-size: 28rpx;
margin-bottom: 28rpx;
}
.edit-item-wrapper {
display: block;
}
<!--packageWorkspace/pages/validReferralCount/referraCountEdit/referraCountEdit.wxml-->
<view class="container">
<view wx:for="{{mockData.sceneTypeEffectiveReferrals}}" class="edit-box">
<view class="merchant-name" wx:if="{{index == 0}}">{{mockData.merchantName}}</view>
<edit-item
item="{{item}}"
bind:draft="onDraft"
bind:submit="onSubmitItem"
class="edit-item-wrapper"
/>
</view>
</view>
...@@ -97,6 +97,7 @@ Page({ ...@@ -97,6 +97,7 @@ Page({
list: [ list: [
[ [
{ {
merchantId: "123456789012345678",
merchantName: "D+广州深圳麦田园区店", merchantName: "D+广州深圳麦田园区店",
// 提交状态:0-未提交 1-已提交 // 提交状态:0-未提交 1-已提交
submitStatus: 0, submitStatus: 0,
...@@ -108,6 +109,7 @@ Page({ ...@@ -108,6 +109,7 @@ Page({
lightModificationSubmitStatus: 0, lightModificationSubmitStatus: 0,
}, },
{ {
merchantId: "123456789012345678",
merchantName: merchantName:
"fjdkjfjsdkfjsdkfjskdfjskldfjkdsjfkdsjfksdjfksldfjksdjfskldfjksldfjksdklfsjdkfsjdkfsjkldfdfsfsfsfs", "fjdkjfjsdkfjsdkfjskdfjskldfjkdsjfkdsjfksdjfksldfjksdjfskldfjksldfjksdklfsjdkfsjdkfsjkldfdfsfsfsfs",
submitStatus: 0, submitStatus: 0,
...@@ -119,6 +121,7 @@ Page({ ...@@ -119,6 +121,7 @@ Page({
lightModificationSubmitStatus: 0, lightModificationSubmitStatus: 0,
}, },
{ {
merchantId: "123456789012345678",
merchantName: merchantName:
"32392932893283298392382989283293829328938232988293892938232938293823", "32392932893283298392382989283293829328938232988293892938232938293823",
submitStatus: 0, submitStatus: 0,
...@@ -130,6 +133,7 @@ Page({ ...@@ -130,6 +133,7 @@ Page({
lightModificationSubmitStatus: 0, lightModificationSubmitStatus: 0,
}, },
{ {
merchantId: "123456789012345678",
merchantName: merchantName:
"嘀加深圳门店店名称门店店名称门店店名称门店店名称门店店名称很长嘀加深圳门店店名称门店店名称门店店名称门店店名称门店店名称很长嘀加深圳门店店名称门店店名称门店店名称门店店名称门店店名称很长", "嘀加深圳门店店名称门店店名称门店店名称门店店名称门店店名称很长嘀加深圳门店店名称门店店名称门店店名称门店店名称门店店名称很长嘀加深圳门店店名称门店店名称门店店名称门店店名称门店店名称很长",
submitStatus: 1, submitStatus: 1,
...@@ -212,6 +216,15 @@ Page({ ...@@ -212,6 +216,15 @@ Page({
} }
}, },
handleDetail(e) {
let { target } = e.currentTarget.dataset;
wx.navigateTo({
url:
"/packageWorkspace/pages/validReferralCount/referraCountEdit/referraCountEdit?merchantId=" +
target.merchantId,
});
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!