<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-4">
              <label class="font_normal_body">抄表册名称</label>
              <input @keyup.enter="search"  style="width:60%"  type="text" class="input_search" v-model="model.f_book_name" placeholder='抄表册名称'
                     condition="f_book_name like '%{}%'" v-next-el='f_userinfo_code' v-el:meternumber>
            </div>
            <div class="col-sm-4">
              <label class="font_normal_body">抄表员</label>
              <input @keyup.enter="search"  style="width:60%"  type="text" class="input_search" v-model="model.f_inputtor" placeholder='抄表员'
                     condition="f_inputtor like '%{}%'" v-next-el='f_userinfo_code' v-el:meternumber>
            </div>
            <div style="float:right;">
              <button class="button_search button_spacing" @click="search()" >查询</button>
              <button class="button_clear button_spacing" @click="$parent.$parent.clear()">清空</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>

          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center"><nobr>{{$index + 1}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_book_name}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.num}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_inputtor}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_create_date}}</nobr></td>
            <td style="text-align:center"><nobr>
              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.modify(row)">修改</button>
              <button type="button" name="button" class="btn btn-link"
                      @click.stop="$parent.$parent.$parent.delete(row)">删除</button>
            </nobr></td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  export default {

    data () {
      return {
        criteriaShow: false,
        model: new PagedList('rs/sql/getNoBookUser', 20, {items: '"*"', tablename: '"t_meter_book"', orderitem: '"id "'}),
        addflag: false,
        addtitle: '',

        // 公司下拉
        curorgid: [this.$login.f.orgid],
        f_orgid: ''
      }
    },
    title: '抄表册查看',
    props: {
      f_filialeids: {
        type: String
      },
      refresh: {
      }
    },
    ready () {
      this.search()
    },
    methods: {
      hidden () {
        this.criteriaShow = !this.criteriaShow
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },

      async delete (row) {
        this.$showMessage('此操作将会删除此抄表册，请确认是否继续？', ['confirm', 'cancel']).then((res) => {
          if (res === 'confirm') {
            if (row.num > 0) {
              this.$showMessage('抄表册内存在用户，无法删除！')
              return
            }
            let parm = {}
            parm.id = row.id
            parm.version = row.version
            parm.f_book_state = '失效'
            this.$resetpost('rs/entity/t_meter_book', parm, {
              resolveMsg: '删除成功',
              rejectMsg: '未通过，删除出错!!!'
            }).then(() => {
              this.$parent.refresh = -1 * this.$parent.refresh
            })
          }
        })
      },
      add (val) {
        this.$parent.meterShow = false
        this.$parent.addShow = true
        this.$parent.changeinfo = {}
        this.$parent.dowhat = 'add'
        if (this.f_filialeids) {
          this.$refs.paged.$refs.grid.selectStore.selected = null
        } else {
          this.$showAlert('请先选择左上角的所在分公司', 'warning', 2000)
        }
      },
      modify (row) {
        this.$parent.changeinfo = row
        this.$parent.dowhat = 'change'
        this.$parent.addShow = true
        this.$parent.meterShow = false
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
        }
        args.condition = `${args.condition} and f_book_state = '有效' and f_orgid=${this.f_filialeids} `
        this.model.search(args.condition, args.model)
      },
      // 清空
      clear () {
        this.$refs.paged.$refs.cri.model = {}
      },
      getorg (val) {
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeids = val[0]
      }
    },
    watch: {
      refresh () {
        this.search()
      }
    }

  }
</script>
