import { API } from '../../../../utils/network/api' import Toast from 'tdesign-miniprogram/toast/index'; import { requestSubscribeMessage } from '../../../../utils/requestSubscribeUtil'; let api = new API() const app = getApp() Page({ data: { navbarData: { showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示 title: '在线问诊设置', //导航栏 中间的标题 }, height: app.globalData.height, // open_note: "已开启,患者可以向您发起图文问诊", // close_note: "已关闭,暂不接诊", note: "", inquiry_type: 1, inquiry_mode: 1, multi_point_status:'', config_setting:{}, info:{ is_open: false, inquiry_price: 0, work_num_day: 0 }, active:0, myprice: "", healthPrice:'图文价格*0.5*6', 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, showSetting:false, difficultSetting:false, showOpenchuFang:false, showOpenTuWen:false, }, onLoad(options){ console.log(options.multi_point_status); this.setData({ multi_point_status:options.multi_point_status }) }, cancelOpenChuFang(){ this.setData({ showOpenchuFang:false }) }, confirmOpenChuFang(){ this.setData({ showOpenchuFang:false }) app.go('/user/pages/yishi/zhiye_identity/index') }, cancelOpenTuWen(){ this.setData({ showOpenTuWen:false }) }, confirmOpenTuWen(){ this.setData({ showOpenTuWen:false, active:0 }) }, onShow(){ let {active}=this.data; this.getDoctorconfig(); this.getDoctorOpen(); this.getSysconfig(); if(active==4){ this.getConfig() } }, getDoctorOpen(){ let {inquiry_type,inquiry_mode}=this.data; api.getOpen({ inquiry_type, inquiry_mode }).then(response => { this.setData({ note: response.data, 'info.is_open': response.data }) }).catch(errors => {console.error(errors);}) }, getDoctorconfig(){ let {inquiry_type,inquiry_mode}=this.data; //接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药) //接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员) //获取医生我的账户数据 api.getDoctorInquiryConfig({ inquiry_type, inquiry_mode }).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 }) }).catch(errors => {console.error(errors);}) }, changeON(){ let is_open = this.data.info.is_open console.log("changeON:", is_open) let detail = false; if(is_open == 0){ detail = true }else{ detail = false } this.doChange(detail) }, onChange({ detail }) { this.doChange(detail) }, getConfig(){ let {inquiry_type,inquiry_mode}=this.data; api.getServiceConfig({ inquiry_type, inquiry_mode }).then(response => { let result=response.data; if(result){ this.setData({ 'config_setting.service_content':result.service_content, 'config_setting.service_process':result.service_process, 'config_setting.service_period':result.service_period, 'config_setting.service_rounds':result.service_rounds, 'config_setting.config_service_id':result.config_service_id, difficultSetting:true }) }else{ this.setData({ difficultSetting:false }) } }).catch(errors => {console.error(errors);}) }, addServiceContent(){ app.go('/user/pages/yishi/addServiceContent/index') }, async doChange(detail){ console.log("onChange: ", detail); let is_open = 0; if(detail){ let inquiry_price = this.data.info.inquiry_price; console.log(this.data.active); if(this.data.active==0){ let check = this.checkPrice(inquiry_price); if(!check) return; }; if(this.data.active==2 && detail){ let {data}=await api.getOpen({inquiry_type:1,inquiry_mode:1}); if(data==0){ this.setData({ showOpenTuWen:true }) return false } if(this.data.multi_point_status!=1){ this.setData({ showOpenchuFang:true }) return false } }; if(this.data.active==3 && detail){ wx.showToast({ title: '即将开通', icon:'none', }) return false } if(this.data.active==3 || this.data.active==4){ if(!this.data.info.work_num_day || !this.data.info.inquiry_price){ this.setData({ showSetting:true }) return false; } } if(this.data.active==4){ if(!this.data.difficultSetting){ wx.showToast({ title: '请先设置服务设置', icon:'none' }) return false; } } this.setData({ note: this.data.open_note }); wx.vibrateShort({ "type": "heavy" }) is_open = 1 }else{ this.setData({ note: this.data.close_note }); is_open = 0 } this.setData({ "info.is_open": is_open }); //修改开关 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) } }) }, settingcancelDialog(){ this.setData({ showSetting: false }) }, settingconfirmDialog(){ let {active}=this.data; this.setData({ showSetting: false }) if(active==0){ app.go("/user/pages/yishi/onlinesetupprice/index?inquiry_mode=1") }else if(active==3){ app.go("/user/pages/yishi/onlinesetupprice/index?inquiry_mode=2") }else if(active==4){ app.go("/user/pages/yishi/onlinesetupprice/index?inquiry_mode=6") } }, onChangeInquiry(event) { let index=event.detail.name; this.setData({ active:index }) if(index==0){ this.setData({ inquiry_type:1, inquiry_mode:1, }) }else if(index==1){ this.setData({ inquiry_type:1, inquiry_mode:9, }) }else if(index==2){ this.setData({ inquiry_type:1, inquiry_mode:8, }) this.getHealthy() }else if(index==3){ this.setData({ inquiry_type:1, inquiry_mode:2, }) }else if(index==4){ this.setData({ inquiry_type:1, inquiry_mode:6, }) this.getConfig(); } this.getDoctorconfig(); this.getDoctorOpen(); this.getSysconfig(); }, 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("修改成功"); // wx.switchTab({ // url: "/user/pages/yishi/wenzhen_v2/wenzhen" // }) // }).catch(errors => {console.error(errors);}) wx.switchTab({ url: "/Pages/yishi/wenzhen_v2/wenzhen" }) }, getHealthy(){ api.getHealthy().then(response => { this.setData({ healthPrice:(response.data.inquiry_price*response.data.service_rate/100).toFixed(2) }) }).catch(errors => {console.error(errors);}) }, getSysconfig(){ let {inquiry_type,inquiry_mode}=this.data; api.getSysconfig({ inquiry_type, inquiry_mode }).then(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 }) }).catch(errors => {console.error(errors);}) }, 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; } }, })