import { API } from "../../utils/network/api";
const api = new API()
const app = getApp()
// commpents/wenzhen_data/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    from_account: {
      type: String,
      value: '10000',
    },
    name: {
      type: String,
      value: '张三三',
    },
    sex: {
      type: String,
      value: '未知',
    },
    age: {
      type: String,
      value: '0',
    },
    date: {
      type: String,
      value: '12:89',
    },
    desc: {
      type: String,
      value: '这是示例备注desc',
      observer(desc) {
        this.setData({
          desc: desc,
        });
      },
    },
    status_text: {
      type: String,
      value: "接诊中",
    },
    status: {
      type: String,
      value: "0",
    },
    status_class: {
      type: String,
    },
    order_inquiry_id: {
      type: String,
      value: '',
    },
    inquiry_type: {
      type: String,
      value: '',
    },
    note: {
      type: String,
      value: '不接诊24小时后自动取消',
    },
    message_dot:{
      type: Boolean,
      value: false,
      observer(dot) {
        this.setData({
          message_dot: dot,
        });
      },
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    show: false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    go(e){
      app.go(e.currentTarget.dataset.url);
    },
    goChat(e){
      this.setData({
        show: false
      })

      console.log("开始订阅消息");
      wx.requestSubscribeMessage({
        tmplIds: ['jhYUf91ULCTX_f69hazqAYwImdFf8ELasRAwB6X-MTM'],
        success (res) {
          console.log(res);
          let from_account = e.currentTarget.dataset.from_account;
          let order_inquiry_id = e.currentTarget.dataset.order_inquiry_id;
          let inquiry_type = e.currentTarget.dataset.inquiry_type;
          let url = e.currentTarget.dataset.url+"?from_account="+from_account+"&order_inquiry_id="+order_inquiry_id+"&inquiry_type="+inquiry_type;
          app.go(url);
        }
      })
    },
    postDoctorInquiry(e){
      this.setData({
        show: false
      })
      console.log("order_inquiry_id: ", e.currentTarget.dataset.order_inquiry_id);
      let params = {};
      params.order_inquiry_id = e.currentTarget.dataset.order_inquiry_id;
      console.log("params: ",params)
      api.postDoctorInquiry(params).then(response => {
        console.log("开始接诊");
        console.log(response);
      }).then(() => {
        this.goChat(e);
      }).catch(errors => {
        console.error(errors);
      })

    },
    tabShow(){
      this.setData({
        show: true
      })
    },
    onClose(){
      this.setData({
        show: false
      })
    }
  }
})
