f<template>
  <div id="boxlist" class="flex" style="flex:1; ">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal  select-overspread auto" partial>
          <div class="row">
            <div class="col-sm-2   form-group">
              <label class="font_normal_body">组织机构</label>
              <res-select restype='organization'
                          :is-mul="false"
                          :initresid="$parent.$parent.curorgid"
                          @res-select="$parent.$parent.getorgCur">
              </res-select>
            </div>
            <div class="col-sm-2  form-group">
              <label class="font_normal_body">编&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_adjustable_id"
                     condition="a.f_adjustable_id like '%{}%'" placeholder='加气枪编号'>
            </div>
            <div class="col-sm-2  form-group">
              <label class="font_normal_body">名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_adjustable_name"
                     condition="f_adjustable_name like '%{}%'" placeholder='加气枪名称'>
            </div>
            <div class="col-sm-2  form-group">
              <label class="font_normal_body">地&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;址</label>
              <input type="text" class="input_search" style="width:60%" v-model="model.f_adjustable_address"
                     condition="f_adjustable_address like '%{}%'" placeholder='加气枪地址'>
            </div>
            <div class="span" style="float:right;">
              <button class="button_search button_spacing" @click="$parent.$parent.search()" v-el:cx>查询</button>
              <button class="button_new button_spacing" @click="$parent.$parent.createNew()" v-el:cx>新建</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>-->

              <export-excel
                :data="{condition: $parent.$parent.excelCondition}"
                :field="$parent.$parent.fields"
                sqlurl="rs/logic/saleExport" progress="saleGetExportProgress" sql-name="adjustableboxQuery"
                template-name='加气枪导出'
                :choose-col="true">
              </export-excel>

            </div>
          </div>
<!--          <div class="row" v-show="$parent.$parent.criteriaShow">-->

<!--          </div>-->
        </div>
      </criteria>
      <data-grid class="list_area table_sy" :model="model" partial='list' v-ref:grid class="l">
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>加气枪编号</th>
            <th>加气枪名称</th>
            <th>加气枪地址</th>
            <!--<th>立管编号</th>-->
            <th>用户数</th>
            <th>操作</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td style="text-align: center;">{{row.f_adjustable_id}}</td>
          <td style="text-align: center;">{{row.f_adjustable_name}}</td>
          <td style="text-align: center;">{{row.f_adjustable_address}}</td>
          <!--<td style="text-align: center;">{{row.f_riser_codes}}</td>-->
          <td style="text-align: center;">{{row.counts}}</td>
          <td style="text-align:center">
            <button class="btn btn-link "   v-if = "row.counts === 0" @click.stop="$parent.$parent.$parent.del(row.f_adjustable_id)"> 删除 </button>
          </td>
        </template>
      </data-grid>
  </criteria-paged>
 </div>
</template>
<script>
import { PagedList } from 'vue-client'

let asyncBoxGen = async function (self) {
  await self.$getConfig(self, 'BoxList')
  self.getfield = self.config.excelHeaders
  self.search()
}

export default {
  title: '加气枪',
  data () {
    return {
      model: new PagedList('rs/sql/adjustableboxQuery', 20),
      config: {
        excelHeaders: {
          'f_adjustable_id': '加气枪编号',
          'f_adjustable_name': '加气枪名称',
          'f_adjustable_address': '加气枪地址',
          'counts': '用户数'
        }
      },
      fields: {
        'f_adjustable_id': '加气枪编号',
        'f_adjustable_name': '加气枪名称',
        'f_adjustable_address': '加气枪地址',
        'counts': '用户数'},
      curorgid: [this.$login.f.orgid],
      f_orgid: '',
      criteriaShow: false,
      getfield: {},
      excelCondition: ''
    }
  },
  props: {
    f_filialeids: {
      type: String
    }
  },
  ready () {
    // asyncBoxGen(this)
    this.search()
  },
  methods: {
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    hidden () {
      this.criteriaShow = !this.criteriaShow
    },
    selfSearch (args) {
      if (!this.f_orgid) {
        this.getorgCur([this.$login.f.orgid])
      }
      if (this.f_orgid) {
        args.condition = `${args.condition} and f_orgid  = ${this.f_orgid}`
      }
      this.excelCondition = args.condition
      this.model.search(args.condition, args.model)
    },
    createNew () {
      if (!this.f_filialeids) {
        this.$showAlert('请先选择左上角的所在分公司', 'warning', 2000)
        return
      }
      this.$dispatch('add')
    },
    del (id) {
      this.$showMessage('确认删除吗?', ['confirm', 'cancel']).then(
        (response) => {
          if (response === 'confirm') {
            this.$resetpost('rs/logic/deleteBox', {data: {id: id}}, {resolveMsg: '删除成功', rejectMsg: '删除失败'})
            .then((res) => { this.$dispatch('success', '加气枪删除', this.data, res) })
            .catch((error) => { this.$dispatch('error', '加气枪删除', this.data, error) })
          } else if (response === 'cancel') {
            this.$dispatch('cancel')
          }
        })
    },

    getorgCur (val) {
      this.f_orgid = this.$login.convertToIn(val)
      this.f_filialeids = val[0]
    }
  },
  computed: {
    // filiales () {
    //   let rs = []
    //   for (let i = 0; i < this.$login.f.f_allfiliale.length; i++) {
    //     rs.push({label: this.$login.f.f_allfiliale[i].label, value: this.$login.f.f_allfiliale[i].label})
    //   }
    //   return [{label: '全部', value: ''}, ...rs]
    // },
    // outlets () {
    //   let rs = []
    //   console.log('档案营业网点。。。', this.$refs.paged.$refs.cri.model.f_filiale)
    //   if (this.$refs.paged.$refs.cri.model.f_filiale.length > 0) {
    //     for (let i = 0; i < this.$login.f.f_allfiliale.length; i++) {
    //       if (this.$login.f.f_allfiliale[i].label === this.$refs.paged.$refs.cri.model.f_filiale[0]) {
    //         rs = this.$login.f.f_allfiliale[i].value
    //       }
    //     }
    //   }
    //   console.log('获取档案营业网点。。。。', rs)
    //   return [{label: '全部', value: ''}, ...rs]
    // }
  }
}
</script>
