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

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

                <button id="btnbbb" class="button_spacing button_search" @click="search()">查询</button>
                <div style="float: right" class="button_spacing"
                     :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                     @click="$parent.$parent.hidden()"></div>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow" >
                <label class="font_normal_body">安检计划</label>
                <input type="text" class="input_search" v-model="$parent.$parent.model.f_check_plan.f_plan_name"
                       @click="$parent.$parent.showChooser"
                       style="width: 60%" placeholder="安检计划" readonly="readonly">
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <label class="font_normal_body">开始时间</label>
                <datepicker
                  class="select_list select"
                  :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_offsite_time > ='{} 00:00:00'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <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_offsite_time <=  '{} 23:59:59'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <label class="font_normal_body">安检状态</label>
                <v-select id="f_entry"
                          class="select_list select"
                          placeholder='安检状态' style="width: 60%"
                          v-model='model.f_entry'
                          :value.sync="$parent.$parent.model.f_entry"
                          :options='$parent.$parent.f_entry_status'
                          condition=""
                          :value-single="true"
                          close-on-select clear-button></v-select>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">

                <label class="font_normal_body">用户状态</label>
                <v-select :value.sync="model.f_user_state" v-model='model.f_user_state'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.user_states' placeholder='用户状态'
                          close-on-select
                          condition="f_user_state = '{}'"></v-select>
              </div>
              <div class="form-group col-sm-2">

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

                <label class="font_normal_body">录音照片</label>
                <v-select :value.sync="model.f_downloadpath" v-model='model.f_downloadpath'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.downloadpaths' placeholder='录音/照片'
                          close-on-select
                          condition="f_downloadpath = '{}'"></v-select>
              </div>
              <div class="col-sm-4 form-group" v-if="$parent.$parent.criteriaShow" style="margin: 0">
                <role-selector-safe
                  role-name="安检员"
                  role-lable="安&nbsp;检&nbsp;员&nbsp;"
                  @re-res="$parent.$parent.getRes"
                  :value.sync="model.f_checker_id"
                  v-model="model.f_checker_id"
                  condition="f_checker_name = '{}'">
                </role-selector-safe>
              </div>
              <div class="form-group col-sm-2" v-show="false">
                <label class="font_normal_body">片&emsp;&emsp;区</label>
                <v-select class="select_list select"
                          placeholder='片区/管理站' style="width: 60%"
                          :value.sync="model.f_slice_area" v-model="model.f_slice_area"
                          :options='$parent.$parent.sliceArea'
                          filer-key="name"
                          close-on-select clear-button
                          condition="f_slice_area='{}'"
                          @change="$parent.$parent.getmeterbook(model.f_slice_area)"
                          :value-single="true">
                </v-select>
              </div>
              <div class="form-group col-sm-2" v-show="false">
                <label class="font_normal_body">抄&ensp;表&ensp;册</label>
                <v-select class="select_list select"
                          placeholder='抄表册' style="width: 60%"
                          :value.sync="model.f_meter_book_num" v-model="model.f_meter_book_num"
                          :options='$parent.$parent.cbc'
                          filer-key="name"
                          close-on-select clear-button
                          condition="f_meter_book_num={}"
                          :value-single="true">
                </v-select>
              </div>
              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">是否作废</label>
                <v-select class="select_list select"
                          placeholder='是否作废' style="width: 60%"
                          :value.sync="model.f_is_delete" v-model="model.f_is_delete"
                          :options='$parent.$parent.isdels'
                          filer-key="name"
                          close-on-select clear-button
                          :value-single="true">
                </v-select>
              </div>
              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">维修结果</label>
                <v-select class="select_list select"
                          placeholder='维修结果' style="width: 60%"
                          :value.sync="model.f_repaired" v-model="model.f_repaired"
                          :options='$parent.$parent.repaireds'
                          filer-key="name"
                          close-on-select clear-button
                          condition="f_repaired = '{}'"
                          :value-single="true">
                </v-select>
              </div>
              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">安检结果</label>
                <v-select class="select_list select"
                          placeholder='安检结果' style="width: 60%"
                          :value.sync="model.f_check_result" v-model="model.f_check_result"
                          :options='$parent.$parent.checkresults'
                          filer-key="name"
                          close-on-select clear-button
                          condition="f_defect_content like'%{}%'"
                          :value-single="true">
                </v-select>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">

                <label class="font_normal_body">安检类型</label>
                <v-select :value.sync="model.f_safecheck_type" v-model='model.f_safecheck_type'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.safecheck_type' placeholder='安检类型'
                          close-on-select
                          condition="f_safecheck_type = '{}'"></v-select>
              </div>
              <div class="form-group col-sm-2" v-show="$parent.$parent.criteriaShow">
                <label class="font_normal_body">是否有改动</label>
                <v-select class="select_list select"
                          placeholder='安检结果' style="width: 60%"
                          :value.sync="model.f_gaodong_flag" v-model="model.f_gaodong_flag"
                          :options='$parent.$parent.isdels'
                          filer-key="name"
                          close-on-select clear-button
                          condition="f_gaodong_flag = '{}'"
                          :value-single="true">
                </v-select>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <label class="font_normal_body">气表状态</label>
                <v-select :value.sync="model.f_table_state" v-model='model.f_table_state'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.table_state' placeholder='气表状态'
                          close-on-select
                          condition="f_table_state = '{}'"></v-select>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <label class="font_normal_body">审核状态</label>
                <v-select :value.sync="model.f_approved" v-model='model.f_approved'
                          :value-single="true" style="width: 60%"
                          class="select_list select"
                          :options='$parent.$parent.review_status' placeholder='审核状态'
                          close-on-select
                          condition="f_approved= '{}'"></v-select>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <label class="font_normal_body">审核开始</label>
                <datepicker
                  class="select_list select"
                  :value.sync="model.f_checksh_start"
                  placeholder='审核开始时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_checksh_start"
                  condition="f_approved_time > ='{} 00:00:00'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <label class="font_normal_body">审核结束</label>
                <datepicker
                  :value.sync="model.f_checksh_end"
                  placeholder='审核结束时间' style="width: 60%"
                  :disabled-days-of-week="[]"
                  :format="'yyyy-MM-dd'"
                  :show-rest-button="reset"
                  v-model="model.f_checksh_end"
                  condition="f_approved_time <=  '{} 23:59:59'">
                </datepicker>
              </div>
              <div class="form-group col-sm-2" v-if="$parent.$parent.criteriaShow">
                <label class="font_normal_body">审&ensp;核&ensp;人</label>
                <input type="text" class="input_search" v-model="model.f_approved_by"
                       style="width: 60%" placeholder="审核人" condition="f_approved_by like '%{}%'">
              </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" style="text-align: center;white-space: nowrap">
                <button class="button_search" @click="$parent.$parent.ok">确认</button>
                <button class="button_search" @click="$parent.$parent.cancel">取消</button>
              </div>
            </modal>
          </div>
        </criteria>
        <data-grid class="list_area table_sy" style="overflow: hidden" :model="model" partial='list' v-ref:grid>
          <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>
                <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>
                <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>
                <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>
                <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;white-space: nowrap">{{ row.f_userinfo_code }}</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.f_check_type }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_user_state }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_residential_area }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_address }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_mapanshu }}</td>
            <td style="text-align: center;white-space: nowrap"
                @dblclick.stop="$parent.$parent.$parent.tochangeRemark(row)">{{ row.f_chazhi }}
            </td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_shengyu_gas }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_bowenguan }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_zibifa }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_contractdate }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_meternumber }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_meter_classify }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_position }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_aroundmeter }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_metertitles }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_table_state }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_safecheck_type }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.defect_content == '无隐患' ? '正常' : '有隐患' }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.defect_content }}</td>
            <!--            <td style="text-align: center;white-space: nowrap">{{ row.repaired}}</td>-->
            <!--            <td style="text-align: center;white-space: nowrap">{{ row.f_repairman}}</td>-->
            <!--            <td style="text-align: center;white-space: nowrap">{{ row.f_repair_date}}</td>-->
            <!--            <td style="text-align: center;white-space: nowrap">{{ row.f_ratification_des}}</td>-->
            <td style="text-align: center;white-space: nowrap">{{ row.f_repair_approved_note }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_entry_status }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_plan_name }}</td>
            <!--整改通知书别名-->
            <td style="text-align: center;white-space: nowrap">{{ row.f_rectification_notice }}</td>
            <td style="text-align: center;white-space: nowrap"
                v-if="row.f_entry_status=='到访不遇'|| row.f_entry_status=='拒检'">{{ row.f_downloadpath }}
            </td>
            <td style="text-align: center;white-space: nowrap" v-else></td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_offsite_time }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_checker_name }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_approved }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_approved_by }}</td>
            <td style="text-align: center;white-space: nowrap">{{ row.f_approved_time }}</td>
            <td style="text-align: center;white-space: nowrap">
              <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.change(row)'>查看</button>
              <!--              <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.del(row)' v-show="$parent.$parent.$parent.isdel=='否'">作废</button>-->
              <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.pass(row)'
                      v-show ="row.f_approved == '未审核'">通过
              </button>
              <button type="button" class="button_new-1 button_spacing" data-toggle="dropdown"
                      @click="$parent.$parent.$parent.print(row)">
                打印
              </button>
            </td>
            <td style="text-align: center;white-space: nowrap" v-if="$parent.$parent.$parent.audioshow">
              <!--              <button class="button_spacing button_search-1" @click='$parent.$parent.$parent.change(row)'>查看</button>-->
              <audio controls="controls" v-if="row.f_recording1_path">
                <source type="audio/mpeg" :src="'rs/audio/file/'+row.f_recording1_path">
              </audio>
            </td>
          </template>
        </data-grid>
      </criteria-paged>
      <check-msg v-if="showcheckmsg" :show="showcheckmsg" :data="checkInfo"></check-msg>
    </div>
    <modal :show.sync="showModal2" :backdrop="false">
      <div slot="modal-header" class="modal-header">
        <h4 class="modal-title">
          用户{{ this.paperrow.f_user_name }}备注修改
        </h4>
      </div>
      <div slot="modal-body" class="modal-body">
        <div class="row" style="margin-top: 10px">
          <label class="control-label font text-left" style="float:left;margin-left:20%;margin-top:5px">备注</label>
          <div class="col-xs-8 col-md-8">
            <textarea class="form-control" type="text" v-model="paperRemark"></textarea>
          </div>
        </div>
      </div>
      <div slot="modal-footer" class="modal-footer" style="text-align: center">
        <button class="button_search" @click="okshow">确认</button>
        <button class="button_search" @click="cancelshow">取消</button>
      </div>
    </modal>
  </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 getNowDate from "../../../utils/getNowDate";
