import {SearchList, date} from 'vue-client'
import {all} from 'vue-client'
import {HttpResetClass} from 'vue-client'
import Vue from "vue"
export default class Comp {
  /*async constructor() {
    await this.ready()
  }*/
  // 用户安检信息列表
  all = new all()
  //气表品牌
  brands=[]
  user=new SearchList(false)
  http = new HttpResetClass()
  isAndNot = ["是", "否"]
  data=[]
  userinfo_code=''
  userinfo={}
  selectTemplate=''
  devices=[]
  userfiles={
    f_meternumber:"",
    f_initial_base:"",
    f_user_type:"",
    f_meter_brand:"",
    f_meter_style:"",
    f_aroundmeter:"",
    f_gas_person:"",
    f_gas_date:"",
    f_userfiles_address:"",
    f_install_person:"",
    f_install_date:"",
  }
  showUser=true
  showFiles=false
  shouDevices=false
  userfiles_address=["厨房","室外"]
  filialeid=Vue.user.orgid
  //filialeid=453

  aroundmeterList=['左表','右表']
  change(filed,f){
    this[filed]=this[filed]?false:true
    f()
  }
  changeUserinfo(modelname,key,val){
    this[modelname][key]=val
  }
  changeUserfiles(key,val){
    this.userfiles[key]=val
  }
  changeDevices(index,key,val){
    this.devices[index][key]=val
  }
  gasmodel=[]

  changeBrand(val,f){
    console.log("-"+"-------"+JSON.stringify(val))
    this.userfiles.f_gasbrand_id=val.id
    this.userfiles.f_meter_brand=val.f_meter_brand
    this.gasmodel=val.gasmodel
    this.userfiles.f_meter_style='请选择'
    f()
  }
  changeBrandModel(val,f){
    console.log("当前gasmodel---"+JSON.stringify(val))
    this.userfiles.f_gasmodel_id=val.id
    this.userfiles.f_meter_style=val.f_meter_style
    f()
  }
  async ready() {
   await this.getAllBrands()
  }
setField(key,val){
    this.user.search.setField(key,val)
}
 async getUserInfo(f){

   //console.log("-----------------")
     /*console.log("1111111111111111111111111"+JSON.stringify(Vue.$appdata.saleParams))
   console.log("22222222222222222222222222"+JSON.stringify(Vue.$appdata))*/
   //Vue.appdata.load()
   //console.log(Vue.appdata.saleParams)
    /*if(Vue.android){    ${this.$androidUtil.getProxyUrl()}
      this.all.$androidUtil.bzLogic(('FetchCheckPaper', {id: "this.item.id"}))
    }else{*/
    this.setFiled("f_filialeid",this.filialeid)
      await this.user.searchList(Vue.androidUtil.getProxyUrl()+"/api/af-safecheck/sql/filemanage_getUserfies",{
        f_filialeid: "u.f_filialeid={}",
        name:"u.f_user_name like '%{}%'",
        code:"u.f_userinfo_code='{}'",
        address:"a.f_address like '%{}%'"
      },{orderitem: "f_userinfo_id DESC"})

   f()
  }

  async getUserfiles(f){
   /* if(Vue.android){
      this.all.$androidUtil.bzLogic(('FetchCheckPaper', {id: "this.item.id"}))
    }else{*/
      let response=await this.http.load("POST", Vue.androidUtil.getProxyUrl()+'/api/af-safecheck/logic/commonSearchByUser', {
        data:{
          f_userinfo_code:this.userinfo_code,
          f_unit:'fen',
          info:[]
        }
      }, {resolveMsg: null, rejectMsg: null})
    this.userinfo=response.data.resJson.userinfo
    if(this.userinfo.userfiles){
      if(this.userinfo.userfiles.devices){
        this.devices=this.userinfo.userfiles.devices
      }else{
        this.userinfo.userfiles.devices=this.devices
      }
      console.log("设备信息")
      console.log(JSON.stringify(this.devices))
      console.log("查询到的设备信息")
      console.log(JSON.stringify(this.userinfo.userfiles.devices))
    }else{
      this.userinfo.userfiles=this.userfiles
    }
    let arr=[]
    arr.push(this.userinfo.userfiles)
    this.userinfo.userfiles=arr
    this.userfiles=this.userinfo.userfiles[0]
    console.log("档案信息")
    console.log(JSON.stringify(this.userinfo))
    console.log("设备信息")
    console.log(JSON.stringify(this.devices))
    //}
    console.log("---------安装位置"+JSON.stringify(this.userfiles_address))
    f()
  }
  getTemplate(){
    if(this.userinfo_code){
      return "component2"
    }else{
      return "component1"
    }
  }
  setFiled(key,val){
    this[key]=val
  }

  addDevicesItem(f){
    this.devices.push({
      f_devices_type:"",
      f_devices_no:"",
      f_brand:"",
      f_devices_model:"",
      f_input_date:this.getNowFormatDate()
    })
    f()
  }

  del(index,f){
      console.log(index+"--------")
      this.devices.splice(index,1)
    f()
  }

//获取所有气表品牌getAllBrands
 async getAllBrands(){
    let response=await this.http.load("POST", Vue.androidUtil.getProxyUrl()+"/api/af-safecheck/logic/getSaleInitData", {
      f_orgid: this.filialeid
    }, {resolveMsg: null, rejectMsg: null})
   this.brands=response.data.gasbrands
  }
//保存用户档案信息
  async saveUserInfo(f){
    for(let i=0;i<this.devices.length;i++){this.devices[i].img={content:"",filename:""}}

    console.log(this.userinfo)
    this.userinfo.f_operator_record="文明"

    this.userinfo.userfiles[0].devicesinfo=this.userinfo.userfiles[0].devices
    let response=await this.http.load("POST", Vue.androidUtil.getProxyUrl()+"/api/af-safecheck/logic/filemanage_fileSave", {
      data:{
        userinfo:this.userinfo,
        address:{id:this.userinfo.userfiles[0].f_useraddress_id}
      }
    }, {resolveMsg: "修改成功！", rejectMsg: "失败，请联系管理员"})
    this.userinfo_code=''
    f()
  }
  back(f){
    this.userinfo_code=''
    f()
  }
  //获取当前时间
  getNowFormatDate() {
    let date = new Date();
    let seperator1 = "-";
    let seperator2 = ":";
    let month = date.getMonth() + 1;
    let strDate = date.getDate();
    let hour = date.getHours();
    let min = date.getMinutes();
    let second = date.getSeconds();
    if (month >= 1 && month <= 9) {
      month = "0" + month;
    }
    if (strDate >= 0 && strDate <= 9) {
      strDate = "0" + strDate;
    }
    if (hour >= 0 && hour <= 9) {
      hour = "0" + hour;
    }
    if (min >= 0 && min <= 9) {
      min = "0" + min;
    }
    if (second >= 0 && second <= 9) {
      second = "0" + second;
    }
    let currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
      + " " + hour + seperator2 + min
      + seperator2 + second;
    return currentdate;
  }

  //加载更多数据
  async loadMore(modelname,f) {
    await this[modelname].list.loadMore()
    f()
  }
}
