import HTTP from '../../../../../requestFn/Api';
const app = getApp();
Page({

  data: {
    garden_id: null,
    id: null,
    base_info: {},
    list: [],
    status: {
      1: "待受理",
      2: "受理中",
      3: "已完成"
    },
    flag: true,
    type: {
      1: "投诉",
      2: "建议"
    },
    detail: [{
        name: "投诉类型",
        value: 'suggestion_type'
      },
      {
        name: "投诉人",
        value: 'apply_people'
      },
      {
        name: "联系方式",
        value: 'apply_people_phone'
      },
      {
        name: "状态",
        value: 'status'
      },
      {
        name: "投诉内容",
        value: 'apply_content'
      },
    ]
  },

  onLoad(options) {
    const {
      garden_id
    } = app.globalData;
    const {
      id
    } = options;
    this.setData({
      garden_id,
      id
    })
    this.getSuggestion_info()
  },
  async getSuggestion_info() {
    const {
      garden_id,
      id
    } = this.data;
    let res = await HTTP.Suggestion_info({
      garden_id,
      id
    });
    console.log(res);
    const {
      base_info,
      list
    } = res;
    const {
      return_visit_level
    } = base_info
    if (return_visit_level == 2) {
      this.setData({
        flag:false
      })
    }
    this.setData({
      base_info,
      list
    })
  },
  async submit(e) {
    const {
      garden_id,
      id
    } = this.data;
    const {
      return_visit_level,
      return_visit_content
    } = e.detail.value
    if (return_visit_content == '') {
      wx.showToast({
        title: '请输入评价',
        icon: 'error'
      })
      return false
    }
   const res =  await HTTP.Suggestion_return_visit({
      garden_id,
      id: id - 0,
      return_visit_level: return_visit_level - 0,
      return_visit_content
    })
    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],
    })
  }
})