| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372 |
- // pages/user/address/address.js
- var app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- current: 0,
- loading: true,
- loadding: false,
- pages: null,
- addressList: [],
- isSales: false,
- check: false,
- addr: {},
- addrIndex: null,
- startX: 0, //开始坐标
- startY: 0,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- async onLoad(options) {
- let that = this;
- const eventChannel = this.getOpenerEventChannel();
- if (!eventChannel) {
- return;
- }
- eventChannel.on('acceptDataFromOpenerPage', function (data) {
- that.setData({
- check: data.check,
- addr: data.addr
- })
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- async onShow() {
- this.setData({
- current: 0,
- pages: null,
- addressList: []
- });
- if (!wx.getStorageSync('userInfo')) {
- return;
- }
- let {
- data
- } = await app.ajax.gets('/admin/address/check');
- if (data.code == 0) {
- if (data.data == 2004) {
- this.setData({
- isSales: false
- })
- } else if (data.data == 2005) {
- this.setData({
- isSales: true
- })
- }
- }
- this.initData();
- this.setData({
- loading: false,
- })
- },
- searchGoods(e) {
- this.setData({
- current: 0,
- pages: null,
- addressList: []
- });
- this.initData(e);
- },
- async initData(e) {
- let that = this;
- this.setData({
- loadding: true,
- });
- let addrName = e && e.detail.value ? e.detail.value : '';
- let {
- data
- } = await app.ajax.get({
- url: this.data.isSales ? "/admin/address/page" : "/admin/bxdClientAddress/page",
- data: {
- current: this.data.current + 1,
- size: 500,
- addrName
- }
- })
- this.setData({
- current: this.data.current + 1,
- addressList: this.data.addressList.concat(data.data.records.map(v => {
- if (this.data.isSales) {
- v.eccId = v.eccId;
- v.address = v.provice + v.city + v.area + v.address;
- v.addrId = `clientAddrId_${v.id}`;
- v.customerName = v.eccName;
- v.province = v.provice;
- v.addr = v.address;
- v.remainQuota = v.remainQuota;
- v.receiver = v.receiver;
- v.mobile = v.mobile;
- } else {
- v.addrId = v.addrId;
- v.customerName = v.customerName;
- v.receiver = v.receiver;
- v.mobile = v.mobile;
- v.tel = v.tel;
- v.province = v.province;
- v.addr = v.addr;
- v.email = v.email;
- v.remark = v.remark;
- }
- v.city = v.city;
- v.area = v.area;
- v.choseArr = [];
- v.chosePop = false;
- v['check'] = that.data.addr.addrId == v.addrId;
- return v;
- })),
- pages: data.data.pages,
- loadding: false,
- })
- },
- async setAddrd(e) {
- let that = this;
- let item = e.currentTarget.dataset.item;
- await app.ajax.post({
- url: "/admin/bxdClientAddress/default",
- method: 'put',
- data: {
- addrId: item.addrId
- }
- });
- setTimeout(() => {
- wx.showToast({
- title: '设置成功',
- mask: true
- });
- }, 200);
- setTimeout(() => {
- that.setData({
- current: 0,
- pages: null,
- addressList: []
- });
- that.initData();
- }, 1200);
- },
- async delAddr(e) {
- let that = this;
- let item = e.currentTarget.dataset.item;
- wx.showModal({
- title: '提示',
- content: `此操作将删除该 [${item.receiver}] 收货人数据, 是否继续?`,
- complete: async (res) => {
- if (res.confirm) {
- await app.ajax.post({
- url: '/admin/bxdClientAddress',
- method: 'put',
- data: {
- addrId: item.addrId,
- status: 0,
- }
- });
- wx.showToast({
- title: '删除成功!',
- });
- setTimeout(() => {
- that.setData({
- current: 0,
- pages: null,
- addressList: []
- });
- that.initData();
- }, 1000);
- }
- }
- })
- },
- renderAddr() {
- // /admin/bxdClientAddress/addressParse?address=
- },
- chooseAddr: function (e) {
- if (!this.data.check) {
- return;
- }
- let addressList = this.data.addressList.map(v => {
- v['check'] = false;
- return v;
- });
- addressList[Number(e.currentTarget.dataset.index)]['check'] = true;
- this.setData({
- addressList,
- addr: e.currentTarget.dataset.item,
- addrIndex: e.currentTarget.dataset.index,
- })
- },
- goBackPage: function (e) {
- if (!this.data.check) {
- return;
- }
- // let addr = this.data.addressList[this.data.addrIndex];
- // if (!addr || !addr.addrId) {
- // wx.showToast({
- // title: '请选择地址',
- // icon: 'error'
- // });
- // return;
- // }
- if (!this.data.addr || !this.data.addr.addrId) {
- wx.showToast({
- title: '请选择地址',
- icon: 'error'
- });
- return;
- }
- let addrs = this.data.addressList.filter(v => v.addrId == this.data.addr.addrId);
- if (!addrs || addrs.length == 0) {
- wx.showToast({
- title: '请选择地址',
- icon: 'error'
- });
- return;
- } else {
- this.setData({
- addr: addrs[0]
- })
- }
- const eventChannel = this.getOpenerEventChannel()
- //console.log(eventChannel)
- if (!eventChannel || !this.data.check) {
- return;
- }
- eventChannel.emit('acceptDataFromOpenerPage', {
- addr: this.data.addr
- });
- wx.navigateBack({
- data: 1
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- touchE: function (e) {
- // //console.log(e);
- var that = this
- if (e.changedTouches.length == 1) {
- //手指移动结束后触摸点位置的X坐标
- var endX = e.changedTouches[0].clientX;
- //触摸开始与结束,手指移动的距离
- var disX = that.data.startX - endX;
- var delBtnWidth = 120;
- //如果距离小于删除按钮的1/2,不显示删除按钮
- var txtStyle = disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "rpx" : "left:0rpx";
- //获取手指触摸的是哪一项
- var index = e.currentTarget.dataset.index;
- var list = that.data.addressList;
- list[index].txtStyle = txtStyle;
- //更新列表的状态
- that.setData({
- addressList: list
- });
- }
- },
- //手指触摸动作开始 记录起点X坐标
- touchstart: function (e) {
- //开始触摸时 重置所有删除
- this.data.addressList.forEach(function (v, i) {
- if (v.isTouchMove) //只操作为true的
- v.isTouchMove = false;
- })
- this.setData({
- startX: e.changedTouches[0].clientX,
- startY: e.changedTouches[0].clientY,
- addressList: this.data.addressList
- })
- },
- //滑动事件处理
- touchmove: function (e) {
- var that = this,
- index = e.currentTarget.dataset.index, //当前索引
- startX = that.data.startX, //开始X坐标
- startY = that.data.startY, //开始Y坐标
- touchMoveX = e.changedTouches[0].clientX, //滑动变化坐标
- touchMoveY = e.changedTouches[0].clientY, //滑动变化坐标
- //获取滑动角度
- angle = that.angle({
- X: startX,
- Y: startY
- }, {
- X: touchMoveX,
- Y: touchMoveY
- });
- that.data.addressList.forEach(function (v, i) {
- v.isTouchMove = false
- //滑动超过30度角 return
- if (Math.abs(angle) > 30) return;
- if (i == index) {
- if (touchMoveX > startX) //右滑
- v.isTouchMove = false
- else //左滑
- v.isTouchMove = true
- }
- })
- //更新数据
- that.setData({
- addressList: that.data.addressList
- })
- },
- /**
- * 计算滑动角度
- * @param {Object} start 起点坐标
- * @param {Object} end 终点坐标
- */
- angle: function (start, end) {
- var _X = end.X - start.X,
- _Y = end.Y - start.Y
- //返回角度 /Math.atan()返回数字的反正切值
- return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
- },
- })
|