import Toast from '@vant/weapp/toast/toast'
import { API } from './../../../utils/network/api'
const api = new API()
const app = getApp()
Page({
  data: {
    bohuishow: false,
    reasonshow: false,
    resonText: "请选择驳回理由",
    columns: ['用法错误', '超适应症用药', '诊断与用药不符', '抗生素使用不合理', '重复用药'],
    navbarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '处方详情', //导航栏 中间的标题
    },
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.height,
    order_prescription_id: "",
    prescription_img_oss_path: "",
    doctor_sign_image: ""
  },
  onLoad(options) {
    let order_prescription_id = options.order_prescription_id;
    console.log("order_prescription_id: ", order_prescription_id)
    this.setData({
      order_prescription_id: order_prescription_id
    })
  },

  onConfirmReason(event) {
    const { picker, value, index } = event.detail;
    console.log(`当前值：${value}, 当前索引：${index}`);
    let _resonText = `${value}`;
    this.setData({ resonText: _resonText });
    this.setData({ reasonshow: false });
  },

  onCancelReason() {
    this.setData({ reasonshow: false });
  },

  showPopup() {
    this.setData({ bohuishow: true });
  },
  
  showReasonPopup(){
    console.log(222);
    this.setData({ reasonshow: true });
  },

  onClose() {
    console.log(111);
    this.setData({ bohuishow: false });
  },

  onCloseReason(){
    this.setData({ reasonshow: false });
  },
  
  closePopup(){
    this.setData({ bohuishow: false });
  },

  submitBohui(e) {
    console.log(444);
    this.putPharmacistPrescriptionVerify(e);
  },

  submit(){
    console.log(555);
  },
  onShow(){
    api.getPharmacistPrescriptioninfo({order_prescription_id: this.data.order_prescription_id}).then(response => {
      console.log(response.data);
      this.setData({
        prescription_img_oss_path: response.data.prescription_img_oss_path,
        doctor_sign_image: response.data.doctor_sign_image
      })
    }).catch(errors => {console.error(errors);})
  },
  putPharmacistPrescriptionVerify(e){
    console.log(e)
    let params = {};
    params.pharmacist_audit_status = e.currentTarget.dataset.pharmacist_audit_status;
    if(params.pharmacist_audit_status == 2){
      params.pharmacist_fail_reason = this.data.resonText;
    }
    params.order_prescription_id = this.data.order_prescription_id;
    api.putPharmacistPrescriptionVerify(params).then(response => {
      console.log(response.data);
      Toast.success("处理成功");
      setTimeout(() => {
        wx.navigateBack();
      }, 1000);
    }).catch(errors => {console.error(errors);})
  }

})