<template>
  <div class="row">
    <work-busy :is-busy="isbusy"></work-busy>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row" v-show="!$parent.$parent.$parent.showItem">
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户编号</label>
              <input type="text" class="input_search" v-model="model.f_userinfo_code" condition="a.f_userinfo_code = '{}'"
                     style="width: 60%" placeholder="用户编号">
            </div>
            <div :class="$parent.$parent.style2" style="margin: 0">
              <label class="control-label">客户类型</label>
              <v-select :value.sync="model.f_user_type" v-model="model.f_user_type"
                        :value-single="false" clear-button :options='$parent.$parent.user_types' placeholder='客户类型'
                        condition="b.f_user_type = '{}'"></v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户名称</label>
              <input type="text" class="input_search" v-model="model.f_user_name" condition="a.f_user_name like '%{}%'"
                     style="width: 60%" placeholder="用户名称">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户电话</label>
              <input type="text" class="input_search" v-model="model.f_user_phone" condition="a.f_user_phone like '%{}%'"
                     style="width: 60%" placeholder="用户名称">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用户地址</label>
              <input type="text" class="input_search" v-model="model.f_user_address" condition="a.f_user_address like '%{}%'"
                     style="width: 60%" placeholder="用户地址">
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">派单员</label>
              <input type="text" class="input_search" v-model="model.f_operator" condition="a.f_operator like '%{}%'"
                     style="width: 60%" placeholder="派单员">
            </div>
            <div :class="$parent.$parent.style2" style="margin: 0">
              <role-selector-safe
                role-name="安检员"
                role-lable="安&nbsp;检&nbsp;员&nbsp;"
                @re-res="$parent.$parent.getRes"
                :value.sync="model.f_handlercheck_name"
                v-model="model.f_handlercheck_name"
                condition="f_handlercheck_name = '{}'">
              </role-selector-safe>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">开始时间</label>
              <datepicker
                :value.sync="model.f_check_start"
                placeholder='开始时间' style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_check_start"
                condition="f_handler_time > ='{} 00:00:00'">
              </datepicker>
            </div>
            <div class="form-group col-sm-2">
              <label class="font_normal_body">结束时间</label>
              <datepicker
                :value.sync="model.f_check_end"
                placeholder='结束时间' style="width: 60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model="model.f_check_end"
                condition="f_handler_time <=  '{} 23:59:59'">
              </datepicker>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-2 form-group" style="margin: 0">
              <label class="font_normal_body">安检状态</label>
              <v-select :value.sync="model.f_handler_state" v-model="model.f_handler_state" style="width: 60%"
                        :value-single="false" clear-button :options='$parent.$parent.handler_states' placeholder='安检状态'
                        condition="f_handler_state = '{}'"></v-select>
            </div>
            <div class="col-sm-2 form-group" style="margin: 0">
              <label class="font_normal_body">安检结果</label>
              <v-select :value.sync="model.f_last_check_state" v-model="model.f_last_check_state" style="width: 60%"
                        :value-single="false" clear-button :options='$parent.$parent.last_check_states' placeholder='安检结果'
                        condition="f_handler_state = '已安检' and f_last_check_state = '{}'"></v-select>
            </div>
            <div class=" col-sm-4 form-group button-range">
              <div class="span" style="float: right;margin-top: 8px">
                <button style="float: right" class="button_search button_spacing" @click="search">查询</button>
                <button style="float: right" class="button_search button_spacing"
                        @click="$parent.$parent.yyChange(1)">转单</button>
                <button style="float: right" class="button_search button_spacing"
                        @click="$parent.$parent.yyChange(2)">取消预约</button>
              </div>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <template partial='head'>
          <tr>
            <th>
              <nobr><input type="checkbox" onClick="event.cancelBubble = true"
                           :checked="$parent.$parent.$parent.checkAll" @change="$parent.$parent.$parent.setCheckAll()" />全选
              </nobr>
            </th>
            <th>
              <nobr>用户编号</nobr>
            </th>
            <th>
              <nobr>客户类型</nobr>
            </th>
            <th>
              <nobr>用户名</nobr>
            </th>
            <th>
              <nobr>用户电话</nobr>
            </th>
            <th>
              <nobr>用户地址</nobr>
            </th>
            <th>
              <nobr>预约时间</nobr>
            </th>
            <th>
              <nobr>安检时间</nobr>
            </th>
            <th>
              <nobr>安检员</nobr>
            </th>
            <th>
              <nobr>派单员</nobr>
            </th>
            <th>
              <nobr>备注</nobr>
            </th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;white-space:nowrap;"><input type="checkbox" @click="$event.cancelBubble = true" v-if="row.f_handler_state == '已预约'"
                                                                    :checked="$parent.$parent.$parent.isChecked(row.f_userinfo_id)"
                                                                    @change="$parent.$parent.$parent.setCheckes(row.f_userinfo_id)"></input></td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_userinfo_code }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.user_type }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_user_name }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_user_phone }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.address }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_handler_time }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_last_check_date }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_handlercheck_name }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_single_man }}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_safe_remark }}</td>
        </template>
      </data-grid>
    </criteria-paged>
    <modal :show.sync="selecetChecker" :backdrop="false">
      <div slot="modal-header" class="modal-header">
      </div>
      <div slot="modal-body" class="modal-body">
        <div class="row">
          <div style="margin: 0">
            <label class="control-label">安&nbsp;&nbsp;检&nbsp;&nbsp;员</label>
            <v-select :value.sync="changeData.f_handlercheck_name" v-model="changeData.f_handlercheck_name"
                      :value-single="false" clear-button :options='checkers' placeholder='安检员'></v-select>
          </div>
          <div style="margin: 0">
            <label class="control-label" >备&emsp;&emsp;注</label>
            <input class="input_search" type="text" style="margin-left: 5px;width: 60%" v-model="changeData.f_safe_remark" placeholder="备注">
          </div>
        </div>
      </div>
      <div slot="modal-footer" class="modal-footer" style="text-align: center">
        <button class="button_search" style="margin-right: 20px" @click="ok">确认</button>
        <button class="button_search" @click="selecetChecker = false">取消</button>
      </div>
    </modal>
  </div>
