<template>
  <div id="boxlist" class="flex" style="flex:1; ">
    <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">
            <label for="f_ajustable_name" class = "control-form">银行名称:</label>
            <input type="text" class="form-control" v-model="model.f_bank_name"
            condition="f_bank_name like '%{}%'" placeholder='银行名称'>
          </div>
          <div class="form-group">
            <label for="f_ajustable_name" class = "control-form">终端号:</label>
            <input type="text" class="form-control" v-model="model.f_terminal_num"
            condition="f_terminal_num like '%{}%'" placeholder='终端号'>
          </div>
          <div class="form-group">
            <label for="f_ajustable_address" class = "control-form">网点名称:</label>
            <input type="text" class="form-control" v-model="model.f_dot_name"
            condition="f_dot_name like '%{}%'" placeholder='网点'>
          </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>
      </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>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td  style="text-align: center;">{{row.f_bank_name}}</td>
          <td  style="text-align: center;">{{row.f_terminal_num}}</td>
          <td  style="text-align: center;">{{row.f_dot_name}}</td>
          <td  style="text-align: center;">{{row.f_dot_address}}</td>
          <td  style="text-align: center;">{{row.f_link_man}}</td>
          <td  style="text-align: center;">{{row.f_contact_number}}</td>
          <!-- <td style="text-align: center;">
             <dropdown>
              <button type="button" data-toggle="dropdown" style="border: 0px;background: none;">
                <span class="glyphicon glyphicon-th-list" style="position: inherit;"></span>
              </button>
              <ul slot="dropdown-menu" class="dropdown-menu dropdown-menu-right">
                <li >
                  <a href="#" @click.stop="$parent.$parent.$parent.changeuser()">启用</a>
                </li>
                <li >
                     <a href="#" @click.stop="$parent.$parent.$parent.showother()">停用</a>
                </li>
              </ul>
            </dropdown>
          </td> -->
          <td style="text-align:center">
            <button type="button" name="button" class="btn btn-link" v-if="row.f_state==='停用'"
            @click.stop="$parent.$parent.$parent.modifyState(row, 'startup')">启用</button>
            <button type="button" name="button" class="btn btn-link" v-if="row.f_state==='启用'"
            @click.stop="$parent.$parent.$parent.modifyState(row, 'breakdown')">停用</button>
          </td>
        </template>
      </data-grid>
  </criteria-paged>
 </div>
</template>
<script>
import { PagedList } from 'vue-client'


export default {
  title: '银行对接',
  data () {
    return {
      model: new PagedList('rs/sql/singleTable_OrderBy', 20,{
        items:"'*'",tablename:'"t_bankdocking"',orderitem:'"id desc"'
      })
    }
  },
  props: [],
  ready () {
    this.model.search('1=1')
  },
  methods: {
    search () {
      // this.model.search()
      this.$dispatch('search')
    },
    createNew () {
      // console.log('123123')
      this.$dispatch('add')
    },
    modifyState(row,state){
      if (state==='startup') {
        this.$showMessage('确认启用该终端吗?', ['confirm', 'cancel']).then(
          (response) => {
            if (response === 'confirm') {
              this.$resetpost('rs/logic/changebankstate',{
                data:{state:'启用',data:row}
              })
              .then(()=>{
                this.model.search('1=1')
              })
            }
            })
          }else{
        this.$showMessage('确认停用该终端吗?', ['confirm', 'cancel']).then(
          (response) => {
            if (response === 'confirm') {
              this.$resetpost('rs/logic/changebankstate',{
                data:{state:'停用',data:row}
              })
              .then(()=>{
                this.model.search('1=1')
              })
            }
            })
          }
    },
    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')
          }
        })
    }
  }
}
</script>
