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-inline" partial>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_adjustable_id"
            condition="a.f_adjustable_id like '%{}%'" placeholder='调压箱编号'>
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_adjustable_name"
            condition="f_adjustable_name like '%{}%'" placeholder='调压箱名称'>
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_adjustable_address"
            condition="f_adjustable_address like '%{}%'" placeholder='调压箱地址'>
          </div>
          <!--<div class="form-group" >-->
            <!--<v-select :value.sync="model.f_filiale" v-model='model.f_filiale'-->
            <!--:options='$parent.$parent.filiales' placeholder='分公司'-->
            <!--close-on-select-->
            <!--condition="f_filiale = '{}'"></v-select>-->
          <!--</div>-->
          <!--<div class="form-group">-->
            <!--<v-select :value.sync="model.f_outlets" v-model='model.f_outlets'-->
                <!--:options='$parent.$parent.outlets' placeholder='营业网点'-->
                <!--close-on-select-->
                <!--condition="f_outlets = '{}'"></v-select>-->
          <!--</div>-->
          <div class="form-group">
            <button class="btn btn-success width-80" @click="$parent.$parent.search()" v-el:cx>查询</button>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="$parent.$parent.createNew()" v-el:cx>新建</button>
          </div>
          <div class="form-group">
            <export-excel :data="{condition: condition + ` and f_filialeids = '${$login.f.f_orgids}'`}"
                          :field="$parent.$parent.getfield"
                          sqlurl="rs/logic/saleExport" sql-name="adjustableboxQuery" template-name='调压箱导出' :choose-col="true"></export-excel>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <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>{{row.f_adjustable_id}}</td>
          <td>{{row.f_adjustable_name}}</td>
          <td>{{row.f_adjustable_address}}</td>
          <td>{{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')
  console.log('抄表管理config', self.config)
  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': '用户数'
        }
      },
      getfield: {}
    }
  },
  ready () {
    asyncBoxGen(this)
  },
  methods: {
    search () {
      this.$refs.paged.$refs.cri.search()
    },
    selfSearch (args) {
      args.condition = `${args.condition} and f_filialeids = '${this.$login.f.f_orgids}'`
      this.model.search(args.condition, args.model)
    },
    createNew () {
      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')
          }
        })
    }
  },
  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>
