<template>
  <div style="flex:1;" class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
       <div novalidate class="form-inline" partial>
         <div class="form-group">
           <button class="btn btn-success width-100" @click="$parent.$parent.search()" v-el:cba>查询</button>
         </div>
         <div class="form-group">
           <button class="btn btn-success width-100" @click="$parent.$parent.add()" v-el:cba>新增</button>
         </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> -->
             <th>卡类型</th>
             <th>使用人</th>
             <th>分配人</th>
             <th>分配日期</th>
             <!-- <th>状态</th> -->
             <th>操作</th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">{{$index+1}}</td>
            <td style="text-align:center">{{row.f_start_number}}</td>
            <td style="text-align:center">{{row.f_end_number}}</td>
            <td style="text-align:center">
              <input  type="number" class="col-sm-1" style="width:50%;margin-left:30%"v-model="row.f_now_number"
              v-next-el="{id: $index+1}"   @blur="$parent.$parent.$parent.updateNumber(row)" :id="$index"></td>
            <td style="text-align:center">{{row.f_number}}</td>
            <!-- <td style="text-align:center">{{row.f_now_number}}</td> -->
            <td style="text-align:center">{{row.f_card_type}}</td>
            <td style="text-align:center">{{row.f_user}}</td>
            <td style="text-align:center">{{row.f_operator}}</td>
            <td style="text-align:center">{{row.f_operator_date}}</td>
            <!-- <td style="text-align:center">{{row.f_bill_state}}</td> -->
            <td style="text-align:center">
              <button type="button" name="button" class="btn btn-link" v-if="row.f_now_number != row.f_end_number && (row.f_state ==='停用' || row.f_state ==='作废')"
              @click.stop="$parent.$parent.$parent.modifyState(row, '启用')">启用</button>
              <button type="button" name="button" class="btn btn-link" v-if="row.f_now_number != row.f_end_number && row.f_state ==='启用'"
              @click.stop="$parent.$parent.$parent.modifyState(row, '停用')">停用</button>
              <button type="button" name="button" class="btn btn-link" v-if="row.f_now_number === row.f_start_number && row.f_state ==='启用'"
              @click.stop="$parent.$parent.$parent.modifyState(row, '作废')">作废</button>
            </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/getCardAllot', 20)
    }
  },
  props: {
    row: {}
  },
  ready () {
    this.search()
  },
  methods: {
    add () {
      this.$dispatch('addallot', 'add')
    },
    search () {
      this.$dispatch('allotlistsearch')
    },
    modifyState (row, type) {
      let state = row.f_state
      row.f_state = type
      this.$resetpost('rs/entity/t_cardallot', row, {resolveMsg: `${type}成功`, rejectMsg: '更改状态失败'})
      .catch(() => {
        row.f_state = state
      })
    },
    updateNumber (row) {
      this.$resetpost('rs/entity/t_cardallot', row, {resolveMsg: '更改成功', rejectMsg: '更改失败'})
    }
  },
  watch: {
  },
  computed: {
    operator () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('票据分配人')]
    },
    user () {
      return [{label: '全部', value: ''}, ...this.$appdata.getParam('票据使用人')]
    }
  }
}
</script>
