226 lines
6.1 KiB
JavaScript
226 lines
6.1 KiB
JavaScript
import { API } from '../../../../utils/network/api'
|
||
import Toast from '@vant/weapp/toast/toast';
|
||
import { requestSubscribeMessage } from '../../../../utils/requestSubscribeUtil';
|
||
let api = new API()
|
||
const app = getApp()
|
||
Page({
|
||
data: {
|
||
navbarData: {
|
||
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
||
title: '设置价格', //导航栏 中间的标题
|
||
},
|
||
height: app.globalData.height,
|
||
checked: true,
|
||
open_note: "已开启,可在问诊消息中进行接诊",
|
||
close_note: "已关闭,暂不接收公益问诊",
|
||
note: "",
|
||
amountText: "选择金额(元)",
|
||
amountValue: "",
|
||
inquiry_type: 3,
|
||
inquiry_mode: 1,
|
||
amounts: [],
|
||
info:{
|
||
is_open: false,
|
||
inquiry_price: 0,
|
||
work_num_day: 0
|
||
},
|
||
config:{
|
||
"max_work_num_day": 30,
|
||
"min_inquiry_price": 0,
|
||
"max_inquiry_price": 0,
|
||
"default_inquiry_price": 0,
|
||
"times_number": 10,
|
||
"duration": 1440,
|
||
"system_inquiry_price": [
|
||
"0",
|
||
"5",
|
||
"10"
|
||
]
|
||
},
|
||
sub_visible: false,
|
||
},
|
||
|
||
onShow(){
|
||
let params = {};
|
||
params.inquiry_type = this.data.inquiry_type;//接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||
params.inquiry_mode = this.data.inquiry_mode;//接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)
|
||
//获取医生我的账户数据
|
||
api.getDoctorInquiryConfig(params).then(response => {
|
||
console.log(response);
|
||
this.setData({
|
||
'info.inquiry_price': response.data.inquiry_price,
|
||
'info.work_num_day': response.data.work_num_day
|
||
// config: response.data.config,
|
||
})
|
||
// this.formatAmounts();
|
||
// this.formatAmountValue();
|
||
}).then(re =>{
|
||
// let is_open = this.data.info.is_open;
|
||
// let note = this.data.note;
|
||
// if(is_open == 1) note = this.data.open_note;
|
||
// if(is_open == 0) note = this.data.close_note;
|
||
// this.setData({
|
||
// note: note
|
||
// })
|
||
this.getSysconfig()
|
||
}).catch(errors => {console.error(errors);})
|
||
|
||
},
|
||
getSysconfig(){
|
||
let {inquiry_type,inquiry_mode,info}=this.data;
|
||
api.getSysconfig({
|
||
inquiry_type,
|
||
inquiry_mode
|
||
}).then(response => {
|
||
console.log(response);
|
||
this.setData({
|
||
'config': response.data
|
||
// config: response.data.config,
|
||
// note: response.data.info.is_open == 1? this.data.open_note : this.data.close_note
|
||
})
|
||
|
||
if(info.work_num_day===''){
|
||
this.setData({
|
||
'info.work_num_day':response.data.default_work_num_day
|
||
})
|
||
}
|
||
this.formatAmounts();
|
||
this.formatAmountValue();
|
||
}).catch(errors => {console.error(errors);})
|
||
|
||
},
|
||
formatAmounts(){
|
||
let list = this.data.config.system_inquiry_price.map(item => {
|
||
let it = {};
|
||
it.label = item+" 元";
|
||
it.value = item;
|
||
return it;
|
||
});
|
||
this.setData({
|
||
amounts: list
|
||
})
|
||
},
|
||
formatAmountValue(){
|
||
let val = Math.trunc(this.data.info.inquiry_price);
|
||
let valarr = [''+val+'']
|
||
this.setData({
|
||
amountValue: valarr,
|
||
amountText: val
|
||
})
|
||
},
|
||
onChange({ detail }) {
|
||
console.log("onChange: ", detail);
|
||
if(detail){
|
||
this.setData({ note: this.data.open_note });
|
||
}else{
|
||
this.setData({ note: this.data.close_note });
|
||
}
|
||
this.setData({ "info.is_open": detail });
|
||
|
||
//修改开关
|
||
let params = {};
|
||
params.inquiry_type = this.data.inquiry_type;//接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||
params.inquiry_mode = this.data.inquiry_mode;//接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)
|
||
params.is_open = detail?1:0;
|
||
api.putDoctorInquiryOpen(params).then(response => {
|
||
console.log(response);
|
||
}).then(()=>{
|
||
if(detail){
|
||
|
||
let tmplIds = ['G1RIs0RYqsTQ2CuPQWalIMyb6_deuEEbJfajfhGvNzc']
|
||
let sub_promise = requestSubscribeMessage(tmplIds)
|
||
sub_promise.then(res => {
|
||
console.log("订阅成功")
|
||
|
||
}).catch(err => {
|
||
console.log(err)
|
||
let errCode = err.errCode
|
||
if(errCode == 20004){
|
||
this.setData({
|
||
sub_visible: true,
|
||
})
|
||
}
|
||
})
|
||
}
|
||
}).catch(errors => {console.error(errors);})
|
||
},
|
||
subcancelDialog(){
|
||
this.setData({
|
||
sub_visible: false
|
||
})
|
||
},
|
||
subconfirmDialog(){
|
||
this.setData({
|
||
sub_visible: false
|
||
})
|
||
wx.openSetting({
|
||
success (res) {
|
||
console.log(res.authSetting)
|
||
}
|
||
})
|
||
},
|
||
putDoctorInquiryConfig(){
|
||
//修改医生问诊配置
|
||
let params = {};
|
||
params.inquiry_type = this.data.inquiry_type;//接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||
params.inquiry_mode = this.data.inquiry_mode;//接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)
|
||
params.inquiry_price = this.data.info.inquiry_price;
|
||
params.work_num_day = this.data.info.work_num_day;
|
||
api.putDoctorInquiryConfig(params).then(response => {
|
||
console.log(response);
|
||
Toast.success("修改成功");
|
||
setTimeout(() => {
|
||
wx.navigateBack();
|
||
}, 1000);
|
||
}).catch(errors => {console.error(errors);})
|
||
},
|
||
onStepperChange(event) {
|
||
console.log(event.detail);
|
||
wx.vibrateShort({
|
||
"type": "heavy"
|
||
})
|
||
this.setData({
|
||
"info.work_num_day": event.detail
|
||
});
|
||
},
|
||
|
||
onAmountPicker() {
|
||
this.setData({ amountVisible: true });
|
||
},
|
||
|
||
onColumnChange(e) {
|
||
wx.vibrateShort({
|
||
"type": "heavy"
|
||
})
|
||
console.log('picker pick:', e);
|
||
},
|
||
|
||
onPickerChange(e) {
|
||
console.log(e);
|
||
const { key } = e.currentTarget.dataset;
|
||
const { value } = e.detail;
|
||
console.log('picker change:', e.detail);
|
||
this.setData({
|
||
[`${key}Visible`]: false,
|
||
[`${key}Value`]: value,
|
||
[`${key}Text`]: value,
|
||
"info.inquiry_price": value[0]
|
||
});
|
||
|
||
},
|
||
|
||
onPickerCancel(e) {
|
||
const { key } = e.currentTarget.dataset;
|
||
console.log(e, '取消');
|
||
console.log('picker1 cancel:');
|
||
this.setData({
|
||
[`${key}Visible`]: false,
|
||
});
|
||
},
|
||
go(e){
|
||
let url = e.currentTarget.dataset.url;
|
||
wx.switchTab({
|
||
url: url
|
||
})
|
||
}
|
||
}) |