Commit 0cd0b2c2 by 赵雅纹

我的地址和新增地址

parent d999c866
// pages/addAddress/addAddress.js // pages/addAddress/addAddress.js
const wxService = require('../../utils/wxService') const wxService = require('../../utils/wxService')
const { memberId } = wx.getStorageSync('_baseUserInfo')
wxService.page({ wxService.page({
...@@ -8,6 +9,7 @@ wxService.page({ ...@@ -8,6 +9,7 @@ wxService.page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
id:'',
isSelect:true, isSelect:true,
citys: null, citys: null,
cityView: '', cityView: '',
...@@ -15,7 +17,15 @@ wxService.page({ ...@@ -15,7 +17,15 @@ wxService.page({
formData: {}, formData: {},
selectCityName: ['', ''], selectCityName: ['', ''],
multiIndex: [0, 0, 0], multiIndex: [0, 0, 0],
focus: false focus: false,
params:{
userId:'',
name:'',
phone:'',
fullArea:'',
address:'',
type:1
},
}, },
/** /**
...@@ -23,39 +33,34 @@ wxService.page({ ...@@ -23,39 +33,34 @@ wxService.page({
*/ */
onLoad: function (options) { onLoad: function (options) {
console.log(options) console.log(options)
if(options.id){ if (options && options.id){
wx.setNavigationBarTitle({ wx.setNavigationBarTitle({
title: '编辑地址' title: '编辑地址'
}) })
this.setData({ this.setData({
addressId: options.id addressId: options.id,
id: options.id
}) })
}else{ }else{
wx.setNavigationBarTitle({ wx.setNavigationBarTitle({
title: '新增地址' title: '新增地址'
}) })
} }
this.init(options)
}, },
init(options) { /**
const id = options.id * 生命周期函数--监听页面显示
if (id) { */
const addressItem = pageParmas.getObject('addressItem') onShow: function () {
if (addressItem) { this.init()
let cityView = '' if(this.data.id){
if (addressItem.districtName) { this.getAddressInfo()
cityView = addressItem.districtName.replace(/,/g, ' ')
}
this.setData({
formData: addressItem,
isDefault: addressItem.isDefault,
id,
cityView
})
}
} }
},
init() {
wxService.getC1().then((c1) => { wxService.getC1().then((c1) => {
return wxService.Promise.all([wxService.Promise.resolve(c1), wxService.getC2ByC1('北京'), wxService.getC3ByC2('北京北京市')]) return wxService.Promise.all([wxService.Promise.resolve(c1), wxService.getC2ByC1('北京'), wxService.getC3ByC2('北京北京市')])
}).then(res => { }).then(res => {
...@@ -68,6 +73,38 @@ wxService.page({ ...@@ -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) { bindMultiPickerChange(e) {
const citys = this.data.citys const citys = this.data.citys
const multiIndex = e.detail.value const multiIndex = e.detail.value
...@@ -115,16 +152,91 @@ wxService.page({ ...@@ -115,16 +152,91 @@ wxService.page({
} }
}, },
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
settingDefaultAddress(){ settingDefaultAddress(){
this.setData({ this.setData({
isSelect: !this.data.isSelect 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--> <!--pages/addAddress/addAddress.wxml-->
<view class="page-add-address"> <view class="page-add-address">
<view class="form-section"> <view class="form-section">
<form> <form bindsubmit="formSubmit">
<view class="form"> <view class="form">
<view class="form-label">姓名</view> <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>
<view class="form"> <view class="form">
<view class="form-label">电话</view> <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>
<view class="form"> <view class="form">
<view class="form-label">地区</view> <view class="form-label">地区</view>
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
</view> </view>
<view class="form"> <view class="form">
<view class="form-label">详细地址</view> <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>
<view class="default-address" bindtap="settingDefaultAddress"> <view class="default-address" bindtap="settingDefaultAddress">
<view class="{{isSelect ? 'theme-color' : ''}} circle-radio" > <view class="{{isSelect ? 'theme-color' : ''}} circle-radio" >
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<text class="setting-default">设为默认地址</text> <text class="setting-default">设为默认地址</text>
</view> </view>
<view class="address-bottom"> <view class="address-bottom">
<button class="address-btn theme-color">{{addressId ? '保存并使用' : '保存收货地址'}}</button> <button form-type="submit" class="address-btn theme-color">{{addressId ? '保存并使用' : '保存收货地址'}}</button>
</view> </view>
</form> </form>
</view> </view>
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
min-width: 104rpx; min-width: 104rpx;
} }
.form-input{ .form-input{
width: 604rpx;
font-size: 28rpx; font-size: 28rpx;
color: #333333; color: #333333;
height: 82rpx; height: 82rpx;
......
// pages/myAddress/myAddress.js // 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: { data: {
isSelect:0, isSelect:0,
addressList:[ isScroll: true,
{ addressList:[],
name:'111',
phone:'211',
address:'JKDHFJHDF',
shows:''
},
{
name: '111',
phone: '211',
address: 'JKDHFJHDF',
shows:''
}
],
startX: '', startX: '',
delBtnWidth: 66,//删除按钮宽度单位(rpx) delBtnWidth: 132,//删除按钮宽度单位(rpx)
}, },
/** /**
...@@ -36,7 +29,23 @@ Page({ ...@@ -36,7 +29,23 @@ Page({
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { 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({ ...@@ -58,81 +67,92 @@ Page({
//设置默认地址 //设置默认地址
settingDefalutAddress(e){ settingDefalutAddress(e){
console.log(e) console.log(e)
this.setData({ if(!e.currentTarget.dataset.type){
isSelect: e.currentTarget.dataset.index wxService.post(`/member/addressManage/getall?userId=${memberId}`).then(res => {
}) if (!res) return false
const { result, data } = res.data
if (result == 0) {
this.getAddressList()
}
}).finally(() => {
})
}
}, },
// 开始滑动事件 drawStart: function (e) {
touchS: function (e) { var touch = e.touches[0]
console.log('e', e)
if (e.touches.length == 1) { for (var index in this.data.addressList) {
this.setData({ var item = this.data.addressList[index]
//设置触摸起始点水平方向位置 item.right = 0
startX: e.touches[0].clientX
});
} }
this.setData({
addressList: this.data.addressList,
startX: touch.clientX,
})
}, },
touchM: function (e) { drawMove: function (e) {
console.log('333', e) var touch = e.touches[0]
if (e.touches.length == 1) { var item = this.data.addressList[e.currentTarget.dataset.index]
//手指移动时水平方向位置 var disX = this.data.startX - touch.clientX
var moveX = e.touches[0].clientX;
//手指起始点位置与移动期间的差值 if (disX >= 20) {
var disX = this.data.startX - moveX; if (disX > this.data.delBtnWidth) {
var delBtnWidth = this.data.delBtnWidth; disX = 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";
}
} }
var index = e.currentTarget.dataset.index; item.right = disX
var addressList = this.data.addressList;
addressList[index].shows = txtStyle;
console.log("1", addressList[index].shows);
//更新列表的状态
this.setData({ this.setData({
addressList: addressList isScroll: false,
}); addressList: this.data.addressList
})
} else {
item.right = 0
this.setData({
isScroll: true,
addressList: this.data.addressList
})
} }
}, },
// 滑动中事件 drawEnd: function (e) {
touchE: function (e) { var item = this.data.addressList[e.currentTarget.dataset.index]
if (e.changedTouches.length == 1) { if (item.right >= this.data.delBtnWidth / 2) {
//手指移动结束后水平位置 item.right = this.data.delBtnWidth
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);
//更新列表的状态
this.setData({ this.setData({
addressList: addressList isScroll: true,
}); addressList: this.data.addressList,
})
} else { } else {
item.right = 0
this.setData({
isScroll: true,
addressList: this.data.addressList,
})
} }
}, },
deleteAddress(e){ deleteAddress(e){
console.log(e)
var that = this
let id = e.currentTarget.dataset.id
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
content: '确认删除该地址吗?', content: '确认删除该地址吗?',
success: function (res) { success: function (res) {
if (res.confirm) { if (res.confirm) {
console.log('用户点击确定') 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) { } else if (res.cancel) {
console.log('用户点击取消') console.log('用户点击取消')
} }
......
...@@ -7,21 +7,21 @@ ...@@ -7,21 +7,21 @@
</view> </view>
<view class="address-wrap"> <view class="address-wrap">
<view class="address-ul"> <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"> <view class="name">
{{item.name}} {{item.phone}} {{item.name}} {{item.phone}}
</view> </view>
<view class="address-detail">{{item.address}}</view> <view class="address-detail">{{item.fullArea}} {{item.address}}</view>
<view class="default-address" bindtap="settingDefalutAddress" data-index="{{index}}"> <view class="default-address" bindtap="settingDefalutAddress" data-type="{{item.type}}">
<view class="{{isSelect == index ? 'theme-color' : ''}} circle-radio" > <view class="{{item.type == 1 ? 'theme-color' : ''}} circle-radio" >
<image wx:if="{{isSelect == index}}" class="tick-success" src="/assets/imgs/7_1_0/tick-success.png" mode="widthFix"></image> <image wx:if="{{item.type == 1}}" class="tick-success" src="/assets/imgs/7_1_0/tick-success.png" mode="widthFix"></image>
</view> </view>
<text class="setting-default">设为默认地址</text> <text class="setting-default">设为默认地址</text>
</view> </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> <image class="edit-img" mode="widthFix" src="/assets/imgs/7_1_0/edit.png"></image>
</navigator> </navigator>
<view class="delete" bindtap="deleteAddress">删除</view> <view class="delete" bindtap="deleteAddress" data-id="{{item.id}}">删除</view>
</view> </view>
</view> </view>
</view> </view>
......
...@@ -18,9 +18,8 @@ wxService.page({ ...@@ -18,9 +18,8 @@ wxService.page({
baseImgUrl: app.globalData.imageUrl, baseImgUrl: app.globalData.imageUrl,
swiperCurrent: 0, swiperCurrent: 0,
selectSkuName:'', selectSkuName:'',
openPlusStatus:0, openPlusStatus:false,
memberLevel:0 memberLevel:false
}, },
/** /**
...@@ -78,11 +77,11 @@ wxService.page({ ...@@ -78,11 +77,11 @@ wxService.page({
// 获取会员等级开关 // 获取会员等级开关
getMemberLevel(){ 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 const { result, data } = res.data
if (result == 0) { if (result == 0) {
this.setData({ this.setData({
memberLevel: result memberLevel: data
}) })
} }
}).finally(() => { }).finally(() => {
...@@ -92,11 +91,11 @@ wxService.page({ ...@@ -92,11 +91,11 @@ wxService.page({
// 获取plus会员开关 // 获取plus会员开关
getOpenStatus(){ 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 const { result, data } = res.data
if (result == 0) { if (result == 0) {
this.setData({ this.setData({
openPlusStatus:result openPlusStatus:data
}) })
} }
}).finally(() => { }).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