<template>
  <div class="flex" @keyup.enter="search">
    <criteria-paged :model="model" v-ref:paged @dblclick="handDblclick">
      <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="$parent.$parent.style">
              <label class="font_normal_body">组织机构</label>
              <res-select
                restype='organization'
                @res-select="$parent.$parent.getorg"
                is-mul="false"
                :initresid='$parent.$parent.curorgid'>
              </res-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">总表名称</label>
              <input type="text"
                     class="input_search"
                     style="width:60%"
                     v-model="model.f_user_name"
                     condition="f_meter_name like '%{}%'"
                     placeholder="总表名称"
                     :size="model.f_user_name ? model.f_user_name.length*2 : 6"/>
            </div>
            <div class="col-sm-4 form-group button-range">
              <button class="button_search button_spacing" @click="search()">查询</button>
              <button class="button_search button_spacing" style="width: max-content" @click="$parent.$parent.add()">添加总表档案</button>
              <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</button>
              <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-if="$parent.$parent.criteriaShow">
            <div :class="$parent.$parent.style">
              <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 :class="$parent.$parent.style">
              <label class="font_normal_body">总表类型</label>
              <v-select :options='$parent.$parent.user_type'
                        :value.sync="model.f_user_type"
                        close-on-select
                        condition="f_user_type='{}'"
                        placeholder='总表类型'
                        v-model="model.f_user_type">
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">用气性质</label>
              <v-select :options='$parent.$parent.gasproperties'
                        :value.sync="model.f_gasproperties"
                        close-on-select
                        condition="f_gasproperties='{}'"
                        placeholder='用气性质'
                        v-model="model.f_gasproperties">
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">气表类型</label>
              <v-select :options='$parent.$parent.meter_classify'
                        :value.sync="model.f_meter_classify"
                        close-on-select
                        condition="f_meter_classify='{}'"
                        placeholder='气表类型'
                        v-model="model.f_meter_classify">
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">气表品牌</label>
              <v-select :value.sync="model.f_meter_brand" multiple
                        v-model="model.f_meter_brand"
                        :options='$parent.$parent.meterbrands'
                        placeholder='请选择'
                        condition="f_meter_brand in {}"
                        close-on-select>
              </v-select>
            </div>
            <div :class="$parent.$parent.style">
              <label class="font_normal_body">表&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
              <input class="input_search"
                     condition="f_meternumber ='{}'"
                     placeholder='表号'
                     style="width:60%"
                     type="text"
                     v-model="model.f_meternumber" />
            </div>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' :optional="true" style="overflow: auto" class="list_area table_sy" 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>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">
              <nobr>{{ $index + 1 }}</nobr>
            </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_user_type }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_gasproperties }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_meter_classify }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_meter_brand }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_userinfo_code }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_table_num }}</nobr>
            </td>
            <td style="text-align:center">
              <nobr>{{ row.f_comments }}</nobr>
            </td>
            <td style="text-align:center">
              <button type="button" name="button" class="button_search-2 button_spacing width-60"
                      @click.stop="$parent.$parent.$parent.modify(row)">修改
              </button>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
    <add-host-meter-user-list :f_filialeids="f_filialeids"
                              v-if="userListShow"
                              :show.sync="userListShow">
    </add-host-meter-user-list>
  </div>
</template>

<script>
import {PagedList} from 'vue-client'

let readyGen = async function (self) {
  await self.$LoadParams.loadParam(self.f_filialeids)
  self.initBrand()
}

export default {
  data () {
    return {
      criteriaShow: false,
      model: new PagedList('rs/sql/sale_getHostMeterList', 20, {}),
      gasproperties: this.$appdata.getParam('用气性质') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用气性质')] : [],
      meter_classify: this.$appdata.getParam('气表类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('气表类型')] : [],
      user_type: this.$appdata.getParam('用户类型') ? [{label: '全部', value: ''}, ...this.$appdata.getParam('用户类型')] : [],
      meterbrands: [],
      addflag: false,
      addtitle: '',
      userinfoSow: false,
      other: [],
      footer: [],
      getfield: {},
      sumsmodel: {},
      userListShow: false,
      // 公司下拉
      curorgid: [this.$login.f.orgid],
      f_orgid: '',
      // 文件上传弹框
      showFile: false
    }
  },
  title: '总表列表',
  props: {
    f_filialeids: {
      type: String
    },
    style: {
      type: String,
      default: 'col-sm-2 form-group'
    }
  },
  watch: {
  },
  ready () {
    readyGen(this)
    // this.search()
  },
  methods: {
    initBrand () {
      // 初始化气表品牌
      let brandArr = []
      this.$GetSaleParam.getGasbrand().forEach((item) => {
        let temp1 = {}
        temp1.label = item.label
        temp1.value = item.value.f_meter_brand
        brandArr.push(temp1)
      })
      this.meterbrands = [{label: '全部', value: ''}, ...brandArr]
    },
    handDblclick (row) {
      console.log('row', row)
      this.$dispatch('child-dblclick', row)
    },
    dealmsg (row) {
      let type = 'showMeterUser'
      this.$dispatch('showUser', row, type)
    },
    getotherfooter () {
      this.other = []
      this.footer = []
      // let exportdata = this.getCondition;
      let otherInData = []
      otherInData.push(`导出时间: ${this.$login.toStandardTimeString()}`)
      let footerData = []
      let exportField = this.getfield
      footerData.push('合计')
      let self = this
      for (var field in self.sumsmodel) {
        footerData.push(`${exportField[field]}合计:${self.sumsmodel[field]}`)
      }
      this.footer.push(footerData)
      this.other.push(otherInData)
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    // 添加方法
    add () {
      if (this.f_filialeids) {
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.userListShow = true
      } else {
        this.$showAlert('请先选择左上角的所在分公司', 'warning', 2000)
      }
    },
    // 关闭文件上传对话框
    closeFile () {
      this.showFile = false
      // 将选的文件清空
      this.$refs.file.$el.querySelector('input').value = ''
    },
    // 修改
    modify (row) {
      this.$refs.paged.$refs.grid.selectStore.selected = null
      this.handDblclick(row)
    },
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    async selfSearch (args) {
      if (!this.f_orgid) {
        this.getorg([this.$login.f.orgid])
      }
      args.condition = `${args.condition} and f_orgid = '${this.f_filialeids}'`
      await this.model.search(args.condition, args.model)
      this.$parent.show = 0
      this.$refs.paged.$refs.grid.selectInit()
    },
    // 清空
    clear () {
      this.$refs.paged.$refs.cri.model = {}
    },
    getorg (val) {
      this.f_orgid = this.$login.convertToIn(val)
      this.f_filialeids = val[0]
    }
  },
  events: {
    'selectUser' (row) {
      this.userListShow = false
      this.$dispatch('add', row)
    }
  },
  computed: {}

}
</script>
