Commit 0cd0b2c2 by 赵雅纹

我的地址和新增地址

parent d999c866
// pages/addAddress/addAddress.js
const wxService = require('../../utils/wxService')
const { memberId } = wx.getStorageSync('_baseUserInfo')
wxService.page({
......@@ -8,6 +9,7 @@ wxService.page({
* 页面的初始数据
*/
data: {
id:'',
isSelect:true,
citys: null,
cityView: '',
......@@ -15,7 +17,15 @@ wxService.page({
formData: {},
selectCityName: ['', ''],
multiIndex: [0, 0, 0],
focus: false
focus: false,
params:{
userId:'',
name:'',
phone:'',
fullArea:'',
address:'',
type:1
},
},
/**
......@@ -23,39 +33,34 @@ wxService.page({
*/
onLoad: function (options) {
console.log(options)
if(options.id){
if (options && options.id){
wx.setNavigationBarTitle({
title: '编辑地址'
})
this.setData({
addressId: options.id
addressId: options.id,
id: options.id
})
}else{
wx.setNavigationBarTitle({
title: '新增地址'
})
}
this.init(options)
},
init(options) {
const id = options.id
if (id) {
const addressItem = pageParmas.getObject('addressItem')
if (addressItem) {
let cityView = ''
if (addressItem.districtName) {
cityView = addressItem.districtName.replace(/,/g, ' ')
}
this.setData({
formData: addressItem,
isDefault: addressItem.isDefault,
id,
cityView
})
}
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.init()
if(this.data.id){
this.getAddressInfo()
}
},
init() {
wxService.getC1().then((c1) => {
return wxService.Promise.all([wxService.Promise.resolve(c1), wxService.getC2ByC1('北京'), wxService.getC3ByC2('北京北京市')])
}).then(res => {
......@@ -68,6 +73,38 @@ wxService.page({
})
},
// 通过地址id查询
getAddressInfo(){
wxService.post(`/member/addressManage/getbyid?id=${this.data.id}`).then(res => {
const { result, data } = res.data
if (result == 0) {
this.setData({
params: {
userId: data.userId,
name: data.name,
phone: data.phone,
fullArea: data.fullArea,
address: data.address,
type: data.type
},
isSelect: data.type,
cityView: data.fullArea
})
wxService.getC1().then((c1) => {
return wxService.Promise.all([wxService.Promise.resolve(c1), wxService.getC2ByC1('北京'), wxService.getC3ByC2('北京北京市')])
}).then(res => {
const citys = res.map(item => {
return [...item]
})
this.setData({
citys
})
})
}
}).finally(() => {
})
},
bindMultiPickerChange(e) {
const citys = this.data.citys
const multiIndex = e.detail.value
......@@ -115,16 +152,91 @@ wxService.page({
}
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
settingDefaultAddress(){
this.setData({
isSelect: !this.data.isSelect
})
},
//提交
formSubmit(e){
if (!e.detail.value.name){
wx.showToast({
title: `请输入姓名`,
icon: 'none'
})
return false;
}
if (!e.detail.value.phone) {
wx.showToast({
title: `请输入电话`,
icon: 'none'
})
return false;
}
if (!this.data.cityView) {
wx.showToast({
title: `请选择地区`,
icon: 'none'
})
return false;
}
if (!e.detail.value.address) {
wx.showToast({
title: `请输入详细地址`,
icon: 'none'
})
return false;
}
this.setData({
params:{
userId: memberId,
name: e.detail.value.name,
phone: e.detail.value.phone,
fullArea: this.data.cityView,
address: e.detail.value.address,
type: this.data.isSelect ? 1 : 0
}
})
wx.showLoading({
title: '加载中'
})
if (this.data.addressId){
this.setData({
'params.id': this.data.id
})
wxService.post(`/member/addressManage/update`, this.data.params).then(res => {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
wx.showToast({
title: `修改成功`,
icon: 'none'
})
wxService.router(`/pages/myAddress/myAddress`)
}
}).finally(() => {
wx.hideLoading()
})
}else{
wxService.post(`/member/addressManage/save`, this.data.params).then(res => {
const { result, data } = res.data
if (result == 0) {
wx.hideLoading()
wx.showToast({
title: `保存成功`,
icon: 'none'
})
wxService.router(`/pages/myAddress/myAddress`)
}
}).finally(() => {
wx.hideLoading()
})
}
}
})
\ No newline at end of file
<!--pages/addAddress/addAddress.wxml-->
<view class="page-add-address">
<view class="form-section">
<form>
<form bindsubmit="formSubmit">
<view class="form">
<view class="form-label">姓名</view>
<input class="form-input" placeholder-class="placeholder-picker" name="input" placeholder="请输入收货人真实姓名" />
<input class="form-input" value="{{params.name}}" placeholder-class="placeholder-picker" name="name" placeholder="请输入收货人真实姓名" />
</view>
<view class="form">
<view class="form-label">电话</view>
<input class="form-input" placeholder-class="placeholder-picker" name="input" placeholder="请输入收货人手机号" />
<input class="form-input" value="{{params.phone}}" placeholder-class="placeholder-picker" name="phone" placeholder="请输入收货人手机号" type="number" maxlength="11" />
</view>
<view class="form">
<view class="form-label">地区</view>
......@@ -23,7 +23,7 @@
</view>
<view class="form">
<view class="form-label">详细地址</view>
<input class="form-input" placeholder-class="placeholder-picker" name="input" placeholder="请输入街道、楼牌号" />
<input class="form-input" value="{{params.address}}" placeholder-class="placeholder-picker" name="address" placeholder="请输入街道、楼牌号" />
</view>
<view class="default-address" bindtap="settingDefaultAddress">
<view class="{{isSelect ? 'theme-color' : ''}} circle-radio" >
......@@ -32,7 +32,7 @@
<text class="setting-default">设为默认地址</text>
</view>
<view class="address-bottom">
<button class="address-btn theme-color">{{addressId ? '保存并使用' : '保存收货地址'}}</button>
<button form-type="submit" class="address-btn theme-color">{{addressId ? '保存并使用' : '保存收货地址'}}</button>
</view>
</form>
</view>
......
......@@ -16,6 +16,7 @@
min-width: 104rpx;
}
.form-input{
width: 604rpx;
font-size: 28rpx;
color: #333333;
height: 82rpx;
......
// pages/myAddress/myAddress.js
Page({
const app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo
wxService.page({
/**
* 页面的初始数据
*/
data: {
isSelect:0,
addressList:[
{
name:'111',
phone:'211',
address:'JKDHFJHDF',
shows:''
},
{
name: '111',
phone: '211',
address: 'JKDHFJHDF',
shows:''
}
],
isScroll: true,
addressList:[],
startX: '',
delBtnWidth: 66,//删除按钮宽度单位(rpx)
delBtnWidth: 132,//删除按钮宽度单位(rpx)
},
/**
......@@ -36,7 +29,23 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getAddressList()
},
// 获取地址列表
getAddressList(){
const { memberId } = wx.getStorageSync('_baseUserInfo')
wxService.post(`/member/addressManage/getall?userId=${memberId}`).then(res => {
if (!res) return false
const { result, data } = res.data
if (result == 0) {
this.setData({
addressList: data
})
}
}).finally(() => {
})
},
......@@ -58,81 +67,92 @@ Page({
//设置默认地址
settingDefalutAddress(e){
console.log(e)
this.setData({
isSelect: e.currentTarget.dataset.index
})
if(!e.currentTarget.dataset.type){
wxService.post(`/member/addressManage/getall?userId=${memberId}`).then(res => {
if (!res) return false
const { result, data } = res.data
if (result == 0) {
this.getAddressList()
}
}).finally(() => {
})
}
},
// 开始滑动事件
touchS: function (e) {
console.log('e', e)
if (e.touches.length == 1) {
this.setData({
//设置触摸起始点水平方向位置
startX: e.touches[0].clientX
});
drawStart: function (e) {
var touch = e.touches[0]
for (var index in this.data.addressList) {
var item = this.data.addressList[index]
item.right = 0
}
this.setData({
addressList: this.data.addressList,
startX: touch.clientX,
})
},
touchM: function (e) {
console.log('333', e)
if (e.touches.length == 1) {
//手指移动时水平方向位置
var moveX = e.touches[0].clientX;
//手指起始点位置与移动期间的差值
var disX = this.data.startX - moveX;
var delBtnWidth = this.data.delBtnWidth;
var txtStyle = "";
if (disX == 0 || disX < 0) { //如果移动距离小于等于0,文本层位置不变
txtStyle = "left:0px";
} else if (disX > 0) { //移动距离大于0,文本层left值等于手指移动距离
txtStyle = "left:-" + disX + "px";
if (disX >= delBtnWidth) {
//控制手指移动距离最大值为删除按钮的宽度
txtStyle = "left:-" + delBtnWidth + "px";
}
drawMove: function (e) {
var touch = e.touches[0]
var item = this.data.addressList[e.currentTarget.dataset.index]
var disX = this.data.startX - touch.clientX
if (disX >= 20) {
if (disX > this.data.delBtnWidth) {
disX = this.data.delBtnWidth
}
var index = e.currentTarget.dataset.index;
var addressList = this.data.addressList;
addressList[index].shows = txtStyle;
console.log("1", addressList[index].shows);
//更新列表的状态
item.right = disX
this.setData({
addressList: addressList
});
isScroll: false,
addressList: this.data.addressList
})
} else {
item.right = 0
this.setData({
isScroll: true,
addressList: this.data.addressList
})
}
},
// 滑动中事件
touchE: function (e) {
if (e.changedTouches.length == 1) {
//手指移动结束后水平位置
var endX = e.changedTouches[0].clientX;
//触摸开始与结束,手指移动的距离
var disX = this.data.startX - endX;
var delBtnWidth = this.data.delBtnWidth;
//如果距离小于删除按钮的1/2,不显示删除按钮
var txtStyle = "";
txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "px" : "left:0px";
//获取手指触摸的是哪一项
var index = e.currentTarget.dataset.index;
var addressList = this.data.addressList;
addressList[index].shows = txtStyle;
console.log("1", addressList[index].shows);
//更新列表的状态
drawEnd: function (e) {
var item = this.data.addressList[e.currentTarget.dataset.index]
if (item.right >= this.data.delBtnWidth / 2) {
item.right = this.data.delBtnWidth
this.setData({
addressList: addressList
});
isScroll: true,
addressList: this.data.addressList,
})
} else {
item.right = 0
this.setData({
isScroll: true,
addressList: this.data.addressList,
})
}
},
deleteAddress(e){
console.log(e)
var that = this
let id = e.currentTarget.dataset.id
wx.showModal({
title: '提示',
content: '确认删除该地址吗?',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
wxService.post(`/member/addressManage/delete?id=${id}`).then(res => {
const { result, data } = res.data
if (result == 0) {
wx.showToast({
title: `删除成功`,
icon: 'none'
})
that.getAddressList()
}
}).finally(() => {
})
} else if (res.cancel) {
console.log('用户点击取消')
}
......
......@@ -7,21 +7,21 @@
</view>
<view class="address-wrap">
<view class="address-ul">
<view class="address-list" wx:for="{{addressList}}" wx:key="{{index}}" bindtouchstart="touchS" bindtouchmove="touchM" bindtouchend="touchE" style="{{item.shows}}" data-index="{{index}}">
<view class="address-list" wx:for="{{addressList}}" wx:key="{{index}}" bindtouchstart="drawStart" bindtouchmove="drawMove" bindtouchend="drawEnd" style="right:{{item.right}}rpx" data-index="{{index}}">
<view class="name">
{{item.name}} {{item.phone}}
</view>
<view class="address-detail">{{item.address}}</view>
<view class="default-address" bindtap="settingDefalutAddress" data-index="{{index}}">
<view class="{{isSelect == index ? 'theme-color' : ''}} circle-radio" >
<image wx:if="{{isSelect == index}}" class="tick-success" src="/assets/imgs/7_1_0/tick-success.png" mode="widthFix"></image>
<view class="address-detail">{{item.fullArea}} {{item.address}}</view>
<view class="default-address" bindtap="settingDefalutAddress" data-type="{{item.type}}">
<view class="{{item.type == 1 ? 'theme-color' : ''}} circle-radio" >
<image wx:if="{{item.type == 1}}" class="tick-success" src="/assets/imgs/7_1_0/tick-success.png" mode="widthFix"></image>
</view>
<text class="setting-default">设为默认地址</text>
</view>
<navigator url="/pages/addAddress/addAddress?id=1">
<navigator url="/pages/addAddress/addAddress?id={{item.id}}">
<image class="edit-img" mode="widthFix" src="/assets/imgs/7_1_0/edit.png"></image>
</navigator>
<view class="delete" bindtap="deleteAddress">删除</view>
<view class="delete" bindtap="deleteAddress" data-id="{{item.id}}">删除</view>
</view>
</view>
</view>
......
......@@ -18,9 +18,8 @@ wxService.page({
baseImgUrl: app.globalData.imageUrl,
swiperCurrent: 0,
selectSkuName:'',
openPlusStatus:0,
memberLevel:0
openPlusStatus:false,
memberLevel:false
},
/**
......@@ -78,11 +77,11 @@ wxService.page({
// 获取会员等级开关
getMemberLevel(){
wxService.get(`/merchant/brandSwitchSetting/getOpenStatus?brandId=1001&businessType=2`).then(res => {
wxService.get(`/merchant/brandSwitchSetting/getOpenStatus?businessType=2`).then(res => {
const { result, data } = res.data
if (result == 0) {
this.setData({
memberLevel: result
memberLevel: data
})
}
}).finally(() => {
......@@ -92,11 +91,11 @@ wxService.page({
// 获取plus会员开关
getOpenStatus(){
wxService.get(`/merchant/brandSwitchSetting/getOpenStatus?brandId=1001&businessType=3`).then(res => {
wxService.get(`/merchant/brandSwitchSetting/getOpenStatus?businessType=3`).then(res => {
const { result, data } = res.data
if (result == 0) {
this.setData({
openPlusStatus:result
openPlusStatus:data
})
}
}).finally(() => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment