<template>
  <div class="flex" @keyup.enter="search">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="form-group" :class="{'col-sm-3':$parent.$parent.$parent.areaShow,'col-sm-2':!$parent.$parent.$parent.areaShow}">
              <label class="font_normal_body">组织机构</label>
              <res-select restype='organization'
                          @res-select="$parent.$parent.getorg"
                          :initresid='$parent.$parent.curorgid'>
              </res-select>
            </div>
            <div  class="col-sm-4 form-group button-range">
              <button class="button_search button_spacing" @click="search()" >查询</button>
              <button class="button_new button_spacing" style="width: max-content;" v-show="$parent.$parent.addshow"  @click="$parent.$parent.add()">添加周期</button>
            </div>
          </div>
        </div>
      </criteria>
      <data-grid  :model="model" partial='list' class="list_area table_sy" v-ref:grid>
        <template partial='head'>
          <tr>
            <th><nobr>序号</nobr></th>
            <th><nobr>公司名称</nobr></th>
            <th><nobr>周期（单位：年）</nobr></th>
            <th><nobr>开始日期</nobr></th>
            <th><nobr>备注</nobr></th>
            <th><nobr>操作日期</nobr></th>
            <th><nobr>操作员</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <tr>
            <td style="text-align:center"><nobr>{{$index + 1}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_filiale}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_circle}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_start_time}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_remarks}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_operator_time}}</nobr></td>
            <td style="text-align:center"><nobr>{{row.f_operator}}</nobr></td>
          </tr>
        </template>
        <template partial='foot'></template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

  export default {
    data () {
      return {
        criteriaShow: false,
        model: new PagedList('rs/sql/safe_getcirclelist',20),
        addflag: false,
        addtitle:'',
        addshow:false,

        // 公司下拉
        curorgid: [this.$login.f.orgid],
        f_orgid: '',

      }
    },
    title: '安检周期列表',
    props:{
      f_filialeids:{
        type: String
      },
      f_filiale:{
        type: String
      }
    },
    ready(){
      this.search()
    },
    methods: {
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      search () {
        this.$refs.paged.$refs.cri.search()
      },
      add(){
        if (this.f_filialeids) {
          let http = new HttpResetClass()
          http.load('POST','rs/sql/tel_singleTable_OrderBy', {data: {
              items: '*',
              tablename: 't_safe_circle',
              condition: `f_filialeid  = '${this.f_filialeids}'`,
              orderitem: 'id'
            }}, {resolveMsg: null, rejectMsg: null}).then((res) => {
            if(res.data.length >0 ){
              this.$showMessage('该公司下已有安检周期配置', 'warning')
            }else{
              this.$refs.paged.$refs.grid.selectStore.selected = null
              this.$dispatch('add')
            }
          })
        } else {
          this.$showMessage('请先选择左上角的所在分公司', 'warning')
        }

      },
      modify(val){
        this.$refs.paged.$refs.grid.selectStore.selected = null
        this.$dispatch('modify',val)
      },
      selfSearch (args) {
        if (!this.f_orgid) {
          this.getorg([this.$login.f.orgid])
        }
        args.condition = `${args.condition} and f_filialeid  in ${this.f_orgid}`
        this.model.search(args.condition, args.model)
      },
      //清空
      clear(){
        this.$refs.paged.$refs.cri.model = {}
      },
      getorg (val,orgname) {
        if(val.length == 1){
          this.addshow = true
        }else{
          this.addshow = false
        }
        this.f_orgid = this.$login.convertToIn(val)
        this.f_filialeids = val[0]
        this.f_filiale = orgname != undefined ? orgname[0]:''
      }
    },
    watch:{

    }

  }
</script>
