checkstore.js
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import api from './checkstoreService';
import event from '../../utils/event.js'
const storeApi = new api();
Component({
options: {
multipleSlots: true // 在组件定义时的选项中启用多slot支持
},
properties: {
// 弹窗标题
storeId: { // 属性名
type: Number, // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
value: 0 // 属性初始值(可选),如果未指定则会根据类型选择一个
},
productId: {
type: Number,
value: 0
}
},
data: {
// 弹窗显示控制
content: "Sorry,您的位置不在门店范围内,不能选择门店自提方式购买该商品",
cancelText: "线上购买",
confirmText: "知道了",
type: 0
},
/**
* 组件的方法列表
* 更新属性和数据的方法与更新页面数据的方法类似
*/
methods: {
init() {
return new Promise((resolve) => {
let param = {};
this.dialog = this.selectComponent("#dialog");
wx.getLocation({
success: (res) => {
param.user_latitude = res.latitude;
param.user_longitude = res.longitude;
param.store_id = this.properties.storeId;
storeApi.checkStore(param, () => {
wx.hideLoading();
}).then(r => {
if (!r.isInRange) {
this.setData({
// 弹窗显示控制
content: "Sorry,您的位置不在门店范围内,不能选择门店自提方式购买该商品",
cancelText: "线上购买",
confirmText: "知道了",
type: 0
});
this.dialog.showDialog();
resolve({result: false})
} else {
resolve({
result: true,
data: param
})
}
});
},
fail: () => {
this.setData({
type: 1,
content: "请确保手机打开定位,并允许微信获取您的位置信息",
cancelText: "取消",
confirmText: "去开启",
})
this.dialog.showDialog();
resolve({result: false})
}
});
})
},
cancelEvent() {
if (this.data.type) {
this.dialog.hideDialog();
} else {
wx.navigateTo({url: '/pages/productDetail/index?id=' + this.properties.productId})
}
},
confirmEvent() {
if (this.data.type) {
wx.openSetting({
complete: () => {
this.dialog.hideDialog();
}
});
} else {
this.dialog.hideDialog();
}
}
}
})