import HttpResetClass from "vue-client/src/plugins/HttpResetClass";
import BenzAMRRecorder from 'benz-amr-recorder'

//获取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',
      f_defect_content:'this.f_defect_content',
      orderitem: "'f_offsite_time desc'"
    })
    model.f_plan_id = ''
    model.f_approved = ''
    model.f_entry = ''
    model.f_no_checkplan = ''
    model.f_filialeid = `('${this.$login.f.orgid}')`
    model.f_defect_content="CASE WHEN CHARINDEX( '\"result\":\"正常\"', f_defect_content ) > 0 THEN '无隐患' ELSE replace(replace(replace( replace( RIGHT ( f_defect_content, len( f_defect_content ) - 26 ), substring('{}',2,1), '' ), substring('{}',1,1), '' ),']',''),'\"','') END"
    return {
      showbusy:false,
      audioshow: false,
      paperRemark:'',
      searchData: {
        condition: "1=1",
        orderitem: "f_offsite_time desc",
        f_plan_id: "",
        f_approved: '',
        f_entry_status: '',
        f_defect_content: "CASE WHEN CHARINDEX( '\"result\":\"正常\"', f_defect_content ) > 0 THEN '无隐患' ELSE replace(replace(replace( replace( RIGHT ( f_defect_content, len( f_defect_content ) - 26 ), substring('{}',2,1), '' ), substring('{}',1,1), '' ),']',''),'\"','') END",
        f_no_checkplan: '',
        f_filialeid: `('${this.$login.f.orgid}')`
      },
      model: model,
      //searchData:searchData,
      excelHeaders: {
        'f_userinfo_code': '客户编号',
        'f_user_name': '客户名称',
        'f_user_phone': '客户电话',
        'f_check_type': '客户类型',
        'f_user_state': '客户状态',
        'f_residential_area': '小区',
        'f_address': '地址',
        'f_mapanshu': '码盘数',
        'f_chazhi': '气量差值',
        'f_shengyu_gas':'剩余气量',
        'f_bowenguan':'波纹管数量',
        'f_zibifa':'自闭阀数量',
        'f_contractdate': '合同日期',
        'f_table_state': '气表状态',
        'f_meternumber': '表号',
        'f_meter_classify': '表品牌',
        'f_position': '表位置',
        'f_aroundmeter': '左右表',
        'f_metertitles': '表封号',
        'defect_content': '安检结果',
        // 'repaired': '维修状态',
        // 'f_repairman': '维修人',
        // 'f_repair_date': '维修时间',
        // 'f_ratification_des': '维修描述',
        'f_repair_approved_note': '备注',
        'f_plan_name':'计划名称',
        'f_rectification_notice':'整改通知书',
        'f_downloadpath':'录音/照片',
        'f_entry_status': '安检状态',
        'f_offsite_time': '安检时间',
        'f_checker_name': '安检员',
         'f_approved' : '审核状态',
        'f_approved_by' : '审核人',
        'f_approved_time':'审核时间'
      },
      fun: this.$login.f,
      showModal2:false,
      paperrow:{},
      checkersid: [],
      safetype: [
        {label: '全部', value: ''}, ...this.$appdata.getParam('安检类型')],
      downloadpaths: [{label: '全部', value: ''},{label: '已上传', value: '已上传'},{label: '未上传', value: '未上传'}],
      criteriaShow: false,
      showModal: false,
      table_state: [{label: '全部', value: ''}, ...this.$appdata.getParam('气表状态')],
      f_approval_states: this.$appdata.getParam('安检单审核状态'),
      f_entry_status: [{label: '全部', value: ''}, ...this.$appdata.getParam('安检状态')],
      user_states:[{label: '全部', value: ''}, ...this.$appdata.getParam('用户状态')],
      safecheck_type:[{label: '全部', value: ''}, ...this.$appdata.getParam('安检类型')],
      check_types:[{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')],
      f_checkplans: this.$appdata.getParam('有无计划'),
      showcheckmsg: false,
      checkInfo: {},
      orderDefault: "'f_offsite_time'",
      orderFields: {
        f_offsite_time: 'no'
      },
      sliceArea: [],
      review_status:[{label: '全部', value: ''},{label: '待审核', value: '未审核'},{label: '正常', value: '通过'}],
      isdels: [{label: '全部', value: ''},{label: '是', value: '是'},{label: '否', value: '否'}],
      repaireds: [{label: '全部', value: ''},{label: '已修', value: '已修'},{label: '未修', value: '未修'}],
      checkresults: [{label: '全部', value: ''},{label: '正常', value: '正常'},{label: '有隐患', value: '有隐患'}],
      isdel: '否',
      cbc: []
    }
  },
  methods: {
    tochangeRemark(row){
      //tag
      this.paperRemark=row.f_chazhi
      this.paperrow=row
      this.showModal2=true

    },
    okshow(){
      let sql=`update t_check_paper set f_chazhi='${this.paperRemark}' where id='${this.paperrow.id}'`
      //tag
      new  HttpResetClass().load('post','rs/logic/runSQL',{data:{sql:sql}},{resolveMsg:'修改成功',rejectMsg:'修改失败'}).then(res=>{
        // this.$showMessage("修改成功")
        let e = document.createEvent("MouseEvents");
        e.initEvent("click", true, true);
        document.getElementById("btnbbb").dispatchEvent(e);
        this.showModal2=false
      })

    },
    cancelshow(){
      this.showModal2=false
    },
    pass(row) {
      //判断当前登录人是否有审核权限
      if(this.$appdata.getSingleValue('开启安检审核权限')=='是'){
        if(!this.$login.r.includes('安检结果审核')){
          //提示无审核权限
          this.$showMessage('您无审核权限')
          return
        }
      }
      var reqdata = {
        audit_result: '通过',
        operator: "success",
        audit_time: Util.getNowDate(),
        user_name: this.$login.f.name,
        id: row.id,
        f_check_item_id: row.f_check_item_id
      }
      this.$showMessage('确认通过当前安检单吗？', ['confirm', 'cancel']).then((res) => {
        if (res === 'confirm') {
          this.$resetpost('/rs/logic/updateAafeAudit', {data: reqdata}).then((res) => {
            //tag
            if (res.data.code == 200) {
              this.$showMessage('通过成功')
              this.search()
            } else {
              this.$showMessage('通过失败！')
            }
          }).catch((e) => {
            this.$showMessage(JSON.stringify(e) + '通过失败！')
          })
        }
      })
    },
    del(row) {
      //tag
      this.$showMessage('确认作废当前安检单吗？', ['confirm', 'cancel']).then((res) => {
        if (res === 'confirm') {
          this.$resetpost('rs/logic/DelCheckPaper', {id:row.id}).then((res) => {
            //tag
            if(res.data.code == 200){
              this.$showMessage('作废成功')
              this.search()
            }else {
              this.$showMessage('作废失败！')
            }
          }).catch((e) => {
            this.$showMessage(JSON.stringify(e) +'作废失败！')
          })
        }
      })
    },
    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
      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
            })
          })
        })
      }
    },
    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.$refs.paged.$refs.criteria.search()
    },

    change(row) {
      // Vue.$login = {jwt: row.f_checker_id}
      asyncReady(this).then(() => {
        ////tag)
        row.f_upload_state = '已传'
        this.$goto('new-check-paper', {
          f_plan_id: row.f_check_plan_id,
          item: row,
          role: 'view',
          isdel: this.isdel
        }, 'self')
      }).catch(
        (respanse) => {
          alert('获取配置文件失败')
        })
    },
    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() {
      this.$refs.paged.$refs.criteria.search()
    },
    selfSearch(args) {
      ////tag
      //args.condition+=" and f_check_type='民用'"
      //tag
      // //tag
      if (this.$refs.paged.$refs.criteria.model.f_is_delete == '是') {
        //tag
        this.isdel = '是'
        this.model.url = 'rs/sql/QueryDelCheckPaper'

      } else {
        //tag
        this.isdel = '否'
        this.model.url = 'rs/sql/查找安检单'
      }
      // if (args.condition.indexOf('f_table_state') == -1){
      //   args.condition += " and f_table_state = '正常'"
      // }
      this.model.search(args.condition, args.model, args.condValue)
    }
  },

  ready() {
    ////tag
    this.function = this.f
    ////tag

    let gen = select(this)
    //this.pianqu()
    this.Mreadibook(`('${this.$login.f.orgid}')`)
    co(gen)
  },
  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) {
      if (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) {
      if (val) {

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

}
</script>
