<template>
  <div  class="flex">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div novalidate class="form-inline auto" partial>
          <div class="form-group" >
            <input  type="text" class="form-control" v-model="model.f_change_name"
                    condition="f_change_name like '%{}%'" placeholder="登记人"
                    :size="model.f_change_name ? model.f_change_name.length : 3"/>
          </div>

          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_exploit_name"
                   condition="f_exploit_name like '%{}%'" placeholder='开发人'
                   :size="model.f_exploit_name ? model.f_exploit_name.length : 3"/>
          </div>

          <div class="form-group form-input-group" >
            <datepicker id="startDate" placeholder="开始日期" width='100%'
                        v-model="model.startDate"
                        :value.sync="model.startDate"
                        :format="'yyyy-MM-dd'"
                        :show-reset-button="true"
                        condition="f_edit_date >= '{} 00:00:00'">
            </datepicker>
          </div>
          <div class="form-group form-input-group" >
            <datepicker id="startDate" placeholder="结束日期" width='100%'
                        v-model="model.endDate"
                        :value.sync="model.endDate"
                        :format="'yyyy-MM-dd'"
                        :show-reset-button="true"
                        condition="f_edit_date <= '{} 23:59:59'">
            </datepicker>
          </div>
          <div class="form-group">
            <v-select id="f_bill_style"
                      v-model="model.f_state"
                      placeholder='状态'
                      :value.sync="model.f_state"
                      :options='$parent.$parent.listState'
                      condition= "f_state = '{}'"
                      close-on-select>
            </v-select>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="search()" v-el:cx>查询</button>
            <button class="btn btn-success width-80" @click="$parent.$parent.add()" 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>
            <th>操作</th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center">{{$index+1}}</td>
            <td style="text-align:center">{{row.f_model_name}}</td>
            <td style="text-align:center">{{row.f_change_message}}</td>
            <td style="text-align:center">{{row.f_change_name}}</td>
            <td style="text-align:center">{{row.f_exploit_name}}</td>
            <td style="text-align:center">{{row.f_change_date}}</td>
            <td style="text-align:center">{{row.f_edit_date}}</td>
            <td style="text-align:center">{{row.f_state}}</td>
            <td style="text-align:center">
            <button type="button" name="button" class="btn btn-link"
                    @click.stop="$parent.$parent.$parent.delete(row)"
                    v-if="row.f_state=='作废'">删除</button>
            </td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  let readySync = async function (self) {
    await self.$refs.paged.$refs.cri.search()
  }
  export default {
    data () {
      return {
        model: new PagedList('rs/sql/singleTable_OrderBy', 20,
          {tablename: '`t_changedeclare`', items: '`*`', orderitem: '`f_change_date desc`'})
      }
    },
    ready () {
      readySync(this).then(() => {
        this.$emit('ready')
      }).catch((error) => {
        this.$emit('error', error)
      })
    },
    methods: {
      add () {
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.$dispatch('add')
      },
      delete (row) {
        if (row.id) {
          var id = row.id
          this.$resetdelete('rs/entity/t_changedeclare', {id: id}, {resolveMsg: '删除成功', rejectMsg: '删除失败'}).then((res) => {
            this.$dispatch('refresh')
          })
        }
      }
    },
    computed: {
      listState () {
        return [{label: '全部', value: ''}, {label: '已测', value: '已测'}, {label: '未测', value: '未测'}, {label: '作废', value: '作废'}]
      }
    }
  }
</script>
