xcx_temp/pages/usercenter/index.js
2023-11-19 17:37:26 +08:00

195 lines
3.2 KiB
JavaScript

import {
fetchUserCenter
} from '~/services/usercenter/fetchUsercenter';
import {
getCustomerServiceList
} from '~/services/usercenter/getCustomerServiceList';
import {
getOpenId
} from '~/services/login/getOpenId';
import Toast from 'tdesign-miniprogram/toast/index';
const menuData = [
[
{
title: '设置',
tit: '',
url: '',
type: 'set',
},
],
[
// {
// title: '帮助中心',
// tit: '',
// url: '',
// type: 'help-center',
// },
{
title: '联系客服',
tit: '',
url: '',
type: 'service',
icon: 'service',
},
],
];
const getDefaultData = () => ({
showMakePhone: false,
userInfo: {
avatarUrl: '',
nickName: '正在登录...',
phoneNumber: '',
},
collectData: {
collectCount: 0,
historyCount: 0,
},
menuData,
customerServiceInfo: {},
currAuthStep: 1,
showKefu: true,
CustomerService: {},
});
Page({
data: getDefaultData(),
onLoad() {
this.onGetCustomerServiceList();
},
onShow() {
this.getTabBar().init();
this.init();
},
onPullDownRefresh() {
this.init();
},
init() {
this.fetUseriInfoHandle();
},
/** 获取客户信息 */
fetUseriInfoHandle() {
fetchUserCenter().then(
({
userInfo,
collectData,
}) => {
this.setData({
userInfo,
collectData,
currAuthStep: 2,
});
wx.stopPullDownRefresh();
},
);
},
onClickCell({
currentTarget
}) {
const {
type
} = currentTarget.dataset;
switch (type) {
case 'service': {
this.openMakePhone();
break;
}
case 'set': {
wx.navigateTo({
url: '/pages/usercenter/set/index'
});
break;
}
default: {
Toast({
context: this,
selector: '#t-toast',
message: '未知跳转',
icon: '',
duration: 1000,
});
break;
}
}
},
jumpAllOrder() {
wx.navigateTo({
url: '/pages/order/order-list/index'
});
},
jumpCollect() {
wx.navigateTo({
url: '/pages/usercenter/goods-collect/index'
});
},
jumpHistory() {
wx.navigateTo({
url: '/pages/usercenter/goods-history/index'
});
},
openMakePhone() {
this.setData({
showMakePhone: true
});
},
closeMakePhone() {
this.setData({
showMakePhone: false
});
},
call() {
wx.makePhoneCall({
phoneNumber: this.data.customerServiceInfo.servicePhone,
});
},
getOpenIdFun() {
wx.login({
success(res) {
getOpenId({
code: res.code
}).then((res) => {
wx.setStorageSync('openId', res.data)
})
},
});
},
gotoUserEditPage() {
const {
currAuthStep
} = this.data;
if (currAuthStep === 2) {
wx.navigateTo({
url: '/pages/usercenter/person-info/index'
});
} else {
// this.fetUseriInfoHandle();
}
},
// 获取客服列表
onGetCustomerServiceList() {
getCustomerServiceList().then((res) => {
if (res.code == 200) {
this.setData({
CustomerService: res.data[0]
})
}
})
},
});