<style>
  .bg {
    background-color: blue;
    height: 1px;
    border: 0;
  }
  .app-row {
    background-color: white;
    padding: 10px 10px 0 10px;
    border-bottom: 1px solid rgba(235, 235, 235, 0.5);
  }
  .search_input {
    border: 0;
    outline: none;
  }
  .font{
    font: 15px PingFang-SC-Medium;
    color: #666666;
  }
  .input-font{
    font: 15px PingFang-SC-Medium;
    color: #333333;
  }
  .btn-font{
    font:600 16px PingFang-SC-Bold;
    color: #499EDF;
  }
  .btn-color{
    background-color: #FFFFFF;
    border-radius: 10px ;
    border: 1px solid #499EDF;
  }
  .app-text {
    font-size: 12px;
  }
  .panel-self{
    border-radius: 10px;
    border:1px solid #499EDF;
    background-color: #F8F8F8;
  }
  .yybtn-color{
    background-color:#499edf;
    border-radius: 4px ;
    border: 1px solid #499EDF;
    color: #FFFFFF;
    font: 14px PingFang-SC-Bold;
  }
  .qxbtn-color{
    background-color: #FFFFFF;
    border-radius: 4px ;
    color: #499edf;
    font: 14px PingFang-SC-Bold;
    border: 1px solid #499EDF;
  }

</style>

