<template>
  <div class="auto">
    <div class="row text-center" style="margin-top: 20px;">
      <button class="btn  btn-primary" style="width: 15%;  border-radius: 5px ;" @click= "upload()">上传</button>
    </div>

    <div v-for="row in model" v-if="model.length > 0">
      <div @click="inspect(row)" class="auto app-text" style="margin-top: 5px;">
        <div class="panel" style="padding: 10px 10px 5px 10px;">
          <div class="panel-body panel-self">
            <div class="col-xs-6">
              <p class="panel-title col-xs-5 text-left font"><b>用户编号:</b></p>
              <p class="panel-title col-xs-7 text-left input-font">{{ row.f_userinfo_code }}</p>
            </div>
            <div class="col-xs-6">
              <p class="panel-title col-xs-5 text-left font"><b>用户名称:</b></p>
              <p class="panel-title col-xs-7 text-left input-font">{{ row.f_user_name }}</p>
            </div>
            <div class="col-xs-6">
              <p class="panel-title col-xs-5 text-left font"><b>用户类型:</b></p>
              <p class="panel-title col-xs-7 text-left input-font">{{ row.f_user_type }}
              </p>
            </div>
            <div class="col-xs-12">
              <p class="panel-title text-left font" style="width: 23%;float: left"><b>用户电话:</b></p>
              <p class="panel-title text-left input-font" style="width: 77%">{{ row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone }}
                <img src="../../assets/phone.png" style="width: 6%" v-on:click.stop.prevent='$parent.$parent.$parent.makeAPhoneCall(row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone)'></img>
              </p>
            </div>
            <div class="col-xs-12">
              <p class="panel-title text-left font" style="width: 23%;float: left"><b>用户地址:</b></p>
              <p class="panel-title text-left input-font" style="width: 77%">{{ row.f_address }}</p>
            </div>
            <div class="col-xs-6">
              <p class="panel-title col-xs-5 text-left font"><b>安检状态:</b></p>
              <p class="panel-title col-xs-7 text-left input-font">{{ row.f_state }}</p>
            </div>
            <div class="col-xs-6">
              <p class="panel-title col-xs-5 text-left font"><b>上传状态:</b></p>
              <p class="panel-title col-xs-7 text-left input-font">{{ row.f_upload_state }}</p>
            </div>
            <div class="row">
              <p class="panel-title col-xs-4 text-left font">有无安检计划</p>
              <p class="panel-title col-xs-8 text-left input-font">{{ row.f_no_checkplan }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-if="model.length == 0">
      暂无数据
    </div>
    <work-busy :is-busy="isSend"></work-busy>
  </div>
</template>

<script>
import $ from "jquery";

export default {
  title:'抄表用户信息',
  data () {
    return {
      model:[],
      isSend:false,
      context: '',
      enableButton:false,
      // 测试用数组
      result: [{"f_check_item_id":"441e7ecc05bd418494011c1524437a70","f_checker_id":"18518","row":{"f_devices":[{"f_device_type":"热水器","f_items":[{"f_item_value":"正常","f_is_defect":"","f_item_name":"热水器烟道","f_path":"","id":"0dac97b7715c4177a656b00d1995da24","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"selector","selected":""},{"f_item_value":"","f_is_defect":"","f_item_name":"热水器品牌","f_path":"","id":"b00231992fac40aa9a8e7d33b9eefbb7","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"string"},{"f_item_value":"卫生间","f_is_defect":"","f_item_name":"安装位置","f_path":"","id":"f5c5ea59791a4bb5b76a58272e776b56","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"selector","selected":""},{"f_item_value":"正常","f_is_defect":"","f_item_name":"工作状态","f_path":"","id":"fabaf277bb9c4858948db63b7c55a365","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"selector","selected":""}]},{"f_device_type":"燃气表","f_items":[{"f_item_value":null,"f_is_defect":"","f_item_name":"表号","f_path":"","id":"56cb352415de406783c304ca25ed9be7","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"number"},{"f_item_value":null,"f_is_defect":"","f_item_name":"表封号","f_path":"","id":"6bc8d49e473b43cb92a8bfc15c5a57bf","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"number"},{"f_item_value":"0","f_is_defect":"","f_item_name":"累计购气量","f_path":"","id":"a213f5f4092c4d5a96f0d856a13fd0af","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"number"},{"f_item_value":"安然中海油","f_is_defect":"","f_item_name":"表品牌","f_path":"","id":"acc505d987304d689a9801b199527cf8","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"string"},{"f_item_value":"G2.5","f_is_defect":"","f_item_name":"表型号","f_path":"","id":"ceb6c96ca39e4fcf89b26bfc6fa42a45","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"selector","selected":""},{"f_item_value":"厨房","f_is_defect":"","f_item_name":"位置","f_path":"","id":"dffeb7d1d4dc4a989a5d333f092416bf","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"selector","selected":""}]}],"device0":[{"f_device_type":"热水器","f_items":[{"f_item_value":"正常","f_is_defect":"","f_item_name":"热水器烟道","f_path":"","id":"0dac97b7715c4177a656b00d1995da24","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"selector","selected":""},{"f_item_value":"","f_is_defect":"","f_item_name":"热水器品牌","f_path":"","id":"b00231992fac40aa9a8e7d33b9eefbb7","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"string"},{"f_item_value":"卫生间","f_is_defect":"","f_item_name":"安装位置","f_path":"","id":"f5c5ea59791a4bb5b76a58272e776b56","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"selector","selected":""},{"f_item_value":"正常","f_is_defect":"","f_item_name":"工作状态","f_path":"","id":"fabaf277bb9c4858948db63b7c55a365","f_defect_level":null,"f_device_id":"20e6dea47ed84ecb88070b3f4c3777b7","type":"selector","selected":""}]}],"device1":[],"device2":[],"device3":[],"device4":[],"device5":[{"f_device_type":"燃气表","f_items":[{"f_item_value":null,"f_is_defect":"","f_item_name":"表号","f_path":"","id":"56cb352415de406783c304ca25ed9be7","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"number"},{"f_item_value":null,"f_is_defect":"","f_item_name":"表封号","f_path":"","id":"6bc8d49e473b43cb92a8bfc15c5a57bf","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"number"},{"f_item_value":"0","f_is_defect":"","f_item_name":"累计购气量","f_path":"","id":"a213f5f4092c4d5a96f0d856a13fd0af","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"number"},{"f_item_value":"安然中海油","f_is_defect":"","f_item_name":"表品牌","f_path":"","id":"acc505d987304d689a9801b199527cf8","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"string"},{"f_item_value":"G2.5","f_is_defect":"","f_item_name":"表型号","f_path":"","id":"ceb6c96ca39e4fcf89b26bfc6fa42a45","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"selector","selected":""},{"f_item_value":"厨房","f_is_defect":"","f_item_name":"位置","f_path":"","id":"dffeb7d1d4dc4a989a5d333f092416bf","f_defect_level":null,"f_device_id":"3c90473662d54fc689d5da673f45a6bb","type":"selector","selected":""}]}],"f_approved_time":null,"f_street":null,"f_client_evaluation":null,"f_defect_urgency":null,"f_repair_approved_time":null,"f_notified_path":null,"f_longitude":null,"f_cutoff_gas":null,"f_approved_by":null,"f_check_item_id":"441e7ecc05bd418494011c1524437a70","f_card_id":null,"f_pic3_path":null,"f_recording1_path":null,"f_remark":null,"f_building":"2号楼","f_room_style":"多层","f_client_suggestion":null,"f_close_valve_path":null,"f_state":"未检","f_defect_registered":null,"f_repaired_uploaded":null,"id":"15eb6a232bd4495485b2a6352a83045d","f_heating_style_":null,"f_heating_style":"热力公司集中供暖","f_complete":null,"f_recording2_path":null,"f_overall_path":null,"f_defect_expand":null,"f_zero_meter":null,"f_defect_notified":null,"f_recording3_path":null,"f_pic1_path":null,"f_SafeToRepair_id":null,"f_residential_area":null,"f_overall2_path":null,"f_cutoff_gas_path":null,"f_usegas":null,"f_stop_service":null,"f_user_phone":"","f_nongasuser_path":"file:///android_asset/nopic.png","f_approved":"未审核","f_unit":"2单元","f_signname":null,"f_sign_imgid":null,"f_no_gas_device":false,"f_check_plan_id":"7b892a031f2f40e99e944e8969d7329c","f_checker_id":"18518","f_prearranged_date":null,"f_noncivil_style":null,"f_check_type":"民用","f_defect_dorm":null,"f_defect_other":null,"f_amr_path":null,"f_orgstr":"1531.1535.18506.18518.","f_close_valve":false,"f_repaired":null,"f_repair_date":null,"f_approved_note":null,"f_orgid":"1531.1535.","f_empty_pipe":null,"f_floor":"1层","f_entry_status":"入户","f_close_adjuster":null,"f_repair_approved_note":null,"f_onsite_time":"2019-04-13 15:18:29","f_repair_approved":"未审核","f_stop_devices":null,"f_ratification_des":null,"f_no_checkplan":"有计划安检","f_repair_approved_by":null,"f_room":"20101号","f_address":"77高新区-怕踢街道-zqxiaoqu2号楼号楼2单元单元1层层20101号室","f_sign_path":null,"f_userinfoid":"548","f_offsite_time":"2019-04-13 15:18:34","f_defect_notfixed":null,"f_subcompany":"中海油.海南分公司","f_notfixed_path":null,"f_close_adjuster_path":null,"f_pic2_path":null,"f_noanswer_path":"file:///android_asset/nopic.png","f_unload_battery":false,"f_latitude":null,"f_usage":null,"f_repairman":null,"f_plan_id":null,"f_user_name":"111","f_checker_name":"测试1","style__":"","style_view_":"","f_entry_class":"success"}}
      ]
      // 获取用户信息数组
    }
  },
  methods: {
    inspect(row){
      if(this.enableButton){
        return
      }
      this.enableButton=true
      if (row.f_upload_state == '未传' || (row.f_upload_state == '已传' && row.f_state == '未检')) {
        this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/查询计划项表信息`, {data: {f_userid: row.f_userinfoid}},{resolveMsg: null,rejectMsg: null}).then((response) => {
          row['f_plan_meters'] = response.data
          let pardate = {
            _this:this,
            tittle:'安检已办',
            safe:false
          }
          this.$dispatch('gotoson',pardate)
          this.enableButton=false
          this.$goto('safecheck-order-v', {f_plan_id: row.f_plan_id, item: row, role: 'inspect',buttonState:false}, 'self', this.refresh)
        }).catch((msg)=>{
          this.enableButton=false
          let criteria = {
            items: '*',
            tablename: 't_plan_item_meter',
            condition: `f_plan_item_id = '${row.id}'`,
            groupitem: 'f_plan_item_id'
          }
          let result = HostApp._executeTask({'type':'sql', 'data':{'alias': 'safe_singleTable_GroupBy', 'criteria': criteria}})
          if(result.code == 200){
            row['f_plan_meters'] = result.data.rows
            let pardate = {
              _this:this,
              tittle:'安检已办',
              safe:false
            }
            this.$dispatch('gotoson',pardate)
            this.enableButton=false
            this.$goto('safecheck-order-v', {f_plan_id: row.f_plan_id, item: row, role: 'inspect',buttonState:false}, 'self', this.refresh)
          }
        })
      }else{
        this.$showMessage("该安检单已被上传！")
        this.enableButton=false
      }
    },
    async uploadAll() {
      if(this.model.length>0){
        let param = {
          rows:this.model
        }
        let paramStr = JSON.stringify(param)
        let subLength = 800
        for (let i = 0; i < paramStr.length; i += subLength) {
          HostApp.param_cache(paramStr.substr(i, subLength))
        }
        HostApp.__this__ = this
        HostApp.syncLogic({
          'logic': 'UploadAll',
          'callback': 'javascript:HostApp.__this__.uploadCallBack()',
          'backresult': 1
        })
      }else{
        this.$showMessage('暂无可上传数据')
        this.isSend = false
        return false
      }
    },
    upload(){
      this.saveNoclick()
      this.isSend = true
      this.uploadAll().then((res)=>{
        this.refresh()
      })
    },
    saveNoclick() {
      $("#savebut").addClass("noclickbut");
      setTimeout(function(){
        $("#savebut").removeClass("noclickbut");
      },5000);
    },
    uploadCallBack(jo){
      this.isSend = false
      if(jo.state == 'ok'){
        let ret = JSON.parse(jo.result)
        if(ret.state == 0){
          HostApp.alert(`${ret.successcount}条安检单上传成功，${ret.invalidcount}条安检单已作废，${ret.nocheckcount}条安检单由于网络异常上传失败！，${ret.nocheckcount}条安检单由于pc端计划被调整上传失败！,${ret.imgcount}条安检单由于图片上传失败！`)
          this.refresh()
          return true
        }
      }
    },
    refresh() {
      let value = this.$androidUtil.path({alias: 'getCheckPlan', data:{}})
      if(value.data.length > 0){
        this.model = value.data
      }else{
        this.model = []
      }
    },
  },

  ready () {
    this.refresh()
  }
}
</script>
<style>
.bg {
  background-color: blue;
  height: 1px;
  border: 0;
}
.app-row {
  background-color: white;
  padding: 10px 10px 0 10px;
  border-bottom: 1px solid rgba(235, 235, 235, 0.5);
}
.search_input {
  border: 0;
  outline: none;
}
.font{
  font: 15px PingFang-SC-Medium;
  color: #666666;
}
.input-font{
  font: 15px PingFang-SC-Medium;
  color: #333333;
}
.btn-font{
  font:600 16px PingFang-SC-Bold;
  color: #499EDF;
}
.btn-color{
  background-color: #FFFFFF;
  border-radius: 10px ;
  border: 1px solid #499EDF;
}
.app-text {
  font-size: 12px;
}
.panel-self{
  border-radius: 10px;
  border:1px solid #499EDF;
  background-color: #F8F8F8;
}
.yybtn-color{
  border-radius: 4px ;
  border: 1px solid #499EDF;
}
.qxbtn-color{
  background-color: #FFFFFF;
  border-radius: 4px ;
  border: 1px solid #499EDF;
}

</style>
