<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">卡&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
            <input type="text" class="form-control" v-model="model.f_card_id"
                   style="height:34px;margin-top: 8px"    placeholder="卡号" condition="f_card_id='{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">用户名称</label>
            <input type="text" class="form-control" v-model="model.f_user_name"
                   style="height:34px;margin-top: 8px"    placeholder="用户名称" condition="f_user_name = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">用户电话</label>
            <input type="text" class="form-control" v-model="model.f_user_phone"
                   style="height:34px;margin-top: 8px"    placeholder="用户电话" condition="f_user_phone like '%{}%'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">表&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
            <input type="text" class="form-control" v-model="model.f_meternumber"
                   style="height:34px;margin-top: 8px"    placeholder="表号" condition="f_meternumber = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">小&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;区</label>
            <input type="text" class="form-control" v-model="model.f_residential_area"
                   style="height:34px;margin-top: 8px"    placeholder="小区" condition="f_residential_area like '%{}%'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
            <input type="text" class="form-control" v-model="model.f_building"
                   style="height:34px;margin-top: 8px"    placeholder="楼号" condition="f_building = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;元</label>
            <input type="text" class="form-control" v-model="model.f_unit"
                   style="height:34px;margin-top: 8px"    placeholder="单元" condition="f_unit = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;层</label>
            <input type="text" class="form-control" v-model="model.f_floor"
                   style="height:34px;margin-top: 8px"    placeholder="楼层" condition="f_floor = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">门&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;牌</label>
            <input type="text" class="form-control" v-model="model.f_room"
                   style="height:34px;margin-top: 8px"    placeholder="门牌" condition="f_room = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检计划</label>
            <input type="text" class="form-control" v-model="$parent.$parent.model.f_check_plan.f_plan_name" @click="$parent.$parent.showChooser"
                   style="height:34px;margin-top: 8px"   placeholder="安检计划" readonly="readonly">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检状态</label>
            <v-select id="f_entry"
                      placeholder='安检状态' style="margin-top: 8px"
                      v-model='model.f_entry'
                      :value.sync="model.f_entry"
                      :options='$parent.$parent.f_entry_status'
                      condition="f_entry_status = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">开始时间</label>
            <datepicker
              :value.sync="model.f_check_start"
              placeholder='开始时间' style="margin-top: 8px"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM-dd'"
              :show-rest-button="reset"
              v-model = "model.f_check_start"
              condition="f_offsite_time > ='{} 00:00:00'">
            </datepicker>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">结束时间</label>
            <datepicker
              :value.sync="model.f_check_end"
              placeholder='结束时间' style="margin-top: 8px"
              :disabled-days-of-week="[]"
              :format="'yyyy-MM-dd'"
              :show-rest-button="reset"
              v-model = "model.f_check_end"
              condition="f_offsite_time <=  '{} 23:59:59'">
            </datepicker>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检账号</label>
            <input type="text" class="form-control" v-model="model.f_checker_name"
                   style="height:34px;margin-top: 8px"    placeholder="安检账号" condition="f_checker_name = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检人员</label>
            <input type="text" class="form-control" v-model="model.f_order_checker_name"
                   style="height:34px;margin-top: 10px"    placeholder="安检员" condition="f_order_checker_name = '{}'">
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">安检类型</label>
            <v-select :value.sync="model.f_no_checkplan" v-model='model.f_no_checkplan'
                      :value-single="true" style="margin-top: 10px"
                      :options='$parent.$parent.f_checkplans'
                      close-on-select
                      condition="f_no_checkplan = '{}'"></v-select>
          </div>

          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">小区性质</label>
            <v-select id="f_residential_properties"
                      placeholder='小区性质' style="margin-top: 10px"
                      v-model='model.f_residential_properties'
                      :value.sync="model.f_residential_properties"
                      :options='$parent.$parent.residentialProperties'
                      condition="f_residential_properties = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">运行区域</label>
            <v-select id="f_distinct"
                      placeholder='运行区域' style="margin-top: 10px"
                      v-model='model.f_opera_area'
                      :value.sync="model.f_opera_area"
                      :options='$parent.$parent.distincts'
                      condition="f_opera_area = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">供暖方式</label>
            <v-select id="f_heating_style"
                      placeholder='供暖方式' style="margin-top: 10px"
                      v-model='model.f_heating_style'
                      :value.sync="model.f_heating_style"
                      :options='$parent.$parent.heating_style'
                      condition="f_heating_style = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">重点用户</label>
            <v-select id="f_focususer_type"
                      placeholder='重点用户' style="margin-top: 10px"
                      v-model='model.f_focususer_type'
                      :value.sync="model.f_focususer_type"
                      :options='$parent.$parent.keyuser'
                      condition="ui.f_emphasis_user like '%{}%'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4 form-group form-input-group" style="width: 20%">
            <label class="control-label">用气情况</label>
            <v-select id="f_focususer_type"
                      placeholder='用气情况' style="margin-top: 10px"
                      v-model='model.f_gas_env'
                      :value.sync="model.f_gas_env"
                      :options='$parent.$parent.gasenvs'
                      condition="f_gas_env like '%{}%'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-md-5 form-group form-input-group" style="width: 20%">
            <label class="control-label" >告知书单号</label>
            <input type="text" class="form-control"  v-model="model.f_notification_number"
                   style="height:34px;margin-top: 10px"   placeholder="告知书单号" condition="f_notification_number = '{}'">
          </div>
          <div class="col-md-5 form-group form-input-group" style="width: 20%">
            <label class="control-label">工单编号</label>
            <input type="text" class="form-control"  v-model="model.workorderguid"
                   style="height:34px;margin-top: 10px"   placeholder="工单编号" condition="workorderguid = '{}'">
          </div>
          <div class="col-md-5 form-group form-input-group" style="width: 20%">
            <label class="control-label">是否一级隐患</label>
            <v-select id="f_heating_style"
                      placeholder='是否一级隐患' style="margin-top: 10px"
                      v-model='model.f_iskeyuser'
                      :value.sync="model.f_iskeyuser"
                      :options='$parent.$parent.yesorno'
                      condition="f_iskeyuser = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="col-md-5 form-group form-input-group" style="width: 20%">
            <label class="control-label" >是否气价变更</label>
            <v-select id="f_heating_style"
                      placeholder='是否气价变更' style="margin-top: 10px"
                      v-model='model.f_haschange_price'
                      :value.sync="model.f_haschange_price"
                      :options='$parent.$parent.yesorno'
                      condition="f_haschange_price = '{}'"
                      close-on-select clear-button> </v-select>
          </div>
          <div class="row">
            <div class="span" style="margin-top:8px;float:right">
              <button class="button_spacing button_search" @click="search()">查询</button>
            </div>
          </div>

            <modal :show.sync="$parent.$parent.showModal" v-ref:modal>
              <div slot="modal-header" class="modal-header">
                <h4 class="modal-title">
                  选择计划
                </h4>
              </div>
              <div slot="modal-body" class="modal-body">
                <plan-chooser :f.sync="$parent.$parent.fun"  v-ref:chooser></plan-chooser>
              </div>
              <div slot="modal-footer" class="modal-footer">
                <button  class="btn btn-success width-80" @click="$parent.$parent.ok">确认</button>
                <button  class="btn btn-success width-80" @click="$parent.$parent.cancel">取消</button>
              </div>
              </modal>
          </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>查看</th>
            <th>安检单类型</th>
            <th>安检状态</th>
            <th>卡号</th>
            <th>用户名称</th>
            <th>表号</th>
            <th>入户时间</th>
            <th>离开时间</th>
            <th>上传时间</th>
            <th>安检账号</th>
            <th>安检人员</th>
            <th>用户类型</th>
            <th>详细地址</th>
            <th>工单编号</th>
            <th>入户时长</th>
            <th>录音时长</th>
          </tr>
        </template>
        <template partial='body'>
          <td><button class="btn btn-default"  @click='$parent.$parent.$parent.change(row)'>查看</button>
            <!--<button type="button" class="btn btn-success" data-toggle="dropdown"  @click="$parent.$parent.$parent.print(row)">-->
              <!--打印-->
            <!--</button>-->
          </td>
          <td>{{row.f_no_checkplan}}</td>
          <td>{{row.f_entry_status}}</td>
          <td>{{row.f_card_id}}</td>
          <td>{{row.f_user_name}}</td>
          <td>{{row.f_meternumber}}</td>
          <td>{{row.f_onsite_time}}</td>
          <td>{{row.f_offsite_time}}</td>
          <td>{{row.f_upload_time}}</td>
          <td>{{row.f_checker_name}}</td>
          <td>{{row.f_order_checker_name}}</td>
          <td>{{row.f_user_type}}</td>
          <td>{{row.f_address}}</td>
          <td>{{row.workorderguid}}</td>
          <td>{{row.f_ruhu_time}}</td>
          <td>{{row.f_luyin_time}}</td>
        </template>
      </data-grid>
    </criteria-paged>
    <check-msg v-if="showcheckmsg" :show="showcheckmsg" :data="checkInfo"></check-msg>
  </div>
