doctorLists.js 5.19 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
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
// pages/doctorsList/doctorsList.js
// 网络请求工具类
var networkUtil = require('../../utils/network_util.js')
var api = require('../../utils/apiFile.js')

Page({

/**
* 页面的初始数据
*/
data: {
list: [],
hospitalName: "",
hospitalId: "",
hostitalprice: 0,
totalPrize: 0, //总价
ids: '', //服务id
doctorIds: '', //选中的医生id
hospitalList: [],
count: 1500,
isShowToast: false,
chooseDoctServiceName: '',
// 高危时的服务开通时间类型
serviceType:'',
index: 0 //选中医院的下标
},

/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
networkUtil.showLoading();
networkUtil._get(api.getWxDoctors,{},function(res){
var data = res.data.doctors;
var hospitals=[];
for (var k in data){
data[k].forEach(item => {
item.isCheck = false;
})
hospitals.push({name:k,data:data[k]})
}
console.log('医院列表',hospitals)
that.setData({
hospitalList:hospitals,
hospitalName:hospitals[0].name,
list:hospitals[0].data
})
},function(){

})
},

/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {

},

/**
* 生命周期函数--监听页面显示
*/
onShow: function () {

},

/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {

},

/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {

},

/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {

},

/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {

},

/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {

},
godoctor: function(e) {
var doctorId = e.currentTarget.dataset.doctorid;
var doctor = e.currentTarget.dataset.doctor;
wx.setStorage({
key: 'doctor_'+doctorId,
data: doctor,
})
wx.navigateTo({
url: '../expert/expert?doctorId='+doctorId,
})
},
itemClick: function(e) {
var doctorId = e.currentTarget.dataset.doctorid
var self = this
var totalPrize = 0
var ids = ''
var hospitalId = ''
for (var i = 0; i < self.data.list.length; i++) {
if (self.data.list[i].id == doctorId) {
self.data.list[i].isCheck = !self.data.list[i].isCheck
} else {
self.data.list[i].isCheck = false
}
}

for (var i = 0; i < self.data.list.length; i++) {
if (self.data.list[i].isCheck) {
totalPrize += self.data.list[i].price;
hospitalId = self.data.list[i].hospitalId;
ids = self.data.list[i].id;
}
}
self.setData({
list:self.data.list,
hospitalId: hospitalId,
totalPrize: totalPrize,
doctorIds: ids
})

},
hospitailClick: function(e) {
console.log(e)
var self = this
var hospitalName = this.data.hospitalList[e.detail.value].name
var doctors = this.data.hospitalList[e.detail.value].data
self.setData({
hospitalName: hospitalName,
index: e.detail.value,
list:doctors
})
//self.getDoctorsFromServer()
},
toPay: function(e) {
if (this.data.totalPrize == 0) {
wx.showToast({
title: '价格不能为0',
})
return
}
var content = []
var self = this

if (self.data.list.length > 0) {
for (var i = 0; i < self.data.list.length; i++) {
var checked = {
"goodId":13,
"hId": self.data.list[i].hospitalId,
"doctorId": ""
}
if (self.data.list[i].isCheck) {
checked.doctorId = self.data.list[i].id
content.push(checked)
}
}
}
networkUtil.showLoading()
this.refreshOpenid(content)
},
refreshOpenid(content) {
var self = this
var jscode = ''
wx.login({
success: function(res) {
// success
jscode = res.code
networkUtil._get(api.refreshOpenId + "?jscode=" + jscode + "&type=1", {}, function(res) {
console.log(res)
self.getPayMessage(content)
}, function(res) {

})
},
fail: function(res) {
// fail
},
complete: function(res) {
// complete
}
})
},
getPayMessage(content) {
var self = this
var param = JSON.stringify(content)
networkUtil._post(api.goodsbuy, {
param: param
}, function(res) {
console.log(res)
wx.requestPayment({
timeStamp: res.data.payParams.timeStamp + "",
nonceStr: res.data.payParams.nonceStr,
package: res.data.payParams.package,
signType: res.data.payParams.signType,
paySign: res.data.payParams.paySign,
'success': function(res1) {
console.log(res1)
wx.navigateTo({
url: '../paySuccess/paySuccess?goodsOrderId=' + res.data.goodsOrderId + '&ids=' + self.data.ids + '&goodId=12',
})
},
'fail': function(res1) {
console.log('fali', res1)
wx.navigateTo({
url: '../payFail/payFail',
})
}
})
}, function(res) {

})
},
})