<template>
  <div class="flex-row">
    <div class="basic-main">
      <criteria-paged v-ref:paged :model="model" @sort="sort">
        <criteria v-ref:criteria class="search_area" partial='criteria' @condition-changed='$parent.selfSearch'>
          <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
            <div class="row">
              <div class="form-group col-sm-2">
                <label class="font_normal_body">客户编号</label>
                <input v-model="model.f_userinfo_code" class="input_search" condition="f_userinfo_code='{}'"
                       placeholder="客户编号" style="width: 60%" type="text">
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">客户名称</label>
                <input v-model="model.f_user_name" class="input_search" condition="f_user_name like '%{}%'"
                       placeholder="客户名称" style="width: 60%" type="text">
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">客户电话</label>
                <input v-model="model.f_user_phone" class="input_search" condition="f_user_phone like '%{}%'"
                       placeholder="客户电话" style="width: 60%" type="text">
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">客户表号</label>
                <input v-model="model.f_meternumber" class="input_search" condition="f_meternumber like '%{}%'"
                       placeholder="客户表号" style="width: 60%" type="text">
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">小&emsp;&emsp;区</label>
                <input v-model="model.f_residential_area" class="input_search" condition="f_residential_area like '%{}%'"
                       placeholder="小区" style="width: 60%" type="text">
              </div>
              <div class="form-group col-sm-2">
                <label class="font_normal_body">详细地址</label>
                <input v-model="model.f_address" class="input_search" condition="f_address like '%{}%'"
                       placeholder="详细地址" style="width: 60%" type="text">
              </div>
              <div class="form-group col-sm-2" style="width: auto;margin-top:8px;float: right">

                <export-excel-safe :choose-col="true"
                                   :data="$parent.$parent.searchData"
                                   :field="$parent.$parent.excelHeaders"
                                   sql-name="查找安检单" sqlurl="rs/logic/SafeExportExcel"
                                   template-name='安检记录明细'></export-excel-safe>
                <button v-if="$parent.$parent.audioshow" class="button_spacing button_search"
                        @click="$parent.$parent.showaudio()">隐藏
                </button>

                <button class="button_spacing button_search" @click="search()">查询</button>
                <div :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}" class="button_spacing"
                     style="float: right"
                     @click="$parent.$parent.hidden()"></div>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">安检计划</label>
                <input v-model="$parent.$parent.model.f_check_plan.f_plan_name" class="input_search" placeholder="安检计划"
                       readonly="readonly"
                       style="width: 60%" type="text" @click="$parent.$parent.showChooser">
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">开始时间</label>
                <datepicker
                  v-model="model.f_check_start"
                  :disabled-days-of-week="[]" :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.f_check_start"
                  condition="f_offsite_time > ='{} 00:00:00'"
                  placeholder='开始时间'
                  style="width: 60%">
                </datepicker>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">结束时间</label>
                <datepicker
                  v-model="model.f_check_end"
                  :disabled-days-of-week="[]" :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.f_check_end"
                  condition="f_offsite_time <=  '{} 23:59:59'"
                  placeholder='结束时间'
                  style="width: 60%">
                </datepicker>
              </div>


              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">

                <label class="font_normal_body">安检类型</label>
                <v-select v-model='model.f_safecheck_type' :options='$parent.$parent.safetype'
                          :value-single="true" :value.sync="model.f_safecheck_type"
                          class="select_list select"
                          close-on-select condition="f_safecheck_type = '{}'"
                          placeholder='安检类型'
                          style="width: 60%"></v-select>
              </div>

              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">

                <label class="font_normal_body">客户类型</label>
                <v-select v-model='model.f_check_type' :options='$parent.$parent.checktype'
                          :value-single="true" :value.sync="model.f_check_type"
                          class="select_list select"
                          close-on-select condition="f_check_type = '{}'"
                          placeholder='客户类型'
                          style="width: 60%"></v-select>
              </div>


              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">安检状态</label>
                <v-select id="f_entry"
                          v-model='model.f_entry'
                          :options='$parent.$parent.f_entry_status' :value-single="true"
                          :value.sync="$parent.$parent.model.f_entry"
                          class="select_list select"
                          clear-button
                          close-on-select
                          condition=""
                          placeholder='安检状态' style="width: 60%"></v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="col-sm-4 form-group" style="margin: 0">
                <role-selector-safe
                  v-model="model.f_checker_id"
                  :value.sync="model.f_checker_id"
                  condition="f_checker_name = '{}'"
                  role-lable="安&nbsp;检&nbsp;员&nbsp;"
                  role-name="安检员"
                  @re-res="$parent.$parent.getRes">
                </role-selector-safe>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">片&emsp;&emsp;区</label>
                <v-select v-model="model.f_slice_area"
                          :options='$parent.$parent.sliceArea' :value-single="true"
                          :value.sync="model.f_slice_area" class="select_list select"
                          clear-button
                          close-on-select
                          condition="f_slice_area='{}'" filer-key="name"
                          placeholder='片区/管理站'
                          style="width: 60%"
                          @change="$parent.$parent.getmeterbook(model.f_slice_area)">
                </v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">抄&ensp;表&ensp;册</label>
                <v-select v-model="model.f_meter_book_num"
                          :options='$parent.$parent.cbc' :value-single="true"
                          :value.sync="model.f_meter_book_num" class="select_list select"
                          clear-button
                          close-on-select
                          condition="f_meter_book_num={}" filer-key="name"
                          placeholder='抄表册'
                          style="width: 60%">
                </v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">省&ensp;市&ensp;区</label>
                <v-select v-model="model.f_pcd"
                          :options='$parent.$parent.pcds' :value-single="true"
                          :value.sync="model.f_pcd" class="select_list select"
                          clear-button
                          close-on-select
                          condition="f_pcd='{}'" filer-key="name"
                          placeholder='请选择'
                          style="width: 60%">
                </v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">开户时间</label>
                <datepicker
                  v-model="model.f_check_gasstart"
                  :disabled-days-of-week="[]" :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.f_check_gasstart"
                  condition="f_gas_date > ='{} 00:00:00'"
                  placeholder='开始时间'
                  style="width: 60%">
                </datepicker>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">开户时间</label>
                <datepicker
                  v-model="model.f_check_gasend"
                  :disabled-days-of-week="[]" :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.f_check_gasend"
                  condition="f_gas_date <=  '{} 23:59:59'"
                  placeholder='结束时间'
                  style="width: 60%">
                </datepicker>
              </div>
              <div v-show="$parent.$parent.safeAudit && $parent.$parent.criteriaShow " class="form-group col-sm-2">
                <label class="font_normal_body">审&ensp;核&ensp;人</label>
                <input v-model="model.f_approved_by" class="input_search" condition="f_approved_by like '%{}%'"
                       placeholder="审核人" style="width: 60%" type="text">
              </div>
              <div v-show="$parent.$parent.safeAudit && $parent.$parent.criteriaShow " class="form-group col-sm-2">
                <label class="font_normal_body">审核时间</label>
                <datepicker
                  v-model="model.f_approved_timestart"
                  :disabled-days-of-week="[]" :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.f_approved_timestart"
                  condition="f_approved_time > ='{} 00:00:00'"
                  placeholder='开始时间'
                  style="width: 60%">
                </datepicker>
              </div>
              <div v-show="$parent.$parent.safeAudit && $parent.$parent.criteriaShow " class="form-group col-sm-2">
                <label class="font_normal_body">审核时间</label>
                <datepicker
                  v-model="model.f_approved_timeend"
                  :disabled-days-of-week="[]" :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  :value.sync="model.f_approved_timeend"
                  condition="f_approved_time <=  '{} 23:59:59'"
                  placeholder='结束时间'
                  style="width: 60%">
                </datepicker>
              </div>
              <div v-show="$parent.$parent.safeAudit &&$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body" title="参数管理：安检审核状态">审核状态</label>
                <v-select v-model="model.f_approved"
                          :options='$parent.$parent.approveds' :value-single="true"
                          :value.sync="model.f_approved" class="select_list select"
                          clear-button
                          close-on-select
                          condition="f_approved='{}'" filer-key="name"
                          placeholder='请选择'
                          style="width: 60%">
                </v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">气表品牌</label>
                <v-select
                  v-model='model.tableBrand'
                  :options='$parent.$parent.tableBrands' :value-single="true"
                  :value.sync="model.tableBrand"
                  class="select_list select"
                  clear-button
                  close-on-select
                  condition="f_meter_brand = '{}'"
                  placeholder='气表品牌' style="width: 60%"></v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">有无计划</label>
                <v-select v-model="model.f_no_checkplan"
                          :options='$parent.$parent.no_checkplans' :value-single="true"
                          :value.sync="model.f_no_checkplan" class="select_list select"
                          clear-button
                          close-on-select
                          condition="f_no_checkplan='{}'" filer-key="name"
                          placeholder='请选择'
                          style="width: 60%">
                </v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">未用燃气</label>
                <v-select v-model="model.f_usegas"
                          :options='$parent.$parent.usegas' :value-single="true"
                          :value.sync="model.f_usegas" class="select_list select"
                          clear-button
                          close-on-select
                          condition="f_usegas='{}'" filer-key="name"
                          placeholder='请选择'
                          style="width: 60%">
                </v-select>
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">客户卡号</label>
                <input v-model="model.f_card_id" class="input_search" condition="f_card_id like '%{}%'"
                       placeholder="客户卡号" style="width: 60%" type="text">
              </div>
              <div v-show="$parent.$parent.criteriaShow" class="form-group col-sm-2">
                <label class="font_normal_body">距上次安检天数</label>
                <input v-model="model.f_check_date" class="input_search" placeholder="距上次安检天数"
                       style="width: 60%" type="number">
              </div>
            </div>
            <modal v-ref:modal :show.sync="$parent.$parent.showModal" backdrop="false">
              <div slot="modal-header" class="modal-header">
                <h4 class="modal-title">
                  选择计划
                </h4>
              </div>
              <div slot="modal-body" class="modal-body">
                <plan-chooser v-ref:chooser :f.sync="$parent.$parent.fun"></plan-chooser>
              </div>
              <div slot="modal-footer" class="modal-footer" style="text-align: center">
                <button class="button_search" @click="$parent.$parent.ok">确认</button>
                <button class="button_search" @click="$parent.$parent.cancel">取消</button>
              </div>
            </modal>
          </div>
        </criteria>
        <data-grid v-ref:grid :model="model" class="list_area table_sy" partial='list' style="overflow: hidden">
          <template partial='head'>
            <tr>
              <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>
              <th>
                <data-order field="f_offsite_time" name="安检时间"></data-order>
              </th>
              <th>
                <nobr>安检员</nobr>
              </th>
              <th>
                <nobr>备注</nobr>
              </th>
              <th>
                <nobr>开户时间</nobr>
              </th>
              <th v-if="$parent.$parent.$parent.safeAudit">
                <nobr>审核人</nobr>
              </th>
              <th v-if="$parent.$parent.$parent.safeAudit">
                <nobr>审核起始</nobr>
              </th>
              <th v-if="$parent.$parent.$parent.safeAudit">
                <nobr>审核结束</nobr>
              </th>
              <th v-if="$parent.$parent.$parent.safeAudit">
                <nobr>审核状态</nobr>
              </th>
              <th v-if="$parent.$parent.$parent.safeAudit">
                <nobr>审核未通过原因</nobr>
              </th>
              <th>
                <nobr>操作</nobr>
              </th>
              <th v-if="$parent.$parent.$parent.audioshow">
                <nobr>录音</nobr>
              </th>
            </tr>
          </template>
          <template partial='body'>

            <td style="text-align: center">{{ row.f_userinfo_code }}</td>
            <td style="text-align: center">{{ row.f_user_name }}</td>
            <td style="text-align: center">{{ row.f_meternumber }}</td>
            <td style="text-align: center">{{ row.f_meter_brand }}</td>
            <td style="text-align: center">{{ row.f_user_phone }}</td>
            <td style="text-align: center">{{ row.f_check_type }}</td>

            <td style="text-align: center">{{ row.f_address }}</td>
            <td style="text-align: center">{{ row.f_entry_status }}</td>
            <td style="text-align: center">{{ row.f_plan_name }}</td>
            <td style="text-align: center">{{ row.f_usegas }}</td>
            <td style="text-align: center">{{ row.f_offsite_time }}</td>
            <td style="text-align: center">{{ row.f_checker_name }}</td>
            <td style="text-align: center">{{ row.f_repair_approved_note }}</td>
            <td style="text-align: center">{{ row.f_gas_date }}</td>
            <td v-show="$parent.$parent.$parent.safeAudit" style="text-align: center">{{ row.f_approved_by }}</td>
            <td v-show="$parent.$parent.$parent.safeAudit" style="text-align: center">{{
                row.f_approvedstart_time
              }}
            </td>
            <td v-show="$parent.$parent.$parent.safeAudit" style="text-align: center">{{ row.f_approved_time }}</td>
            <td v-show="$parent.$parent.$parent.safeAudit" style="text-align: center">
              {{ row.f_approved ? row.f_approved : '未审核' }}
            </td>
            <td v-show="$parent.$parent.$parent.safeAudit" style="text-align: center">
              {{ row.f_approved_note }}
            </td>
            <td style="text-align: center">
              <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.change(row)'>查看</button>


            </td>
            <td v-if="$parent.$parent.$parent.audioshow" style="text-align: center">
              <!--              <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.change(row)'>查看</button>-->
              <audio v-if="row.f_recording1_path" controls="controls">
                <source :src="'rs/audio/file/'+row.f_recording1_path" type="audio/mpeg">
              </audio>
              <!--<button type="button" class="button_new-1 button_spacing" data-toggle="dropdown"
                      @click="$parent.$parent.$parent.print(row)">
                打印
              </button>-->
            </td>
          </template>
        </data-grid>
      </criteria-paged>
      <check-msg v-if="showcheckmsg" :data="checkInfo" :show="showcheckmsg"></check-msg>
    </div>
  </div>
