167 lines
4.7 KiB
JavaScript
167 lines
4.7 KiB
JavaScript
import { API } from '../../../../utils/network/api'
|
||
import Toast from 'tdesign-miniprogram/toast/index';
|
||
let api = new API()
|
||
const app = getApp()
|
||
Page({
|
||
|
||
data: {
|
||
navbarData: {
|
||
showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
|
||
title: '价格设置', //导航栏 中间的标题
|
||
},
|
||
inquiry_type: 1,
|
||
inquiry_mode: 1,
|
||
info:{
|
||
is_open: false,
|
||
inquiry_price: 0,
|
||
work_num_day: 0
|
||
},
|
||
myprice: "",
|
||
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"
|
||
]
|
||
}
|
||
},
|
||
onLoad(options){
|
||
if(options.inquiry_mode){
|
||
this.setData({
|
||
inquiry_mode:options.inquiry_mode
|
||
})
|
||
}
|
||
},
|
||
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,
|
||
// note: response.data.info.is_open == 1? this.data.open_note : this.data.close_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
|
||
})
|
||
}
|
||
}).catch(errors => {console.error(errors);})
|
||
|
||
},
|
||
onStepperChange(event) {
|
||
console.log(event.detail);
|
||
wx.vibrateShort({
|
||
"type": "heavy"
|
||
})
|
||
this.setData({
|
||
"info.work_num_day": event.detail
|
||
});
|
||
},
|
||
onPriceChange(e){
|
||
console.log(e.detail);
|
||
let price = e.detail.value;
|
||
this.setData({
|
||
"info.inquiry_price": price
|
||
})
|
||
|
||
},
|
||
myToast(message){
|
||
Toast({
|
||
context: this,
|
||
selector: '#t-toast',
|
||
message: message,
|
||
theme: 'error',
|
||
direction: 'column',
|
||
});
|
||
},
|
||
checkPrice(price){
|
||
let value = Number(price);
|
||
let min = Number(this.data.config.min_inquiry_price);
|
||
let max = Number(this.data.config.max_inquiry_price);
|
||
if(value < min){
|
||
value = min;
|
||
let message = '价格不能低于' + min + '元';
|
||
this.myToast(message);
|
||
return false;
|
||
}else if(value >= min && value <=max ){
|
||
return true;
|
||
}else{
|
||
value = max;
|
||
let message = '价格不能高于' + max + '元';
|
||
this.myToast(message);
|
||
return false;
|
||
}
|
||
},
|
||
async updateConfig(){
|
||
|
||
if(this.data.inquiry_mode==1){
|
||
let check = this.checkPrice(this.data.info.inquiry_price);
|
||
console.log("checkcheckcheck:", check);
|
||
if(!check){
|
||
return;
|
||
}
|
||
}
|
||
if(this.data.inquiry_mode==2 || this.data.inquiry_mode==6){
|
||
//console.log(parseFloat(this.data.info.inquiry_price))
|
||
if(!(parseFloat(this.data.info.inquiry_price)>=10 && parseFloat(this.data.info.inquiry_price)<=2999)){
|
||
wx.showToast({
|
||
title: '问诊单价为10~2999元',
|
||
icon:'none'
|
||
})
|
||
return false;
|
||
}
|
||
}
|
||
|
||
//修改医生问诊配置
|
||
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;
|
||
const result = await api.putDoctorInquiryConfig(params).then(response => {
|
||
console.log(response);
|
||
this.myToast("修改成功");
|
||
return true;
|
||
}).then(res => {
|
||
setTimeout(() => {
|
||
wx.navigateBack();
|
||
|
||
}, 1000);
|
||
}).catch(errors => {
|
||
console.error(errors);
|
||
return false;
|
||
})
|
||
|
||
console.log("updateConfig result result: ", result);
|
||
return result;
|
||
}
|
||
}) |