// pages/index/repair/detail/detail.js
import HTTP from "../../../../../requestFn/Api"
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    base_info: {},
    list: [],
    id: null,
    garden_id: null,
    flag: true,
    detail: [{
        name: "报修区域",
        value: "area",
      },
      {
        name: "报修分类",
        value: "class_name"
      },
      {
        name: "报修人",
        value: "apply_people"
      },
      {
        name: "联系方式",
        value: "apply_people_phone"
      },
      {
        name: "预约时间",
        value: "appointment"
      },
      {
        name: "联系地址",
        value: "house_name"
      },
      {
        name: "状态",
        value: "status"
      },
      {
        name: "报修内容",
        value: "apply_content"
      },
    ],
    status: {
      1: "未派单",
      2: "已派单",
      3: "已完结"
    },
    area_list: {
      1: "公共区域",
      2: "室内"
    }
  },

  onLoad(options) {
    const that = this;
    const {
      id,garden
    } = options;
    const {
      garden_id
    } = app.globalData;
    that.setData({
      id,
      garden_id
    })
    that.getOrderInfo(garden_id, id)
  },
  getOrderInfo(garden_id, id) {
    const that = this;
    HTTP.Order_info({
      garden_id,
      id
    }).then(res => {
      const {
        base_info,
        list
      } = res;
      const {
        return_visit_level
      } = base_info
      if (return_visit_level == 2) {
        that.setData({
          flag: false
        })
      }
      that.setData({
        base_info,
        list
      })
    })
  },
  submit(e) {
    const {
      garden_id,
      id
    } = this.data;
    const {
      return_visit_level,
      return_visit_content
    } = e.detail.value
    if(!return_visit_level){
      wx.showToast({
        title: '请选择满意度',
        icon: "error",
      })
      return false
    }
    if(!return_visit_content){
      wx.showToast({
        title: '请输入评价详情',
        icon: "error",
      })
      return false
    }
    HTTP.Repair_return_visit({
      garden_id,
      id: id - 0,
      return_visit_level: return_visit_level - 0,
      return_visit_content
    }).then(res => {
      if (res.code == 0) {
        wx.showToast({
          title: '提交成功',
          icon: "success",
          duration: 2000,
          success(){
            setTimeout(()=>{
              wx.navigateBack({
                delta:1
              })
            },500)
          }
        })
      }
    })
  },
  chickImage(e) {
    const {
      index
    } = e.currentTarget.dataset;
    const {
      base_info: {
        apply_pic
      }
    } = this.data;
    wx.previewImage({
      urls: apply_pic,
      current: apply_pic[index],
    })
  },
  chickRepair(e){
    const {
      index
    } = e.currentTarget.dataset;
    const {
      base_info: {
        repair_pic
      }
    } = this.data;
    wx.previewImage({
      urls: repair_pic,
      current: repair_pic[index],
    })
  }
})