</template>

<script>
import {PagedList} from 'vue-client'
import Vue from 'vue'
import co from 'co'
import * as Util from '../../Util'
import HttpResetClass from "vue-client/src/plugins/HttpResetClass";
import BenzAMRRecorder from 'benz-amr-recorder'
import {toEndDateString, toStartDateString} 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 http = new HttpResetClass()
  let getGasman = yield http.load('POST', '/rs/search', {
    source: 'this.getParentByType($department$).getAllChildrens().where(row.getAttributes().get($rolestr$).indexOf($安检员$) != -1))',
    userid: self.$login.f.id
  }, {resolveMsg: null, rejectMsg: null})
  ////tag
  self.checkersid.push({label: '全部', value: ''})
  getGasman.data.forEach((checker) => {
    self.checkersid.push({label: checker.name, value: checker.id})
  })
}

export default {
  title: '安检结果查看',
  data() {
    let model = new PagedList('rs/sql/查找安检单', 20, {
      f_plan_id: 'this.f_plan_id',
      f_approved: 'this.f_approved',
      f_entry_status: 'this.f_entry',
      f_no_checkplan: 'this.f_no_checkplan',
      f_filialeid: 'this.f_filialeid',
      orderitem: "'f_offsite_time desc'"
    })
    model.f_check_type = ''
    model.f_plan_id = ''
    model.f_approved = ''
    model.f_entry = ''
    model.f_no_checkplan = ''
    model.f_filialeid = `('${this.$login.f.orgid}')`
    //model.f_check_type='民用'
    // let searchData={
    //     f_plan_id: this.model.f_checker_id==undefined?"":this.model.f_checker_id,
    //     f_approved: this.model.f_approved,
    //     f_entry_status: this.model.f_entry,
    //     f_no_checkplan:this.model.f_no_checkplan[0],
    //     f_filialeid: this.model.f_filialeid,
    //     //orderitem: this.model.f_offsite_time,
    //     //condition:this.model.condition
    // }
    // model.f_subcompany = this.$login.f.f_fengongsi
    return {
      tableBrands: [{label: '全部', value: ''}],
      audioshow: false,
      safeAudit: this.$appdata.getSingleValue('安检审核') == '是' ? true : false,
      searchData: {
        condition: "1=1",
        orderitem: "f_offsite_time desc",
        f_plan_id: "",
        f_approved: '',
        f_entry_status: '',
        f_no_checkplan: '',
        f_filialeid: `('${this.$login.f.orgid}')`
      },
      model: model,
      excelHeaders: {
        //searchData:searchData,
        'f_userinfo_code': '客户编号',
        'f_user_name': '客户姓名',
        'f_meternumber': '客户表号',
        'f_user_phone': '客户电话',
        'f_check_type': '客户类型',
        'f_residential_area': '小区',
        'f_address': '客户地址',
        'f_entry_status': '安检状态',
        'f_usegas': '用气状态',
        'f_offsite_time': '安检时间',
        'f_checker_name': '安检员',
        'f_safecheck_type': '安检类型',
        'f_repair_approved_note': '备注',
        'f_gas_date': '开户时间',
        'f_plan_name': '计划名称'
      },
      fun: this.$login.f,
      pcds: [],
      checkersid: [],
      approveds: this.$appdata.getParam('安检审核状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('安检审核状态')] : [{label: '全部', value: ''}],
      safetype: this.$appdata.getParam('安检类型') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('安检类型')] : [{label: '全部', value: ''}],
      criteriaShow: false,
      checktype: this.$appdata.getParam('用户类型') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('用户类型')] : [{label: '全部', value: ''}],
      f_check_type: [{label: '全部', value: ''}, {label: '民用', value: '民用'}, {label: '非民用', value: '非民用'}],
      showModal: false,
      safe_types: this.$appdata.getParam('计划类型') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('计划类型')] : [{label: '全部', value: ''}],
      f_approval_states: this.$appdata.getParam('安检单审核状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('安检单审核状态')] : [{label: '全部', value: ''}],
      f_entry_status: this.$appdata.getParam('安检状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('安检状态')] : [{label: '全部', value: ''}],
      no_checkplans: this.$appdata.getParam('有无计划') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('有无计划')] : [{label: '全部', value: ''}],
      usegas: this.$appdata.getParam('用气状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('用气状态')] : [{label: '全部', value: ''}],
      showcheckmsg: false,
      checkInfo: {},
      orderDefault: "'f_offsite_time'",
      orderFields: {
        f_offsite_time: 'no'
      },
      sliceArea: [],
      cbc: []
    }
  },
  methods: {
    //气表品牌查询
    getTableBrands() {
      new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_OrderBy`,
        {data: {items: "*", tablename: "t_gasbrand", orderitem: "id", condition: ` 1=1 `}},
        {resolveMsg: null, rejectMsg: null}).then((resp) => {
        resp.data.forEach((result) => {
          this.tableBrands.push({label: result.f_meter_brand, value: result.f_meter_brand})
        })
      })
    },
    //获取省市区列表
    getPcd(val) {
      this.pcds = [{label: '全部', value: ''}]
      new HttpResetClass().load("POST", `/rs/sql/safe_singleTable_OrderBy`,
        {data: {items: "*", tablename: "t_pcd", orderitem: "id", condition: `f_orgid in ${val}`}},
        {resolveMsg: null, rejectMsg: null}).then((pcdlist) => {
        pcdlist.data.forEach((result) => {
          this.pcds.push({label: result.f_pcd, value: result.f_pcd})
        })
      })
    },
    showaudio() {
      //tag
      this.audioshow = !this.audioshow
      //tag
    },
    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
      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 = []
          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
            })
          })
        })
      }
    },
    getRes(obj) {
      this.model.f_filialeid = this.$login.convertToIn(obj.resids);
      this.searchData.f_filialeid = this.$login.convertToIn(obj.resids);
      this.Mreadibook(this.model.f_filialeid)
      this.getAllMeterBook(this.model.f_filialeid)
      this.getPcd(this.model.f_filialeid)
      //this.$refs.paged.$refs.criteria.search()
    },

    change(row) {
      row.f_upload_state = '已传'
      this.$goto('new-check-paper', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
    },
    readConfig() {
      let gen = asyncReady(this)
      return co(gen)
    },
    showChooser() {
      this.showModal = true
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    refresh() {
      this.$refs.paged.$refs.criteria.search()
    },
    ok() {
      this.showModal = false
      if (this.$refs.paged.$refs.criteria.$refs.modal.$children[0].selectedRow.id) {
        this.model.f_plan_id = 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: ''}
      this.model.f_plan_id = ''
    },
    print(row) {
      this.showcheckmsg = true
      this.checkInfo = row
    },

    sort(field, rule) {
      // 将所有排序方式设为不排序，实现相互排斥
      for (let key in this.orderFields) {
        if (key === field) {
          this.orderFields[key] = rule
        } else {
          this.orderFields[key] = 'no'
        }
      }
      // 如果新规则不排序，还原为默认排序
      if (rule === 'no') {
        this.model.paramSource.orderitem = `'${this.orderDefault}'`
      } else {
        this.model.paramSource.orderitem = `'${field} ${rule}'`
      }
      this.search()
    },
    search() {
      console.log('审核通过回调')
      this.$refs.paged.$refs.criteria.search()
    },
    selfSearch(args) {
      ////tag
      //args.condition+=" and f_check_type='民用'"
      if (args.model.f_check_date) {
        const daysBefore = Number(args.model.f_check_date);
        if (daysBefore > 0) {
          // 获取当前日期
          const now = new Date();
          // 计算三天前的日期
          const threeDaysBefore = new Date(now.getTime() - (daysBefore * 24 * 60 * 60 * 1000));
          // 如果需要格式化日期，可以使用Date对象的方法
          var formattedDate = threeDaysBefore.toISOString().split('T')[0];
          args.condition += `  and f_offsite_time <='${formattedDate} 23:59:59'`;
        } else {
          console.error('f_check_date不是一个有效的正整数');
        }
      }
      this.model.search(args.condition, args.model, args.condValue)
    }
  },
  ready() {
    if (this.safeAudit) {
      let oa = {
        'f_approved_by': '审核人',
        'f_approvedstart_time': '审核开始时间',
        'f_approved_time': '审核结束时间',
        'f_approved': '审核状态',
        'f_approved_note': '审核备注'
      }
      this.excelHeaders = Object.assign({}, this.excelHeaders, oa)
    }
    this.function = this.f
    //获取气表品牌
    this.getTableBrands()
    let gen = select(this)
    //this.pianqu()
    this.Mreadibook(`('${this.$login.f.orgid}')`)
    co(gen)
    this.$refs.paged.$refs.criteria.model.f_check_start = Util.toStartDateString() + ' 00:00:00'
    this.$refs.paged.$refs.criteria.model.f_check_end = Util.toEndDateString() + ' 23:59:59'
  },
  watch: {
    'model.f_no_checkplan'(val) {
      if (this.model.f_no_checkplan) {
        this.searchData.f_no_checkplan = val
      }
      if (this.model.f_no_checkplan == '有计划安检') {

        this.showChooser()
      }
    },
    'model.condition'(val) {
      if (val) {
        this.searchData.condition = val
      }

    },
    'model.f_entry'(val) {
      this.searchData.f_entry_status = val
    },
    'model.f_plan_id'(val) {
      if (val) {
        this.searchData.f_plan_id = val
      }
    },
    'model.f_slice_area'(val) {
    },
    'model.f_approved'(val) {
      if (val) {
        this.searchData.f_approved = val
      }
    },
  }

}
</script>
