<template >
  <div class="flex-row">
    <div @keyup.enter="search1" class="basic-main">
      <criteria-paged :model="model" v-ref:paged>
        <criteria @condition-changed='$parent.search' partial='criteria' v-ref:criteria>
          <div class="form-horizontal select-overspread container-fluid auto" novalidate partial>
            <div class="row">
              <div class="col-sm-2">
                <res-select-group :show-component="['company']" :initres="$parent.$parent.org" @re-res="$parent.$parent.getorg" style="width:60%"></res-select-group>
              </div>
              <div class="col-sm-2 form-group ">
                <label class="font_normal_body">客户编号</label>
                <input
                       class="input_search" condition="f_userinfo_code = '{}'"
                       placeholder='客户编号'
                       style="width:60%"
                       type="text"
                       v-model="model.f_userinfo_code">
              </div>

              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户名称</label>
                <input
                       class="input_search" condition="f_user_name like '%{}%'"
                       placeholder='客户名称'
                       style="width:60%"
                       type="text"
                       v-model="model.f_user_name"
                >
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">客户地址</label>
                <input  class="input_search"
                       condition="f_address like '%{}%'"
                       placeholder='客户地址'
                       style="width:60%"
                       type="text"
                       v-model="model.f_address"
                >
              </div>

              <div style="float:right">
                <button @click="search()" class="button_search" v-el:cba>查询</button>
                <button @click="$parent.$parent.clearmsg" class="button_clear">清空</button>
                <export-excel
                  :choose-col="true"
                  :data="{condition: $parent.$parent.condition,
                          f_orgid: $parent.$parent.f_orgid,
                          f_start_date: $parent.$parent.f_start_date,
                          f_end_date: $parent.$parent.f_end_date
                          }"
                  :field="$parent.$parent.getfield" sql-name="operationValueRecord" sqlurl="api/af-revenue/logic/openapi/exportfile"
                  template-name='开关阀记录'></export-excel>
                <div
                  :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                  @click="$parent.$parent.hidden()" class="button_spacing" style="float: right"></div>
              </div>
            </div>
            <div class="row" v-show="$parent.$parent.criteriaShow">
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">用气性质</label>
                <v-select style="width:60%" :value.sync="model.f_gasproperties" v-model="model.f_gasproperties"
                          placeholder='用气性质'
                          value-single="true"
                          :options='$parent.$parent.Gasproperties'
                          close-on-select
                          condition="f_gasproperties = '{}'"
                ></v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">表&ensp;&ensp;&ensp;&ensp;号</label>
                <input
                  class="input_search" condition="u1.f_meternumber = '{}'"
                  placeholder='表号'
                  style="width:60%"
                  type="text"
                  v-model="model.f_meternumber">
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">气表品牌</label>
                <v-select
                  :options='$parent.$parent.meterbrand'

                  :value.sync="model.f_gasbrand"
                  close-on-select
                  condition="f_meter_brand='{}'"
                  placeholder='气表品牌'
                  style="width:60%"
                  v-model="model.f_gasbrand">
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">操作时间</label>
                <datepicker :format="'yyyy-MM-dd HH:mm:ss'" :value.sync="model.f_start_date"
                            condition="f_instruct_date >= '{}'"
                            placeholder="起始时间"
                            style="width:60%"
                            v-model="model.f_start_date"
                ></datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">&emsp;&emsp;至&emsp;</label>
                <datepicker :format="'yyyy-MM-dd HH:mm:ss'" :value.sync="model.f_end_date"
                            condition="f_instruct_date <= '{}'"
                            placeholder="结束时间"
                            style="width:60%"
                            v-model="model.f_end_date"
                ></datepicker>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">操作类型</label>
                <v-select
                  :options='$parent.$parent.operatetypes'

                  :value.sync="model.f_instruct_title"
                  close-on-select
                  condition="f_instruct_title='{}'"
                  placeholder='操作类型'
                  style="width:60%"
                  v-model="model.f_instruct_title">
                </v-select>
              </div>
              <div class="col-sm-2 form-group">
                <label class="font_normal_body">气表类型</label>
                <v-select :value.sync="model.f_meter_type"
                          :options='$parent.$parent.metertypes' placeholder='请选择' v-model="model.f_meter_type"
                          condition="u4.f_meter_type in {}"
                          close-on-select></v-select>
              </div>
            </div>
          </div>
        </criteria>
        <data-grid :model="model" class="list_area table_sy" id="queryinstruct" partial='list' :modelval="$parent.$parent.modelval" v-ref:grid>
          <template partial='head'>
            <tr>
              <th style="text-align:center">
                <nobr>序号</nobr>
              </th>
              <th style="text-align:center">
                <nobr>客户编号</nobr>
              </th>
              <th style="text-align:center">
                <nobr>客户名称</nobr>
              </th>
              <th style="text-align:center">
                <nobr>客户地址</nobr>
              </th>
              <th style="text-align:center">
                <nobr>表号</nobr>
              </th>
              <th style="text-align:center">
                <nobr>气表品牌</nobr>
              </th>
              <th style="text-align:center"><nobr>操作类型</nobr></th>
              <th style="text-align:center"><nobr>操作人</nobr></th>
              <th style="text-align:center"><nobr>操作时间</nobr></th>
              <th style="text-align:center"><nobr>开关阀原因</nobr></th>
              <th style="text-align:center"><nobr>组织机构</nobr></th>
              <th style="text-align:center"><nobr>附件</nobr></th>
            </tr>
          </template>
          <template partial='body'>
            <tr>
              <td style="text-align:center">
                <nobr>{{$index+1}}</nobr>
              </td>
              <td style="text-align:center">
               {{row.f_userinfo_code}}
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_user_name}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_address}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_meternumber}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_meter_brand}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_instruct_title}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_operator}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_instruct_date}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_info}}</nobr>
              </td>
              <td style="text-align:center">
                <nobr>{{row.f_orgname}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>
                  <button v-if="row.f_hl_file_path" class="button_search button_spacing width-60" @click.stop="$parent.$parent.$parent.handImgShow(row.f_hl_file_path)">查看</button>
                </nobr>
              </td>

            </tr>
          </template>
        </data-grid>
      </criteria-paged>
      <modal :show.sync="imgShow" v-ref:modal backdrop="true">
        <header slot="modal-header" class="modal-header">
          开关阀图片
        </header>
        <article slot="modal-body" class="modal-body">
          <div class="from-group">
            <img-self :src="imageFileUrl" width="500" height="500"></img-self>
          </div>
        </article>
        <footer slot="modal-footer" class="modal-footer">
          <button type="button" class="btn btn-success" @click='imgClose'>关闭</button>
        </footer>
      </modal>
    </div>

  </div>
</template>
<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  import * as Util from '../../Util'

  let readyGen = async function (self) {
    await self.$MagLoadParams.loadParam()
    self.getfield = self.config.excelHeaders
    self.initQueryParam();
  }
  export default {
    title: '开关阀记录查询',
    data () {
      return {
        model: new PagedList('api/af-revenue/sql/operationValueRecord', 50),
        row: null,
        isLoading: true,
        searchshow: true,
        criteriaShow:false,
        Gasproperties:[],
        meterbrand: [],
        userType:[],
        instructtype:[],
        instructstate:[],
        org:{
          org:[this.$login.f.orgid],
          dep:[],
          user:[],
        },
        orgcondition:'',
        show: false,
        imgShow: false,
        imageFileUrl: '',
        condition:'',
        f_orgid:'',
        f_start_date:'',
        f_end_date:'',
        getfield: {},
        config: {
          excelHeaders: {
            'f_userinfo_code': '客户编号','f_address': '客户地址','f_user_name': '客户姓名',
            'f_meternumber': '表号','f_meter_brand': '气表品牌','f_instruct_title':'操作类型',
            'f_info':'开关阀原因','f_inputtor':'操作人','f_instruct_date':'操作时间',
            'f_orgname': '组织机构'
          }
        },
        instructtitle: [],
        detailShow: false,
        f_instruct_content: '',
        modelval: [
          '序号','客户编号','客户名称','客户地址','表号','气表品牌','操作类型','操作人','操作时间','充值金额','开发阀原因','组织机构','附件'
        ]
      }
    },
    ready () {
      readyGen(this)
      this.$refs.paged.$refs.criteria.model.f_start_date = Util.toStandardDateString() + ' 00:00:00'
      this.$refs.paged.$refs.criteria.model.f_end_date = Util.toStandardDateString() + ' 23:59:59'
      this.$refs.paged.$refs.grid.modelval = this.modelval
    },
    methods: {
      imgClose(){
        this.imgShow = false
      },
      handImgShow(val){
        this.imageFileUrl = `rs/image/file/` + val
        this.imgShow = true
      },
      hidden(){
        this.criteriaShow = !this.criteriaShow
      },
      getorg(condition,obj) {
        this.orgcondition = condition.replace('f_orgid','i.f_orgid')
        this.orgcondition = this.orgcondition.replace('f_depid','i.f_depid')
        this.orgcondition = this.orgcondition.replace('f_operatorid','i.f_operatorid')
        this.orgname = obj.orgnames[0]
      },
      initQueryParam () {
        let arr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          if(item.value.f_meter_type==='物联网表' || item.value.f_meter_type==='机表'){
            temp.label = item.label
            temp.value = item.value.f_meter_brand
            arr.push(temp )
          }

        })
        this.meterbrand = [{label: '全部', value: ''}, ...arr]
      },
      clearmsg () {
        this.$refs.paged.$refs.criteria.model = {}
      },
      clickshow () {
        this.searchshow = !this.searchshow
      },
      dealmsg (val) {
        val.model = this.model.model
        this.$emit('deal-msg', val)
      },
      async search (args) {
        // this.obj.resids = this.obj.resids.replace(/\./g, ''),
        args.condition =  `${args.condition}`+this.orgcondition
        console.log(args.condition+"args.condition")
        this.condition = args.condition
        if( this.$refs.paged.$refs.criteria.model.f_start_date!=null &&  this.$refs.paged.$refs.criteria.model.f_start_date!=''){
          this.model.params.f_start_date = `'${this.$refs.paged.$refs.criteria.model.f_start_date}'`;
          this.f_start_date = `'${this.$refs.paged.$refs.criteria.model.f_start_date}'`;
        }else{
          this.model.params.f_start_date = '';
          this.f_start_date = '';
        }
        if( this.$refs.paged.$refs.criteria.model.f_end_date!=null &&  this.$refs.paged.$refs.criteria.model.f_end_date!=''){
          this.model.params.f_end_date = `'${this.$refs.paged.$refs.criteria.model.f_end_date}'`;
          this.f_end_date = `'${this.$refs.paged.$refs.criteria.model.f_end_date}'`;
        }else{
          this.model.params.f_end_date  = "";
          this.f_end_date  = "";
        }
        if(this.f_orgid_new == '' || this.f_orgid_new == null){
          this.model.params.f_orgid = `'${this.$login.f.orgid}'`;
          this.f_orgid = `${this.$login.f.orgid}`;
        }else{
          this.model.params.f_orgid = `'${this.f_orgid_new}'`;
          this.f_orgid = `${this.f_orgid_new}`;
        }
        await this.model.search(args.condition, args.model)
        await this.$refs.paged.$refs.grid.InitializedData()
        await this.$refs.paged.$refs.grid.displayColumnSettings(undefined)

      },

    },
    computed: {
      userType () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
      Gasproperties () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')]
      },
      operatetypes () {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('开关阀操作类型')]
      },
      metertypes () {
        return [{label: ' 全部 ', value: ''}, ...this.$appdata.getParam('气表类型')]
      }
    }
  }
</script>
<style>
  .form-input-group label {
    text-align: right;
    width: auto;
  }
  .datapanel {
    color: #333;
    background-color: white;
    box-shadow: darkgrey 0.5px 0.5px 0.5px 0.5px ;
    padding: 10px 30px 10px 30px;
    border-radius:15px;
  }
</style>
