<template>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:criteria>
        <validator name='v' partial>
          <div  class="form-inline auto" >
            <div class="form-group">
              <v-select id="f_user_type"
                        placeholder='请选择用户类型'
                        :value.sync="$parent.$parent.model.f_user_type"
                        :options='$parent.$parent.user_types'
                        close-on-select clear-button></v-select>
            </div>
            <div class="form-group">
              <v-select id="f_check_type"
                        placeholder='请选择设备类型'
                        :value.sync="$parent.$parent.model.f_device_type"
                        :options='$parent.$parent.devices_option'
                        close-on-select clear-button> </v-select>
            </div>
            <div class="form-group">
              <button class="btn btn-success width-80" @click="search()">查询</button>
              <button class="btn btn-default width-80" @click="$parent.$parent.showMo()">新增</button>
            </div>
          </div>
  </validator>
  </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>
      </tr>
    </template>
    <template partial='body'>
      <td>{{row.f_device_type}}</td>
      <td>{{row.f_defect_level}}</td>
      <td>{{row.f_defect}}</td>
      <td>{{row.f_defect_field}}</td>
      <td>{{row.f_defect_path}}</td>
      <td><span class="glyphicon glyphicon-trash" @click="$parent.$parent.$parent.delete(row)"></span></td>
    </template>
  </data-grid>
  </criteria-paged>
  <adddefect-modal v-show="showModal"></adddefect-modal>
</template>

<script>
  import { PagedList } from 'vue-client'
  import  co from  'co'
  import Vue from 'vue'
  import * as Util from '../Util'
  import AppData from '../../stores/AppData'

  let syncDelete = function * (self,row) {
    yield self.$remove('rs/entity/t_defect_info/', {id: row.id})
    self.$refs.paged.$refs.criteria.search()
  }
  export default {
    title: '隐患设置',
    data () {
      let model = new PagedList('api/af-safecheck/sql/getDefect', 20,)

      return {
        fun:this.$login.f,
        defect:{},
        devices_option:[],
        model: model,
        user_types: this.$appdata.getParam('用户类型'),
        showModal: false,
        defects_option: this.$appdata.getParam('隐患级别')
      }
    },

    methods: {
      showMo () {
        this.showModal = true
      },
      delete(row){
        let gen = syncDelete(this,row)
        return co(gen)
      },
      undo(){
        this.showModal = false
      },
    },
    ready(){
      this.$resetpost("api/af-safecheck/logic/获取安检设备",{condition: '1 =1'}).then((respanse) => {
        respanse.data.data.forEach((item)=>{
          this.devices_option.push({label:item.f_device_name,value:item.f_device_name})
        })
      })
    }
  }
</script>
