<style scoped>
  .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;
  }

  .button_shrink_top {
    width: 35px;
    height: 35px;
    background-size: 100%;
    background-image: url("../../../static/newStyle/stretch_top.png")
  }

  .button_shrink_bottom {
    width: 35px;
    height: 35px;
    background-size: 100%;
    background-image: url("../../../static/newStyle/stretch_bottom.png")
  }

  .button_shrink_left {
    width: 35px;
    height: 35px;
    background-size: 100%;
    background-image: url("../../../static/newStyle/stretch_left.png")
  }

  .button_shrink_right {
    width: 35px;
    height: 35px;
    background-size: 100%;
    background-image: url("../../../static/newStyle/stretch_right.png")
  }
</style>
<template>
  <div class="auto">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:cri>
        <div partial>
          <form>
            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-4">
                <img src="../../assets/用户姓名.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户姓名：</label>
              </div>
              <div class="col-xs-8">
                <input class="search_input input-font" v-model=model.f_user_name condition="f_user_name like '%{}%'"/>
              </div>
            </div>


            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-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">
                <input id="f_userinfo_code" class="search_input input-font"
                       v-model=model.f_userinfo_code condition="f_userinfo_code like '%{}%'"/>
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/用户类型.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户类型：</label>
              </div>
              <div class="col-xs-8">
                <v-select :value.sync="model.f_user_type" class="input-font"
                          :options='$parent.$parent.user_types' placeholder='请选择用户类型' :value-single="true"
                          v-model="model.f_user_type"
                          condition="f_user_type = '{}'"
                          close-on-select clear-button></v-select>
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">小区名称：</label>
              </div>
              <div class="col-xs-8">
                <input style="width: 100%" class="search_input input-font" v-model="model.f_districtname"
                       condition="f_residential_area like '%{}%'" placeholder="请输入用户小区（可模糊查询）">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">楼&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</label>
              </div>
              <div class="col-xs-8">
                <input style="width: 100%" class="search_input input-font" v-model="model.f_building"
                       condition="f_building = '{}'" placeholder="请输入用户楼号（可模糊查询）">
              </div>
            </div>
            <div class="row app-row">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;元：</label>
              </div>
              <div class="col-xs-8">
                <input style="width: 100%" class="search_input input-font" v-model="model.f_unit"
                       condition="f_unit = '{}'" placeholder="请输入用户单元（可模糊查询）">
              </div>
            </div>
            <div class="row app-row" v-if="$parent.$parent.criteriaShow">
              <div class="col-xs-4">
                <img src="../../assets/小区.png" style="width: 20px;margin-bottom: 5px" alt="">
                <label class="font text-left">用户地址：</label>
              </div>
              <div class="col-xs-8">
                <input class="search_input input-font"
                       v-model="model.f_keyword" condition="f_address like '%{}%'"/>
              </div>
            </div>
            <div class="row text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 25%;" @click="search">查询
              </button>
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 25%;margin-left: 10px"
                      @click="$parent.$parent.selectplanmany">抽取
              </button>
            </div>
            <div class="row text-center" style="margin-top: 20px;">
              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 25%;" @click="$parent.$parent.setPlanParamAll">本页全选
              </button>
