<template>
  <div id="unit" class="flex-row">
    <div class="basic-main" @keyup.enter="search">
      <div class="flex">
        <criteria-paged :model="model" v-ref:paged>
          <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri >
            <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
              <div class="row">
                <div class="col-sm-2 form-group">
                  <label for="startDate" class="font_normal_body">开始日期</label>
                  <datepicker id="startDate" placeholder="开始日期" style="width:60%"
                              v-model="model.startDate"
                              :value.sync="model.startDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                              condition="modifitime >= '{}'">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <label for="endDate" class="font_normal_body">结束日期</label>
                  <datepicker id="endDate" placeholder="结束日期" style="width:60%"
                              v-model="model.endDate"
                              :value.sync="model.endDate"
                              :format="'yyyy-MM-dd HH:mm:ss'"
                              :show-reset-button="true"
                              condition="modifitime <= '{}'">
                  </datepicker>
                </div>
                <div class="col-sm-2 form-group">
                  <label class="font_normal_body">维护类型</label>
                  <v-select :value.sync="model.changetype"
                            :options='$parent.$parent.changetype'
                            placeholder='请选择' v-model="model.changetype"
                            condition="changetype = '{}'"
                            close-on-select></v-select>
                </div>

                <div class="span" style="float:right;">
                  <button class="button_search button_spacing" @click="search()">查询</button>
                  <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>

                  <export-excel :data="$parent.$parent.getCondition"
                                :field="$parent.$parent.getfield"
                                :footer="$parent.$parent.footer"
                                :header="$parent.$parent.other"
                                sqlurl="api/af-revenue/logic/openapi/exportfile"
                                sql-name="infoOperateRecordQuery"
                                template-name='维护记录导出'
                                :choose-col="true"></export-excel>
                  <print-data :model="$parent.model"
                              :field="$parent.$parent.getfield"
                              titletable="维护记录导出"></print-data>

                  <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>



              <div class="row" v-show="$parent.$parent.criteriaShow">
                <res-select-group :initres="$parent.$parent.initres" :show-component="$parent.$parent.showComponent" @re-res="$parent.$parent.getRes" v-ref:sel></res-select-group>



              </div>
            </div>
          </criteria>

          <data-grid :model="model" partial='list' class="list_area table_sy" v-ref:grid>
            <template partial='head'>
              <tr>
                <th>
                  <nobr>维护类型</nobr>
                </th>
                <th>
                  <nobr>记录id</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;">
                <nobr>{{row.changetype}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.changeid}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.fieldname}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.chinesename}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.oldvalue}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.newvalue}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.modifitime}}</nobr>
              </td>
              <td style="text-align: center;">
                <nobr>{{row.operator}}</nobr>
              </td>
            </template>
            <template partial='foot'></template>
          </data-grid>
        </criteria-paged>
      </div>
    </div>
  </div>
  <modal :show.sync="showupload" v-if="showupload" width="80%" style="width:auto;"  v-ref:modal middle backdrop="false">
    <article slot="modal-body">
      <upload :blodid="selected.f_userinfo_id" v-ref:upload isupload="false" takeimg="false"  fusetype="批量调价" :isremark="false" style="width:auto" ></upload>
    </article>
    <footer slot="modal-footer" class="modal-footer">
    </footer>
  </modal>
</template>

