Commit 9a003b6c by chenwq

重构代码,移除不必要的API调用,新增车系和品牌查询功能,优化页面加载组件

1 parent 5fe8fbde
......@@ -19,17 +19,13 @@ module.exports = {
noSignAttr: ["file"],
});
},
/** 首页、发现列表 搜索接口 */
search(data) {
return http.post({
method: "scrm.api.carlife.weapp.homeSearch.search",
pageSize: 10,
...data,
});
},
/** 根据sap编码获取商户详情 */
getBySapCode(data) {
return http.fetch(`scrm.api.carlife.merchant.getBySapCode`,data);
/** 查询车品牌(品牌-车系-车型树形结构) */
getCarBrandList() {
return http.get({method: '/rest/ropApi/getCarBrandComplete'})
},
/** 根据车系ID查询车型列表 */
getCarTypeList(csId) {
return http.get({method: '/rest/ropApi/getCarTypeList', csId});
},
/**获取图片版本号 */
getImgVersion() {
......@@ -39,58 +35,8 @@ module.exports = {
passwordLogin(data) {
return http.fetch('/rest/login', data)
},
/**手机号验证码登录 */
phoneSmsLogin(data) {
return http.fetch('scrm.api.sso.sms.login', {
source: 'MINIAPP',
...data
})
},
/**微信授权手机号登录 */
authPhoneLogin(data) {
return http.fetch('scrm.api.sso.weapp.auth.phone', {
source: 'MINIAPP',
...data
})
},
/**获取积分渠道列表 */
getPointsSourceList(data) {
return http.fetch('scrm.api.shopmall.score.get.channelSource', {
...data
})
},
/**查询积分钱包 */
getPointsWalletData(data) {
return http.fetch('scrm.api.shopmall.pointswallet.get', {
...data
})
},
/**开通积分钱包 */
openPointsWallet(data) {
return http.fetch('scrm.api.shopmall.pointswallet.open', {...data})
},
/**替换积分钱包昵称 */
replaceWalletName(data) {
return http.fetch('scrm.api.sso.nickName.replace', {...data})
},
/**获取积分汇总数据 */
getPointsSummary(data) {
return http.fetch('scrm.api.shopmall.score.summary.search', {...data})
},
/**获取用户信息 */
getLoginInfo(data) {
return http.get({method: '/rest/login/userInfo', ...data}, true)
},
/**获取门店数据 */
getMerchantData(data) {
return http.fetch('scrm.api.shopmall.score.list.merchant', {...data})
},
/**进入商品详情页面埋点 */
dynamicRecordAdd(data) {
return http.fetch('scrm.api.shopmall.scrm.customer.dynamic.record.add', {...data})
},
/**离开商品详情页面埋点 */
dynamicRecordLeave(data) {
return http.fetch('scrm.api.shopmall.scrm.customer.dynamic.record.leave', {...data})
}
};
......@@ -40,7 +40,8 @@
"root": "packageIndex",
"pages": [
"pages/editOrder/index/index",
"pages/carBrands/carBrands"
"pages/carBrands/carBrands",
"pages/carSeries/carSeries"
]
},
{
......
......@@ -83,6 +83,7 @@ Component({
});
let thisPage = wx.p.router.getPageInstance();
wx.p.eventbus.on("set_car_info", (n) => {
console.log("GLCustForm received set_car_info event:", n);
let { targetIdx, dataAttrName, formDataList } = this.data;
let formData = null;
if (dataAttrName && dataAttrName.includes(".")) {
......@@ -213,7 +214,7 @@ Component({
getHeight(selector) {
return new Promise((resolve) => {
wx.$util.getViewInfo(
wx.p.wxApi.getViewInfo(
selector,
(res) => {
return resolve(res);
......@@ -494,7 +495,7 @@ Component({
},
navOcr(e) {
let { type } = e.currentTarget.dataset;
wx.$router.go(`ocrUsedCarModules?type=${type}`);
wx.p.router.go(`ocrUsedCarModules?type=${type}`);
},
},
});
\ No newline at end of file
// components/PageLoading/PageLoading.js
Component({
/**
* 组件的属性列表
*/
properties: {
color: {
type: String,
value: '#347BFF'
},
isFullScreen: Boolean
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
/* components/PageLoading/PageLoading.wxss */
.nothing {
display: flex;
align-items: center;
justify-content: center;
aspect-ratio: 1/1;
flex-direction: column;
font-size: var(--fontSize28);
color: rgb(40, 40, 41);
}
.nothing.true{
position: fixed;
top: 50%;
width: 100%;
transform: translateY(-50%);
}
.loading {
height: var(--fontSize48);
margin-bottom: var(--fontSize16);
}
.loading view {
width: var(--fontSize16);
height: 100%;
display: inline-block;
animation: stretchdelay 1.2s infinite ease-in-out;
margin: 0 var(--fontSize4);
}
.loading view:nth-child(2) {
animation-delay: -1.1s;
}
.loading view:nth-child(3) {
animation-delay: -1s;
}
.loading view:nth-child(4) {
animation-delay: -.9s;
}
@keyframes stretchdelay {
0%,
100%,
40% {
transform: scaley(.33);
}
20% {
transform: scaley(1);
}
}
\ No newline at end of file
<!--components/PageLoading/PageLoading.wxml-->
<view class="nothing {{isFullScreen}}">
<view class="loading ">
<block wx:for="{{4}}" wx:key="index">
<view style="background-color: {{color}};"></view>
</block>
</view>
<slot></slot>
</view>
\ No newline at end of file
// packageIndex/pages/carBrands/carBrands.js
import carLifeApi from "../../../carEquityApi";
import commonApi from "~/api/module/common.js";
Page({
/**
* 页面的初始数据
......@@ -16,7 +16,7 @@ Page({
*/
onLoad(options) {
console.log("[carBrands onLoad] options:", options);
wx.$util.getViewInfo("#search-input", (res) => {
wx.p.wxApi.getViewInfo("#search-input", (res) => {
this.setData({
inputHeight: res.height,
});
......@@ -30,9 +30,10 @@ Page({
cartips: cartips,
});
}
carLifeApi.getCarBrandList().then((res) => {
commonApi.getCarBrandList().then((res) => {
console.log("[carBrands getCarBrandList] res:", res);
// this.setLocalStorage('wx_scrm_car_brand_list', carInfo)
const carInfo = res.data;
const carInfo = res.carinfos;
this.formatData(carInfo);
});
},
......@@ -53,7 +54,7 @@ Page({
this.setCarData(brandList);
},
setCarData(brandList) {
wx.$util.showLoading("加载中...");
wx.p.wxApi.showLoading("加载中...");
let count = 0;
let settime = setInterval(() => {
if (null != brandList[count].list && brandList[count].list.length > 0)
......@@ -88,8 +89,8 @@ Page({
},
getSideBarInfo() {
let _this = this;
wx.$util.getViewInfo("#letter-A", (res) => {
wx.$util.getViewInfo("#side-bar", (_res) => {
wx.p.wxApi.getViewInfo("#letter-A", (res) => {
wx.p.wxApi.getViewInfo("#side-bar", (_res) => {
_this.setData({
letterHeight: res.height,
toTop: res.height + _res.top,
......@@ -136,6 +137,7 @@ Page({
vehicleBrandId: item.id,
vehicleBrandName: item.name,
};
console.log("showCarSeries item:", item)
if (item.childs && item.childs.length) {
if (level) {
this.setData({
......@@ -151,7 +153,7 @@ Page({
if (this.data.cartips) {
params.cartips = this.data.cartips;
}
wx.$router.go("carSeries", params);
wx.p.router.go("/packageIndex/pages/carSeries/carSeries", params);
} else this.showToast("暂无该品牌车系");
},
cancel() {
......@@ -161,7 +163,7 @@ Page({
},
choose(e) {
const { item } = e.currentTarget.dataset;
wx.$router.back((page) => {
wx.p.router.back((page) => {
page.changeCarBrand && page.changeCarBrand(item);
});
},
......
// packageIndex/pages/carSeries/carSeries.js
// import carLifeApi from "../../../carEquityApi";
import commonApi from "~/api/module/common.js";
Page({
/**
* 页面的初始数据
*/
data: {
cartips: "",
cartipsHeight: 0, // cartips 的高度
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 接收 cartips 参数
if (options.cartips) {
const cartips = decodeURIComponent(options.cartips);
console.log("[carSeries onLoad] cartips:", cartips);
this.setData(
{
cartips: cartips,
},
() => {
// 设置完 cartips 后获取高度
this.getCartipsHeight();
},
);
}
wx.p.router.getRouterParams(options).then((res) => {
// 如果路由数据中也有 cartips,使用路由数据中的
if (res.cartips) {
this.setData(
{
cartips: res.cartips,
},
() => {
// 设置完 cartips 后获取高度
this.getCartipsHeight();
},
);
}
console.log("[carSeries onLoad] router params:", res);
this.setData(res);
wx.setNavigationBarTitle({
title: res.brandInfo.vehicleBrandName || "",
});
res.list.map((e, index) => {
let data = e.childs;
if (!data) data = [];
this.setData({
[`list[${index}].done`]: true,
[`list[${index}].childs`]: data,
});
});
});
},
// 获取 cartips 高度
getCartipsHeight() {
if (!this.data.cartips) return;
wx.nextTick(() => {
const query = wx.createSelectorQuery().in(this);
query.select(".cartips").boundingClientRect();
query.exec((res) => {
if (res && res[0]) {
console.log("[carSeries] 获取到的 cartips 高度:", res[0].height);
this.setData({
cartipsHeight: res[0].height || 0,
});
} else {
console.log("[carSeries] 未找到 .cartips 元素");
}
});
});
},
getCarSeriesList(e, { index, brandId }) {
// commonApi
// .getCarSeriesList({
// brandId,
// childBrandId: e.id,
// })
// .then((res) => {
// let { data } = res;
// if (!data) data = [];
// this.setData({
// [`list[${index}].done`]: true,
// [`list[${index}].childs`]: data,
// });
// });
},
showCarType(e) {
console.log(e);
let { i, item } = e.currentTarget.dataset,
{ brandInfo, carTypeList } = this.data;
if (
brandInfo.vehicleSeriesId == i.id &&
carTypeList &&
carTypeList.length
) {
this.setData({
showType: true,
});
return;
}
brandInfo = {
...brandInfo,
vehicleSubBrandId: item.id,
vehicleSubBrandName: item.name,
vehicleSeriesId: i.id,
vehicleSeriesName: i.name,
};
carTypeList = [];
wx.p.wxApi.showLoading();
commonApi.getCarTypeList(i.id).then((res) => {
console.log("[carSeries getCarTypeList] res:", res);
let data = res.carinfos;
wx.hideLoading();
if (!data || !data.length) wx.p.wxApi.showToast("暂无该车型");
else carTypeList = data || [];
this.setData({
brandInfo,
carTypeList,
showType: data && data.length,
});
});
},
cancel() {
this.setData({
showType: false,
});
},
go(e) {
let { index } = e.currentTarget.dataset;
this.setData({
letter: `series-${index}`,
});
},
choose(e) {
this.setData({
showType: false,
});
const prePage = wx.p.router.getPageInstance(2);
let { brandInfo } = this.data,
{ i } = e.currentTarget.dataset,
carInfo = {
...brandInfo,
vehicleShapeId: i.id,
vehicleShapeName: i.name,
};
console.log("[carSeries choose] selected carInfo:", carInfo);
wx.p.eventbus.emit("set_car_info", carInfo);
wx.p.router.back(
(pre) => {
console.log(pre);
},
prePage.route == "packageIndex/pages/carBrands/carBrands"
? 2
: 1,
);
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
// 在 onReady 时也尝试获取一次高度(兜底)
this.getCartipsHeight();
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {},
/**
* 用户点击右上角分享
*/
// onShareAppMessage() {}
});
{
"navigationBarTitleText": "加载中...",
"usingComponents": {
"page-loading": "/components/PageLoading/PageLoading"
}
}
\ No newline at end of file
<!--packageIndex/pages/carSeries/carSeries.wxml-->
<view class="car-brands-box">
<view class="car-brands">
<view wx:if="{{cartips}}" class="cartips">{{cartips}}</view>
<scroll-view style="height:calc(100% - {{cartipsHeight}}px);" scroll-y scroll-into-view="{{letter}}">
<block wx:for="{{list}}" wx:key="index">
<view id="series-{{index}}">
<view class="title car-y-center">{{item.name}}</view>
<view class="box">
<block wx:if="{{item.done}}">
<block wx:for="{{item.childs}}" wx:for-item="i" wx:key="ind" wx:for-index="ind">
<view class="brands" catchtap="showCarType" data-item="{{item}}" data-i="{{i}}">
<view class="list car-y-center">{{i.name}}</view>
</view>
</block>
</block>
<block wx:else>
<page-loading>加载中...</page-loading>
</block>
</view>
</view>
</block>
</scroll-view>
<view class="side-bar" id="side-bar">
<block wx:for="{{list}}" wx:key="index">
<view class="view" data-index="{{index}}" bindtap="go">{{item.name}}</view>
</block>
</view>
</view>
</view>
<block wx:if="{{showType}}">
<view class="car-type-box">
<view class="bg" bindtap="cancel" catchtouchmove="noScroll"></view>
<view class="car-view">
<block wx:for="{{carTypeList}}" wx:key="index">
<view class="flex item" bindtap="choose" data-i="{{item}}">{{item.name}}</view>
</block>
</view>
</view>
</block>
\ No newline at end of file
/* packageIndex/pages/carSeries/carSeries.wxss */
@import "../carBrands/carBrands.wxss";
.cartips {
border-radius: var(--fontSize16);
background: #fef4e8;
color: #ff9d0a;
font-size: var(--fontSize26);
font-weight: 400;
padding: var(--fontSize8) var(--fontSize16);
margin: var(--fontSize16) var(--fontSize32) var(--fontSize16)
var(--fontSize32);
}
.car-y-center {
display: flex;
align-items: center;
transform: translateY(0);
}
.side-bar {
width: auto;
}
.side-bar .view {
padding: 0 var(--fontSize16) 0 var(--fontSize32);
font-size: var(--fontSize20);
width: auto;
}
.car-type-box {
position: fixed;
left: 0;
top: 0;
width: 100vw;
height: 100vh;
font-size: var(--fontSize28);
color: #333;
z-index: 9999;
}
.car-type-box .bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
}
.car-view {
position: absolute;
top: 0;
right: 0;
height: 100vh;
width: 75vw;
padding-bottom: constant(safe-area-inset-bottom) !important;
padding-bottom: env(safe-area-inset-bottom) !important;
background: #fff;
-webkit-overflow-scrolling: touch;
animation: move 0.4s;
box-sizing: border-box;
overflow-y: scroll;
}
.car-view .item {
padding: var(--fontSize20) var(--fontSize32);
border-bottom: var(--fontSize2) solid #e9e9e9;
}
......@@ -168,7 +168,7 @@ Component({
},
// 获取推荐人列表
// getEmployee() {
// let userInfo = wx.$util.getStorageSync("dj_boutique_user_info");
// let userInfo = wx.p.wxApi.getStorageSync("dj_boutique_user_info");
// this.setData({
// userInfo,
// });
......@@ -181,7 +181,7 @@ Component({
// employeeList: res.data,
// });
// } else {
// wx.$util.showToast(res.message || "接口异常");
// wx.p.wxApi.showToast(res.message || "接口异常");
// }
// });
// },
......
......@@ -9,6 +9,7 @@ Page({
step: "first", // first | second | third | fourth
currentStep: 1, // 当前步骤:1-基本信息 | 2-车辆详情 | 3-价格设置 | 4-照片上传
isEdit: true,
formData: {},
stepList: [
{ step: 1, name: "基本信息" },
{ step: 2, name: "车辆详情" },
......
......@@ -27,8 +27,8 @@
<first-step
wx:if="{{step === 'first'}}"
id="FirstStep"
serviceInfo="{{ formData.carBaseReqDTO }}"
dataAttrName="formData.carBaseReqDTO"
serviceInfo="{{ formData }}"
dataAttrName="formData"
evalOrderBasicReqDTO="{{ formData.evalOrderBasicReqDTO }}"
isEdit="{{ isEdit }}"
bindconfirm="handleFirstConfirm"
......
......@@ -20,7 +20,7 @@ Page({
// if (code == '0') {
// // wx.$Track.setTrack({}, 4)
// wx.p.isLogin = false
// // wx.$util.removeSystemStorage()
// // wx.p.wxApi.removeSystemStorage()
// wx.p.storage.rm('userInfo')
// wx.p.storage.rm('token')
// wx.p.storage.rm('isVIP')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!