<template>
  <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-3">
              <label class="font_normal_body">组织机构</label>
              <res-select restype='organization'
                          class="select select_list"
                          style="width: 60%"
                          @res-select="$parent.$parent.getorg"
                          :initresid='$parent.$parent.curorgid'>
              </res-select>
            </div>
            <div class="col-sm-3">
              <label class="font_normal_body">优惠名称</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_privilege_name"
                     placeholder='优惠名称' condition="f_privilege_name like '%{}%'">
            </div>
            <div class="span" style="float:right;">
              <button class="button_search" @click="$parent.$parent.search()" v-el:cx>查询</button>
              <button class="button_new" @click="$parent.$parent.add()">新增</button>
            </div>
          </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>优惠名称</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">{{$index + 1}}</td>
            <td style="text-align:center">{{row.f_privilege_name}}</td>
            <td style="text-align:center">{{row.f_privilege_type}}</td>
            <td style="text-align:center">{{row.f_user_type}}</td>
            <td style="text-align:center">{{row.f_gasproperties}}</td>
            <td style="text-align:center">{{row.f_payment}}</td>
            <td style="text-align:center">{{row.f_perform_date}}</td>
            <td style="text-align:center">{{row.f_end_date}}</td>
            <td style="text-align:center">{{row.f_filialename}}</td>
            <td style="text-align:center">
              <nobr>{{row.f_comments}}</nobr>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  /**
   *阶梯气价查询列表
   */
  import {PagedList} from 'vue-client'

  export default {
    data () {
      return {
        model: new PagedList('rs/sql/getPrivilegeInfo', 20),
        show: false,
        // 公司下拉
        curorgid: [this.$login.f.orgid],
        // 分公司查询条件
        f_filialeids: ''
      }
    },
    props: {},
    ready () {
      this.search()
    },
    methods: {
      search () {
        this.$refs.paged.$refs.cri.search()
        this.$dispatch('search')
      },
      getorg (val) {
        this.f_filialeids = this.$login.convertToIn(val)
      },
      selfSearch (args) {
        if (!this.f_filialeids) {
          this.getorg(this.curorgid)
        }
        console.log('查询。。。', this.f_filialeids)
        if (this.f_filialeids) {
          args.condition = `f_filialeid  in ${this.f_filialeids} and ${args.condition}`
        }
        this.$refs.paged.$refs.grid.$el.scrollTop = 0
        this.model.search(args.condition, args.model)
      },
      add () {
        // 新增时取消选中状态
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.$dispatch('select-changed')
      }
    },
    watch: {
    }
  }
</script>
