yuminge-app/yun-min-program-plugin-master/packageG/mycomponent/selfpick/selfpick.js

120 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// packageG/mycomponent/selfpick/selfpick.js
const app = getApp();
var location = require("../../../mybehaviors/location/location");
Component({
behaviors: [location],
/**
* 组件的属性列表
*/
properties: {
datas: {
type: null
},
component_id: {
type: null
}
},
/**
* 组件的初始数据
*/
data: {
activeID: 0,
deliverInfo: {
deliver_name: "正在获取中...",
loading: true //正在获取数据
}
},
lifetimes: {
// 生命周期函数可以为函数或一个在methods段中定义的方法名
attached() {
this.initData();
},
moved() {},
detached() {},
},
pageLifetimes: {
show: function() {
// 页面被展示
this.initData();
},
hide: function() {
// 页面被隐藏
},
resize: function(size) {
// 页面尺寸变化
}
},
/**
* 组件的方法列表
*/
methods: {
gotoUrl() {
if (this.data.deliverInfo.loading) {
return;
}
wx.navigateTo({
url: '/packageC/selfCarry/selectSelfPickupPoint/selectSelfPickupPoint?tag=1'
});
},
initData() {
let deliverIDStorage = null;
try {
deliverIDStorage = wx.getStorageSync('deliverId'); //获取当前会话是否存储了自提点id
} catch (e) {
// Do something when catch error
}
if (deliverIDStorage) {
// 当前会话有存储自提点id可能是链接上储存起来有或者通过手动切换了自提点
this.data.activeID = deliverIDStorage;
}
this._getLocation(() => {
this.getNowPackageDeliver();
});
},
getNowPackageDeliver(lat, lng) {
//获取自提点信息
let _json = {
lng: this.data.point.lng||'',
lat: this.data.point.lat||''
};
if (this.data.activeID) {
_json.deliver_id = this.data.activeID;
}
let urlStr = app.getNetAddresss('plugin.package-deliver.frontend.decorate-deliver.getNowPackageDeliver');
app._postNetWork({
url: urlStr,
data: _json,
success: (resdata) => {
let res = resdata.data;
if (res.result == 1) {
this.setData({
deliverInfo: res.data,
total_page: res.data.last_page,
});
wx.setStorageSync("deliverId", res.data.id);
} else {
wx.showToast({
title: res.msg,
duration: 1000,
icon: 'none'
});
this.setData({
['deliverInfo.deliver_name']: "请手动切换选择!"
});
}
this.setData({
['deliverInfo.loading']: false
});
},
fail: function (res) {
console.log(res.msg);
}
});
}
}
});