<template>
  <div class="auto">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div partial>
          <form>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label  class="font text-left">小区名称：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input  class="search_input input-font"
                        v-model=model.f_residential_area condition="ti.f_residential_area like '%{}%'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_building" class="font text-left">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_building" class="search_input input-font"
                       v-model="model.f_building" condition="ti.f_building like '%{}%'" />
              </div>
            </div>

            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_unit" class="font text-left">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;元：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_unit" class="search_input input-font"
                       v-model="model.f_unit" condition="ti.f_unit like '%{}%'" />
              </div>
            </div>

            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label  class="font text-left">用户地址：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input  class="search_input input-font"
                       v-model=model.f_address condition="ti.f_address like '%{}%'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户ID.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_userinfo_code" class="font text-left">用户编号：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_userinfo_code" class="search_input input-font"
                       v-model=model.f_userinfo_code condition="ti.f_userinfo_code like '%{}%'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户ID.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">表号：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input class="search_input input-font"
                       v-model=model.f_meter_no condition="tm.f_meter_no like '%{}%'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/用户姓名.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_user_name" class="font text-left">用户姓名：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_keyword" class="search_input input-font"
                       v-model=model.f_user_name condition="ti.f_user_name like '%{}%'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/shijian.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_plan_year" class="font text-left">计划年份：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_plan_year" class="search_input input-font"
                       v-model="model.f_plan_year" condition="f_plan_year = '{}'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/shijian.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_plan_month" class="font text-left">计划月份：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <input id="f_plan_month" class="search_input input-font"
                       v-model="model.f_plan_month" condition="f_plan_month = '{}'" />
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/安检状态.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_plan_name" class="font text-left">计划名称：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <v-select   :value.sync="model.f_plan_name"
                            :options='$parent.$parent.planNames' placeholder='请选择计划名称'
                            :value-single="true"
                            v-model="model.f_plan_name" condition="f_plan_name like '%{}%'" close-on-select clear-button></v-select>
              </div>
            </div>
            <div class="row col-xs-12 col-sm-6 col-md-6 app-row">
              <div class="col-xs-4 col-sm-4 col-md-4">
                <img src="../../assets/安检状态.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label for="f_plan_name" class="font text-left">计划类型：</label>
              </div>
              <div class="col-xs-8 col-sm-8 col-md-8" >
                <v-select   :value.sync="model.f_no_checkplan"
                            :options='$parent.$parent.planstates' placeholder='请选择计划类型'
                            :value-single="true"
                            v-model="model.f_no_checkplan" condition="ti.f_no_checkplan='{}'" close-on-select clear-button></v-select>
              </div>
              <!--<div class="col-xs-8 col-sm-8 col-md-8" >-->
              <!--<input id="f_plan_name" class="search_input input-font"-->
              <!--v-model=model.f_plan_name condition="f_plan_name like '%{}%'" />-->
              <!--</div>-->
            </div>
            <div class="row col-xs-12 col-sm-12 col-md-6 text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 45%;" @click="search">查询</button>
            </div>
            <!--<div class="row col-xs-12 col-sm-6 col-md-6 app-btn">-->
              <!--<button class="btn btn-primary col-xs-6" type="button"  @click="search"><span class="glyphicon  glyphicon-search" style="margin-right: 20px;">查询</span></button>-->
            <!--</div>-->
            <div style="height:30px;"></div>
            <div style="height: auto;" class="row col-xs-12 col-sm-12 col-md-12">
              <div class="auto app-text" style="margin-top: 5px;">
                <div class="panel" style="padding: 10px 10px 5px 10px;">
                  <div class="panel-body panel-self">
                    <div class="row col-xs-12 col-sm-12 col-md-12">
                      <span class="panel-title col-xs-3 col-sm-3 col-md-3 text-left font">全部:{{ $parent.$parent.totalItems }}</span>
                      <span class="panel-title col-xs-3 col-sm-3 col-md-3 text-left font">已安检:{{ $parent.$parent.countYijian }}</span>
                      <span class="panel-title col-xs-3 col-sm-3 col-md-3 text-left font">拒访:{{ $parent.$parent.countJufang }}</span>
                      <span class="panel-title col-xs-3 col-sm-3 col-md-3 text-left font">无人:{{ $parent.$parent.countWuren }}</span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </form>
        </div>
      </criteria>
      <list :model="model" partial='list'>
        <div partial>
          <div @click="$parent.$parent.$parent.inspect(row)" class="auto app-text" style="margin-top: 5px;">
            <div class="panel" style="padding: 10px 10px 5px 10px;">
              <div class="panel-body panel-self">
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户编号</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_userinfo_code }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户姓名</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_name }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户类型</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_type }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户电话</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone }}
                    <img src="../../assets/phone.png" style="width: 6%;" v-on:click.stop.prevent='$parent.$parent.$parent.makeAPhoneCall(row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone)'></img>
                  </p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">小区名称</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_residential_area }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">用户地址</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_address }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">上次安检状态</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_last_check_state }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">安检状态</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_state }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">上传状态</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_upload_state }}</p>
                </div>
                <div class="row col-xs-12 col-sm-6 col-md-6">
                  <p class="panel-title col-xs-4 col-sm-4 col-md-4 text-left font">计划类型</p>
                  <p class="panel-title col-xs-8 col-sm-8 col-md-8 text-left input-font">{{ row.f_no_checkplan }}</p>
                </div>
                <!--<div class="row col-xs-12 col-sm-12 col-md-12 text-right" v-show="row.f_upload_state != '已传'" >-->
                      <!--<button type="button" class="btn yybtn-color" v-on:click.stop.prevent='$parent.$parent.$parent.reserve($index)'>预约</button>&nbsp;-->
                      <!--<button type="button" class="btn qxbtn-color" v-if ='row.f_prearranged_date'-->
                              <!--v-on:click.stop.prevent='$parent.$parent.$parent.cancelReserve($index, row.id)'>取消预约</button>-->
                <!--</div>-->
              </div>
            </div>


            <!--<table class="table" class="table table-user-information table table-striped">-->
              <!--<tbody>-->
              <!--<tr>-->
                <!--<td class="h5">用户姓名：</td>-->
                <!--<td>{{row.f_user_name}}&nbsp;<span v-show="row.f_upload_state != '已传'"><button type="button" class="btn btn-primary" v-on:click.stop.prevent='$parent.$parent.$parent.reserve($index)'>预约</button>&nbsp;<button type="button" class="btn btn-primary" v-if ='row.f_prearranged_date'  v-on:click.stop.prevent='$parent.$parent.$parent.cancelReserve($index, row.id)'>取消预约</button></span></td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">用户编号：</td>-->
                <!--<td>{{row.f_userinfo_code}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">电话：</td>-->
                <!--<td>{{row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone}}&nbsp;&nbsp;&nbsp;&nbsp;<span class="glyphicon glyphicon-earphone" v-on:click.stop.prevent='$parent.$parent.$parent.makeAPhoneCall(row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone)'></span></td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">小区：</td>-->
                <!--<td>{{row.f_residential_area}} </td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">地址：</td>-->
                <!--<td>{{row.f_address}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">上次安检状态：</td>-->
                <!--<td>{{row.f_last_check_state}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">安检状态：</td>-->
                <!--<td>{{row.f_state}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">上传状态：</td>-->
                <!--<td>{{row.f_upload_state}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">预约时间：</td>-->
                <!--<td>{{row.f_prearranged_date}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">有无安检计划：</td>-->
                <!--<td>{{row.f_no_checkplan}}</td>-->
              <!--</tr>-->
              <!--</tbody>-->
            <!--</table>-->
          </div>
        </div>
      </list>
    </criteria-paged>
    <modal :show.sync="showModal">
      <div slot="modal-header" class="modal-header">
        <h4 class="modal-title">
          选择预约时间
        </h4>
      </div>
      <div slot="modal-body" class="modal-body">
        <input type="datetime-local" v-model="f_preset_dt">
      </div>
      <div slot="modal-footer" class="modal-footer">
        <button type="button" class="btn btn-default" @click="genuineReserve">确认</button>
      </div>
    </modal>
    <back-page :need-back='true'  @flag="$back()"></back-page>
  </div>
</template>

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

  export default {
    title: '安检计划项',
    data() {
      return {
        model:Vue.android? new LocalPagedList('AndroidGetFollowUpUserInfo',20): new PagedList( 'AndroidRest/rs/sql/AndroidGetFollowUpUserInfo',20),
        showModal: false,
        param: null,
        f_preset_dt : Util.to3339TimeString(),
        flow_direction:[
          {label: '全部', value: null},
          {label: '左表', value: '左表'},
          {label: '右表', value: '右表'}
        ],
        check_states: [
          {label: '请选择安检状态', value: null},
          {label: '未检', value: '未检'},
          {label: '已检', value: '已检'},
        ],
        last_check_states: [
          {label: '请选择上次安检状态', value: null},
          {label: '入户', value: '入户'},
          {label: '拒检', value: '拒检'},
          {label: '到访不遇', value: '到访不遇'},
          {label: '未使用天然气', value: '未使用天然气'}
        ],
        upload_states: [
          {label: '请选择上传状态', value: null},
          {label: '未传', value: '未传'},
          {label: '已传', value: '已传'}
        ],
        user_types: [
          {label: '请选择用户类型', value: null},
          {label: '民用', value: '民用'},
          {label: '非民用', value: '非民用'},
        ],
        verify_state: [
          {label: '请选择审核状态', value: null},
          {label: '未审核', value: '未审核'},
          {label: '打回', value: '打回'}
        ],
        planNames:[
          {label: '全部', value: ''}
        ],
        planstates:[
          {label: '全部', value: ''},
          {label: '重点用户跟进单', value: '重点用户跟进单'},
          {label: '一级隐患跟进单', value: '一级隐患跟进单'},
          {label: '偷盗气用户跟进单', value: '偷盗气用户跟进单'}
        ],
        totalItems:0,//总计划项数
        countYijian:0,//今日已检数
        countWuren:0,//今日无人数
        countJufang:0,//今日拒访数
        startTime:'',
        endTime:''
      }
    },
    ready(){
      this.startTime = Util.toStandardDateString()+' 00:00:00'
      this.endTime = Util.toStandardDateString()+' 23:59:59'
    //  this.refresh()
      let res = this.$androidUtil.bzLogic('getDownPlanName',{condition:" cpi.f_no_checkplan like '%跟进单%' and cpi.f_no_checkplan !='无计划安检' "})
      console.log('计划名称'+JSON.stringify(res))
      if(res.code == 200 ){
        if(res.data.length > 0){
          for (let i in res.data){
            let val = {
              label:res.data[i].f_plan_name,
              value:res.data[i].f_plan_name
            }
            this.planNames.push(val)
          }
        }
      }
      this.CollectTodayPapers()
    },
    methods: {
      refresh() {
        console.log("refresh items state")
        // hard code relationship
        this.$refs.paged.$refs.cri.search()
      },
      reload(){
        console.log('页面刷新 ')
        this.$refs.paged.loadPage(this.$refs.paged.model.pageIndex)
        this.CollectTodayPapers()
      },
      CollectTodayPapers(){
        console.log('获取今日统计结果')
        let condition = " 1=1 and cpi.f_no_checkplan like '%跟进单%' and cpi.f_no_checkplan !='无计划安检'"
        console.log('this.$refs.paged.$refs.cri.model.f_plan_name'+this.$refs.paged.$refs.cri.model.f_plan_name)
        if(this.$refs.paged.$refs.cri.model.f_plan_name != ''){
          condition += `tcp.f_plan_name = '${this.$refs.paged.$refs.cri.model.f_plan_name}'`
        }

        // this.$resetpost('rs/logic/CollectTodayPapers',{data:{startTime:this.startTime,endTime:this.endTime,condition:condition}}).then((res)=>{
        //   if(res.data.code == 200){
        //     console.log('今日统计结果'+JSON.stringify(res.data))
        //     if(res.data.collect.length>0){
        //       this.totalItems = res.data[0].totalItems
        //       this.countYijian = res.data[0].countYijian
        //       this.countWuren = res.data[0].countWuren
        //       this.countJufang = res.data[0].countJufang
        //     }
        //   }
        // })
        let res = this.$androidUtil.bzLogic('CollectTodayPapers',{startTime:this.startTime,endTime:this.endTime,condition:condition})
        if(res.code == 200){
          console.log('今日统计结果'+JSON.stringify(res.data))
          if(res.data.rows.length>0){
            this.totalItems = res.data.rows[0].totalItems
            this.countYijian = res.data.rows[0].countYijian
            this.countWuren = res.data.rows[0].countWuren
            this.countJufang = res.data.rows[0].countJufang
          }
        }
      },
      selfSearch () {
        console.log('this.$refs.paged.$refs.cri.condition==>'+this.$refs.paged.$refs.cri.condition)
        this.CollectTodayPapers()
      },
      inspect(row) {
        if(row.f_no_checkplan == '一级隐患跟进单'){
          this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/logic/getMeterAndDefect`, {data: {f_userid: row.f_userinfoid,f_last_paper_id: row.f_last_paper_id}}).then((response) => {
            console.log(JSON.stringify(response))
            this.$goto('paper-set', {f_plan_id: row.f_plan_id, item: row, defects:response.data.defects,role: 'inspect'}, 'self', this.reload)
          })
        }else{
          this.$goto('paper-set', {f_plan_id: row.f_plan_id, item: row,role: 'inspect'}, 'self', this.reload)
        }


      },
      makeAPhoneCall(phoneNumber) {
        this.$androidUtil.makeAPhoneCall(phoneNumber)
      },
      reserve (idx) {
        this.param = idx
        this.showModal = true
      },
      cancelReserve (idx, id) {
        if(Vue.android){
          let res =  this.$androidUtil.bzLogic('BookingCheck', {dt: '', id: id})
          this.$set('model.rows[' + idx + '].f_prearranged_date', null)
          if (res.code == 200) {
            HostApp.alert("取消预约成功")
          }
        }else {
          this.$androidUtil.bzLogic('PCbookingCheck', {dt: '', id: id}).then((repanse) => {
            this.$set('model.rows[' + idx + '].f_prearranged_date', null)
            if (repanse.data.code == 200) {
              alert("取消预约成功!")
            }
          })
        }},
      genuineReserve () {
        if(Vue.android){
          if (!this.f_preset_dt) {
            HostApp.alert('请选择一个日期')
            return
          }
          let pdt = this.f_preset_dt.replace('T', ' ')
          let respanse =  this.$androidUtil.bzLogic('BookingCheck', {id: this.model.rows[this.param].id, dt: pdt})
          this.$set('model.rows[' + this.param + '].f_prearranged_date', pdt)
          if(respanse.code == 200) {
            HostApp.alert("预约成功!")
          }
          this.showModal = false
        }else {
          if (!this.f_preset_dt) {
            alert('请选择一个日期')
            return
          }
          let pdt = this.f_preset_dt.replace('T', ' ')
          this.$androidUtil.bzLogic('PCbookingCheck', {id: this.model.rows[this.param].id, dt: pdt}).then((res) => {
            this.$set('model.rows[' + this.param + '].f_prearranged_date', pdt)
            if(res.data.code == 200) {
              alert("预约成功!")
            }
            this.showModal = false
          })
        }
      }
    }
  }
</script>