</template>

<script>
import { PagedList } from 'vue-client'
import Vue from 'vue'
import co from 'co'
import AppData from '../../stores/AppData'
import * as Util from '../Util'
import {toStartDateString, toStartDateYearString} from "../Util";

//获取json配置文件
let asyncReady = async function(self) {
  // 获取配置信息
  try {
    let res = await Vue.resetget(`/phone/rs/vue`,{data: {}},{resolveMsg: null, rejectMsg: null})
    Vue.config = res.data
  } catch (error) {
    // 忽略704,文件找不到异常R
    if (error.status !== 704) {
      throw error
    }
  }
}

let select = function * (self) {
  let getGasman = yield self.$resetpost('/rs/search', {
    source: 'this.getParentByType($organization$).getChildByName($安检员$).getUsers()',
    userid: self.$login.f.id
  }, {resolveMsg: null, rejectMsg: null})
  console.log('获取安检员', getGasman)
  getGasman.data.forEach((checker)=>{
  self.checkersid.push({label:checker.name,value:checker.id})
  self.checkersname.push({label:checker.name,value:checker.name})
})
  self.checkersname.push({label:'全部',value:''})
  self.checkersid.push({label:'全部',value:''})
}

export default {
  title: '安检单查看',
  data () {
    let model = new PagedList('rs/sql/查找安检单', 20, {f_plan_id: 'this.f_check_plan.id', f_approved: 'this.f_approved[0]', f_entry_status: 'this.f_entry[0]', f_no_checkplan:'this.f_no_checkplan[0]',f_filialeids: 'this.f_filialeids'})
    model.f_check_plan = {f_plan_name: '', id: ''}
    model.f_approved = ['']
    model.f_entry = ['']
    model.f_no_checkplan = ['']
    model.f_filialeids = this.$login.f.f_orgids
    model.f_subcompany = this.$login.f.f_fengongsi
    return {
      model:model,
      fun:this.$login.f,
      residentialProperties: [
        {label: '物业小区', value: '物业小区'},
        {label: '企事业单位', value: '企事业单位'},
        {label: '安置小区', value: '安置小区'},
        {label: '自建房', value: '自建房'},
        {label: '公租房', value: '公租房'},
        {label: '廉租房', value: '廉租房'}
      ],
      distincts: [
        {label: '全部', value: ''},
        {label: '航天', value: '航天'},
        {label: '韦曲', value: '韦曲'},
        {label: '高新', value: '高新'},
        {label: '沣东', value: '沣东'},
        {label: '中心站', value: '中心站'},
        {label: '沣西', value: '沣西'},
        {label: '浐灞生态区', value: '浐灞生态区'}
      ],
      heating_style: [
        {label: '壁挂炉供暖', value: '壁挂炉供暖'},
        {label: '集中供暖', value: '集中供暖'},
        {label: '其他', value: '其他'},
        {label: '燃气取暖器供暖', value: '燃气取暖器供暖'}
      ],
      checkersid:[],
      checkersname:[],
      showModal: false,
      // f_approval_states: this.$appdata.getParam('安检单审核状态'),
      f_entry_status: [
        {label: '全部', value: ''},
        {label: '正常', value: '入户'},
        {label: '无人', value: '到访不遇'},
        {label: '拒检', value: '拒检'}
      ],
      f_checkplans: [
      {label: '全部', value: ''},
      {label: '集中安检单', value: '集中安检单'},
      {label: '抄表单', value: '抄表单'},
      {label: '无计划安检', value: '无计划安检'},
      {label: '点火通气单', value: '点火通气单'},
      {label: '预约安检单', value: '预约安检单'},
      {label: '预约开户单', value: '预约开户单'},
      {label: '预约过户单', value: '预约过户单'},
      {label: '重点用户跟进单', value: '重点用户跟进单'},
      {label: '用户隐患跟进单', value: '用户隐患跟进单'},
      {label: '临街商铺安检单', value: '临街商铺安检单'},
      {label: '长期未检跟进单', value: '长期未检跟进单'},
      {label: '问题表跟进单', value: '问题表跟进单'},
      {label: '大锅灶安检单', value: '大锅灶安检单'}
    ],
      keyuser: [
        {label: '全部', value: ''},
        {label: '职工用户', value: '职工用户'},
        {label: '外联单位用户', value: '外联单位用户'},
        {label: '村内餐饮', value: '村内餐饮'},
        {label: '否', value: '否'},
        {label: '民改商', value: '民改商'},
        {label: '孤寡老人', value: '孤寡老人'},
        {label: '重大隐患', value: '重大隐患'},
        {label: '气量出入', value: '气量出入'},
        {label: '临街商铺', value: '临街商铺'},
        {label: '小区大锅灶', value: '小区大锅灶'},
      ],
      gasenvs: [
        {label: '全部', value: ''},
        {label: '常住', value: '常住'},
        {label: '已装修未接燃气具', value: '已装修未接燃气具'},
        {label: '燃气具连接长期无人', value: '燃气具连接长期无人'},
        {label: '毛坯', value: '毛坯'}
      ],
      yesorno: [
        {label: '全部', value: ''},
        {label: '是', value: '是'},
        {label: '否', value: '否'}
      ],
      showcheckmsg:false,
      checkInfo:{}
    }
  },
  methods: {
    search(){
      console.log('this.$refs.paged.$refs.criteria.condition',this.$refs.paged.$refs.criteria.condition)
      let con=this.$refs.paged.$refs.criteria.condition
      if(!this.$refs.paged.$refs.criteria.model.f_no_checkplan){
        con=`${this.$refs.paged.$refs.criteria.condition} and f_no_checkplan in ('集中安检单','无计划安检','预约安检单','重点用户跟进单','预约开户单','临街商铺安检单','有计划安检','点火通气单','长期未检跟进单','用户隐患跟进单','问题表跟进单')`
      }
      this.model.search({condition:con,f_plan_id: this.model.f_check_plan.id})
    },
    change (row) {
      if(row.f_no_checkplan == '抄表单'){
        this.$goto('read-meter-message', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
      }else{
        Vue.$login.jwt =  775
        asyncReady(this).then(()=> {
          row.f_upload_state = '已传'
          // if (row.f_user_type == '民用') {
          // this.$goto('paper-set', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
          this.$goto('paper-message', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
          // } else {
          // this.$goto('paper-set-noncivil', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
          // this.$goto('paper-message-nocivil', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
          // }
        }).catch(
          (respanse) => {
            alert('获取配置文件失败')
          })
      }

    },
    readConfig () {
      let gen =  asyncReady(this)
      return co(gen)
    },
    showChooser () {
      this.showModal = true
    },
    refresh() {
      this.$refs.paged.$refs.criteria.search()
      console.log('modle',this.model)
      // this.$refs.paged.model.loadPage(5)
    },
    ok () {
      this.showModal = false
      if(this.$refs.paged.$refs.criteria.$refs.modal.$children[0].selectedRow.id) {
        this.model.f_check_plan = this.$refs.paged.$refs.criteria.$refs.modal.$children[0].selectedRow
      }
    },
    cancel () {
      this.showModal = false
      this.model.f_check_plan = {f_plan_name: '', id: ''}
    },
    print(row){
      this.showcheckmsg = true
      this.checkInfo = row
    }
  },
  ready(){
    this.$refs.paged.$refs.criteria.model.f_check_start=Util.toStartDateYearString()
    this.function = this.f
    asyncReady(this).then(()=> {
      let gen = select(this)
      co(gen)
    })
  },
  watch:{
    'model.f_no_checkplan'(val){
      if(this.model.f_no_checkplan[0] == '集中安检单'){
        this.showChooser()
      }
    }
  }

}
</script>
