Commit 6abaf8f2 by 岑成威

fix: 订单拦截

1 parent a10bed0d
......@@ -544,6 +544,14 @@ module.exports = {
getUserScene(data) {
return api.post("dj.api.smartcarlife.scene.config.getUserScene", data);
},
/** 保存用户最近选择场景 */
saveUserScene(data) {
return api.post("dj.api.smartcarlife.scene.recent.saveUserScene", data);
},
/** 查询用户最近选择场景 */
getRecentUserScene(data) {
return api.post("dj.api.smartcarlife.scene.recent.getUserScene", data);
},
fetchApiConfig(bucketName, systemSource = "dj") {
return api.post(
"dj.api.script.common.aliyun.oss.acs.sts.credentials/1.0.0?bucketName=" +
......
......@@ -479,12 +479,18 @@ Component({
// 过滤选中的商户和员工
// let merchantListObj = merchantList.
let filter = selesList.find((item) => item.active);
let filterMerchant = merchantList.find((item) => item.active);
let filterMerchant =
merchantList.find((item) => item.active) || merchantList?.[0];
console.log(filter, "filter");
if (!filter) {
wx.$util.showToast(subTitle);
return;
}
// 门店必须有值:否则会导致后续商品接口 merchantId 为空
if (!filterMerchant) {
wx.$util.showToast(title || "请选择合作门店");
return;
}
if (form) {
this.assignment(type, filter)
......
......@@ -94,13 +94,15 @@ Component({
vinValid: true,
createAllGoodsFlag: 1,
showSceneSelect: false,
sceneColumns: []
sceneColumns: [],
sceneDefaultIndex: 0
},
lifetimes: {
attached() {
async attached() {
this.getEmployee()
this.getShopMerchantPointConfig()
await this.prefillRecentScene()
this.getUserSceneList()
// 没有才走获取档案接口逻辑修改配置,有是必填优先及更高
// 在createOrderCarQuotationSimple 页面做逻辑判断
......@@ -113,6 +115,28 @@ Component({
* 组件的方法列表
*/
methods: {
async prefillRecentScene() {
const userInfo = wx.$util.getUserInfo() || {}
const thisPage = wx.$router.getPageInstance()
const orderInfo = thisPage?.data?.orderInfo || {}
if (orderInfo?.baseSceneCode) return
try {
const res = await commonApi.getRecentUserScene({
sceneType: String(userInfo.sceneType ?? ''),
phone: userInfo.phone
})
const recent = res?.code == 0 ? res?.data : null
const baseSceneCode = recent?.baseSceneCode || ''
if (!baseSceneCode) return
thisPage.setData({
'orderInfo.baseSceneCode': baseSceneCode,
'orderInfo.sceneType': recent?.sceneType
}, () => {
// recent 场景回显后,主动触发一次商品池刷新(内部会调用 getSelectOrderGoodsList)
thisPage.resetGoods && thisPage.resetGoods()
})
} catch (e) {}
},
getUserSceneList() {
const userInfo = wx.$util.getUserInfo() || {}
commonApi
......@@ -122,12 +146,27 @@ Component({
})
.then(res => {
const list = res?.code == 0 && res?.data?.length ? res.data : []
const sceneColumns = list.map(item => ({
...item,
name: item.name || item.staffName
}))
const thisPage = wx.$router.getPageInstance()
const orderInfo = thisPage?.data?.orderInfo || {}
const code = orderInfo?.baseSceneCode || ''
const idx = code
? sceneColumns.findIndex(s => s.baseSceneCode == code)
: 0
const currentScene = code && idx >= 0 ? sceneColumns[idx] : null
this.setData({
sceneColumns: list.map(item => ({
...item,
name: item.name || item.staffName
}))
sceneColumns,
sceneDefaultIndex: idx >= 0 ? idx : 0
})
if (currentScene) {
thisPage.setData({
'orderInfo.baseSceneName': currentScene.name || '',
'orderInfo.sceneType': currentScene.sceneType
})
}
})
.catch(() => {
this.setData({
......@@ -143,10 +182,19 @@ Component({
onConfirmSceneSelect(e) {
const scene = e.detail.value || {}
const thisPage = wx.$router.getPageInstance()
const userInfo = wx.$util.getUserInfo() || {}
thisPage.setData({
'orderInfo.baseSceneCode': scene.baseSceneCode || '',
'orderInfo.baseSceneName': scene.name || scene.staffName || ''
})
scene.baseSceneCode &&
commonApi
.saveUserScene({
baseSceneCode: scene.baseSceneCode,
sceneType: userInfo.sceneType,
phone: userInfo.phone
})
.catch(() => {})
// 切换场景后,重新按场景拉取可选商品
thisPage.resetGoods && thisPage.resetGoods()
this.setData({
......
......@@ -88,6 +88,7 @@
title="场景名称"
bind:cancel="onCloseSceneSelect"
columns="{{ sceneColumns }}"
default-index="{{ sceneDefaultIndex }}"
value-key="name"
bind:confirm="onConfirmSceneSelect"
/>
......
......@@ -39,6 +39,39 @@ Component({
* 组件的方法列表
*/
methods: {
async tryClear4logCacheOnce() {
// 某些调试/日志组件会把日志写到 USER_DATA_PATH/4log,文件过大时会触发
// writeFile:fail the maximum size of the file storage limit is exceeded
// 进而导致选图/上传等流程异常。这里做一次兜底清理,不影响正常业务。
if (this.__cleared4logOnce) return
this.__cleared4logOnce = true
const fs = wx.getFileSystemManager()
const baseDir = `${wx.env.USER_DATA_PATH}/4log`
const safeReaddir = dirPath =>
new Promise(resolve => {
fs.readdir({
dirPath,
success: res => resolve(res?.files || []),
fail: () => resolve([])
})
})
const safeUnlink = filePath =>
new Promise(resolve => {
fs.unlink({
filePath,
complete: () => resolve()
})
})
const files = await safeReaddir(baseDir)
if (!files.length) return
// 只删除该目录下的文件(不递归删子目录,避免误删)
await Promise.all(
files.map(name => safeUnlink(`${baseDir}/${name}`))
)
},
noScroll() { },
close() {
let thisPage = wx.$router.getPageInstance()
......@@ -66,37 +99,68 @@ Component({
})
},
// 上传付款凭证
upLoad(event) {
async upLoad(event) {
let _this = this
let { payVoucherList } = _this.data
const { file } = event.detail
let tempFiles = file?.url
if (!tempFiles) return wx.$util.showToast('请选择图片')
let imgType = tempFiles.split('.')[1]
let type = imgType == 'unknown' ? 'jpg' : imgType
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$util.showLoading('上传中...')
api
.uploadImg({
file: `${type}@${_res.data}`
})
.then(img => {
wx.$util.hideLoading()
console.log(img)
let { code, data, message } = img
if (code == 0) {
payVoucherList.push({ url: data })
_this.setData({
payVoucherList
})
} else {
wx.$util.showToast(message)
}
const fs = wx.getFileSystemManager()
const readBase64 = () =>
new Promise((resolve, reject) => {
fs.readFile({
filePath: tempFiles,
encoding: 'base64',
success: res => resolve(res?.data),
fail: err => reject(err)
})
})
try {
wx.$util.showLoading('上传中...')
const base64 = await readBase64()
const img = await api.uploadImg({
file: `${type}@${base64}`
})
wx.$util.hideLoading()
const { code, data, message } = img || {}
if (code == 0) {
payVoucherList.push({ url: data })
_this.setData({ payVoucherList })
} else {
wx.$util.showToast(message || '上传失败')
}
} catch (err) {
wx.$util.hideLoading()
const msg = err?.errMsg || ''
// 本地存储满:尝试清理日志缓存后重试一次
if (msg.includes('maximum size of the file storage limit is exceeded')) {
await this.tryClear4logCacheOnce()
try {
wx.$util.showLoading('上传中...')
const base64 = await readBase64()
const img = await api.uploadImg({
file: `${type}@${base64}`
})
wx.$util.hideLoading()
const { code, data, message } = img || {}
if (code == 0) {
payVoucherList.push({ url: data })
_this.setData({ payVoucherList })
return
}
wx.$util.showToast(message || '上传失败')
return
} catch (err2) {
wx.$util.hideLoading()
}
}
})
wx.$util.showToast(msg || '读取图片失败,请稍后重试')
}
},
// 删除上传
deletePayVoucher(e) {
......
......@@ -218,6 +218,10 @@ Component({
{
text: '组合付款',
value: 5
},
{
text: '内部结算',
value: 6
}
],
orderTypeName: '正常订单',
......
......@@ -21,11 +21,19 @@ const checkRequired = function (obj, formRule) {
let item = formRule[attr]
let requirObj = item.find(k => k.required == true)
let validFn = item.find(k => k.validator)
if (requirObj && !obj[attr]) {
if (requirObj) {
const value = obj[attr]
// 客户来源(salesType)允许数值 0;其他字段沿用原有 !value 判空逻辑
const isEmpty =
attr === 'salesType'
? value === undefined || value === null || value === ''
: !value
if (isEmpty) {
return {
...requirObj,
attr
}
}
}
if (validFn) {
let validObj = validFn.validator({}, obj[attr])
......
......@@ -1077,6 +1077,12 @@ Page({
return item;
}
);
// 缓存详情返回的“原始”商品列表(后续等按场景拉到商品池后再做一次回显映射)
this._rawDetailVdQuotationGoodsList = wx.$util.deepClone(
tableInfo.vdQuotationGoodsList || []
);
// 标记:等待商品池(selectOrderGoods.list)回来后再做一次回显映射(主要用于多规格商品)
this._pendingEchoFromDetail = true;
wx.hideLoading();
if (code == 0) {
tableInfo.vdQuotationGoodsList = tableInfo.vdQuotationGoodsList.reduce(
......@@ -1242,6 +1248,11 @@ Page({
// this.getQuotationInfo()
// 判断有没有勾选商品,有的话调用一下
orderInfo.vdQuotationGoodsList.length && this.totalFee();
// 编辑态:详情回显后如果已有场景编码,则按场景重新拉取商品列表并回显
const { orderInfo: newOrderInfo, id: currentId } = this.data;
if (currentId && newOrderInfo?.baseSceneCode) {
this.getQuotationInfo(true);
}
}
})
.catch((err) => {});
......@@ -1401,7 +1412,11 @@ Page({
this.setData({
["orderInfo.vdQuotationGoodsList"]: [],
["orderInfo.quotationGoodsInfoList"]: [],
["orderInfo.total"]: "",
});
// 切换场景时:清空详情回显缓存,避免商品池回来后把旧商品“重建回显”
this._rawDetailVdQuotationGoodsList = [];
this._pendingEchoFromDetail = false;
const { orderInfo } = this.data
// 未选择场景名称时,不拉取商品列表(对齐精品升级逻辑)
if (!orderInfo?.baseSceneCode) return
......@@ -1575,9 +1590,150 @@ Page({
}
return ele;
});
this.setData({
quotationGoodsList: data,
});
this.setData(
{
quotationGoodsList: data,
},
() => {
// 编辑态:先拿详情、再按场景拉商品池;商品池回来后再把详情里的“原始 vdQuotationGoodsList”
// 映射成前端可渲染结构(尤其是多规格商品需要靠 specificationGoodsMap 做回显)
if (
id &&
this._pendingEchoFromDetail &&
this._rawDetailVdQuotationGoodsList &&
this._rawDetailVdQuotationGoodsList.length
) {
const quotationGoodsList = this.data.quotationGoodsList || [];
const rebuilt = this._rawDetailVdQuotationGoodsList.reduce(
(pre, item) => {
// 普通商品
if (
!item.packageName &&
!item.packageId &&
!item.specificationsValue
) {
let obj = {
...item,
basePrice: undefined,
upgradeGoodsId: item.goodsId,
merchantGoodsId: item.goodsId,
price: item.price,
goodsPrice: item.price,
finalPrice: item.finalPrice,
minSellPrice: quotationGoodsList?.find(
(val) =>
val?.goods?.merchantGoodsId ==
item.goodsId
)?.goods?.minSellPrice,
validMinSellPrice: quotationGoodsList?.find(
(val) =>
val?.goods?.merchantGoodsId ==
item.goodsId
)?.goods?.validMinSellPrice,
};
pre.push({
goodsFlag: 1,
goods: obj,
packageGoods: null,
});
}
// 套餐
if (item.packageName || item.packageId) {
let obj = {
...item,
basePrice: undefined,
upgradeGoodsId: item.goodsId,
upgradeGoodsId: item.goodsId,
price: item.price,
goodsPrice: item.price,
finalPrice: item.finalPrice,
minSellPrice: quotationGoodsList
?.find(
(val) =>
val.packageGoods?.goodsList
?.length &&
val.packageGoods?.packageCode ==
item?.packageId
)
?.packageGoods?.goodsList?.find(
(subV) =>
subV.merchantGoodsId ==
item.goodsId
)?.minSellPrice,
validMinSellPrice: quotationGoodsList
?.find(
(val) =>
val.packageGoods?.goodsList
?.length &&
val.packageGoods?.packageCode ==
item?.packageId
)
?.packageGoods?.goodsList?.find(
(subV) =>
subV.merchantGoodsId ==
item.goodsId
)?.validMinSellPrice,
};
let index = pre.findIndex((ele) => {
if (ele.packageGoods) {
return (
ele.packageGoods.packageId ==
item.packageId
);
}
});
if (index != -1) {
pre[index].packageGoods.goodsList.push(obj);
pre[index].price = NP.plus(
pre[index].price,
obj.price
);
} else {
pre.push({
goods: null,
goodsFlag: 3,
price: item.price,
packageGoods: {
...item,
goodsPrice: item.price,
finalPrice: item.finalPrice,
packageCode: item.packageId,
goodsList: [
{
...obj,
},
],
},
});
}
}
// 多规格商品(靠商品池映射)
if (
!item.packageName &&
!item.packageId &&
item.specificationsValue
) {
let specificdata =
this.handleSpecificationsEcho(item);
pre = pre.concat(specificdata);
}
return pre;
},
[]
);
this._pendingEchoFromDetail = false;
this.setData(
{
["orderInfo.vdQuotationGoodsList"]: rebuilt,
},
() => {
rebuilt.length && this.totalFee();
}
);
}
}
);
// debugger
setTimeout(() => {
wx.hideLoading();
......
......@@ -497,7 +497,8 @@ Component({
2: '打折策略',
3: '买赠策略',
4: '冲量活动',
5: '组合付款'
5: '组合付款',
6: '内部结算'
}
// 1: '审批中',
// 2: '审批中',
......
......@@ -257,7 +257,7 @@
</block>
<block wx:if="{{ !staffUuid&&isOrder }}">
<view
wx:if="{{ item.orderStatus == '-1' || item.orderStatus == '0' }}"
wx:if="{{ item.orderStatus == '0' }}"
class="order-btn"
bindtap="handleClickBtn"
data-target="{{ item }}"
......
......@@ -68,7 +68,26 @@ Page({
}
],
showSceneSelect: false,
sceneColumns: []
sceneColumns: [],
sceneDefaultIndex: 0
},
async prefillRecentScene() {
const userInfo = this.data.userInfo || wx.$util.getUserInfo() || {}
const currentCode = this.data.orderObj?.baseSceneCode || ''
if (currentCode) return
try {
const res = await commonApi.getRecentUserScene({
sceneType: String(userInfo.sceneType ?? ''),
phone: userInfo.phone
})
const recent = res?.code == 0 ? res?.data : null
const baseSceneCode = recent?.baseSceneCode || ''
if (!baseSceneCode) return
this.setData({
'orderObj.baseSceneCode': baseSceneCode,
'orderObj.sceneType': recent?.sceneType
})
} catch (e) {}
},
/**设置日期 */
setTimeList(dateNum) {
......@@ -105,10 +124,11 @@ Page({
this.setTimeList(date)
},
onLoad: function (res) {
onLoad: async function (res) {
this.setTimeList()
this.handlerUserInfo()
this.getGoodsProduct()
await this.prefillRecentScene()
this.getUserSceneList()
},
......@@ -155,11 +175,24 @@ Page({
})
.then(res => {
const list = res?.code == 0 && res?.data?.length ? res.data : []
const sceneColumns = list.map(item => ({
...item,
name: item.name || item.staffName
}))
const code = this.data.orderObj?.baseSceneCode || ''
const idx = code
? sceneColumns.findIndex(s => s.baseSceneCode == code)
: 0
const currentScene = code && idx >= 0 ? sceneColumns[idx] : null
this.setData({
sceneColumns: list.map(item => ({
...item,
name: item.name || item.staffName
}))
sceneColumns,
sceneDefaultIndex: idx >= 0 ? idx : 0,
...(currentScene
? {
'orderObj.baseSceneName': currentScene.name || '',
'orderObj.sceneType': currentScene.sceneType
}
: {})
})
})
.catch(() => {
......@@ -175,12 +208,21 @@ Page({
},
onConfirmSceneSelect(e) {
const scene = e.detail.value || {}
const userInfo = this.data.userInfo || wx.$util.getUserInfo() || {}
this.setData({
showSceneSelect: false,
'orderObj.baseSceneCode': scene.baseSceneCode || '',
'orderObj.baseSceneName': scene.name || scene.staffName || '',
'orderObj.sceneType': scene.sceneType
})
scene.baseSceneCode &&
commonApi
.saveUserScene({
baseSceneCode: scene.baseSceneCode,
sceneType: userInfo.sceneType,
phone: userInfo.phone
})
.catch(() => {})
},
handlerUserInfo() {
let userInfo = wx.$util.getUserInfo()
......
......@@ -65,6 +65,7 @@
title="场景名称"
bind:cancel="onCloseSceneSelect"
columns="{{ sceneColumns }}"
default-index="{{ sceneDefaultIndex }}"
value-key="name"
bind:confirm="onConfirmSceneSelect"
/>
......
......@@ -264,7 +264,8 @@ const checkStudyTask = () => {
api.checkStudyTaskAPI().then(res => {
wx.hideLoading()
const modal = initModal()
if (modal && res.data.lockOrder&&res.data?.lockReason !== '2') {
const shouldLock = !!res?.data?.lockOrder && res?.data?.lockReason !== '2'
if (modal && shouldLock) {
modal.open({
title: '未完成学习任务,暂不能开单',
type: 'permission',
......@@ -273,7 +274,7 @@ const checkStudyTask = () => {
res.data?.lockReason == '0' ? '我的课程-待学习' : '我的任务'
})
}
resolve(res.data.lockOrder)
resolve(shouldLock)
})
})
}
......
......@@ -717,7 +717,8 @@ Page({
2: '打折策略',
3: '买赠策略',
4: '冲量活动',
5: '组合付款'
5: '组合付款',
6: '内部结算'
}
e.djOrderTypeText = djOrderTypeMap[e.djOrderType] || ''
......
......@@ -252,7 +252,8 @@ const checkStudyTask = () => {
wx.hideLoading()
const modal = initModal()
// res.data.lockOrder = true
if (modal && res.data.lockOrder&&res.data?.lockReason !== '2') {
const shouldLock = !!res?.data?.lockOrder && res?.data?.lockReason !== '2'
if (modal && shouldLock) {
modal.open({
title: '未完成学习任务,暂不能开单',
type: 'permission',
......@@ -261,7 +262,7 @@ const checkStudyTask = () => {
res.data?.lockReason == '0' ? '我的课程-待学习' : '我的任务'
})
}
resolve(res.data.lockOrder)
resolve(shouldLock)
})
})
}
......
......@@ -184,6 +184,11 @@ module.exports = {
return api.post('dj.api.smartcarlife.scene.recent.saveUserScene', data)
},
/** 查询用户最近选择场景 */
getRecentUserScene(data) {
return api.post('dj.api.smartcarlife.scene.recent.getUserScene', data)
},
/** 根据订单更新技师信息 */
updateTechnicianInfo(data) {
return api.post('dj.api.smartcarlife.order.updateTechnicianInfo', data)
......
......@@ -7,7 +7,6 @@ import { checkStudyTask, checkAbnormalOrder } from '~/store/ModalToQueueControl'
const app = getApp()
let toastList = {
employeeName: '销售顾问不能为空',
baseSceneCode: '场景名称不能为空',
subShopMerchantId: '二级流量方不能为空',
customerName: '车主姓名不能为空',
customerPhone: '手机号不能为空',
......@@ -38,11 +37,15 @@ Page({
userInfo: {},
showSceneSelect: false,
sceneColumns: [],
sceneDefaultIndex: 0,
notUpgradeOrderList: [
{
customerName: '',
customerPhone: '',
customerSex: 1,
baseSceneCode: '',
baseSceneName: '',
sceneType: '',
confirmIndex: false
}
// {
......@@ -73,6 +76,81 @@ Page({
},
selectCustomIndex: 0
},
async prefillRecentScene() {
const freshUserInfo = wx.$util.getUserInfo() || {}
const userInfo =
(this.data.userInfo && Object.keys(this.data.userInfo).length
? this.data.userInfo
: freshUserInfo) || {}
try {
const res = await api.getRecentUserScene({
sceneType: String(userInfo.sceneType || ''),
phone: userInfo.phone
})
const recent = res?.code == 0 ? res?.data : null
const baseSceneCode = recent?.baseSceneCode || ''
if (!baseSceneCode) return
const list = this.ensureNotUpgradeOrderList()
const next = list.map(item =>
item?.baseSceneCode
? item
: { ...item, baseSceneCode, sceneType: recent?.sceneType }
)
this.setData({
userInfo,
notUpgradeOrderList: next
})
} catch (e) {}
},
ensureNotUpgradeOrderList() {
const list = this.data.notUpgradeOrderList
if (Array.isArray(list)) {
this.__lastValidNotUpgradeOrderList = list
return list
}
const normalized = []
if (list && typeof list === 'object') {
Object.keys(list).forEach(k => {
const item = list[k]
if (item && typeof item === 'object') normalized.push(item)
})
}
// 如果当前值是对象(比如被错误 setData 成了 map),优先从当前值还原,避免丢失最新填写/选择的数据
if (normalized.length) {
this.setData({
notUpgradeOrderList: normalized
})
this.__lastValidNotUpgradeOrderList = normalized
return normalized
}
// 如果曾经有过有效数组,回滚到最近一次有效值,避免“突然变 1 条”
if (Array.isArray(this.__lastValidNotUpgradeOrderList)) {
this.setData({
notUpgradeOrderList: this.__lastValidNotUpgradeOrderList
})
return this.__lastValidNotUpgradeOrderList
}
if (!normalized.length) {
normalized.push({
customerName: '',
customerPhone: '',
customerSex: 1,
baseSceneCode: '',
baseSceneName: '',
sceneType: '',
confirmIndex: false
})
}
this.setData({
notUpgradeOrderList: normalized
})
this.__lastValidNotUpgradeOrderList = normalized
return normalized
},
routerBack() {
wx.$router.back()
},
......@@ -97,9 +175,12 @@ Page({
let customer = {
customerName: '',
customerPhone: '',
customerSex: 1
customerSex: 1,
baseSceneCode: '',
baseSceneName: '',
sceneType: ''
}
let { notUpgradeOrderList } = this.data
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
notUpgradeOrderList.push(customer)
this.setData({
notUpgradeOrderList
......@@ -178,7 +259,7 @@ Page({
},
delBtn(e) {
let ind = e.currentTarget.dataset.ind
let { notUpgradeOrderList } = this.data
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
notUpgradeOrderList.splice(ind, 1)
this.setData({
......@@ -218,7 +299,8 @@ Page({
// console.log(e)
//开始触摸时 重置所有删除
this.data.notUpgradeOrderList.forEach(item => {
const notUpgradeOrderList = this.ensureNotUpgradeOrderList()
notUpgradeOrderList.forEach(item => {
item.isTouchMove = false
item.confirmIndex = false
})
......@@ -226,12 +308,12 @@ Page({
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
notUpgradeOrderList: this.data.notUpgradeOrderList
notUpgradeOrderList
})
},
//滑动事件处理
touchmove: function (e) {
let { notUpgradeOrderList } = this.data
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
// 为1就不能再删除了
if (notUpgradeOrderList.length == 1) return
......@@ -288,13 +370,13 @@ Page({
...(e.detail || {})
}
let { showName, index } = payload
if (showName === 'showSceneSelect') {
this.getUserSceneList()
}
this.setData({
[showName]: true,
selectCustomIndex: index
})
if (showName === 'showSceneSelect') {
this.getUserSceneList()
}
},
async getUserSceneList() {
const freshUserInfo = wx.$util.getUserInfo() || {}
......@@ -313,19 +395,28 @@ Page({
...item,
name: item.name || item.staffName
}))
const { orderObj } = this.data
const { notUpgradeOrderList, selectCustomIndex } = this.data
const currentCustomer = notUpgradeOrderList?.[selectCustomIndex] || {}
const currentScene =
orderObj.baseSceneCode &&
currentCustomer.baseSceneCode &&
sceneColumns.find(
item => item.baseSceneCode == orderObj.baseSceneCode
item => item.baseSceneCode == currentCustomer.baseSceneCode
)
const currentIndex = currentCustomer.baseSceneCode
? sceneColumns.findIndex(
item => item.baseSceneCode == currentCustomer.baseSceneCode
)
: 0
this.setData({
userInfo,
sceneColumns,
sceneDefaultIndex: currentIndex >= 0 ? currentIndex : 0,
...(currentScene
? {
'orderObj.baseSceneName': currentScene.name || '',
'orderObj.sceneType': currentScene.sceneType
[`notUpgradeOrderList[${selectCustomIndex}].baseSceneName`]:
currentScene.name || '',
[`notUpgradeOrderList[${selectCustomIndex}].sceneType`]:
currentScene.sceneType
}
: {})
})
......@@ -344,17 +435,29 @@ Page({
onConfirmSceneSelect(e) {
const scene = e.detail.value || {}
const userInfo = this.data.userInfo || wx.$util.getUserInfo() || {}
const list = this.ensureNotUpgradeOrderList()
const rawIndex = this.data.selectCustomIndex
const selectCustomIndex =
typeof rawIndex === 'number' ? rawIndex : Number(rawIndex)
const safeIndex =
Number.isFinite(selectCustomIndex) && list[selectCustomIndex]
? selectCustomIndex
: 0
this.setData({
showSceneSelect: false,
'orderObj.baseSceneCode': scene.baseSceneCode || '',
'orderObj.baseSceneName': scene.name || scene.staffName || '',
'orderObj.sceneType': scene.sceneType
[`notUpgradeOrderList[${safeIndex}].baseSceneCode`]:
scene.baseSceneCode || '',
[`notUpgradeOrderList[${safeIndex}].baseSceneName`]:
scene.name || scene.staffName || '',
[`notUpgradeOrderList[${safeIndex}].sceneType`]: scene.sceneType
}, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
scene.baseSceneCode &&
api
.saveUserScene({
baseSceneCode: scene.baseSceneCode,
sceneType: scene.sceneType,
sceneType: userInfo.sceneType,
phone: userInfo.phone
})
.catch(() => {})
......@@ -364,10 +467,15 @@ Page({
let { value } = e.detail
let { name, index } = e.currentTarget.dataset
console.log(name, index)
if (!notUpgradeOrderList?.[index]?.customerSex) {
notUpgradeOrderList[index].customerSex = 1
}
// [`notUpgradeOrderList.${index}.${name}`]:
notUpgradeOrderList[index][name] = value
this.setData({
notUpgradeOrderList
}, () => {
this.__lastValidNotUpgradeOrderList = this.data.notUpgradeOrderList
})
},
......@@ -456,7 +564,8 @@ Page({
if (abnormalOrderCheck) return false
this.checkPhoneUseConfig()
let { type } = i.currentTarget.dataset
let { orderObj, notUpgradeOrderList, dateObj } = this.data
let { orderObj, dateObj } = this.data
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
let key = this.checkRequired(orderObj)
// debugger
......@@ -472,6 +581,9 @@ Page({
if (!notUpgradeOrderList[index].customerName) {
return this.showToast(`请输入第${index + 1}位客户姓名`)
}
if (!notUpgradeOrderList[index].baseSceneCode) {
return this.showToast(`请选择第${index + 1}位客户场景名称`)
}
if (!phoneRex.test(notUpgradeOrderList[index].customerPhone)) {
this.showToast(`请输入第${index + 1}位客户正确的手机号`)
return
......@@ -489,8 +601,8 @@ Page({
if (type == 'success') {
orderObj.preliminaryOrders = (notUpgradeOrderList || []).map(item => ({
...item,
baseSceneCode: orderObj.baseSceneCode,
sceneType: orderObj.sceneType
baseSceneCode: item.baseSceneCode,
sceneType: item.sceneType
}))
} else {
orderObj.notUpgradeOrderList = notUpgradeOrderList
......@@ -547,7 +659,7 @@ Page({
// 导入动态校验字段
// console.log(requiredList) ...requiredList,
let { requiredList } = this.data
let target = [...requiredList, 'employeeName', 'baseSceneCode']
let target = [...requiredList, 'employeeName']
try {
target.map(key => {
......@@ -561,7 +673,8 @@ Page({
return false
},
checkPhoneUseConfig() {
let { phoneShow, orderObj, notUpgradeOrderList } = this.data
let { phoneShow, orderObj } = this.data
let notUpgradeOrderList = this.ensureNotUpgradeOrderList()
if (phoneShow && orderObj.merchantName && orderObj.employeeName) {
// && !orderObj.customer.customerPhone
// let list = phoneShow.shopMerchantPhoneList
......@@ -641,7 +754,7 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (res) {
onLoad: async function (res) {
this.setTimeList()
console.log(res)
const userInfo = wx.$util.getUserInfo() || {}
......@@ -649,6 +762,7 @@ Page({
userInfo
})
res && this.initOPtions(res)
await this.prefillRecentScene()
this.getUserSceneList()
},
/**
......
......@@ -59,24 +59,6 @@
</block>
</gl-cell>
</view>
<view class="baseSceneCode" >
<gl-cell
border
valueAlign="right"
label="场景名称"
requiredAfter
labelWidth="var(--fontSize140)"
required
haveArrow
bindclick="showPopup"
data-show-name="showSceneSelect"
placeholder="点击选择"
>
<block wx:if="{{ orderObj.baseSceneName }}">
<view class="between">{{orderObj.baseSceneName}}</view>
</block>
</gl-cell>
</view>
<view class="subShopMerchantId" wx:if="{{isShowSubShopMerchant}}">
<gl-cell
border
......@@ -157,22 +139,41 @@
data-name="customerName"
always-embed></input>
</gl-cell>
<view class="baseSceneCode">
<gl-cell
border
valueAlign="right"
label="场景名称"
requiredAfter
labelWidth="var(--fontSize140)"
required
haveArrow
bindclick="showPopup"
data-show-name="showSceneSelect"
data-index="{{ind}}"
placeholder="点击选择"
>
<block wx:if="{{ li.baseSceneName }}">
<view class="between">{{li.baseSceneName}}</view>
</block>
</gl-cell>
</view>
<gl-cell
border
label="性别"
valueAlign="right"
labelWidth="var(--fontSize140)">
<view class="gender-box">
<view class="block text-center {{li.customerSex==1?'':'right'}}" />
<view class="block text-center {{(li.customerSex||1)==1?'':'right'}}" />
<view
class="male text-center {{li.customerSex == 1?'active':''}}"
class="male text-center {{(li.customerSex||1) == 1?'active':''}}"
bindtap="changeGender"
data-index="{{ind}}"
data-gender="1">
男
</view>
<view
class="woman text-center {{li.customerSex == 2?'active':''}}"
class="woman text-center {{(li.customerSex||1) == 2?'active':''}}"
bindtap="changeGender"
data-index="{{ind}}"
data-gender="2">
......@@ -309,6 +310,7 @@
title="场景名称"
bind:cancel="onCloseSceneSelect"
columns="{{ sceneColumns }}"
default-index="{{ sceneDefaultIndex }}"
value-key="name"
bind:confirm="onConfirmSceneSelect"
/>
......
......@@ -129,6 +129,7 @@ Page({
isErrorOrder: false,
isAlreadyExistOrder: false,
showTips: false,
sceneDefaultIndex: 0,
associateOrderType: false,
tipsProps: {
tipsText: '该门店产生异常订单,请点击补录!',
......@@ -471,6 +472,29 @@ Page({
// console.log(type)
wx.$router.go(`ocr?type=${type}`)
},
async prefillRecentScene() {
const freshUserInfo = wx.$util.getUserInfo() || {}
const userInfo =
(this.data.userInfo && Object.keys(this.data.userInfo).length
? this.data.userInfo
: freshUserInfo) || {}
const currentCode = this.data.orderObj?.baseSceneCode || ''
if (currentCode) return
try {
const res = await api.getRecentUserScene({
sceneType: String(userInfo.sceneType || ''),
phone: userInfo.phone
})
const recent = res?.code == 0 ? res?.data : null
const baseSceneCode = recent?.baseSceneCode || ''
if (!baseSceneCode) return
this.setData({
userInfo,
'orderObj.baseSceneCode': baseSceneCode,
'orderObj.sceneType': recent?.sceneType
})
} catch (e) {}
},
showPopup(e) {
console.log(e)
let {
......@@ -533,19 +557,41 @@ Page({
...item,
name: item.name || item.staffName
}))
const currentScene = sceneColumns.find(
item => item.baseSceneCode == this.data.orderObj.baseSceneCode
const currentCode = this.data.orderObj?.baseSceneCode || ''
const currentIndex = currentCode
? sceneColumns.findIndex(item => item.baseSceneCode == currentCode)
: 0
const currentScene =
currentCode && currentIndex >= 0 ? sceneColumns[currentIndex] : null
this.setData(
{
userInfo,
sceneColumns,
sceneDefaultIndex: currentIndex >= 0 ? currentIndex : 0,
...(currentScene
? {
'orderObj.baseSceneName': currentScene.name || '',
'orderObj.sceneType': currentScene.sceneType
}
: {})
},
() => {
// recent.getUserScene 可能只回 baseSceneCode,sceneType 需要在这里通过列表匹配后才能拿到
const { orderObj } = this.data
if (
currentScene &&
orderObj?.merchantId &&
orderObj?.userId &&
orderObj?.baseSceneCode
) {
this.getOrderBaseGoodsList(orderObj.merchantId, currentScene.sceneType)
this.getSelectOrderGoodsList(
orderObj.merchantId,
currentScene.sceneType
)
}
}
)
this.setData({
userInfo,
sceneColumns,
...(currentScene
? {
'orderObj.baseSceneName': currentScene.name || '',
'orderObj.sceneType': currentScene.sceneType
}
: {})
})
} catch (e) {
this.setData({
sceneColumns: []
......@@ -569,6 +615,17 @@ Page({
'orderObj.userId': last.userId || '',
'orderObj.employeeName': last.employeeName || ''
})
// 注意:sceneType 需要以“当前选中场景”为准;若 recent 只回 baseSceneCode,则等 getUserSceneList 匹配后再触发
const nextOrderObj = this.data.orderObj || {}
if (nextOrderObj?.merchantId && nextOrderObj?.baseSceneCode) {
// 尝试直接用已存在的 sceneType;没有的话交给 getUserSceneList() 的回调触发
if (nextOrderObj.sceneType !== undefined && nextOrderObj.sceneType !== null && nextOrderObj.sceneType !== '') {
this.getOrderBaseGoodsList(nextOrderObj.merchantId, nextOrderObj.sceneType)
this.getSelectOrderGoodsList(nextOrderObj.merchantId, nextOrderObj.sceneType)
} else {
this.getUserSceneList()
}
}
} catch (e) {}
},
onCloseSceneSelect() {
......@@ -588,7 +645,7 @@ Page({
scene.baseSceneCode &&
api.saveUserScene({
baseSceneCode: scene.baseSceneCode,
sceneType: scene.sceneType,
sceneType: userInfo.sceneType,
phone: userInfo.phone
}).catch(() => {})
const { orderObj } = this.data
......@@ -1242,6 +1299,7 @@ Page({
console.log('setOrderObj', options)
// debugger
wx.$util.showLoading('加载中...')
const prevOrderObj = this.data.orderObj || {}
let orderObj = {}
Object.keys(options).map(e => {
if (options[e] != null && options[e] != undefined) {
......@@ -1255,6 +1313,24 @@ Page({
}
})
// 保留“进入页面通过 recent.getUserScene 预填”的场景信息,避免选择门店/销售顾问时被覆盖丢失
if (!orderObj.baseSceneCode && prevOrderObj.baseSceneCode) {
orderObj.baseSceneCode = prevOrderObj.baseSceneCode
}
if (!orderObj.baseSceneName && prevOrderObj.baseSceneName) {
orderObj.baseSceneName = prevOrderObj.baseSceneName
}
if (
(orderObj.sceneType === undefined ||
orderObj.sceneType === null ||
orderObj.sceneType === '') &&
prevOrderObj.sceneType !== undefined &&
prevOrderObj.sceneType !== null &&
prevOrderObj.sceneType !== ''
) {
orderObj.sceneType = prevOrderObj.sceneType
}
// 兼容处理 orderType 赋值给 djOrderType
if (orderObj.djOrderType === undefined || orderObj.djOrderType === null) {
if (orderObj.orderType !== undefined && orderObj.orderType !== null) {
......@@ -1408,7 +1484,7 @@ Page({
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
onLoad: async function (options) {
// 2:防抖 (Debounce) 处理
// 建议:对于触发价格重算的输入事件(如 inputDiscountValue),引入防抖机制。
// 收益:避免用户快速输入时频繁调用 setGoodsTotal 和 setData,提升输入流畅度。
......@@ -1431,6 +1507,7 @@ Page({
if (options.orderCode) {
this.onRoute(options)
}
await this.prefillRecentScene()
this.getUserSceneList()
this.prefillLastSeller()
// 添加埋点
......@@ -1534,7 +1611,8 @@ Page({
api
.getSelectOrderGoodsList({
merchantId,
sceneType: sceneType ?? 1
sceneType: sceneType ?? 1,
baseSceneCode: orderObj?.baseSceneCode || ''
})
.then(result => {
let { code, data, message } = result
......@@ -1658,6 +1736,7 @@ Page({
.getOrderBaseGoodsList({
merchantId,
sceneType,
baseSceneCode: orderObj?.baseSceneCode || '',
upradeFlag: selectPayType ? 'N' : 'Y'
})
.then(res => {
......
......@@ -891,6 +891,7 @@ value="{{ orderObj.remark }}"
title="场景名称"
bind:cancel="onCloseSceneSelect"
columns="{{ sceneColumns }}"
default-index="{{ sceneDefaultIndex }}"
value-key="name"
bind:confirm="onConfirmSceneSelect"
/>
......
......@@ -55,24 +55,6 @@
</block>
</gl-cell>
</view>
<view class="baseSceneCode">
<gl-cell
border
valueAlign="right"
label="场景名称"
requiredAfter
labelWidth="var(--fontSize140)"
required
haveArrow
bindclick="showPopup"
data-show-name="showSceneSelect"
placeholder="点击选择"
>
<block wx:if="{{ orderObj.baseSceneName }}">
<view class="between">{{orderObj.baseSceneName}}</view>
</block>
</gl-cell>
</view>
<view class="subShopMerchantId" wx:if="{{ isShowSubShopMerchant }}">
<gl-cell
border
......@@ -157,6 +139,25 @@
disabled="{{ orderObj.orderSource == 5 }}"
></input>
</gl-cell>
<view class="baseSceneCode">
<gl-cell
border
valueAlign="right"
label="场景名称"
requiredAfter
labelWidth="var(--fontSize140)"
required
haveArrow
bindclick="showPopup"
data-show-name="showSceneSelect"
data-index="{{ ind }}"
placeholder="点击选择"
>
<block wx:if="{{ li.baseSceneName }}">
<view class="between">{{li.baseSceneName}}</view>
</block>
</gl-cell>
</view>
<gl-cell border label="性别" valueAlign="right" labelWidth="var(--fontSize140)">
<view class="gender-box">
<view class="block text-center {{ li.customer.customerSex==1?'':'right' }}" />
......@@ -751,6 +752,7 @@
title="场景名称"
bind:cancel="onCloseSceneSelect"
columns="{{ sceneColumns }}"
default-index="{{ sceneDefaultIndex }}"
value-key="name"
bind:confirm="onConfirmSceneSelect"
/>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!