<template>
  <div>
    <criteria-paged :model="model" pager='false' v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.search' v-ref:criteria>
        <div novalidate partial class="form-inline auto">
          <div class="form-group">
            <label class="control-label" for="f_plan_year">年份</label>
            <input type="text" class="form-control" id="f_plan_year" v-model="model.f_plan_year" size="6"
                   condition="f_plan_year={}" readonly="readonly">
          </div>
          <div class="form-group">
            <label class="control-label" for="c_plan_month">月份</label>
            <input type="text" class="form-control" v-model="model.f_plan_month" id="c_plan_month" size="2"
                   condition="f_plan_month={}" readonly="readonly">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_plan_name" id="f_plan_name"
                   placeholder="计划名称" condition="c.f_plan_name like '%{}%'">
          </div>
          <div class="form-group">
            <input type="text" class="form-control" v-model="model.f_residential_area" id="f_residential_area"
                   placeholder="小区" condition="f_residential_area like '%{}%'">
          </div>
          <div class="form-group">
            <label class="control-label">安检员</label>
            <v-select :value.sync="model.f_checker_id" v-model='model.f_checker_id'
                      :value-single="true"
                      :options='$parent.$parent.$parent.checkersid' placeholder='安检员'
                      close-on-select
                      condition="c.f_checker_id = '{}'"></v-select>
          </div>
          <div class="form-group">
            <button type="button" class="btn btn-success width-80" @click="search()">查询</button>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th><nobr>序号</nobr></th>
            <th>计划名称</th>
            <th>用户编号</th>
            <th>用户名称</th>
            <th>小区名称</th>
            <th>地址</th>
            <th>操作</th>
            <th>标记</th>
          </tr>
        </template>
        <template partial='body'>
          <td>{{$index+1}}</td>
          <td>{{row.f_plan_name}}</td>
          <td>{{row.f_userinfo_code}}</td>
          <td>{{row.f_user_name}}</td>
          <td>{{row.f_residential_area}}</td>
          <td>{{row.f_address}}</td>
          <td><span class="glyphicon glyphicon-trash" @click="$parent.$parent.$parent.delete(row)"></span></td>
          <td>{{row.sign=='1'?'◆':''}}</td>
        </template>
        <template partial="foot">
          <span>共{{ model.count }}项</span>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  let syncDelete = function * (self,row) {
    yield self.$resetpost('rs/logic/deleteCheckPlanItem',{tablename:'t_check_plan_item',id:row.id },{
      warnMsg: '删除数据不可恢复，确认删除吗？',
      resolveMsg: '恭喜！删除成功！',
      rejectMsg: '删除失败：'
    })
    self.$refs.paged.$refs.criteria.search()
  }

  export default {
    title: '安检员B',
    data () {
      let model = new PagedList('rs/sql/根据安检员查询安检项', 3000,
        {f_subcompany: 'this.f_subcompany', f_checker_id: 'this.chosenOrg.id'})
      model.chosenOrg = {id:0}
      return {
        checker:this.$login.f,
        rightCheckers:this.$parent.checkers,
        f2:this.$login.f,
        model: model,
      }
    },
    methods:{
      search(args ){
        this.model.rows = []
        this.model.count = 0
        this.model.search(args.condition, args.model)
      },
      delete(row){
        let gen = syncDelete(this,row)
        return co(gen)
      }
    },
    ready () {
      //tag
      this.model.id = this.$login.f.id
      this.model.f_subcompany = this.$login.f.f_fengongsi
    },
    watch:{
      'checker'(){
        //tag
        this.model.chosenOrg = this.checker[0]
      }
    },
    computed: {
      selected () {
        return this.$refs.paged.$refs.grid.selected
      }
    }
  }
</script>