<script>
  import {HttpResetClass, PagedList} from 'vue-client'
  import exportConfig from '../config/exportConfig'
  import defaultPrint from '../config/DefaultPrint'

  let readySomething = async function (self) {
    self.$refs.paged.$refs.cri.model.startDate = self.data ? self.data.startDate : self.$login.toStandardDateString() + ' 00:00:00'
    self.$refs.paged.$refs.cri.model.endDate = self.data ? self.data.endDate : self.$login.toStandardDateString() + ' 23:59:59'
    // self.$refs.paged.$refs.cri.model.operateDate = self.$login.toStandardDateString() + ' 00:00:00'
    // self.$refs.paged.$refs.cri.model.performDate = self.$login.toStandardDateString() + ' 23:59:59'
    await self.$MagLoadParams.loadParam()
    self.defaultfield = [...self.defaultfield, ...self.config.defaultPrint]
    self.initParams()
    self.sumsmodel = self.$refs.paged.$refs.grid.model.sums;
  }
  export default {
    props:['data'],
    title: '调价记录查询',
    data() {
      return {
        other:[],
        footer:[],
        config: {
          defaultPrint: ['f_userinfo_code', 'f_user_name','f_address', 'f_user_type', 'f_gasproperties','f_oldprice','f_newprice','oldprice_performdate','newprice_performdate','f_operate_date','f_operator','f_depname']
        },
        //f_price_name:[],
        gasproperties:[],
        data: {},
        initres: {
          org:[this.$login.f.orgid],
          dep:[],
          user:[]
        },
        showComponent:['company','department','operator'],
        model: new PagedList('api/af-revenue/sql/infoOperateRecordQuery', 20, {}, ),
        criteriaShow: false,
        orgCondtionStr: '',
        // 下拉框
        meterbrands: [],
        //合计数据
        defaultfield: [],
        sumsmodel: {},
        showupload:false,
        selected:{},
        f_filialeid: this.$login.f.f_orgid,
        changetype: [{'label':'全部','value':''},{'label':'换表记录维护','value':'换表记录维护'},
          {'label':'票据记录维护','value':'票据记录维护'},{'label':'其他收费记录维护','value':'其他收费记录维护'},
          {'label':'补气记录维护','value':'补气记录维护'},{'label':'收费记录维护','value':'收费记录维护'},
          {'label':'补卡记录维护','value':'补卡记录维护'},{'label':'抄表记录维护','value':'抄表记录维护'}]
      }
    },
    ready() {
      readySomething(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })

    },
    methods: {
      view(row){
        this.showupload = true
        this.selected= row
      },
      initParams() {
        // 初始化气表品牌
        let brandArr = []
        this.$MagGetSaleParam.getGasbrand().forEach((item) => {
          let temp = {}
          temp.label = item.label
          temp.value = item.value.f_meter_brand
          brandArr.push(temp)
        })
        this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
      },

      search(){
        this.$refs.paged.$refs.cri.search()
      },


      selfSearch(args) {
        //小区查询条件
        if (this.data) {
          this.$parent.$parent.$parent.data.operateDate=this.$refs.paged.$refs.cri.model.operateDate
          this.$parent.$parent.$parent.data.performDate=this.$refs.paged.$refs.cri.model.performDate
        }
        let f_orgstr = this.orgCondtionStr
        args.condition = `${args.condition} ` + f_orgstr
        this.model.search(args.condition, args.model)
        this.sumsmodel = this.$refs.paged.$refs.grid.model.sums;

      },
      clear() {
        console.log('---------aaaa')
        //清空部门和人员
        this.$refs.paged.$refs.cri.$refs.sel.$children[1].selectres = []
        //部门和人员变为全选
        this.$refs.paged.$refs.cri.$refs.sel.$children[1].$children[0].isSelectAll = false
        this.$refs.paged.$refs.cri.$refs.sel.$children[2].$children[0].isSelectAll = false
        Object.keys(this.$refs.paged.$refs.cri.model).forEach((key) => {
          this.$refs.paged.$refs.cri.model[key] = []
        })

      },
      dealmsg(val) {
        val.model = this.model.model
        this.$dispatch('deal-msg', val)
      },
      show() {
        this.criteriaShow = true
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      getRes(condition,obj) {
        this.orgCondtionStr = condition
        this.orgname = obj.orgnames[0]
        this.depname = obj.depnames[0]
      },
      userTypeChange () {
        this.gasproperties=[]
        if(this.$refs.paged.$refs.cri.model !==null) {
          this.$refs.paged.$refs.cri.model.f_gasproperties=''
          this.gasproperties = this.$appdata.getParam(this.$refs.paged.$refs.cri.model.f_user_type[0])
        }
        else{
          this.gasproperties =[{label: '全部', value: ''}]
        }
      },

    },
    events:{

    },
    watch: {

      'orgCondtionStr'(val) {
        let res = val.match(/'(.*?)'/)
        console.log('正则提取:',res && res[1])
        if (res) {
          this.f_filialeid = res[1]
        }
      }
    },
    computed: {

      getCondition() {
        return {
          operateDate: this.$refs.paged.$refs.cri.model.operateDate,
          performDate: this.$refs.paged.$refs.cri.model.performDate,
          condition: `${this.$refs.paged.$refs.cri.condition}` + this.orgCondtionStr}
      },
      getfield() {
        return exportConfig.InfoOperateRecordConfig
      },
      metertypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')]
      },
      usertypes() {
        return [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')]
      },
    }
  }
</script>
