-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeals.js
More file actions
211 lines (187 loc) · 5.23 KB
/
meals.js
File metadata and controls
211 lines (187 loc) · 5.23 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
let appInstance = getApp();
Page({
pageNo: 1,
options: {},
data: {
comBoCellData: [],//套餐数据
hospitalData: {},//医院数据
scrollViewHeight: 0,
isLoadComplete: false,//是否加载完毕
isShowNoMeals: false,//是否显示没有套餐页面
},
onPullDownRefresh: function () {
this.getDatas()
},
onShow: function () {
appInstance.data.options = {}; //清空保存在套餐详情的mealId
appInstance.data.additionalItemPackage = []
},
/**
* 针对页面传值或者扫码传值就行判定
*/
onLoad: function (options) {
var _this = this
wx.getSystemInfo({
success: function (res) {
var height = res.windowHeight * 750 / res.windowWidth
_this.setData({
scrollViewHeight: height,
})
}
})
//医院id存在就拼接
if (options.hid) {
//重新给地址赋值
let urlDic = {
hospital: appInstance.data.url + "/hospital/" + options.hid,
setmeals: appInstance.data.url + "/set-meal-list?hospitalId=" + options.hid,
}
this.options = urlDic
this.getDatas()
} else {
//console.log("医院id不存在")
}
},
getDatas: function () {
var _this = this;
wx.showNavigationBarLoading()
//获取单个医院数据
appInstance.getServerce(this.options.hospital, "GET", {}, (isSuccess, data) => {
if (isSuccess) {
_this.setData({
hospitalData: data.data
})
} else {
appInstance.showloadingMessgage(data)
}
})
let params = {
"pageSize": 500,
"pageNo": 1
}
//获取套餐列表数据
appInstance.getServerce(this.options.setmeals, "GET", params, (isSuccess, data) => {
if (isSuccess) {
// success
/**
* 处理 600.00 为600 和 .00
*/
wx.hideNavigationBarLoading()
var isShowNoMeals1 = true;
if (data.data.resultList.length == 0) {
isShowNoMeals1 = false;
}
var arr = _this.resolveMealData(data.data.resultList)
_this.setData({
comBoCellData: arr,
isShowNoMeals: isShowNoMeals1,
})
//关闭刷新
wx.stopPullDownRefresh()
} else {
appInstance.showloadingMessgage(data)
}
})
},
/**
* 加载更多数据
*/
loadMoreData: function () {
return
var _this = this;
wx.showNavigationBarLoading()
let params = {
"pageSize": 20,
"pageNo": this.pageNo
}
//console.log(params)
//console.log(this.options.setmeals)
//获取套餐列表数据
appInstance.getServerce(this.options.setmeals, "GET", params, (isSuccess, data) => {
wx.hideNavigationBarLoading()
if (isSuccess) {
// success
var arr = data.data.resultList
if (arr.length == 0) {
this.setData({
isLoadComplete: true
})
} else {
var arr = _this.resolveMealData(data.data.resultList)
_this.setData({
comBoCellData: this.data.comBoCellData.concat(arr)
})
}
} else {
appInstance.showloadingMessgage(data)
}
})
},
/**
* 处理套餐数据
* 价格统一
* 实现小数点规整
*/
resolveMealData: function (data) {
var arr = data
for (let i in arr) {
let retailPrice = parseFloat(arr[i].retailPrice).toFixed(4).toString()
let salePrice = parseFloat(arr[i].salePrice).toFixed(4).toString()
arr[i].retailPrice = retailPrice.slice(0, retailPrice.length - 2)
arr[i].salePrice = salePrice.slice(0, salePrice.length - 2)
arr[i].salePriceBeforePoint = salePrice.slice(0, salePrice.length - 5)
arr[i].salePricePoint = salePrice.slice(salePrice.length - 5, salePrice.length - 2)
}
return arr
},
pushToComboDetail: function (event) {
wx.navigateTo({
url: '../NewMealDetail/NewMealDetail?mealId=' + event.currentTarget.dataset.id
})
},
/**
* 页面分享配置
*/
onShareAppMessage: function () {
return {
title: (this.data.hospitalData.name || '一键康医院') + '套餐',
path: '/pages/meals/meals?hid=' + this.data.hospitalData.id
}
},
/**
* 打开导航
*/
openLocation: function () {
let gg = this.bd09togcj02(this.data.hospitalData.longitude, this.data.hospitalData.latitude)
wx.openLocation({
latitude: gg[1],
longitude: gg[0],
name: this.data.hospitalData.name
})
},
onReachBottom: function () {
// this.loadMoreMeals()
},
/**
* 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
* 即 百度 转 谷歌、高德
* @param bd_lon
* @param bd_lat
* @returns {*[]}
*/
bd09togcj02: function (bd_lon, bd_lat) {
//定义一些常量
var x_PI = 3.14159265358979324 * 3000.0 / 180.0
var PI = 3.1415926535897932384626
var a = 6378245.0
var ee = 0.00669342162296594323
var x_pi = 3.14159265358979324 * 3000.0 / 180.0
var x = bd_lon - 0.0065
var y = bd_lat - 0.006
var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi)
var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi)
var gg_lon = z * Math.cos(theta)
var gg_lat = z * Math.sin(theta)
return [gg_lon, gg_lat]
}
})