<style>
  .label-8width{
    width: 9em;
  }
  .label-8width-completion{
    width: calc(100% - 10em);
  }
  .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;
  }
  .panel-self{
    border-radius: 10px;
    border:1px solid #499EDF;
    background-color: #F8F8F8;
  }
  .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 text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-primary" style="width: 15%; border-radius: 5px;" @click="search">刷新</button>
            </div>
            <div style="height:30px;"></div>
          </form>
        </div>
      </criteria>

      <list :model="model" partial='list'>
        <div partial>
          <div @click="$parent.$parent.$parent.inspect(row)" class="col-md-12 col-lg-12">
            <div class="panel" style="padding: 10px 10px 5px 10px;">
              <div class="panel-body panel-self">
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户编号</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_userinfo_code }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户姓名</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_user_name }}</p>
                </div>

                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户电话</p>
                  <p class="panel-title col-xs-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">
                  <p class="panel-title col-xs-4 text-left font">小区名称</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_residential_area }}</p>
                </div>
                <!--<div class="row">-->
                  <!--<p class="panel-title col-xs-4 text-left font">楼|单元|层|房：</p>-->
                  <!--<p class="panel-title col-xs-8 text-left input-font">{{row.f_building}} | {{row.f_unit}} | {{row.f_floor}} | {{row.f_room}}</p>-->
                <!--</div>-->
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户地址</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_address }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">用户类型</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_user_type }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">计划名称</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_plan_name }}</p>
                </div>
                <!--<div class="row">-->
                  <!--<p class="panel-title col-xs-4 text-left font">上次安检状态</p>-->
                  <!--<p class="panel-title col-xs-8 text-left input-font">{{ row.f_last_check_state }}</p>-->
                <!--</div>-->
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">安检状态</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_state }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">上传状态</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_upload_state }}</p>
                </div>
                <div class="row">
                  <p class="panel-title col-xs-4 text-left font">预约时间</p>
                  <p class="panel-title col-xs-8 text-left input-font">{{ row.f_prearranged_date }}</p>
                </div>
                <div class="row text-right" v-show="row.f_upload_state != '已传'" >
                  <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">-->
              <!--<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-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_building}} | {{row.f_unit}} | {{row.f_floor}} | {{row.f_room}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">地址：</td>-->
                <!--<td>{{row.f_address}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">用户类型：</td>-->
                <!--<td>{{row.f_user_type}}</td>-->
              <!--</tr>-->
              <!--<tr>-->
                <!--<td class="h5">月计划：</td>-->
                <!--<td>{{row.f_plan_name}}</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>-->
              <!--&lt;!&ndash; <tr>-->
                 <!--<td class="h5">审核状态：</td>-->
                 <!--<td>{{row.f_approved}}</td>-->
               <!--</tr>-->
               <!--<tr>-->
                 <!--<td class="h5">审核意见：</td>-->
                 <!--<td>{{row.f_approved_note}}</td>-->
               <!--</tr>&ndash;&gt;-->
              <!--</tbody>-->
            <!--</table>-->
          </div>
        </div>
      </list>
    </criteria-paged>
    <back-page :need-back='true'   @flag="$back()"></back-page>
  </div>
</template>

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

export default {
  title: '安检计划项',
  data() {
    return {
      model:Vue.android? new LocalPathList('getPlanItemByPrearrange',5): new PagedList( 'AndroidRest/rs/path/getItemByPrearrange', 5),
    }
  },
  methods: {
    refresh() {
      //tag
      // hard code relationship
      this.$refs.paged.$refs.cri.search()
    },
    reload(){
      //tag
      this.$refs.paged.loadPage(this.$refs.paged.model.pageIndex)
    },
    inspect(row) {
      if (row.f_upload_state == '未传' || (row.f_upload_state == '已传' && row.f_state == '未检')) {
        this.$resetpost(`${this.$androidUtil.getProxyUrl()}/rs/sql/查询计划项表信息`, {data: {f_userid: row.f_userinfoid}}).then((response) => {
          //tag)
        row['f_plan_meters'] = response.data

        if (row.f_user_type == '民用') {
          this.$goto('paper-set', {f_plan_id: row.f_plan_id, item: row, role: 'inspect'}, 'self', this.reload)
        } else {
          this.$goto('paper-set-noncivil', {f_plan_id: row.f_plan_id, item: row, role: 'inspect'}, 'self', this.reload)
        }
      })
      }else(
        this.$showMessage("该安检单已被上传！")
      )
    },
    makeAPhoneCall(phoneNumber) {
      this.$androidUtil.makeAPhoneCall(phoneNumber)
    },
    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) {
            this.$showMessage("取消预约成功")
            this.reload()
          }
      }else {
        this.$androidUtil.bzLogic('BookingCheck', {dt: '', id: id}).then((repanse) => {
          this.$set('model.rows[' + idx + '].f_prearranged_date', null)
          if (repanse.code == 200) {
            alert("取消预约成功")
            this.reload()
          }
        })
      }
    },
  },
  ready () {
   // this.refresh()
  }
}
</script>