<!--              <button type="button" class="btn btn-lg btn-font btn-color" style="width: 25%;margin-left: 10px"
                      @click="$parent.$parent.clearplanmany">清空全选
              </button>-->
            </div>
            <div style="height:30px;"></div>
          </form>
        </div>
      </criteria>
      <list :model="model" partial='list'>
        <div partial>
          <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="col-xs-12">
                  <p class="panel-title col-xs-5 text-left font" style="width: 21%;float: left"><b>用户编号:</b></p>
                  <p class="panel-title col-xs-5 text-left input-font" style="width: 74%">{{ row.f_userinfo_code }}</p>
                  <p class="panel-title col-xs-2 text-left input-font" style="width: 5%;float:right">
                    <input type="checkbox" @click="$parent.$parent.$parent.setPlanParam(row.f_check_item_id, $event)" :checked="$parent.$parent.$parent.checkitem(row.f_check_item_id)"/>
                  </p>
                </div>
                <div class="col-xs-12">
                  <p class="panel-title col-xs-5 text-left font" style="width: 21%;float: left"><b>用户名称:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font" style="width: 79%">{{ row.f_user_name }}</p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>用户类型:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_user_type }}
                  </p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>计划名称:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_plan_name }}</p>
                </div>
                <div class="col-xs-12">
                  <p class="panel-title text-left font" style="width: 21%;float: left"><b>用户电话:</b></p>
                  <p class="panel-title text-left input-font" style="width: 79%">
                    {{ row.f_user_phone2 ? row.f_user_phone2 : row.f_user_phone }}
                  </p>
                </div>
                <div class="col-xs-12">
                  <p class="panel-title text-left font" style="width: 21%;float: left"><b>用户地址:</b></p>
                  <p class="panel-title text-left input-font" style="width: 79%">{{ row.f_address }}</p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>安检状态:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_state }}</p>
                </div>
                <div class="col-xs-6">
                  <p class="panel-title col-xs-5 text-left font"><b>计划所属:</b></p>
                  <p class="panel-title col-xs-7 text-left input-font">{{ row.f_checker }}</p>
                </div>
                <div class="col-xs-12" v-if="row.f_state=='已检'">
                  <p class="panel-title text-left font" style="width: 50%;float: left"><b>最后一次安检状态:</b></p>
                  <p class="panel-title text-left input-font" style="width: 50%">{{ row.f_last_check_state }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </list>
    </criteria-paged>
    <modal :show.sync="showModal" v-ref:modal>
      <div slot="modal-header" class="modal-header">
        <h4 class="modal-title">
          选择计划
        </h4>
      </div>
      <div slot="modal-body" class="modal-body">
        <div class="col-xs-12">
          <div class="col-xs-1">
          </div>
          <div class="col-xs-4" style="padding-left: 2px">
            <input class="select-style" placeholder="计划名称" type="text" v-model="plan"
                   style="border: 1px solid #93B2D3;height:34px;width: 100%;line-height: 35px"/>
          </div>
          <div class="col-xs-1">
          </div>
          <div class="col-xs-2" style="float: right">
            <button type="button" class="btn btn-primary" @click="plansearch"
                    style="background-color:#499edf;float: right;margin-right:10px;border: 1px solid #93B2D3;height:34px;width: 100%;line-height: 1px;padding-left: 12px">
              查询
            </button>
          </div>
        </div>
        <table class="table table_sy">
          <thead>
          <tr>
            <th style="width: 30px"></th>
            <th style="font-family: 'Adobe 黑体 Std R'">计划名称</th>
          </tr>
          </thead>
          <tbody>
          <tr v-for="row in planoption">
            <td @click="select(row, $index)">{{ row.selected == true ? '☆' : '&nbsp;&nbsp;&nbsp;&nbsp;' }}</td>
            <td @click="select(row, $index)" style="text-align: center">{{ row.label }}</td>
          </tr>
          </tbody>
        </table>
      </div>
      <div slot="modal-footer" class="modal-footer">
        <button class="button_search button_spacing" @click="isok()">确认</button>
        <button class="button_clear button_spacing" @click="iscancel()">取消</button>
      </div>
    </modal>
    <modal :show.sync="showModal2" v-ref:modal>
      <div slot="modal-header" class="modal-header">
        <h4 class="modal-title">
          选择计划
        </h4>
      </div>
      <div slot="modal-body" class="modal-body">
        <table class="table table_sy">
          <thead>
          <tr>
            <th style="width: 30px"></th>
            <th style="font-family: 'Adobe 黑体 Std R'">计划名称</th>
          </tr>
          </thead>
          <tbody>
          <tr v-for="row in planoption">
            <td @click="select(row, $index)">{{ row.selected == true ? '☆' : '&nbsp;&nbsp;&nbsp;&nbsp;' }}</td>
            <td @click="select(row, $index)" style="text-align: center">{{ row.label }}</td>
          </tr>
          </tbody>
        </table>
      </div>
      <div slot="modal-footer" class="modal-footer">
        <button class="button_search button_spacing" @click="manyisok()">确认</button>
        <button class="button_clear button_spacing" @click="iscancel()">取消</button>
      </div>
    </modal>
  </div>
</template>

<script>
  import Vue from 'vue'
  import {PagedList, HttpResetClass, SearchList} from 'vue-client'
  import * as Util from '../Util'
  export default {
    title: '222',
    data() {
      return {
        planparam: [],
        checkplan: new SearchList(true),
        plan: '',
        planid: '',
        goplanid: '',
        checkAll:false,
        model: new PagedList(`${this.$androidUtil.getProxyUrl()}/rs/sql/planItem`, 20, {condition: 'this.condition'}),
        showModal: false,
        showModal2: false,
        needid: '',
        criteriaShow: true,
        planoption: [],
        condition: '',
        checkers: [],
        param: null,
        user_types: [
          {label: '请选择用户类型', value: ''},
          {label: '民用', value: '民用'},
          {label: '非民用', value: '非民用'},
        ],
        f_preset_dt: Util.to3339TimeString(),
      }
    },
    ready() {
      this.$refs.paged.$refs.cri.search()
    },
    methods: {
      async selectplanmany() {
        this.planoption = []
        await this.checkplan.searchList(`${this.$androidUtil.getProxyUrl()}/rs/sql/预约计划下发`, {}, {
          condition: "f_checker_id='" + Vue.user.id + "' and f_safecheck_type='年度普检' and f_plan_year=" + new Date().getFullYear(),
          groupitem: "",
          f_filialeids: "(" + Vue.user.orgid + ")",
          orderitem: "f_create_time"
        })
        let resoult = this.checkplan.list.data
        for (let i = 0; i < resoult.length; i++) {
          this.planoption.push({label: resoult[i].f_plan_name, selected: false, value: resoult[i].id})
        }
        this.showModal2 = true
      },
      iscancel() {
        this.showModal = false
        this.showModal2 = false
        this.changenull()
      },
      isok() {
        if (this.planoption.length == 0) {
          this.$showMessage("请选择计划")
          return false
        }
        for (let i = 0; i < this.planoption.length; i++) {
          if (this.planoption[i]["selected"] == true) {
            this.planid = this.planoption[i].value
            break
          }
        }
        if (this.planid == '') {
          this.$showMessage("请选择计划")
          return false
        }
        this.okput()
        this.changenull()
        this.$refs.paged.$refs.cri.search()
      },
      manyisok() {
        if (this.planoption.length == 0) {
          this.$showMessage("请选择计划")
          return false
        }
        for (let i = 0; i < this.planoption.length; i++) {
          if (this.planoption[i]["selected"] == true) {
            this.planid = this.planoption[i].value
            break
          }
        }
        if (this.planid == '') {
          this.$showMessage("请选择计划")
          return false
        }
        let http = new HttpResetClass()
        http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/logic/ExtractCheckPlanItem`, {
          data: {
            columnName: "it.id",
            condition: "1=1",
            param: this.planparam,
            f_plan_id: this.planid,
            switchCheckAll: true,
            checkAll: false,
            f_operator: Vue.user.name
          }
        }, {resolveMsg: null, rejectMsg: null}).then((res) => {
          if (res.data.code) {
            this.changenull()
            this.$showMessage("抽单成功，请去代办页面进行刷新！")
            this.$refs.paged.$refs.cri.search()
          } else {
            this.$showMessage("抽单失败！")
          }
        }).catch((msg) => {
          this.$showMessage("抽单失败，网络异常，请重新操作！")
        })

      },
      changenull() {
        this.showModal = false
        this.showModal2 = false
        this.planoption = []
        this.plan = ''
      },
      async okput() {
        let http = new HttpResetClass()
        let res = await http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/logic/ExtractCheckPlanItem`, {
          data: {
            condition: "it.id='" + this.needid + "'",
            f_plan_id: this.planid,
            switchCheckAll: false,
            checkAll: false,
            f_operator: Vue.user.name
          }
        }, {resolveMsg: null, rejectMsg: null})
      },
      async plansearch() {
        this.planoption = []
        let condition = "f_checker_id=" + Vue.user.id + " and f_plan_name like '%" + this.plan + "%'"
        let http = new HttpResetClass()
        let res = await http.load('POST', `${this.$androidUtil.getProxyUrl()}/rs/sql/预约计划下发`, {
          data: {
            condition: condition,
            f_filialeids: "(" + Vue.user.orgid + ")",
            groupitem: '',
            orderitem: 'id'
          }
        }, {resolveMsg: null, rejectMsg: null})
        let resoult = res.data
        for (let i = 0; i < resoult.length; i++) {
          this.planoption.push({label: resoult[i].f_plan_name, selected: false, value: resoult[i].id})
        }
      },
      select(row, idx) {
        this.$set('planoption[' + idx + '].selected', true)
        for (let i = 0; i < this.planoption.length; i++) {
          if (i != idx) {
            this.planoption[i]["selected"] = false
          }
        }
      },
      planclose() {
        this.showModal = false
      },
      async queryplan(val) {
        this.needid = val

        this.showModal = true
      },
      makeAPhoneCall(phoneNumber) {
        this.$androidUtil.makeAPhoneCall(phoneNumber)
      },
      search(args) {
        this.model.rows = []
        this.model.search(args.condition, args.model)
      },
      selfSearch(args) {
        args.condition += " and (i.f_state ='未检' or (i.f_state ='已检' and i.f_last_check_state!='入户')) and i.f_safecheck_type='年度普检' and f_plan_year=" + new Date().getFullYear()
        this.model.search(args.condition, args.model)
        this.planparam = []
      },
      hidden() {
        this.criteriaShow = !this.criteriaShow
      },
      clearplanmany(){
        this.checkAll = false
        this.planparam = []
      },
      checkitem(itemid){
        return this.planparam.indexOf(itemid)>-1
      },
      setPlanParamAll() {
        this.checkAll = true
        this.model.rows.map(item=>{
          if(this.planparam.indexOf(item.f_check_item_id) == -1){
            this.planparam.push(item.f_check_item_id)
          }
        })
      },
      setPlanParam(detailsType, event) {
        if (event.srcElement.checked) {
          this.planparam.push(detailsType)
        } else {
          if (this.planparam.length > 0) {
            let planid = this.planparam.findIndex((value) => {
              return value === detailsType
            })
            this.planparam.splice(planid, 1)
          }
        }
      },
    }
  }
</script>
