const _my = require("../../../__antmove/api/index.js")(my);
const wx = _my;
// pages/wx_airport/Xiaosha_registration/index.js
var util = require("../../../utils/util");
const {
  disinfectScanQrcode,
  disinfectCommit
} = require("../../../utils/api/xiaosha");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo: wx.getStorageSync("userInfo"),
    disinfectAreaId: null,
    //消杀时间id
    timeBreak: null,
    //消杀时间val
    headerData: null,
    status: "2",
    //消杀状态
    disinfectTimeBreakId: null,
    disinfectRemarks: null
  },
  // 重新扫码
  goQrcode() {
    wx.navigateTo({
      url: "/pages/wx_airport/Xiaosha_registration/scan_code/index"
    });
  },
  // 消杀状态
  onChange(event) {
    this.setData({
      status: event.detail
    });
  },
  // 下拉-消杀时间
  getTime(e) {
    let {
      disinfectAreaTimeVOList
    } = this.data.headerData;
    this.setData({
      timeBreak: disinfectAreaTimeVOList[e.detail.value].timeBreak,
      disinfectTimeBreakId: disinfectAreaTimeVOList[e.detail.value].disinfectAreaTimeId
    });
  },
  // 备注
  problemDetailFun(e) {
    this.setData({
      disinfectRemarks: e.detail.value
    });
  },
  // 上报
  report() {
    let {
      status,
      disinfectTimeBreakId,
      disinfectRemarks,
      userInfo,
      disinfectAreaId
    } = this.data;
    if (status == 2 && disinfectTimeBreakId && !disinfectRemarks) {
      wx.showToast({
        title: "标红内容不能为空",
        icon: "none"
      });
      return;
    }
    let data = {
      status,
      adminId: userInfo.orgId,
      userId: userInfo.userId,
      disinfectAreaId,
      disinfectRemarks,
      disinfectTimeBreakId
    };
    disinfectCommit(data).then(res => {
      if (res.code === 200) {
        my.alert({
          title: "提示",
          content: "上报成功!",
          success: res => {
            wx.navigateTo({
              url: "/pages/wx_airport/rlxf_pass/rlxf_pass?orgId=" + userInfo.orgId
            });
          }
        });
      } else {
        wx.showToast({
          title: res.msg,
          icon: "none"
        });
      }
    });
  },
  // 获取顶部信息
  getMsg() {
    let data = {
      adminId: this.data.userInfo.orgId,
      userId: this.data.userInfo.userId,
      disinfectAreaId: this.data.disinfectAreaId
    };
    console.log(data);
    disinfectScanQrcode(data).then(res => {
      if (res.code === 200) {
        if (res.data.waitDisinfectPipei) {
          let index = res.data.disinfectAreaTimeVOList.findIndex(item => {
            return item.timeBreak === res.data.waitDisinfectPipei;
          });
          this.setData({
            timeBreak: res.data.disinfectAreaTimeVOList[index].timeBreak,
            disinfectTimeBreakId: res.data.disinfectAreaTimeVOList[index].disinfectAreaTimeId
          });
        }
        this.setData({
          headerData: res.data
        });
      } else {
        wx.showToast({
          title: res.msg,
          icon: "none"
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (options) {
      this.setData({
        disinfectAreaId: options.disinfectAreaId
      });
    }
    this.getMsg();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
  antmoveAction: function () {
    //执行时动态赋值，请勿删除
  }
});