<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:criteria>
        <div novalidate class="form-inline auto" partial>
          <div class="form-group">
          用户名称:
          <input type="text" class="form-control" v-model="model.f_username"
          condition="f_username like '%{}%'">
          用户电话:
          <input type="text" class="form-control" v-model="model.f_phone"
          condition="f_phone like '%{}%'">
          用户编号:
          <input type="text" class="form-control" v-model="model.f_userid"
          condition="f_userid like '%{}%'">
            有无安检计划:
            <input type="text" class="form-control" v-model="$parent.$parent.model.f_check_plan.f_plan_name" @click="$parent.$parent.showChooser"  readonly="readonly">
          审核状态：
          <v-select id="f_approved"
          placeholder='请选择审核状态'
          v-model='model.f_approved'
          :value.sync="$parent.$parent.model.f_approved"
          :options='$parent.$parent.f_approval_states'
          condition=""
          close-on-select clear-button></v-select>
          <button class="btn btn-default" @click="search()">查询</button>
          <modal :show.sync="$parent.$parent.showModal" v-ref:modal>
            <div slot="modal-header" class="modal-header">
              <h4 class="modal-title">
                选择计划
              </h4>
            </div>
            <div slot="modal-body" class="modal-body">
              <plan-chooser :f.sync="$parent.$parent.f"  v-ref:chooser></plan-chooser>
            </div>
            <div slot="modal-footer" class="modal-footer">
              <button type="button" class="btn btn-default" @click="$parent.$parent.ok">确认</button>
              <button type="button" class="btn btn-default" @click="$parent.$parent.cancel">取消</button>
            </div>
          <modal>
          </div>
        </div>
      </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>
            <th>离开时间</th>
            <th>安检人</th>
            <th>用户类型</th>
            <th>详细地址</th>
           </tr>
        </template>
        <template partial='body'>
          <td>
            <button class="btn btn-default"  @click='$parent.$parent.$parent.change(row)'>查看</button>
            <button class="btn btn-default"  @click='$parent.$parent.$parent.verify(row)'>审核</button>
          </td>
          <td>{{row.f_repaired}}</td>
          <td>{{row.f_repair_approved}}</td>
          <td>{{row.f_userinfo_code}}</td>
          <td>{{row.f_user_name}}</td>
          <td>{{row.f_onsite_time}}</td>
          <td>{{row.f_offsite_time}}</td>
          <td>{{row.f_checker_name}}</td>
          <td>{{row.f_check_type}}</td>
          <td>{{row.f_address}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

export default {
  title: '维修审核',
  props: ['f'],
  data() {
    let model = new PagedList('api/af-safecheck/sql/查找维修单', 20, {
      f_plan_id: 'this.f_check_plan.id',
      f_repair_approved: 'this.f_approved[0]',
      f_no_checkplan: 'this.f_no_checkplan[0]',
      f_subcompany: 'this.f_subcompany'
    })
    model.f_check_plan = {f_plan_name: '', id: ''}
    model.f_approved = ['']
    model.f_entry = ['']
    model.f_subcompany = Vue.f_subcompany
    return {
      model: model,
      showModal: false,
      f_approval_states: this.$appdata.getParam('维修审核状态'),
      f_checkplans: this.$appdata.getParam('有无计划'),
    }
  },
  methods: {
    change(row) {
      if (row.f_check_type == '居民') {
        this.$goto('check-paper', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
      } else {
        this.$goto('check-paper-noncivil', {f_plan_id: row.f_check_plan_id, item: row, role: 'view'}, 'self')
      }
    },
    verify(row) {
      this.$goto('repair-verify-form', {item: row, name: this.$login.f.name}, 'self', this.refresh)
    },
    refresh() {
      this.$refs.paged.$refs.criteria.search()
    },
    showChooser() {
      this.showModal = true
    },
    ok() {
      this.showModal = false
      this.model.f_check_plan = this.$refs.paged.$refs.criteria.$refs.modal.$children[0].selectedRow
    },
    cancel() {
      this.showModal = false
      this.model.f_check_plan = {f_plan_name: '', id: ''}
    }
  },
  watch: {
    'model.f_no_checkplan'(val) {
      if (this.model.f_no_checkplan[0] == '有计划安检') {
        this.showChooser()
      }
    }
  }
}
</script>
