fix 修改主题色,完善收货地址
This commit is contained in:
parent
1e70076d96
commit
c22a924221
@ -4038,7 +4038,7 @@ export const areaData = [
|
||||
children: [
|
||||
{
|
||||
label: '上海市',
|
||||
value: '310100',
|
||||
value: '310010',
|
||||
children: [
|
||||
{
|
||||
label: '黄浦区',
|
||||
|
@ -8,6 +8,7 @@ Page({
|
||||
* 页面的初始数据
|
||||
*/
|
||||
data: {
|
||||
back: true,
|
||||
bg_image: "",
|
||||
checked: true,
|
||||
code: ""
|
||||
@ -24,7 +25,13 @@ Page({
|
||||
}
|
||||
|
||||
// 登录请求
|
||||
login(data)
|
||||
login(data).then((res) => {
|
||||
if (res.data != null) {
|
||||
that.setData({
|
||||
back: false
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {}
|
||||
},
|
||||
|
||||
@ -76,9 +83,12 @@ Page({
|
||||
* 生命周期函数--监听页面卸载
|
||||
*/
|
||||
onUnload() {
|
||||
wx.navigateTo({
|
||||
url: `/pages/home/home`
|
||||
});
|
||||
let that = this
|
||||
if (that.data.back == true) {
|
||||
wx.reLaunch({
|
||||
url: '/pages/home/home'
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1,13 +1,25 @@
|
||||
import Toast from 'tdesign-miniprogram/toast/index';
|
||||
import { fetchDeliveryAddress } from '../../../../services/address/fetchAddress';
|
||||
import { areaData } from '../../../../config/index';
|
||||
import { resolveAddress, rejectAddress } from './util';
|
||||
import {
|
||||
fetchDeliveryAddress
|
||||
} from '~/services/address/fetchAddress';
|
||||
import {
|
||||
addOrUpdateAddress
|
||||
} from '~/services/address/addOrUpdateAddress';
|
||||
import {
|
||||
areaData
|
||||
} from '~/config/index';
|
||||
|
||||
|
||||
const innerPhoneReg = '^1(?:3\\d|4[4-9]|5[0-35-9]|6[67]|7[0-8]|8\\d|9\\d)\\d{8}$';
|
||||
const innerNameReg = '^[a-zA-Z\\d\\u4e00-\\u9fa5]+$';
|
||||
const labelsOptions = [
|
||||
{ id: 0, name: '家' },
|
||||
{ id: 1, name: '公司' },
|
||||
const labelsOptions = [{
|
||||
id: 0,
|
||||
name: '家'
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
name: '公司'
|
||||
},
|
||||
];
|
||||
|
||||
Page({
|
||||
@ -47,15 +59,17 @@ Page({
|
||||
privateData: {
|
||||
verifyTips: '',
|
||||
},
|
||||
|
||||
|
||||
onLoad(options) {
|
||||
const { id } = options;
|
||||
const {
|
||||
id
|
||||
} = options;
|
||||
this.init(id);
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
if (!this.hasSava) {
|
||||
rejectAddress();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hasSava: false,
|
||||
@ -65,10 +79,17 @@ Page({
|
||||
this.getAddressDetail(Number(id));
|
||||
}
|
||||
},
|
||||
|
||||
/** 获取收货地址详情 */
|
||||
getAddressDetail(id) {
|
||||
fetchDeliveryAddress(id).then((detail) => {
|
||||
this.setData({ locationState: detail }, () => {
|
||||
const { isLegal, tips } = this.onVerifyInputLegal();
|
||||
this.setData({
|
||||
locationState: detail
|
||||
}, () => {
|
||||
const {
|
||||
isLegal,
|
||||
tips
|
||||
} = this.onVerifyInputLegal();
|
||||
this.setData({
|
||||
submitActive: isLegal,
|
||||
});
|
||||
@ -76,12 +97,17 @@ Page({
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/** 地区Change事件 */
|
||||
onInputValue(e) {
|
||||
const { item } = e.currentTarget.dataset;
|
||||
const {
|
||||
item
|
||||
} = e.currentTarget.dataset;
|
||||
if (item === 'address') {
|
||||
const { selectedOptions = [] } = e.detail;
|
||||
this.setData(
|
||||
{
|
||||
const {
|
||||
selectedOptions = []
|
||||
} = e.detail;
|
||||
this.setData({
|
||||
'locationState.provinceCode': selectedOptions[0].value,
|
||||
'locationState.provinceName': selectedOptions[0].label,
|
||||
'locationState.cityName': selectedOptions[1].label,
|
||||
@ -91,7 +117,10 @@ Page({
|
||||
areaPickerVisible: false,
|
||||
},
|
||||
() => {
|
||||
const { isLegal, tips } = this.onVerifyInputLegal();
|
||||
const {
|
||||
isLegal,
|
||||
tips
|
||||
} = this.onVerifyInputLegal();
|
||||
this.setData({
|
||||
submitActive: isLegal,
|
||||
});
|
||||
@ -99,13 +128,17 @@ Page({
|
||||
},
|
||||
);
|
||||
} else {
|
||||
const { value = '' } = e.detail;
|
||||
this.setData(
|
||||
{
|
||||
const {
|
||||
value = ''
|
||||
} = e.detail;
|
||||
this.setData({
|
||||
[`locationState.${item}`]: value,
|
||||
},
|
||||
() => {
|
||||
const { isLegal, tips } = this.onVerifyInputLegal();
|
||||
const {
|
||||
isLegal,
|
||||
tips
|
||||
} = this.onVerifyInputLegal();
|
||||
this.setData({
|
||||
submitActive: isLegal,
|
||||
});
|
||||
@ -115,12 +148,18 @@ Page({
|
||||
}
|
||||
},
|
||||
onPickArea() {
|
||||
this.setData({ areaPickerVisible: true });
|
||||
this.setData({
|
||||
areaPickerVisible: true
|
||||
});
|
||||
},
|
||||
onPickLabels(e) {
|
||||
const { item } = e.currentTarget.dataset;
|
||||
const {
|
||||
locationState: { labelIndex = undefined },
|
||||
item
|
||||
} = e.currentTarget.dataset;
|
||||
const {
|
||||
locationState: {
|
||||
labelIndex = undefined
|
||||
},
|
||||
labels = [],
|
||||
} = this.data;
|
||||
let payload = {
|
||||
@ -128,7 +167,10 @@ Page({
|
||||
addressTag: labels[item].name,
|
||||
};
|
||||
if (item === labelIndex) {
|
||||
payload = { labelIndex: null, addressTag: '' };
|
||||
payload = {
|
||||
labelIndex: null,
|
||||
addressTag: ''
|
||||
};
|
||||
}
|
||||
this.setData({
|
||||
'locationState.labelIndex': payload.labelIndex,
|
||||
@ -141,10 +183,16 @@ Page({
|
||||
});
|
||||
},
|
||||
confirmHandle() {
|
||||
const { labels, labelValue } = this.data;
|
||||
const {
|
||||
labels,
|
||||
labelValue
|
||||
} = this.data;
|
||||
this.setData({
|
||||
visible: false,
|
||||
labels: [...labels, { id: labels[labels.length - 1].id + 1, name: labelValue }],
|
||||
labels: [...labels, {
|
||||
id: labels[labels.length - 1].id + 1,
|
||||
name: labelValue
|
||||
}],
|
||||
labelValue: '',
|
||||
});
|
||||
},
|
||||
@ -154,15 +202,25 @@ Page({
|
||||
labelValue: '',
|
||||
});
|
||||
},
|
||||
onCheckDefaultAddress({ detail }) {
|
||||
const { value } = detail;
|
||||
onCheckDefaultAddress({
|
||||
detail
|
||||
}) {
|
||||
const {
|
||||
value
|
||||
} = detail;
|
||||
this.setData({
|
||||
'locationState.isDefault': value,
|
||||
});
|
||||
},
|
||||
|
||||
/** 表单验证 */
|
||||
onVerifyInputLegal() {
|
||||
const { name, phone, detailAddress, districtName } = this.data.locationState;
|
||||
const {
|
||||
name,
|
||||
phone,
|
||||
detailAddress,
|
||||
districtName
|
||||
} = this.data.locationState;
|
||||
const prefixPhoneReg = String(this.properties.phoneReg || innerPhoneReg);
|
||||
const prefixNameReg = String(this.properties.nameReg || innerNameReg);
|
||||
const nameRegExp = new RegExp(prefixNameReg);
|
||||
@ -216,7 +274,10 @@ Page({
|
||||
};
|
||||
},
|
||||
|
||||
builtInSearch({ code, name }) {
|
||||
builtInSearch({
|
||||
code,
|
||||
name
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.getSetting({
|
||||
success: (res) => {
|
||||
@ -259,7 +320,10 @@ Page({
|
||||
},
|
||||
|
||||
onSearchAddress() {
|
||||
this.builtInSearch({ code: 'scope.userLocation', name: '地址位置' }).then(() => {
|
||||
this.builtInSearch({
|
||||
code: 'scope.userLocation',
|
||||
name: '地址位置'
|
||||
}).then(() => {
|
||||
wx.chooseLocation({
|
||||
success: (res) => {
|
||||
if (res.name) {
|
||||
@ -294,8 +358,12 @@ Page({
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/** 保存 */
|
||||
formSubmit() {
|
||||
const { submitActive } = this.data;
|
||||
const {
|
||||
submitActive
|
||||
} = this.data;
|
||||
if (!submitActive) {
|
||||
Toast({
|
||||
context: this,
|
||||
@ -306,46 +374,50 @@ Page({
|
||||
});
|
||||
return;
|
||||
}
|
||||
const { locationState } = this.data;
|
||||
const {
|
||||
locationState
|
||||
} = this.data;
|
||||
|
||||
this.hasSava = true;
|
||||
|
||||
resolveAddress({
|
||||
saasId: '88888888',
|
||||
uid: `88888888205500`,
|
||||
authToken: null,
|
||||
id: locationState.addressId,
|
||||
addressId: locationState.addressId,
|
||||
phone: locationState.phone,
|
||||
name: locationState.name,
|
||||
countryName: locationState.countryName,
|
||||
countryCode: locationState.countryCode,
|
||||
provinceName: locationState.provinceName,
|
||||
provinceCode: locationState.provinceCode,
|
||||
cityName: locationState.cityName,
|
||||
cityCode: locationState.cityCode,
|
||||
districtName: locationState.districtName,
|
||||
districtCode: locationState.districtCode,
|
||||
detailAddress: locationState.detailAddress,
|
||||
isDefault: locationState.isDefault === 1 ? 1 : 0,
|
||||
addressTag: locationState.addressTag,
|
||||
latitude: locationState.latitude,
|
||||
longitude: locationState.longitude,
|
||||
storeId: null,
|
||||
addOrUpdateAddress({
|
||||
CustomerAddressId: locationState.customerAddressId,
|
||||
CustomerAddressGuid: locationState.customerAddressGuid,
|
||||
// countryName: locationState.countryName, // 国家
|
||||
// countryCode: locationState.countryCode,
|
||||
ProvinceCode: locationState.provinceCode, // 省Code
|
||||
CityCode: locationState.cityCode, // 市Code
|
||||
DistrictCode: locationState.districtCode, // 区Code
|
||||
CustomerAddressPhone: locationState.phone, // 手机号
|
||||
CustomerAddressName: locationState.name, // 收货人
|
||||
CustomerAddressDetailed: locationState.detailAddress, // 地址
|
||||
IsDefault: locationState.isDefault === true ? 1 : 0, // 是否为默认地址
|
||||
}).then((res) => {
|
||||
wx.reLaunch({
|
||||
url: '/pages/usercenter/address/list/index',
|
||||
})
|
||||
});
|
||||
|
||||
wx.navigateBack({ delta: 1 });
|
||||
},
|
||||
|
||||
|
||||
/** 获取微信地址 */
|
||||
getWeixinAddress(e) {
|
||||
const { locationState } = this.data;
|
||||
const {
|
||||
locationState
|
||||
} = this.data;
|
||||
const weixinAddress = e.detail;
|
||||
this.setData(
|
||||
{
|
||||
locationState: { ...locationState, ...weixinAddress },
|
||||
this.setData({
|
||||
locationState: {
|
||||
...locationState,
|
||||
...weixinAddress
|
||||
},
|
||||
},
|
||||
() => {
|
||||
const { isLegal, tips } = this.onVerifyInputLegal();
|
||||
const {
|
||||
isLegal,
|
||||
tips
|
||||
} = this.onVerifyInputLegal();
|
||||
this.setData({
|
||||
submitActive: isLegal,
|
||||
});
|
||||
|
@ -69,7 +69,7 @@
|
||||
</t-cell>
|
||||
|
||||
<view class="divider-line" />
|
||||
<t-cell
|
||||
<!-- <t-cell
|
||||
class="form-cell"
|
||||
t-class-note="t-cell-note address__tag"
|
||||
t-class-title="t-cell-title"
|
||||
@ -92,7 +92,7 @@
|
||||
<t-icon name="add" size="40rpx" color="#bbb" />
|
||||
</t-button>
|
||||
</view>
|
||||
</t-cell>
|
||||
</t-cell> -->
|
||||
<view class="divider-line" />
|
||||
<t-cell title="设置为默认收货地址" bordered="{{false}}">
|
||||
<t-switch
|
||||
|
@ -1,33 +0,0 @@
|
||||
let addressPromise = [];
|
||||
|
||||
/** 地址编辑Promise */
|
||||
export const getAddressPromise = () => {
|
||||
let resolver;
|
||||
let rejecter;
|
||||
const nextPromise = new Promise((resolve, reject) => {
|
||||
resolver = resolve;
|
||||
rejecter = reject;
|
||||
});
|
||||
|
||||
addressPromise.push({ resolver, rejecter });
|
||||
|
||||
return nextPromise;
|
||||
};
|
||||
|
||||
/** 用户保存了一个地址 */
|
||||
export const resolveAddress = (address) => {
|
||||
const allAddress = [...addressPromise];
|
||||
addressPromise = [];
|
||||
|
||||
console.info('用户保存了一个地址', address);
|
||||
|
||||
allAddress.forEach(({ resolver }) => resolver(address));
|
||||
};
|
||||
|
||||
/** 取消编辑 */
|
||||
export const rejectAddress = () => {
|
||||
const allAddress = [...addressPromise];
|
||||
addressPromise = [];
|
||||
|
||||
allAddress.forEach(({ rejecter }) => rejecter(new Error('cancel')));
|
||||
};
|
@ -1,14 +1,13 @@
|
||||
/* eslint-disable no-param-reassign */
|
||||
import { fetchDeliveryAddressList } from '../../../../services/address/fetchAddress';
|
||||
import { fetchDeliveryAddressList } from '~/services/address/fetchAddress';
|
||||
import Toast from 'tdesign-miniprogram/toast/index';
|
||||
import { resolveAddress, rejectAddress } from './util';
|
||||
import { getAddressPromise } from '../edit/util';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
addressList: [],
|
||||
deleteID: '',
|
||||
showDeleteConfirm: false,
|
||||
showDeleteConfirm: true,
|
||||
isOrderSure: false,
|
||||
},
|
||||
|
||||
@ -26,26 +25,29 @@ Page({
|
||||
this.selectMode = !!selectMode;
|
||||
this.init();
|
||||
},
|
||||
|
||||
init() {
|
||||
this.getAddressList();
|
||||
},
|
||||
onUnload() {
|
||||
if (this.selectMode && !this.hasSelect) {
|
||||
rejectAddress();
|
||||
rejectAddress(this.data.addressList);
|
||||
}
|
||||
},
|
||||
|
||||
/** 获取收货地址列表 */
|
||||
getAddressList() {
|
||||
const { id } = this.data;
|
||||
fetchDeliveryAddressList().then((addressList) => {
|
||||
addressList.forEach((address) => {
|
||||
if (address.id === id) {
|
||||
if (address.customerAddressGuid === id) {
|
||||
address.checked = true;
|
||||
}
|
||||
});
|
||||
this.setData({ addressList });
|
||||
});
|
||||
},
|
||||
|
||||
/** 获取微信地址 */
|
||||
getWXAddressHandle() {
|
||||
wx.chooseAddress({
|
||||
success: (res) => {
|
||||
@ -80,6 +82,8 @@ Page({
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
/** 删除地址操作 */
|
||||
confirmDeleteHandle({ detail }) {
|
||||
const { id } = detail || {};
|
||||
if (id !== undefined) {
|
||||
@ -109,83 +113,25 @@ Page({
|
||||
showDeleteConfirm: false,
|
||||
});
|
||||
},
|
||||
editAddressHandle({ detail }) {
|
||||
this.waitForNewAddress();
|
||||
|
||||
const { id } = detail || {};
|
||||
wx.navigateTo({ url: `/pages/usercenter/address/edit/index?id=${id}` });
|
||||
/** 跳转编辑 */
|
||||
editAddressHandle({ detail }) {
|
||||
const { customerAddressId } = detail || {};
|
||||
wx.navigateTo({ url: `/pages/usercenter/address/edit/index?id=${customerAddressId}` });
|
||||
},
|
||||
selectHandle({ detail }) {
|
||||
if (this.selectMode) {
|
||||
this.hasSelect = true;
|
||||
resolveAddress(detail);
|
||||
resolveAddress(this.data.addressList,detail);
|
||||
wx.navigateBack({ delta: 1 });
|
||||
} else {
|
||||
this.editAddressHandle({ detail });
|
||||
}
|
||||
},
|
||||
|
||||
/** 跳转添加 */
|
||||
createHandle() {
|
||||
this.waitForNewAddress();
|
||||
wx.navigateTo({ url: '/pages/usercenter/address/edit/index' });
|
||||
},
|
||||
|
||||
waitForNewAddress() {
|
||||
getAddressPromise()
|
||||
.then((newAddress) => {
|
||||
let addressList = [...this.data.addressList];
|
||||
|
||||
newAddress.phoneNumber = newAddress.phone;
|
||||
newAddress.address = `${newAddress.provinceName}${newAddress.cityName}${newAddress.districtName}${newAddress.detailAddress}`;
|
||||
newAddress.tag = newAddress.addressTag;
|
||||
|
||||
if (!newAddress.addressId) {
|
||||
newAddress.id = `${addressList.length}`;
|
||||
newAddress.addressId = `${addressList.length}`;
|
||||
|
||||
if (newAddress.isDefault === 1) {
|
||||
addressList = addressList.map((address) => {
|
||||
address.isDefault = 0;
|
||||
|
||||
return address;
|
||||
});
|
||||
} else {
|
||||
newAddress.isDefault = 0;
|
||||
}
|
||||
|
||||
addressList.push(newAddress);
|
||||
} else {
|
||||
addressList = addressList.map((address) => {
|
||||
if (address.addressId === newAddress.addressId) {
|
||||
return newAddress;
|
||||
}
|
||||
return address;
|
||||
});
|
||||
}
|
||||
|
||||
addressList.sort((prevAddress, nextAddress) => {
|
||||
if (prevAddress.isDefault && !nextAddress.isDefault) {
|
||||
return -1;
|
||||
}
|
||||
if (!prevAddress.isDefault && nextAddress.isDefault) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
this.setData({
|
||||
addressList: addressList,
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
if (e.message !== 'cancel') {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: '地址编辑发生错误',
|
||||
icon: '',
|
||||
duration: 1000,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
@ -11,7 +11,7 @@
|
||||
extra-space="{{extraSpace}}"
|
||||
class-prefix="ym"
|
||||
address="{{address}}"
|
||||
data-id="{{address.id}}"
|
||||
data-id="{{address.customerAddressGuid}}"
|
||||
bind:onSelect="selectHandle"
|
||||
bind:onDelete="deleteAddressHandle"
|
||||
bind:onEdit="editAddressHandle"
|
||||
@ -33,7 +33,7 @@
|
||||
isCustomStyle="{{true}}"
|
||||
bind:navigate="waitForNewAddress"
|
||||
/>
|
||||
<view class="address-btn {{addressList.length >= 20 ? 'btn-default':''}}" bind:tap="createHandle">
|
||||
<view class="address-btn root-bg-color {{addressList.length >= 20 ? 'btn-default':''}}" bind:tap="createHandle">
|
||||
<t-icon
|
||||
name="add"
|
||||
size="48rpx"
|
||||
|
@ -82,7 +82,7 @@ page {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
background-color: #fa4126;
|
||||
/* background-color: #fa4126; */
|
||||
border-radius: 44rpx;
|
||||
color: #fff;
|
||||
}
|
||||
|
@ -15,17 +15,11 @@ export const getAddressPromise = () => {
|
||||
};
|
||||
|
||||
/** 用户选择了一个地址 */
|
||||
export const resolveAddress = (address) => {
|
||||
const allAddress = [...addressPromise];
|
||||
addressPromise = [];
|
||||
|
||||
export const resolveAddress = (allAddress,address) => {
|
||||
allAddress.forEach(({ resolver }) => resolver(address));
|
||||
};
|
||||
|
||||
/** 用户没有选择任何地址只是返回上一页了 */
|
||||
export const rejectAddress = () => {
|
||||
const allAddress = [...addressPromise];
|
||||
addressPromise = [];
|
||||
|
||||
export const rejectAddress = (allAddress) => {
|
||||
allAddress.forEach(({ rejecter }) => rejecter(new Error('cancel')));
|
||||
};
|
||||
|
@ -15,8 +15,8 @@
|
||||
</view>
|
||||
<view class="label-adds">
|
||||
<text class="adds address-info-class">
|
||||
<text wx:if="{{address.isDefault === 1}}" class="tag tag-default default-tag-class">默认</text>
|
||||
<text wx:if="{{address.tag}}" class="tag tag-primary normal-tag-class">{{address.tag}}</text>
|
||||
<text wx:if="{{address.isDefault === true}}" class="tag tag-default default-tag-class">默认</text>
|
||||
<!-- <text wx:if="{{address.tag}}" class="tag tag-primary normal-tag-class">{{address.tag}}</text> -->
|
||||
<text class="address-text">{{address.address}}</text>
|
||||
</text>
|
||||
</view>
|
||||
|
@ -1,5 +1,12 @@
|
||||
import { fetchPerson } from '../../../services/usercenter/fetchPerson';
|
||||
import { phoneEncryption } from '../../../utils/util';
|
||||
import {
|
||||
fetchPerson
|
||||
} from '~/services/usercenter/fetchPerson';
|
||||
import {
|
||||
updatePerson
|
||||
} from '~/services/usercenter/updatePerson';
|
||||
import {
|
||||
phoneEncryption
|
||||
} from '~/utils/util';
|
||||
import Toast from 'tdesign-miniprogram/toast/index';
|
||||
|
||||
Page({
|
||||
@ -11,8 +18,7 @@ Page({
|
||||
phoneNumber: '',
|
||||
},
|
||||
showUnbindConfirm: false,
|
||||
pickerOptions: [
|
||||
{
|
||||
pickerOptions: [{
|
||||
name: '男',
|
||||
code: '1',
|
||||
},
|
||||
@ -30,17 +36,51 @@ Page({
|
||||
init() {
|
||||
this.fetchData();
|
||||
},
|
||||
|
||||
fetchData() {
|
||||
fetchPerson().then((personInfo) => {
|
||||
fetchPerson().then(({
|
||||
personInfo
|
||||
}) => {
|
||||
this.setData({
|
||||
personInfo,
|
||||
'personInfo.phoneNumber': phoneEncryption(personInfo.phoneNumber),
|
||||
});
|
||||
});
|
||||
},
|
||||
onClickCell({ currentTarget }) {
|
||||
const { dataset } = currentTarget;
|
||||
const { nickName } = this.data.personInfo;
|
||||
|
||||
/** 提交 */
|
||||
submit() {
|
||||
let personInfo = this.data.personInfo
|
||||
let data = {
|
||||
customerAvatar: personInfo.avatarUrl,
|
||||
customerNickname: personInfo.nickName,
|
||||
customerGender: personInfo.gender,
|
||||
}
|
||||
updatePerson(data).then((res) => {
|
||||
if (res.code == 200) {
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: `保存成功`,
|
||||
theme: 'success',
|
||||
})
|
||||
wx.reLaunch({
|
||||
url: `/pages/usercenter/index`,
|
||||
});
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/** 点击单元格 */
|
||||
onClickCell({
|
||||
currentTarget
|
||||
}) {
|
||||
const {
|
||||
dataset
|
||||
} = currentTarget;
|
||||
const {
|
||||
nickName
|
||||
} = this.data.personInfo;
|
||||
|
||||
switch (dataset.type) {
|
||||
case 'gender':
|
||||
@ -67,9 +107,10 @@ Page({
|
||||
});
|
||||
},
|
||||
onConfirm(e) {
|
||||
const { value } = e.detail;
|
||||
this.setData(
|
||||
{
|
||||
const {
|
||||
value
|
||||
} = e.detail;
|
||||
this.setData({
|
||||
typeVisible: false,
|
||||
'personInfo.gender': value,
|
||||
},
|
||||
@ -83,7 +124,17 @@ Page({
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
/** 修改昵称 */
|
||||
changeNickName(e) {
|
||||
this.setData({
|
||||
'personInfo.nickName': e.detail.value
|
||||
})
|
||||
},
|
||||
|
||||
/** 修改头像 */
|
||||
async toModifyAvatar() {
|
||||
let that = this
|
||||
try {
|
||||
const tempFilePath = await new Promise((resolve, reject) => {
|
||||
wx.chooseImage({
|
||||
@ -91,24 +142,47 @@ Page({
|
||||
sizeType: ['compressed'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: (res) => {
|
||||
const { path, size } = res.tempFiles[0];
|
||||
const {
|
||||
path,
|
||||
size
|
||||
} = res.tempFiles[0];
|
||||
const tempFilePaths = res.tempFilePaths;
|
||||
let tempFilePath = tempFilePaths[0];
|
||||
// 上传图片到服务器
|
||||
wx.uploadFile({
|
||||
url: 'http://localhost:8888/api/Common/UploadFile', // 上传接口地址
|
||||
filePath: tempFilePath, // 要上传的文件的临时路径
|
||||
name: 'file', // 上传文件对应的字段名
|
||||
success: function (uploadRes) {
|
||||
// 上传成功,服务器返回的数据
|
||||
let url = JSON.parse(uploadRes.data).data.url
|
||||
that.setData({
|
||||
'personInfo.avatarUrl': url
|
||||
})
|
||||
|
||||
},
|
||||
fail: function (uploadError) {
|
||||
// 上传失败,处理错误
|
||||
console.error(uploadError);
|
||||
}
|
||||
});
|
||||
if (size <= 10485760) {
|
||||
resolve(path);
|
||||
} else {
|
||||
reject({ errMsg: '图片大小超出限制,请重新上传' });
|
||||
reject({
|
||||
errMsg: '图片大小超出限制,请重新上传'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => reject(err),
|
||||
});
|
||||
});
|
||||
const tempUrlArr = tempFilePath.split('/');
|
||||
const tempFileName = tempUrlArr[tempUrlArr.length - 1];
|
||||
Toast({
|
||||
context: this,
|
||||
selector: '#t-toast',
|
||||
message: `已选择图片-${tempFileName}`,
|
||||
message: `头像上传成功`,
|
||||
theme: 'success',
|
||||
});
|
||||
})
|
||||
} catch (error) {
|
||||
if (error.errMsg === 'chooseImage:fail cancel') return;
|
||||
Toast({
|
||||
|
@ -7,6 +7,9 @@
|
||||
"t-image": "/components/webp-image/index",
|
||||
"t-dialog": "tdesign-miniprogram/dialog/dialog",
|
||||
"t-toast": "tdesign-miniprogram/toast/toast",
|
||||
"t-select-picker": "../components/ui-select-picker/index"
|
||||
"t-select-picker": "../components/ui-select-picker/index",
|
||||
"t-upload": "tdesign-miniprogram/upload/upload",
|
||||
"t-avatar": "tdesign-miniprogram/avatar/avatar",
|
||||
"t-input": "tdesign-miniprogram/input/input"
|
||||
}
|
||||
}
|
@ -8,17 +8,10 @@
|
||||
arrow
|
||||
t-class-left="order-group__left"
|
||||
>
|
||||
<t-image slot="note" src="{{personInfo.avatarUrl}}" t-class="avatarUrl" mode="aspectFill" />
|
||||
<t-avatar slot="note" image="{{personInfo.avatarUrl}}" class="user-center-card__header__avatar" />
|
||||
<!-- <t-image slot="note" src="{{personInfo.avatarUrl}}" t-class="avatarUrl" mode="aspectFill" /> -->
|
||||
</t-cell>
|
||||
<t-cell
|
||||
title="昵称"
|
||||
arrow
|
||||
note="{{personInfo.nickName}}"
|
||||
data-type="name"
|
||||
bind:click="onClickCell"
|
||||
t-class="t-cell-class"
|
||||
t-class-left="order-group__left"
|
||||
/>
|
||||
<t-input value="{{ personInfo.nickName }}" label="昵称" placeholder="请输入昵称" align="right" bindchange="changeNickName" />
|
||||
<t-cell
|
||||
title="性别"
|
||||
arrow
|
||||
@ -41,7 +34,7 @@
|
||||
</t-cell-group>
|
||||
</view>
|
||||
<view class="person-info__wrapper">
|
||||
<view class="person-info__btn" bind:tap="openUnbindConfirm"> 切换账号登录 </view>
|
||||
<view class="person-info__btn root-bg-color" bind:tap="submit"> 保存 </view>
|
||||
</view>
|
||||
<t-select-picker
|
||||
show="{{typeVisible}}"
|
||||
|
@ -10,6 +10,7 @@ page view {
|
||||
|
||||
.person-info__btn {
|
||||
width: 100%;
|
||||
color: white;
|
||||
border: 2rpx solid #ddd;
|
||||
border-radius: 48rpx;
|
||||
padding: 18rpx 0;
|
||||
@ -21,9 +22,10 @@ page view {
|
||||
width: 100%;
|
||||
padding: 0 32rpx;
|
||||
padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
margin-top: 100rpx;
|
||||
/* position: absolute; */
|
||||
/* bottom: 0; */
|
||||
/* left: 0; */
|
||||
}
|
||||
|
||||
.avatarUrl {
|
||||
@ -43,3 +45,10 @@ page view {
|
||||
.person-info .t-cell-class {
|
||||
height: 112rpx;
|
||||
}
|
||||
|
||||
.user-center-card__header__avatar {
|
||||
width: 96rpx;
|
||||
height: 96rpx;
|
||||
border-radius: 48rpx;
|
||||
overflow: hidden;
|
||||
}
|
@ -24,7 +24,7 @@ export function request(option) {
|
||||
header: {
|
||||
Authorization: `Bearer ${getStorage('Authorization')}`,
|
||||
},
|
||||
timeout: 30000, //设置超时时间
|
||||
timeout: 50000, //设置超时时间
|
||||
url: ServerBasePath + url,
|
||||
data: data,
|
||||
method: method,
|
||||
|
22
services/address/addOrUpdateAddress.js
Normal file
22
services/address/addOrUpdateAddress.js
Normal file
@ -0,0 +1,22 @@
|
||||
import {
|
||||
request
|
||||
} from '../_utils/request';
|
||||
|
||||
|
||||
/** 编辑个人资料 */
|
||||
export function addOrUpdateAddress(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `CustomerAddressApi/addOrUpdateCustomerAddress`,
|
||||
method: 'POST',
|
||||
data: data,
|
||||
success: function (res) {
|
||||
|
||||
resolve(res);
|
||||
},
|
||||
fail: function (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@ -1,48 +1,42 @@
|
||||
import { config } from '../../config/index';
|
||||
import {
|
||||
request
|
||||
} from '../_utils/request';
|
||||
|
||||
/** 获取收货地址 */
|
||||
function mockFetchDeliveryAddress(id) {
|
||||
const { delay } = require('../_utils/delay');
|
||||
const { genAddress } = require('../../model/address');
|
||||
|
||||
return delay().then(() => genAddress(id));
|
||||
}
|
||||
/** 获取收货地址详情 */
|
||||
export function fetchDeliveryAddress(id) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `CustomerAddressApi/getCustomerAddressDetails?CustomerAddressId=` + id,
|
||||
method: 'GET',
|
||||
success: function (res) {
|
||||
let detail = res.data;
|
||||
|
||||
/** 获取收货地址 */
|
||||
export function fetchDeliveryAddress(id = 0) {
|
||||
if (config.useMock) {
|
||||
return mockFetchDeliveryAddress(id);
|
||||
resolve(detail);
|
||||
},
|
||||
fail: function (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
resolve('real api');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取收货地址列表 */
|
||||
function mockFetchDeliveryAddressList(len = 0) {
|
||||
const { delay } = require('../_utils/delay');
|
||||
const { genAddressList } = require('../../model/address');
|
||||
|
||||
return delay().then(() =>
|
||||
genAddressList(len).map((address) => {
|
||||
return {
|
||||
...address,
|
||||
phoneNumber: address.phone,
|
||||
address: `${address.provinceName}${address.cityName}${address.districtName}${address.detailAddress}`,
|
||||
tag: address.addressTag,
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/** 获取收货地址列表 */
|
||||
export function fetchDeliveryAddressList(len = 10) {
|
||||
if (config.useMock) {
|
||||
return mockFetchDeliveryAddressList(len);
|
||||
export function fetchDeliveryAddressList() {
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `CustomerAddressApi/getCustomerAddressList`,
|
||||
method: 'GET',
|
||||
success: function (res) {
|
||||
let list = res.data;
|
||||
|
||||
resolve(list);
|
||||
},
|
||||
fail: function (error) {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
resolve('real api');
|
||||
});
|
||||
});
|
||||
}
|
23
services/address/getRegionTreeList.js
Normal file
23
services/address/getRegionTreeList.js
Normal file
@ -0,0 +1,23 @@
|
||||
import {
|
||||
request
|
||||
} from '../_utils/request';
|
||||
|
||||
|
||||
/** 获取省市区树形列表 */
|
||||
export function getRegionTreeList() {
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `RegionApi/getRegionTreeList`,
|
||||
method: 'GET',
|
||||
success: function (res) {
|
||||
let list = res.data;
|
||||
|
||||
resolve(list);
|
||||
},
|
||||
fail: function (error) {
|
||||
console.log(error,'报错');
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@ -8,7 +8,7 @@ import {
|
||||
|
||||
/** 登录 */
|
||||
export function login(data) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `WeChatLogin/Login`,
|
||||
method: 'POST',
|
||||
@ -19,14 +19,17 @@ export function login(data) {
|
||||
const pages = getCurrentPages(); //获取小程序页面栈
|
||||
const beforePage = pages[pages.length - 1]; //获取上个页面的实例对象 -3是上上一个页面
|
||||
wx.navigateBack({
|
||||
delta: 2,
|
||||
delta: 1,
|
||||
});
|
||||
beforePage.onLoad();
|
||||
wx.showToast({
|
||||
icon: 'success',
|
||||
title: '登录成功',
|
||||
});
|
||||
resolve(res);
|
||||
},
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
}
|
@ -8,14 +8,16 @@ import {
|
||||
|
||||
/** 发送验证码 */
|
||||
export function sendPhoneCode(data) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `WeChatLogin/sendPhoneCode`,
|
||||
method: 'POST',
|
||||
data: data,
|
||||
success: async function (res) {
|
||||
|
||||
resolve(res);
|
||||
},
|
||||
});
|
||||
})
|
||||
|
||||
}
|
@ -1,28 +1,32 @@
|
||||
import { config } from '../../config/index';
|
||||
import {
|
||||
request
|
||||
} from '../_utils/request';
|
||||
import {
|
||||
getStorage
|
||||
} from '~/utils/storage'
|
||||
const userData = getStorage('userInfo');
|
||||
|
||||
/** 获取个人中心信息 */
|
||||
function mockFetchPerson() {
|
||||
const { delay } = require('../_utils/delay');
|
||||
const { genSimpleUserInfo } = require('../../model/usercenter');
|
||||
const { genAddress } = require('../../model/address');
|
||||
const address = genAddress();
|
||||
return delay().then(() => ({
|
||||
...genSimpleUserInfo(),
|
||||
address: {
|
||||
provinceName: address.provinceName,
|
||||
provinceCode: address.provinceCode,
|
||||
cityName: address.cityName,
|
||||
cityCode: address.cityCode,
|
||||
},
|
||||
}));
|
||||
}
|
||||
|
||||
/** 获取个人中心信息 */
|
||||
/** 获取个人中心详情信息 */
|
||||
export function fetchPerson() {
|
||||
if (config.useMock) {
|
||||
return mockFetchPerson();
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `CustomerApi/getCustomerDetails?CustomerGuid=` + userData?.customerGuid,
|
||||
method: 'GET',
|
||||
success: function (res) {
|
||||
let personInfo = res.data;
|
||||
let data = {
|
||||
personInfo: {
|
||||
avatarUrl: personInfo.customerAvatar,
|
||||
nickName: personInfo.customerNickname,
|
||||
phoneNumber: personInfo.customerMobilePhoneNumber,
|
||||
gender : personInfo.customerGender,
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
resolve('real api');
|
||||
};
|
||||
resolve(data);
|
||||
},
|
||||
fail: function (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@ -17,17 +17,14 @@ export function logout() {
|
||||
removeStorage('userInfo')
|
||||
removeStorage('Authorization')
|
||||
|
||||
// 回到上一页
|
||||
const pages = getCurrentPages(); //获取小程序页面栈
|
||||
const beforePage = pages[pages.length - 1]; //获取上个页面的实例对象 -3是上上一个页面
|
||||
wx.navigateBack({
|
||||
delta: 2,
|
||||
});
|
||||
beforePage.onLoad();
|
||||
// 回到首页
|
||||
wx.showToast({
|
||||
icon: 'success',
|
||||
title: '登出成功',
|
||||
});
|
||||
wx.reLaunch({
|
||||
url: '/pages/home/home'
|
||||
})
|
||||
resolve(res);
|
||||
},
|
||||
fail: function (error) {
|
||||
|
22
services/usercenter/updatePerson.js
Normal file
22
services/usercenter/updatePerson.js
Normal file
@ -0,0 +1,22 @@
|
||||
import {
|
||||
request
|
||||
} from '../_utils/request';
|
||||
|
||||
|
||||
/** 编辑个人资料 */
|
||||
export function updatePerson(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
request({
|
||||
url: `CustomerApi/UpdateCustomer`,
|
||||
method: 'POST',
|
||||
data: data,
|
||||
success: function (res) {
|
||||
|
||||
resolve(res);
|
||||
},
|
||||
fail: function (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
/* 主题定制 */
|
||||
.root-bg-color{
|
||||
background-color: #1989fa;
|
||||
}
|
||||
|
||||
.t-input {
|
||||
--td-input-placeholder-text-color: #bbbbbb;
|
||||
--td-input-text-color: #333333;
|
||||
@ -10,7 +14,7 @@
|
||||
}
|
||||
|
||||
.t-cascader {
|
||||
--td-cascader-active-color: #fa4126;
|
||||
--td-cascader-active-color: #1989fa;
|
||||
}
|
||||
|
||||
.t-switch {
|
||||
@ -21,13 +25,13 @@
|
||||
--td-button-font-weight: 500;
|
||||
--td-button-medium-font-size: 32rpx;
|
||||
--td-button-default-color: #fff;
|
||||
--td-button-default-bg-color: #fa4126;
|
||||
--td-button-default-border-color: #fa4126;
|
||||
--td-button-default-bg-color: #1989fa;
|
||||
--td-button-default-border-color: #1989fa;
|
||||
--td-button-default-disabled-color: #fff;
|
||||
--td-button-default-disabled-bg: #cccccc;
|
||||
--td-button-default-disabled-border-color: #cccccc;
|
||||
--td-button-default-active-bg-color: #fa4126;
|
||||
--td-button-default-active-border-color: #fa4126;
|
||||
--td-button-default-active-bg-color: #1989fa;
|
||||
--td-button-default-active-border-color: #1989fa;
|
||||
}
|
||||
|
||||
.t-textarea {
|
||||
@ -35,11 +39,11 @@
|
||||
}
|
||||
|
||||
.t-checkbox {
|
||||
--td-checkbox-icon-checked-color: #fa4126;
|
||||
--td-checkbox-icon-checked-color: #1989fa;
|
||||
}
|
||||
|
||||
.dialog__button-confirm {
|
||||
color: #fa4126 !important;
|
||||
color: #1989fa !important;
|
||||
}
|
||||
|
||||
.dialog__button-cancel {
|
||||
|
Loading…
Reference in New Issue
Block a user