<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:criteria>
        <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
          <div class="row">
            <div class="col-sm-4 form-group form-input-group" style="width: 20%">
              <label class="control-label">小区名称</label>
              <input type="text" class="form-control" v-model="model.f_residential_area"
                     style="height:34px;margin-top: 8px"    placeholder="小区名称"
                     condition="f_residential_area like '%{}%'">
            </div>
            <div class="col-sm-4 form-group form-input-group" style="width: 20%">
              <label class="control-label">联系电话</label>
              <input type="text" class="form-control" v-model="model.f_defect_type"
                     style="height:34px;margin-top: 8px"      placeholder="联系电话"
                     condition="f_user_phone = '{}'">
            </div>
            <div class="col-sm-4 form-group form-input-group" style="width: 20%">
              <label class="control-label">卡号</label>
              <input type="text" class="form-control" v-model="model.f_card_id"
                     style="height:34px;margin-top: 8px"      placeholder="卡号"
                     condition="f_card_id = '{}'">
            </div>
            <div class="col-sm-4 form-group form-input-group" style="width: 20%">
              <label class="control-label">起始时间</label>
              <datepicker
                :value.sync="model.f_start_time"
                placeholder='起始安检时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "model.f_start_time"
                condition="f_onsite_time > ='{} 00:00:00'">
              </datepicker>
            </div>
            <div class="col-sm-4 form-group form-input-group" style="width: 20%">
              <label class="control-label">结束时间</label>
              <datepicker
                :value.sync="model.f_end_time"
                placeholder='结束安检时间' style="width:60%"
                :disabled-days-of-week="[]"
                :format="'yyyy-MM-dd'"
                :show-rest-button="reset"
                v-model = "model.f_end_time"
                condition="f_onsite_time < ='{} 23:59:59'">
              </datepicker>
            </div>
          </div>
          <div class="row">
            <div class="col-sm-4 form-group form-input-group" style="width: 20%">
              <label class="control-label">跟进方式</label>
              <v-select placeholder='跟进方式'
                        :value.sync="model.f_followup_way"
                        :value-single="true" style="width:60% "
                        class="select select_list"
                        :options='$parent.$parent.followupWays'
                        v-model="model.f_followup_way"
                        condition="f_followup_way='{}'"
                        close-on-select clear-button> </v-select>
            </div>
          </div>
          <div class="row">
            <div class="span" style="margin-top:8px;float:right">
              <button class="button_search button_spacing" @click="search()">查询</button>
              <export-excel :data="$parent.$parent.getCondition"
                            :field="$parent.$parent.getfield"
                            sqlurl="rs/logic/SafeExportExcel" sql-name="OneLevelFollowUp" template-name='一级隐患跟进导出'  :choose-col="true"></export-excel>
            </div>
          </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>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center">{{row.f_residential_area}}</td>
          <td style="text-align: center">{{row.f_address}}</td>
          <td style="text-align: center">{{row.f_user_phone}}</td>
          <td style="text-align: center">{{row.f_card_id}}</td>
          <td style="text-align: center">{{row.f_onsite_time}}</td>
          <td style="text-align: center">{{row.f_notification_number}}</td>
          <td style="text-align: center">{{row.f_onsite_time}}</td>
          <td style="text-align: center">{{row.f_followup_way}}</td>
          <td style="text-align: center">{{$parent.$parent.$parent.getDefectContent(row.f_defect_content)}}</td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

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

export default {
  title: '一级隐患跟进',
  data () {
    let model = new PagedList('rs/sql/OneLevelFollowUp', 20)
    return {
      show:true,
      fun:this.$login.f,
      f_check_result:'',
      checkersid:[],
      model: model,
      showModal: false,
      selfcondition:'',
      followupWays:[{label: '全部', value: ''}, {label: '电话跟进', value: '电话跟进'},{label: '上门跟进', value: '上门跟进'},{label: '记录跟进', value: '记录跟进'}],
    }
  },
  methods: {
    cancel () {
      this.showModal = false
      this.$set('selfcondition','')
    },
    search(args) {
      var str = args.condition
      str += this.selfcondition
      this.model.search(str, args.model)
    },
  },
  computed: {
    getCondition() {
      return {
        condition: `${this.$refs.paged.$refs.criteria.condition} `,
      }
    },
    getfield() {
      let Config = {
        "f_residential_area": "小区名称",
        "f_address": "楼房号",
        "f_user_phone": "联系电话",
        "f_card_id": "卡号",
        "f_onsite_time": "安检时间",
        "f_notification_number": "安检告知书编号",
        // "f_onsite_time": "跟进时间",
        "f_followup_way": "跟进方式"
      }
      return Config
    },
    getDefectContent(){
      return function (row) {
        console.log('row',row)
        let isDefect = JSON.parse(row)['result']
        let defect = JSON.parse(row)['data']
        let result = ''
        if(isDefect == '正常'){
          result = '正常'
        }else {
          for (let i in defect){
            for (let key in  defect[i]){
              result = key + ':' + defect[i][key] +';'
            }
          }
        }
        console.log('result===>',result)
        return result
      }
    }
  }
}
</script>
