<template>
  <div class="over col-md-6">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search'>
        <form class="form-inline" partial>
          <div class="form-group">
            <label class="control-label">设备</label>
            <v-select id="f_device_name" :value.sync="$parent.$parent.model.f_device_name"
                      condition="f_device_name={}"
                      placeholder="设备" :options='$parent.$parent.devices_list' close-on-select clear-button> </v-select>
          </div>
          <div class="form-group">
            <label class="control-label">用户类型</label>
            <v-select id="f_user_type" :value.sync="$parent.$parent.model.f_user_type" placeholder='用户类型'
                      condition="f_user_type={}"
                      :options='$parent.$parent.user_types' close-on-select clear-button> </v-select>
          </div>
          <div class="form-group">
            <label class="control-label">是否必检</label>
            <v-select id="f_write_must" :value.sync="$parent.$parent.f_write_must" placeholder='是否必检'
                      condition="f_write_must={}"
                      :options='$parent.$parent.write_must' close-on-select clear-button> </v-select>
          </div>
          <div class="form-group">
            <button type="button" class="btn btn-success width-80" @click="search()">查询</button>
            <button type="button" class="btn btn-default width-80" @click="showMo()">新增</button>
          </div>
        </form>
      </criteria>
      <data-grid :model="model" partial='list'  v-ref:grid>
        <template partial='head'>
          <tr>
            <th>设备</th>
            <th>用户类型</th>
            <th>保存字段</th>
            <th>是否必检</th>
          </tr>
        </template>
        <template partial='body'>
          <td @click="$parent.$parent.$parent.checkitem(row)">{{row.f_device_name}}</td>
          <td @click="$parent.$parent.$parent.checkitem(row)">{{row.f_user_type}}</td>
          <td @click="$parent.$parent.$parent.checkitem(row)">{{row.f_device_field}}</td>
          <td @click="$parent.$parent.$parent.checkitem(row)">{{row.f_write_must}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
  <div  class="span-row over col-md-6">
    <devices-and-item ></devices-and-item>
  </div>
  <add-devices></add-devices>
</template>
<script>
  import { PagedList } from 'vue-client'
  import co from 'co'
  import Vue from 'vue'
  import * as Util from '../Util'
  import DevicesAndItem from "./DevicesAndItem";

  let syncDelete = function * (self,row) {
    yield self.$remove('rs/entity/t_defect_info/', {id: row.id})
    self.$refs.paged.$refs.criteria.search()
  }

  export default {
    components: {DevicesAndItem},
    title: '安检项配置',
    data () {
      return {
        model:new PagedList('rs/path/getDevices',20) ,
        user_types: this.$appdata.getParam('用户类型'),
        write_must: this.$appdata.getParam('是否必检'),
        devices_list:[],
        device:[],
        showModal:false
      }
    },
    ready(){
      this.$resetpost("rs/logic/获取安检设备",{condition: '1 =1'}).then((respanse) => {
        respanse.data.data.forEach((item)=>{
          this.devices_list.push({label:item.f_device_name,value:item.f_device_name})
        })
      })
    },
    computed: {
      selected () {
        return this.$refs.paged.$refs.grid.selected
      }
    },
    methods:{
      checkitem(row){
      this.$set('device',row.f_device_item)
      },
      showMo () {
        this.showModal = true
      },
      delete(row){
        let gen = syncDelete(this,row)
        return co(gen)
      },
      undo(){
        this.showModal = false
      },
    }
  }
</script>
