<template>
  <div>
    <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>
          <ul class="nav nav-tabs">
            <li role="presentation" class="active"><a style="	color: #5ac0d9 !important;">下发明细</a></li>
          </ul>
          <div class="col-sm-2 ">
            <label class="font_normal_body">安检员</label>
            <v-select id="checker"
                      v-model="model.f_checker_id"
                      :value.sync="model.f_checker_id" placeholder='安检员'
                      condition="tcp.f_checker_id = '{}'"
                      :value-single="true"
                      class="select_list select"
                      style="width: 60%"
                      :options='$parent.$parent.checkers' close-on-select clear-button> </v-select>
          </div>
          <div class="col-sm-4" style="width: 20%;float: right;">
            <div class="span" style="text-align: center;">
              <button class="button_search" @click="search()">查询</button>
            </div>
          </div>
        </div>

      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid class="list_area table_sy">
        <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'>
          <td style="text-align: center;white-space:nowrap;">{{row.f_plan_name}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_send_operator}}</td>
          <td style="text-align: center;white-space:nowrap;">{{row.f_issue_time}}</td>
        <td style="text-align: center;white-space:nowrap;">
          <div v-if="row.f_state=='已检'" @click='$parent.$parent.$parent.goDetail(row)'>{{row.f_state}}</div>
          <div v-if="row.f_state=='未检'">{{row.f_state}}</div>
        </td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_state=='已检' ? row.f_last_check_date : ''}}</td>
          <td style="text-align: center;white-space:nowrap;">{{ row.f_state=='已检' ? row.f_last_check_state : ''}}</td>
          <td style="text-align: center;white-space:nowrap;">{{  row.f_checker }}</td>

        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>
<script>
import {HttpResetClass, PagedList} from 'vue-client'
import * as Util from '../Util'
import Vue from "vue";

let asyncReady = async function (self) {
  // 获取配置信息
  try {
    let res = await Vue.resetget(`/phone/rs/vue`, {data: {}}, {resolveMsg: null, rejectMsg: null})
    Vue.config = res.data
  } catch (error) {
    // 忽略704,文件找不到异常R
    if (error.status !== 704) {
      throw error
    }
  }
}
export default {
  title: '用户计划下发情况',

  props: ['check'],
  data() {
    let model = new PagedList('api/af-safecheck/sql/safe_singleTable_OrderBy', 20, {
      items: "' tcp.f_plan_name,tcpi.f_plan_id,tcpi.f_userinfo_code userinfocode,tcp.f_send_operator,tcpi.f_state,tcp.f_issue_time,tcpi.f_last_check_date,tcpi.f_last_check_state,tcp.f_checker,cp.id,cp.f_check_type,cp.f_collection_type,cp.f_entry_status '",
      tablename: "'t_check_plan tcp left join t_check_plan_item tcpi on tcp.id=tcpi.f_plan_id LEFT JOIN (SELECT cpb.*,cpa.id,cpa.f_check_type,cpa.f_collection_type,cpa.f_entry_status FROM t_check_paper cpa LEFT JOIN ( SELECT f_check_item_id, MAX ( f_offsite_time ) f_offsite_time FROM t_check_paper GROUP BY f_check_item_id ) cpb ON cpb.f_check_item_id = cpa.f_check_item_id AND cpb.f_offsite_time = cpa.f_offsite_time ) cp ON cp.f_check_item_id = tcpi.id '",
      orderitem: "'1'"
    })
    model.f_filialeids = '(' + this.$login.f.orgid + ')'
    return {
      f_filialeids:'(' + this.$login.f.orgid + ')',
      userid: this.$login.f.id,
      f: this.$login.f,
      model: model,
      checkers: [],
      // criteriaShow: false,
      source: `tool.getFullTree(this.getRights().where(row.getType() != $zone$).where(row.getType() == $organization$))`,
    }
  },
  watch: {
    'check'() {
      let condition = `tcpi.f_state !='作废' and tcpi.f_userinfo_code = '${this.check.f_userinfo_code}'`
      if (this.$parent.$refs.check.$refs.paged.$refs.criteria.model.f_plan_year){
        condition += ` and tcp.f_plan_year = ${this.$parent.$refs.check.$refs.paged.$refs.criteria.model.f_plan_year} `
      }
      this.model.search(condition)
    }
  },
  ready(){
    let condition = `tcpi.f_state !='作废' and tcpi.f_userinfo_code = '${this.check.f_userinfo_code}'`
    if (this.$parent.$refs.check.$refs.paged.$refs.criteria.model.f_plan_year){
      condition += ` and tcp.f_plan_year = ${this.$parent.$refs.check.$refs.paged.$refs.criteria.model.f_plan_year} `
    }
    this.model.search(condition)

    this.getCheckerList()

  },
  methods: {
    getCheckerList() {
      let http = new HttpResetClass()
      http.load('POST', `/rs/search`, {
        source: 'tool.getChildrenOfResName($安检员$)',
        userid: this.$login.f.id
      }, {resolveMsg: null, rejectMsg: null}).then((res) => {
        res.data.forEach((checker)=>{
          this.checkers.push({label:checker.name,value:checker.id})
        })
        this.checkers.push({label:'全部',value:''})
      })
    },
    selfSearch(args) {
      return this.model.search(args.condition, args.model)
    },
    //查看的方法
    goDetail(row){
      asyncReady(this).then(() => {
        row.f_upload_state = '已传'
        this.$goto('new-check-paper', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
      }).catch(
        (respanse) => {
          alert('获取配置文件失败')
        })
    },
    search(args) {
      this.model.search(args.condition, args.model)
    },
    getRes(obj) {
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
      console.log(this.f_filialeids)
      console.log('11111111111'+JSON.stringify(this.model))
      console.log('11111111111'+JSON.stringify(this.obj))
    },
  },
  computed: {
    selected() {
      return this.$refs.paged.$refs.grid.selected
    }
  }
}
</script>


<style lang="less" scoped>
                   .select-error {
button {
  border-bottom: 1px solid #a94442 !important;
}
}
</style>

