123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- var map = require('../../../utils/map.js');
- var app = getApp();
- Page({
- data: {
- addressList: [],
- total: 0,
- addressName: "",
- isShowServiceAddress: false
- },
- onLoad: function (options) {
- // 页面初始化 options为页面跳转所带来的参数
- var pages = getCurrentPages();
- var prevPage = pages[pages.length - 2];
- if (prevPage.route == "pages/index/index") {
- this.setData({
- isShowServiceAddress: true
- })
- }
- this.getUserLocation();
- },
- shaxin() {
- this.getUserLocation();
- },
- getUserLocation: function () {
- map.getUserLocation();
- let that = this;
- setTimeout(function () {
- that.setData({
- addressName: app.globalData.currentLocationName
- })
- }, 2000)
- },
- onReady: function () {
- // 页面渲染完成
- },
- onShow: function () {
- // 页面显示
- this.getAddressList();
- },
- getAddressList() {
- let that = this;
- util.request(api.AddressList).then(function (res) {
- if (res.errno === 0) {
- that.setData({
- addressList: res.data.list,
- total: res.data.total
- });
- }
- });
- },
- updateAddress(event) {
- let addressId = event.currentTarget.dataset.addressId;
- wx.navigateTo({
- url: '/pages/ucenter/addressAdd/addressAdd?id=' + addressId
- })
- },
- async updateAddressData(address) {
- await util.request(api.AddressSave, address, 'POST').then(function (res) {
- if (res.errno === 0) {
- var city = res.data.city.indexOf("市辖") != -1 ? res.data.province : res.data.city;
- var addresInfo = {
- city: city,
- lng: res.data.lng,
- lat: res.data.lat,
- shopId: res.data.shopId,
- address: res.data.addressDetail
- }
- wx.setStorageSync('addressInfo', addresInfo);
- }
- });
- },
- addressAddOrUpdate(event) {
- // console.log(event)
- let addressId = event.currentTarget.dataset.addressId;
- let name = event.currentTarget.dataset.addressName;
- let tel = event.currentTarget.dataset.addressTel;
- let addressDetail = event.currentTarget.dataset.addressDetail;
- let address = null;
- this.data.addressList.forEach(item => {
- if (addressId == item.id)
- address = item;
- })
- console.info(address)
- //返回之前,先取出上一页对象,并设置addressId
- var pages = getCurrentPages();
- var prevPage = pages[pages.length - 2];
- if (null != address && (prevPage.route == "pages/index/index" || prevPage.route == "pages/ucenter/serviceDetail/serviceDetail")) {
- // console.log("市辖区".indexOf("市"));
- var city = address.city.indexOf("市辖") != -1 ? address.province : address.city;
- //通过jz_shop的shop_no关联服务力分配的门店id,拿实际的jz_shop的门店id
- //这个是拿的服务力分配的门店,如果不转要改后台查询商品,要用shopNo,这里的shopId是shopNo
- // let distribution_unit=address.shopId;
- if (address.shopId == null) {
- this.updateAddressData(address);
- } else {
- var addresInfo = {
- city: city,
- lng: address.lng,
- lat: address.lat,
- shopId: address.shopId,
- address: address.addressDetail,
- shopName: address.shopName,
- name: name,
- tel: tel,
- addressId:address.id
- }
- wx.setStorageSync('addressInfo', addresInfo);
- }
- wx.navigateBack();
- } else if (prevPage.route == "pages/checkout/checkout") {
- try {
- wx.setStorageSync('addressId', event.currentTarget.dataset.addressId);
- } catch (e) {
- }
- if (addressId && addressId != 0) {
- wx.navigateBack();
- } else {
- wx.navigateTo({
- url: '/pages/ucenter/addressAdd/addressAdd?id=' + addressId
- })
- }
- } else if (prevPage.route == "pages/goods/infoCollect/infoCollect") {
- if (addressId && addressId != 0) {
- app.globalData.infoAddress = {
- addressId: addressId,
- addressDetail: addressDetail
- }
- wx.navigateBack();
- } else {
- wx.navigateTo({
- url: '/pages/ucenter/addressAdd/addressAdd?id=' + addressId
- })
- }
- } else {
- wx.navigateTo({
- url: '/pages/ucenter/addressAdd/addressAdd?id=' + event.currentTarget.dataset.addressId
- })
- }
- },
- deleteAddress(event) {
- console.log(event.target)
- let that = this;
- wx.showModal({
- title: '',
- content: '确定要删除地址?',
- success: function (res) {
- if (res.confirm) {
- let addressId = event.target.dataset.addressId;
- util.request(api.AddressDelete, {
- id: addressId
- }, 'POST').then(function (res) {
- if (res.errno === 0) {
- that.getAddressList();
- wx.removeStorage({
- key: 'addressId',
- success: function (res) {},
- })
- }
- });
- console.log('用户点击确定')
- }
- }
- })
- return false;
- },
- onHide: function () {
- // 页面隐藏
- },
- onUnload: function () {
- // 页面关闭
- }
- })
|