</template>
<script>
import { PagedList } from 'vue-client'
import HttpResetClass from "vue-client/src/plugins/HttpResetClass";
import co from 'co'
import Vue from 'vue'
import * as Util from '../../components/Util'

let select = function* (self) {
  let http = new HttpResetClass()
  let getGasman = yield http.load('POST', '/rs/search', {
    source: 'this.getParentByType($organization$).getChildByName($安检员$).getUsers()',
    userid: self.$login.f.id
  }, { resolveMsg: null, rejectMsg: null })
  //tag
  self.checkers.push({ label: '全部', value: '' })
  getGasman.data.forEach((checker) => {
    self.checkers.push({ label: checker.name, value: checker })
  })
}
export default {
  title: '预约安检',
  data() {
    let model = new PagedList('rs/sql/safe_singleTable_OrderBy', 20, {
      items: "'a.*,b.f_user_type as user_type,c.f_address as address,swo.f_single_man'",
      tablename: "'t_userinfo a left join t_userfiles b on a.f_userinfo_id = b.f_userinfo_id left join t_user_address c on a.f_userinfo_id = c.f_userinfo_id left join t_serviceworkorder swo on swo.f_service_id = a.f_service_id' ",
      orderitem: "'f_handler_time desc'"
    })
    return {
      f: this.$login.f,
      model: model,
      changeData: {},
      criteriaShow: false,
      selecetChecker: false,
      checkAll: false,
      timercount: 0,
      showModal2: false,
      repairTypeOptions: this.$appdata.getParam('报修类型'),
      user_types: [{ label: '全部', value: '' }, { label: '民用', value: '民用' }, { label: '非民用', value: '非民用' }],
      handler_states:[{ label: '全部', value: '' }, { label: '已预约', value: '已预约' }, { label: '已安检', value: '已安检' }],
      last_check_states:[{ label: '全部', value: '' }, { label: '到访不遇', value: '到访不遇' }, { label: '拒检', value: '拒检' }, { label: '入户', value: '入户' }],
      dispatchTypeOptions: [{ label: '派发给站点', value: '派发给站点' }, { label: '派发给维修员', value: '派发给维修员' }],
      checkes: [],
      showModal: false,
      f_check_plan: { f_plan_name: '', id: '' },
      sumsmodel: {},
      resids: {},
      all: false,
      fields: {},
      f_filialeid:this.$login.f.orgid,
      selectData: {
        dispatchType: '',
        f_repairman: '',
        f_remarks: '',
        f_repairtype: ''
      },
      progressbarWidth: '0',
      modelval: [],
      isbusy: false,
      transfer: null,
      checkers: [],
      showModal3: false,
      toRepairCount: 0,
      sliceArea: [],
      callSends: [],
      cbc: [],
      repairedOptions: [{ label: '全部', value: '' }, { label: '已修', value: '已修' }, { label: '未修', value: '未修' }],
      repairers: [],
      cbcs: [],
      thead: '',
      headData: ['入户状态', '用户编号', '用户名', '用户电话', '用户小区', '用户地址', '安检时间', '安检员', '计划名', '是否有隐患', '隐患数', '隐患明细', '处理数', '完成数', '处理情况', '完成情况', '维修员'],
      bodyData: ['f_entry_status', 'f_userinfo_code', 'f_user_name', 'f_user_phone', 'f_residential_area', 'address', 'f_offsite_time', 'f_checker_name', 'f_plan_name', 'f_has_defect', 'f_defect_count', 'defecttext', 'f_deal_count', 'f_repair_count', 'f_is_deal', 'f_is_repair', 'f_repairman'],
    }
  },
  props: {
    style: {
      type: String,
      default: 'col-sm-2 form-group'
    },
    style2: {
      type: String,
      default: 'col-sm-4 form-group'
    }

  },

  methods: {
    yyChange(type) {
      if (!this.checkAll && this.checkes.length === 0) {
        this.$showMessage('请选择用户')
        return
      }
      if (type == 1) {
        this.selecetChecker = true
      } else {
        let userinfoIds = []
        if (this.checkAll) {
          userinfoIds = this.model.rows.map(row => {
            return `'${row.f_userinfo_id}'`
          })
        } else if (this.checkes.length > 0) {
          userinfoIds = this.checkes
        }
        let sql = `update t_userinfo set f_handler_time = null,f_handler_state= null,f_handlercheck_id=null,f_handlercheck_name=null,f_safe_remark=null,f_contact_phone=null,f_safe_urgency=null,f_safe_isUrgent=null,f_service_id=null where f_userinfo_id in (${userinfoIds.join()})`
        new HttpResetClass().load('POST', 'rs/logic/runSQL', { data: { sql: sql } }, { resolveMsg: null, rejectMsg: '取消预约失败' }).then(() => {
          this.$refs.paged.$refs.criteria.search()
        }).catch(()=>{
          this.$showMessage('取消预约失败')
        })
      }
    },
    getSiteRes(obj) {
      console.log('siteRes ---> ')
      console.log(obj)
      if (obj.resids[0]) {
        this.selectData.f_meetunit = obj.res.join('.')
        this.selectData.f_reciever = obj.resids.join('.')
        this.selectData.f_outlets = obj.res[obj.res.length - 1]
      } else {
        this.selectData.f_meetunit = ''
        this.selectData.f_reciever = ''
        this.selectData.f_outlets = ''
      }
    },
    trouble(val) {
      // return val.replaceAll("'",'')
      // .replaceAll("\"",'')
      // .replaceAll("{",'')
      // .replaceAll("}",'')
      // .replaceAll("]",'')
      // .replaceAll("[",'')
      // .replaceAll("result:",'')
      // .replaceAll("data:",'')
      // .replaceAll("有隐患",'')
      // .replaceAll(",",'')


      const defect_content = JSON.parse(val)
      let result = ''
      if (defect_content.data) {
        const jsonData = defect_content.data
        for (const itemdata of jsonData) {
          const keys = Object.keys(itemdata)
          for (const itm of keys) {
            const value = itemdata[itm]
            result += itm + ':' + value
          }
        }
      }
      return result
    },
    getEmp() {
      let val = { source: 'this.getParentByType($organization$).getSpecialResByType($user$).where(row.getAttributes().get($rolestr$)!=null ).where(row.getAttributes().get($rolestr$).indexOf($维修员$) != -1))', userid: `${this.$login.f.id}` }
      let http = new HttpResetClass()
      http.load('POST', '/rs/search', { data: val }, { resolveMsg: null, rejectMsg: null }).then((res) => {
        let str = `'`
        res.data.forEach((item, idx, arr) => {
          //tag
          if (idx + 1 == arr.length) {
            str += item.id + `'`
          } else {
            str += item.id + `','`
          }

        })
        let http1 = new HttpResetClass()
        http1.load('POST', 'rs/sql/tel_singleTable_OrderBy', {
          data: {
            items: 'id,f_user_telephone',
            tablename: 't_user',
            condition: `id  in  (${str})`,
            orderitem: 'id'
          }
        }, { resolveMsg: null, rejectMsg: null }).then((ress) => {

          res.data.forEach((user) => {
            try {
              ress.data.forEach((tel, tidx, arr) => {
                //tag
                if (user.id == tel.id) {
                  this.repairers.push({ label: `${user.name}：${tel.f_user_telephone}`, value: user.name })
                  ress.data.splice(tidx, 1)
                  //tag
                  throw new Error("跳出循环");
                }
              })
            } catch (e) {
              //tag
            }
          })
        })

      })
    },
    toRepair() {
      if (this.checkes.length == 0) {
        return this.$showMessage('请先选择需要转维修的用户！')
      }
      this.showModal2 = true
    },
    async rectification() {

      if (this.selectData.dispatchType) {
        if (this.selectData.dispatchType == '派发给站点') {
          if (!this.selectData.f_reciever) {
            this.$showMessage('请选择部门！')
            return
          }
        } else {
          if (!this.selectData.f_repairman) {
            this.$showMessage('请选择维修员！')
            return
          }
        }
      } else {
        this.$showMessage('请选择派发类型！')
        return
      }

      if (!this.selectData.f_repairtype) {
        this.$showMessage('请选择报修类型！')
        return
      }
      this.showModal3 = true
      let act = {}
      let toRepair = ''
      let successCount = 0
      if (this.selectData.dispatchType == '派发给站点') {
        act = { f_meetunit: this.selectData.f_meetunit, f_reciever: this.selectData.f_reciever, f_service_acitivity_type: '派单' }
        toRepair = null
      } else {
        console.log('派发给维修员---------' + this.selectData.f_repairman)
        act = { f_meetunit: '', f_reciever: this.selectData.f_repairman, f_service_acitivity_type: '派单' }
        toRepair = '一级派单'
      }
      let rep = {
        loginUser: {
          name: this.$login.f.name,
          ename: this.$login.f.ename
        },
        f_meetunit: this.$login.f.deps,
        f_attendant: this.$login.f.name,
        f_outlets: this.$login.f.deps,
        f_remarks: this.selectData.f_remarks,
        f_repairtype: this.selectData.f_repairtype,
        toRepair: toRepair,
        activity: act
      }
      for (let i = 0; i < this.checkes.length; i++) {
        try {
          let result = await new HttpResetClass().load('post', '/rs/logic/phoneUploadRectification', {
            id: this.checkes[i],
            repData: rep,
            source: 'pc'
          }, { resolveMsg: null, rejectMsg: null })
          if (result.data.code == 200) {
            successCount += result.data.successcon
            this.progressbarWidth = Math.ceil((i + 1) * 100 / (this.checkes.length))
          }
        } catch (e) {
          this.showModal3 = false
          this.$showMessage('网络异常，请稍后再试！')
          return
        }
      }
      this.showModal3 = false
      this.cancel1()
      this.$showMessage('本次转维修成功' + successCount + '单')
    },
    /*async rectification(){
      this.isbusy =true
      console.log("----this.checkes",this.checkes.toString())
      console.log("----this.getcon()",this.getcon())
      if(this.checkes.length==0){
        return this.$showMessage('请先选择需要转维修的用户！')
      }
      // if (this.checkAll){
      let data={
        f_filialeid: this.model.params.f_filialeid,
        f_defect_content: this.model.params.f_defect_content,
        condition: `${this.model.params.condition} and id in(${this.getcon()})`
      }
      let res1= await new HttpResetClass().load('post','rs/sql/GetCheckPaperByDefectNew',{data: data })
      for (let i = 0; i < res1.data.length; i++) {
        let data1={
          f_paper_id: res1.data[i].id,
          condition:`f_repaire_type = '隐患未处理'`
        }
        let res2 = await new HttpResetClass().load('POST' , 'rs/sql/GetDefectByPaperIdNew' , {data: data1 } )
        //tag
        if(res2.data.length==0){
          continue
        }
        const uploadData = {
          model: {
            serviceacitivity: [{
              f_service_acitivity_type: '派单'
            }],
            f_repairitems: {},
            failure: '',
            f_source: '安检',
            f_service_id: '',
            f_contact_phone: res1.data[i].f_user_phone,
            f_meetunit: this.$login.f.deps,
            f_phone: '',
            f_user_name: res1.data[i].f_user_name,
            f_address: res1.data[i].f_address,
            f_repair_date: Util.getNowDate(),
            f_reciever: '',
            f_remarks: this.selectData.f_remarks,
            f_user_type: res1.data[i].f_check_type,
            f_area: '',
            f_unit_name: '',
            f_street: res1.data[i].f_street,
            f_residential_area: res1.data[i].f_residential_area,
            f_building: res1.data[i].f_building,
            f_unit: res1.data[i].f_unit,
            f_floor: res1.data[i].f_floor,
            f_room: res1.data[i].f_room,
            aState: '',
            f_repairtype: this.selectData.f_repairtype,
            f_userinfo_id: res1.data[i].f_userinfo_id,
            f_userinfo_code: res1.data[i].f_userinfo_code,
            f_orgstr: res1.data[i].f_filialeid,
            f_outlets: '',
            f_attendant: this.$login.f.name
          },
          loginUser: {
            name: this.$login.f.name,
            ename: this.$login.f.ename
          },
          user: {
            f_userinfo_id: res1.data[i].f_userinfo_id
          },
          callObj: null
        }
        uploadData.model.serviceacitivity[0].f_reciever = this.selectData.f_repairman
        // uploadData.model.f_meetunit = self.$login.f.orgpathnames
        // uploadData.model.f_orgstr = self.$login.f.orgpathstr
        // uploadData.model.f_outlets = self.$login.f.f_parentname
        uploadData.model.f_orgid = this.$login.f.orgid
        uploadData.model.f_filiale = this.$login.f.org
        uploadData.model.f_outlets = this.$login.f.deps
        uploadData.model.f_filiale_id = this.$login.f.orgid
        uploadData.toRepair = '一级派单'
        // let res3 = await new HttpResetClass().load('post','/rs/sql/GetUserForRepaireNew', {data: {f_userinfo_id: res1.data[i].f_userinfo_id}})
        // uploadData.model = Object.assign(uploadData.model, res3.data[0])
        let failure = []
        res2.data.forEach(row => {
            console.log('row.f_item_value',row.f_item_value)
            failure.push({
              f_failure_type: row.f_item_name,
              failurecase: row.f_item_value?row.f_item_value.split(','):''
            })
        })
        uploadData.model.failure = failure
        // 拼接repairitems
        let rows = JSON.parse(JSON.stringify(res2.data))
        let repairitems = {
          data: []
        }
        let safecheckOptions = [{"data": "已处理"}, {"data": "未处理"}]
        // 取隐患未处理的
        rows = rows.filter(row => row.f_repaire_type == '隐患未处理')
        //tag)
        // 开始拼接
        rows.forEach(row => {
          let existIndex = -1
          // 判断该设备是否已经存在
          for (let i = 0; i < repairitems.data.length; i++) {
            if (repairitems.data[i].f_type == row.f_device_type) {
              existIndex = i
              break
            }
          }
          if (existIndex == -1) {
            // 不存在则新建
            let newItem = {
              f_type: row.f_device_type,
              details: [{
                f_defect_id: row.id,
                f_project: `${row.f_item_name}:${row.f_item_value}`,
                type: 'selector',
                options: safecheckOptions
              }]
            }
            repairitems.data.push(newItem)
          } else {
            // 存在则追加
            repairitems.data[existIndex].details.push({
              f_defect_id: row.id,
              f_project: `${row.f_item_name}:${row.f_item_value}`,
              type: 'selector',
              options: safecheckOptions
            })
          }
        })
        uploadData.model.f_repairitems = repairitems
        uploadData.rows=rows
        //tag)
        //tag
        console.log('uploadData---', uploadData)
        if (uploadData.model.f_repairitems.data.length>0){
          this.callSends.push(uploadData)
        }else{
          //tag
        }
      }
      //tag)
      let timer = setInterval(async ()=>{
        this.showModal3=true
        this.isbusy=false
        if (this.timercount<this.callSends.length){
          //tag)
          let rows=this.callSends[this.timercount].rows
          //tag)
          let result = await this.$resetpost('/rs/logic/callerSend1', this.callSends[this.timercount])
          //tag)
          if (result.data.f_service_id) {
            const data = {
              f_paper_id: rows[0].f_paper_id,
              f_service_id: result.data.f_service_id,
              itemsId: this.$login.convertToIn(rows.map(row => row.id))
            }
            //tag
            let updateRes = await this.$resetpost('/rs/logic/updateDefectStateNew', data)
          }
          this.toRepairCount++
          //tag
          this.timercount++
        }else{
          clearInterval(timer)
          //tag
          this.callSends=[]
          this.timercount=0
          this.showModal3=false
          this.cancel1()
          this.$showMessage('本次转维修成功'+this.toRepairCount+'单')
          this.toRepairCount=0
        }
      }, 3000)
    },*/
    cancel1() {
      this.showModal2 = false
      this.selectData = {
        dispatchType: '',
        f_repairman: '',
        f_remarks: '',
        f_repairtype: ''
      }
    },
    sleep(d) {
      //tag)
      var t = Date.now()
      while (Date.now - t <= d) {

      }
      //tag)
    },
    isChecked(v) {
      // 如果全选，不在的按选中算，否则，在的按选中算
      if (this.checkAll) {
        return this.checkes.indexOf(v) == -1
      } else {
        return this.checkes.indexOf(v) != -1
      }
    },
    setCheckAll() {
      this.checkAll = this.checkAll ? false : true;
      // 全选改变后，清空选中数据
      this.checkes = []
    },
    setCheckes(id) {
      let index = this.checkes.indexOf(id)
      if (index < 0) {
        this.checkes.push(id)
      } else {
        this.checkes.splice(index, 1)
      }
    },

    getmeterbook(val) {
      this.cbc = []
      this.cbc.push({
        label: '全部',
        value: ''
      })
      if (val == '') {

        this.cbcs.forEach(res => {
          this.cbc.push({
            label: res.f_book_name,
            value: res.id
          })
        })
      } else {
        this.cbcs.forEach(res => {
          if (res.f_book_slice_area == val) {
            this.cbc.push({
              label: res.f_book_name,
              value: res.id
            })
          }
        })
      }
    },

    // Mreadibook(val){
    //   //tag
    //   //tag
    //   this.sliceArea=[]
    //   if (val){
    //     new HttpResetClass().load('POST',`/rs/sql/tel_singleTable_OrderBy`, {data: {
    //         items: 'name',
    //         tablename: 't_zone',
    //         condition: `parentid  in ${val}`,
    //         orderitem: 'id'
    //       }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
    //       this.sliceArea.push({
    //         label:'全部',
    //         value:''
    //       })
    //       res.data.forEach(ress=>{
    //         this.sliceArea.push({
    //           label:ress.name,
    //           value:ress.name
    //         })
    //       })
    //
    //     })
    //   }
    // },
    // getAllMeterBook(val){
    //   //tag
    //   //tag
    //   this.cbcs=[]
    //   if (val){
    //     new HttpResetClass().load('POST',`/rs/sql/tel_singleTable_OrderBy`, {data: {
    //         items: 'f_book_name,f_book_slice_area,id',
    //         tablename: 't_meter_book',
    //         condition: `f_filiale_id  in ${val}`,
    //         orderitem: 'id'
    //       }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
    //       res.data.forEach(ress=>{
    //         this.cbcs.push({
    //           id:ress.id,
    //           f_book_name:ress.f_book_name,
    //           f_book_slice_area:ress.f_book_slice_area
    //         })
    //       })
    //       this.cbc=[]
    //       this.cbc.push({
    //         label:'全部',
    //         value:''
    //       })
    //       this.cbcs.forEach(res=>{
    //         this.cbc.push({
    //           label:res.f_book_name,
    //           value:res.id
    //         })
    //       })
    //     })
    //   }
    // },
    hiddenr() {
      this.$parent.showItem = !this.$parent.showItem
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    search(args) {
      args.condition += ` and a.f_filialeid in ${this.f_filialeid}`
      args.condition += ` and a.f_handler_state in ('已预约','已安检')`
      this.model.search(args.condition, args.model)
    },
    getRes(obj) {
      //tag
      this.resids = { res: obj.res[0], resids: obj.resids[0] }
      this.f_filialeid = this.$login.convertToIn(obj.resids);
    },
    showChooser() {
      this.showModal = true
    },
    ok() {
      if (!this.changeData.f_handlercheck_name || this.changeData.f_handlercheck_name.length == 0) {
        this.$showMessage('请选择安检员')
        return
      }
      let userinfoIds = []
      if (this.checkAll) {
        userinfoIds = this.model.rows.map(row => {
          return `'${row.f_userinfo_id}'`
        })
      } else if (this.checkes.length > 0) {
        userinfoIds = this.checkes
      }
      let sql = `update t_userinfo set f_handler_time = '${Util.toStandardTimeString()}',f_handlercheck_id='${this.changeData.f_handlercheck_name[0].id}',f_handlercheck_name='${this.changeData.f_handlercheck_name[0].name}',f_safe_remark='${this.changeData.f_safe_remark}' where f_userinfo_id in (${userinfoIds.join()})`
      new HttpResetClass().load('POST', 'rs/logic/runSQL', { data: { sql: sql } }, { resolveMsg: null, rejectMsg: '预约转单失败' }).then(() => {
        this.$refs.paged.$refs.criteria.search()
        this.changeData = {}
        this.selecetChecker = false
      }).catch(()=>{
        this.$showMessage('转单失败')
      })
    },
    cancel() {
      this.showModal = false
      this.f_check_plan = { f_plan_name: '', id: '' }
    }
  },
  ready() {
    //tag
    this.transfer = Vue.$appdata.getSingleValue('安检转工单')
    this.$refs.paged.$refs.criteria.model.f_has_defect = '有隐患'
    this.getEmp()
    let gen = select(this)
    // this.Mreadibook(`('${this.$login.f.orgid}')`)
    co(gen)
  },
  watch: {
    'timercount'() {
      if (this.timercount === 0) {
        this.progressbarWidth = '0'
      } else {
        //tag
        //tag
        this.progressbarWidth = parseInt(this.timercount * 100 / (this.callSends.length + 1))
      }

    }
  },
  computed: {
    selected() {
      return this.$refs.paged.$refs.grid.selected
    },
    getfield() {
      //tag
      let data = {}
      this.bodyData.forEach((value, index) => {
        data[this.bodyData[index]] = this.headData[index]
      })
      //合计字段打印
      this.tfoot = `<tr><th colspan=${this.modelval.length}>全表汇总信息: `
      if (this.sumsmodel) {
        Object.keys(this.sumsmodel).forEach((key) => {
          this.tfoot += this.fields[key] + '合计: ' + `<font color="blue">${this.sumsmodel[key]} </font>`
        })
      } else {
        this.tfoot += '暂无'
      }
      this.tfoot += '</th></tr>'
      return data
    }
  }
}
</script>
