<template>
  <div>
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='$parent.selfSearch' v-ref:criteria>
        <div partial>
          <div class="row " >
            <label class="form-group font_normal_body"><b>用户信息</b></label>

            <div class="form-group col-sm-1" >
              <input type="text" class="input_search" v-model="model.f_userinfo_code"
                     style="width: 95%" placeholder="客户编号" condition="ui.f_userinfo_code='{}'">
            </div>
            <div class="form-group col-sm-1" >
              <input type="text" class="input_search" v-model="model.f_user_name"
                     style="width: 95%" placeholder="客户名称" condition="ui.f_user_name like '%{}%'">
            </div>
            <div class="form-group col-sm-1" >
              <input type="text" class="input_search" v-model="model.f_address"
                     style="width: 95%" placeholder="客户地址" condition="ua.f_address like '%{}%'">
            </div>
            <div class="form-group col-sm-1 upuserinfo_sel" >
              <v-select
                class="select select_list"
                :width="'95%'"
                :value.sync="model.f_area"
                v-model="model.f_area"
                :options='$parent.$parent.areaList'
                :timeout="500"
                @select-search="$parent.$parent.select_search"
                placeholder='小区选择'
                condition="ua.f_residential_area = '{}'"
                close-on-select
                value-single
              >
              </v-select>
            </div>
            <div class="form-group col-sm-4" >
              <button class="button_new" style="margin-right: 10px"  @click="$parent.$parent.showUserCondition()">更多条件</button>
              <button class="button_new" style="margin-right: 10px"  @click="$parent.$parent.showUploadCodeCondition()">导入编号</button>
              <button class="button_new" style="margin-right: 10px"  @click="$parent.$parent.clearUserInfoId()">清空编号</button>
              <button class="button_search" style="margin-right: 10px"  @click="search()">查询</button>
            </div>
            <div class="form-group col-sm-2" style="float: right">
              <button class="button_search" style="margin-right: 10px"  @click="$parent.$parent.dragtoPlanItem()">添入计划</button>
            </div>
            <modal :show.sync="$parent.$parent.showCondtion" v-ref:modal :width="'50%'" :backdrop="false">
              <div slot="modal-header" class="modal-header">
                <h4 class="modal-title">
                  用户查询条件
                </h4>
              </div>
              <div slot="modal-body" class="modal-body">
                <div class="row">
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">用户类型:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_user_type"
                      v-model="model.f_user_type"
                      :options='$parent.$parent.userTypes'
                      placeholder='请选择'
                      condition="uf.f_user_type='{}'"
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">用户状态:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_user_state"
                      v-model="model.f_user_state"
                      :options='$parent.$parent.userStates'
                      placeholder='请选择'
                      condition="ui.f_user_state='{}'"
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">用气性质:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_gasproperties"
                      v-model="model.f_gasproperties"
                      :options='$parent.$parent.gasproperties'
                      placeholder='请选择'
                      condition="uf.f_gasproperties='{}'"
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">气表分类:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.meter_classify"
                      v-model="model.meter_classify"
                      :options='$parent.$parent.meter_classifys'
                      placeholder='请选择'
                      condition="uf.F_METER_CLASSIFY='{}'"
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">气表状态:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_table_state"
                      v-model="model.f_table_state"
                      :options='$parent.$parent.table_states'
                      placeholder='请选择'
                      condition="uf.f_table_state='{}'"
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">气表品牌:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_meter_brand"
                      v-model="model.f_meter_brand"
                      :options='$parent.$parent.meter_brands'
                      placeholder='请选择'
                      condition="gb.f_meter_brand='{}'"
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <!--<div class="form-group col-sm-4" >
                    <label class="font_normal_body">小区名称:</label>
                    <input type="text" class="input_search" v-model="model.f_userinfo_code"
                           style="width: 60%" placeholder="请选择" condition="ua.f_residential_area = '{}'">
                  </div>-->
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">楼&ensp;栋&ensp;号:</label>
                    <input type="text" class="input_search" v-model="model.f_building"
                           style="width: 60%" placeholder="请选择" condition="ua.f_building='{}'">
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">单&ensp;元&ensp;号:</label>
                    <input type="text" class="input_search" v-model="model.f_unit"
                           style="width: 60%" placeholder="请选择" condition="ua.f_unit='{}'">
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">楼&ensp;层&ensp;号:</label>
                    <input type="text" class="input_search" v-model="model.f_floor"
                           style="width: 60%" placeholder="请选择" condition="ua.f_floor='{}'">
                  </div>
<!--                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">开户起始:</label>
                    <datepicker
                      placeholder='请选择'
                      style="width:60%"
                      :disabled-days-of-week="[]"
                      :format="'yyyy-MM-dd'"
                      :show-rest-button="reset"
                      :value.sync="model.f_startfile_time"
                      v-model="model.f_startfile_time"
                      condition="ui.f_createfile_date >= '{} 00:00:00'">
                    </datepicker>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">开户截止:</label>
                    <datepicker
                      placeholder='请选择'
                      :disabled-days-of-week="[]"
                      style="width:60%"
                      :format="'yyyy-MM-dd'"
                      :show-rest-button="reset"
                      :value.sync="model.f_endfile_time"
                      v-model="model.f_endfile_time"
                      condition="ui.f_createfile_date <= '{} 23:59:59'">
                    </datepicker>
                  </div>-->
<!--                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">表&ensp;箱&ensp;号:</label>
                    <input type="text" class="input_search" v-model="model.f_metertitles"
                           style="width: 60%" placeholder="请输入" condition="uf.f_metertitles='{}'">
                  </div>-->
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">用户电话:</label>
                    <input type="text" class="input_search" v-model="model.f_user_phone"
                           style="width: 60%" placeholder="请输入" condition="ui.f_user_phone='{}'">
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">距上次安检:</label>
                    <input type="text" class="input_search" v-model="model.f_start_cdate"
                           style="width: 25%;margin-right: 5px" placeholder=">=时间" condition="DATEDIFF(dd,isnull(ua.f_last_check_date,ui.f_createfile_date),GETDATE())>={}">

                    <input type="text" class="input_search" v-model="model.f_end_cdate"
                           style="width: 25%" placeholder="<=时间" condition="DATEDIFF(dd,isnull(ua.f_last_check_date,ui.f_createfile_date),GETDATE())<={}">
                  </div>
<!--                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">片&ensp;&ensp;&ensp;&ensp;区:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_book_slice_area"
                      v-model="model.f_book_slice_area"
                      :options='$parent.$parent.sliceArea'
                      @change="$parent.$parent.slice_areaChange(model.f_book_slice_area)"
                      placeholder='请选择'
                      condition="ua.f_slice_area  ='{}'"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">抄&ensp;表&ensp;册:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_meter_book_num"
                      v-model="model.f_meter_book_num"
                      :options='$parent.$parent.cbc'
                      placeholder='请选择'
                      condition="uf.f_meter_book_num='{}'"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>-->
<!--                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">派发情况:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.yearCheck"
                      v-model="model.yearCheck"
                      :options='$parent.$parent.yearCheckList'
                      placeholder='请选择'
                      condition="{}"
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">安检起始:</label>
                    <datepicker
                      placeholder='请选择'
                      style="width:60%"
                      :disabled-days-of-week="[]"
                      :format="'yyyy-MM-dd'"
                      :show-rest-button="reset"
                      :value.sync="model.f_start_time"
                      v-model="model.f_start_time"
                   >
                    </datepicker>
                  </div>
                  <div class="form-group col-sm-4" >
                    <label class="font_normal_body">安检截止:</label>
                    <datepicker
                      placeholder='请选择'
                      :disabled-days-of-week="[]"
                      style="width:60%"
                      :format="'yyyy-MM-dd'"
                      :show-rest-button="reset"
                      :value.sync="model.f_end_time"
                      v-model="model.f_end_time"
                      >
                    </datepicker>
                  </div>
                  <div class="form-group col-sm-4">
                    <label class="font_normal_body">安检状态:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_last_check_state"
                      v-model="model.f_last_check_state"
                      :options='$parent.$parent.entry_status'
                      placeholder='请选择'
                      :search="false"
                      close-on-select
                      value-single
                    >
                    </v-select>
                  </div>-->
                  <!--<div class="form-group col-sm-4" >
                    <label class="font_normal_body">入户情况:</label>
                    <v-select
                      class="select select_list"
                      :value.sync="model.f_hasHousehold"
                      v-model="model.f_hasHousehold"
                      :options='$parent.$parent.hasHousehold'
                      placeholder='请选择'
                      close-on-select
                      :search="false"
                      value-single
                    >
                    </v-select>
                  </div>-->

                </div>
              </div>
              <div slot="modal-footer" class="modal-footer" style="text-align: center">
                <button class="button_search" style="margin-right: 15px" @click="search()">查询</button>
                <button class="button_search" @click="$parent.$parent.cancel">取消</button>
              </div>
            </modal>
            <modal :show.sync="$parent.$parent.excelUserCondtion" width="500px" v-ref:modal1 >
              <div slot="modal-header" class="modal-header">
                <h4 class="modal-title">
                  导入用户编号
                </h4>
              </div>
              <div slot="modal-body" class="modal-body">
                <div class="row">
                  <file-upload class="my-file-uploader " name="UploadFile" class="btn btn-success" style="border-radius: 2px;"
                               action="/api/af-safecheck/file/uploadFile" tagname="档案信息导入" v-ref:file :headers="headers" multiple></file-upload>
                  <img src="../../assets/Excelformat.png" style="width: 100%"/>
                </div>
              </div>
              <footer slot="modal-footer" class="modal-footer">
              </footer>
            </modal>
            <!--<div class="form-group col-sm-4 button-range" >

              <button class="button_search" style="margin-right: 10px"  @click="search()">查询</button>
              <export-excel-safe   :data="$parent.$parent.exportParameter"
                                   :field="$parent.$parent.excelHeaders"
                                   sqlurl="api/af-safecheck/SafeExportExcel" sql-name="planItem"
                                   template-name='安检计划明细' :choose-col="true">
              </export-excel-safe>

            </div>-->
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' class="table_sy">

        <template partial='head'>
          <tr>
            <th><nobr><input type="checkbox" onClick="event.cancelBubble = true" :checked="$parent.$parent.$parent.checkAll" @change="$parent.$parent.$parent.setCheckAll()"/> 全选</nobr></th>
            <th><nobr>用户编号</nobr></th>
            <th><nobr>用户名称</nobr></th>
            <th><nobr>用户类型</nobr></th>
            <th><nobr>用户电话</nobr></th>
            <th><nobr>表具类型</nobr></th>
            <th><nobr>小区名称</nobr></th>
            <th><nobr>片区</nobr></th>
            <th><nobr>抄表册</nobr></th>
            <th title="当前所在的安检计划名称"><nobr>所属计划</nobr></th>
            <th title="最后一次安检日期"><nobr>安检日期</nobr></th>
            <th><nobr>详细地址</nobr></th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;white-space:nowrap;"><input type="checkbox" onClick="event.cancelBubble = true" :checked="$parent.$parent.$parent.isChecked(row.id)"  @change="$parent.$parent.$parent.setCheckes(row.id)" /></td>
          <td style="text-align: center"><nobr>{{row.f_userinfo_code}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_user_name}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_user_type}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_user_phone}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_meter_classify}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_residential_area}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_book_slice_area}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_book_name}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_plan_name}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_last_check_date}}</nobr></td>
          <td style="text-align: center"><nobr>{{row.f_address}}</nobr></td>
        </template>
      </data-grid>
    </criteria-paged>
  </div>
</template>

<script>
  import {HttpResetClass, PagedList} from "vue-client";
  import * as Util from "../Util";
  import Vue from "vue";

  export default {
    name: "PlanManage",
    title: '计划管理',
    data() {
      return {
        // FetchUserFileByOrgNoRuHuSXQZX AddCheckPlanItemCivil
        model:new PagedList(this.$parent.check_type=='年度普检'?'/api/af-safecheck/sql/FetchUserFileByOrgNoRuHuSXQTS':'/api/af-safecheck/sql/FetchUserFileByOrgNoRuHuSXQZXTS', 100, {
          "orderitem": "'f_residential_area,f_building,f_unit,f_floor,f_room'",
          "f_usertype": "''",
          "month": "''",
          "SafeCheckSX": {"f_check_start": '', "f_check_end": ''},
          "SafeCheckCQ": "''",
          "startday":"''",
          "f_plan_year":new Date().getFullYear(),
          "endday":"''"}),
        a:'1',
        opt:[{label:"测试",value:"测试"}],
        showCondtion:false,
        userTypes:[],//用户类型
        userStates:[],//用户状态
        gasproperties:[],//用气性质
        meter_classifys:[],//气表类型
        table_states:[],// 气表状态
        meter_brands:[],// 气表品牌
        hasHousehold:[{label:"全部",value:""},{label:"已入户",value:"已入户"},{label:"未入户",value:"未入户"}],
        yearCheckList:[{label:"全部",value:""},{label:"已在计划中",value:"ua.f_plan_id is not null"},{label:"未在计划中",value:"ua.f_plan_id is null"}],
        entry_status: this.$appdata.getParam('安检状态')?[{label: '全部', value: ''}, ...this.$appdata.getParam('安检状态')]:[{label: '全部', value: ''}],
        sliceArea:[],
        meterbooks:[],
        hasCheckBooks:'否',
        checkBooks:[],
        cbc:[],
        areaList:[],
        checkAll:false,
        checkes:[],
        excelUserCondtion:false,
        uploadCodeCondition:''
      }
    },
    props:["selectplan","userlogin"],
    ready(){
      console.log('user====================', this.$parent.check_type)
      this.$refs.paged.$refs.criteria.model.f_user_state='正常'
      this.$refs.paged.$refs.criteria.model.f_user_type='民用'
      this.hasCheckBooks=this.$appdata.getSingleValue('是否使用安检册')
      // this.$refs.paged.$refs.criteria.model.f_endfile_time=Util.toStartDateYearString()
      //this.$refs.paged.$refs.criteria.model.f_hasHousehold='未入户'
      // this.getCheckBook()
      this.setConList()
      this.loadpage()
      this.getMeterBrands()
    },
    methods: {
      getMeterBrands(){
        new HttpResetClass().load('POST', '/api/af-revenue/logic/getSaleInitData', {data:{
            f_orgid: `${this.userlogin.orgid}`
          }}, {resolveMsg: null, rejectMsg: null}).then((res)=>{
          console.log("--------:"+JSON.stringify(res))
          this.saleParam=res.data
          if(this.saleParam.gasbrands.length>0){
            this.saleParam.gasbrands.forEach((r)=>{
              this.meter_brands.push({label:r.f_meter_brand,value:r.f_meter_brand})
            })
          }
        })
      },
      getCheckBook(){
        this.checkBooks=[]
        new HttpResetClass().load('POST', `/api/af-safecheck/sql/safe_singleTable_OrderBy`, {
          data: {
            items: 'id,f_check_book_name,f_check_book_type',
            tablename: 't_check_book',
            condition: `f_orgid = '${this.userlogin.orgid}'`,
            orderitem: 'id desc'
          }
        }, {resolveMsg: null, rejectMsg: null}).then(res => {
          this.checkBooks.push({label: '全部', value: ''})
          res.data.forEach(ress => {
            this.checkBooks.push({
              label: ress.f_check_book_name,
              value: `${ress.id}-${ress.f_check_book_type}`
            })
          })
        })
      },
      loadpage(){
        this.select_search()
        // this.Mreadibook()
        this.getSliceArea()
      },
      cancel(){
        this.showCondtion=false
        this.excelUserCondtion=false
      },
      //清空用户编号
      clearUserInfoId(){
        this.uploadCodeCondition=''
        Vue.showMessage("已清空用户编号")
      },
      showUploadCodeCondition(){
        this.excelUserCondtion=true
      },
      selfSearch (args) {
        //tag)
        args.condition += ` and ui.f_filialeid='${this.userlogin.orgid}'`
        /*if(args.model.f_hasHousehold=='已入户'){
          args.condition +=` and Extract(year from TO_DATE(ua.f_last_check_date,'yyyy-mm-dd hh24:mi:ss'))=2021 and ua.F_LAST_CHECK_STATE='入户'`
        }else if(args.model.f_hasHousehold=='未入户'){
          args.condition +=` and (Extract(year from nvl(TO_DATE(ua.f_last_check_date,'yyyy-mm-dd hh24:mi:ss'),'1990-01-01 00:00:00'))!=2021 or nvl(ua.F_LAST_CHECK_STATE,'未入户')!='入户')`
        }*/

        if (args.model.f_last_check_state == '未检') {
          let nocheckcon = 'and ( ui.f_last_check_date is null '
          if(args.model.f_start_time){
            nocheckcon += ` or ui.f_last_check_date <='${args.model.f_start_time} 00:00:00' `
          }
          if(args.model.f_end_time){
            nocheckcon += ` or ui.f_last_check_date >='${args.model.f_end_time} 23:59:59' `
          }
          nocheckcon += ')'
          args.condition +=  nocheckcon
        }else{
          if(args.model.f_last_check_state){
            args.condition += ` and ui.f_last_check_state  = '${args.model.f_last_check_state}'`
          }
          if(args.model.f_start_time){
            args.condition += ` and ui.f_last_check_date >='${args.model.f_start_time} 00:00:00' `
          }
          if(args.model.f_end_time){
            args.condition += ` and ui.f_last_check_date <='${args.model.f_end_time} 23:59:59' `
          }
        }

        if(args.model.checkBook){
          let arr=args.model.checkBook.split('-')
          if(arr[1] == '用户'){
            args.condition +=` and ua.f_check_book_id='${arr[0]}'`
          }else{
            args.condition +=` and area.f_check_book_id=${arr[0]} and ua.f_check_book_id is null`
          }
        }
        if(this.uploadCodeCondition){
          args.condition +=` and ${this.uploadCodeCondition}`
        }
        this.cancel()
        this.checkes=[]
        this.checkAll=false
        this.model.search(args.condition, args.model, args.condValue)
      },
      showUserCondition(){
        this.showCondtion=true
      },
      setConList(){
        this.userTypes=this.$appdata.getParam('用户类型') ? [{
          label: '全部',
          value: ''
        }, ...this.$appdata.getParam('用户类型')] : [{label: '全部', value: ''}]

        this.userStates=this.$appdata.getParam('安检用户状态') ? [...this.$appdata.getParam('安检用户状态')] : []
        this.gasproperties=this.$appdata.getParam('用气性质') ? [{
          label: '全部',
          value: ''
        }, ...this.$appdata.getParam('用气性质')] : [{label: '全部', value: ''}]
        this.meter_classifys=this.$appdata.getParam('气表类型') ? [{
          label: '全部',
          value: ''
        }, ...this.$appdata.getParam('气表类型')] : [{label: '全部', value: ''}]
        this.table_states=this.$appdata.getParam('气表状态') ? [{
          label: '全部',
          value: ''
        }, ...this.$appdata.getParam('气表状态')] : [{label: '全部', value: ''}]
      },
      select_search(text){
        //tag
        let pcdText=text?` and f_residential_area like '%${text}%'`:''
        new HttpResetClass().load("POST", `${this.$androidUtil.getProxyUrl()}/api/af-safecheck/sql/safe_singleTable_OrderBy`, {data:{items:"*",tablename:"t_area",orderitem:"id",condition:`f_orgid = '${this.userlogin.orgid}' ${pcdText} `}}, {resolveMsg: null, rejectMsg: null}).then((res)=>{
          //tag)
          if(res.data.length>0){
            this.areaList=[]
            this.areaList.push({label:"全部",value:""})
            res.data.forEach((result)=>{
              this.areaList.push({label:result.f_residential_area,value:result.f_residential_area})
            })
          }
          //tag)
        })
      },
      //获取抄表册
      async Mreadibook(){
        this.cbc=[]
        this.sliceArea=[]
        let http = new HttpResetClass()
        let getMeterReadingBooks = await http.load('POST','api/af-safecheck/getMeterBooksData',
          {data: {f_orgid: "('"+this.userlogin.orgid+"')"}},
          {resolveMsg: null, rejectMsg: '获取失败！！！'})
        this.cbc = [{label: '全部', value: ''}]
        //tag
        //tag)
        //tag
        this.meterbooks=[]
        this.meterbooks=getMeterReadingBooks.data.meterbooks
        this.meterbooks.forEach((res) => {
          this.cbc.push({label: res.f_book_name, value: res.id})
          /*if(res.f_book_slice_area){
            if(this.sliceArea.indexOf(res.f_book_slice_area)<0){
              this.sliceArea.push(res.f_book_slice_area)
            }
          }*/
        })

      },
      //片区获取
      async getSliceArea()  {
        let http = new HttpResetClass()
        let getAllArea = await http.load('POST', '/rs/search', {
          source: 'this.getParentByType($organization$).getAllChildrens().where(row.getType() == $zone$)',
          userid: this.userlogin.id
        }, {resolveMsg: null, rejectMsg: '获取片区出错！！！'})
        this.sliceArea = [{label: '全部', value: ''}]
        //tag
        //tag
        //tag
        getAllArea.data.forEach((res) => {
          if(res.parentid==this.userlogin.orgid){
            this.sliceArea.push({label:res.name,value:res.name})
          }
        })
        //tag
      },
      //片区改变-对应抄表册下拉重新赋值
      slice_areaChange(value) {
        //tag
        if(!value){
          this.cbc=[]
          this.meterbooks.forEach((res) => {
            this.cbc.push({label: res.f_book_name, value: res.id})
          })
        }else{
          this.cbc=[]
          this.meterbooks.forEach((res) => {
            if(res.f_book_slice_area==value){
              this.cbc.push({label: res.f_book_name, value: res.id})
            }
          })
        }
      },
      isChecked(v) {
        // 如果全选，不在的按选中算，否则，在的按选中算
        if (this.checkAll) {
          return this.checkes.indexOf(v) == -1
        } else {
          return this.checkes.indexOf(v) != -1
        }
      },
      setCheckAll() {
        this.checkAll=this.checkAll?false:true;
        // 全选改变后，清空选中数据
        this.checkes = []
      },
      setCheckes(id) {
        let index=this.checkes.indexOf(id)
        if(index<0){
          this.checkes.push(id)
        }else{
          this.checkes.splice(index,1)
        }
      },
      //将客户信息拖至计划中
      async dragtoPlanItem() {
        if(this.model.rows.length==0){
          Vue.showMessage("未检测到列表中有用户！")
          return
        }
        if(!this.checkAll && this.checkes.length==0){
          Vue.showMessage("请先勾选你要添入到上方计划中的用户！")
          return
        }
        if(this.selectplan && this.selectplan.id){
          this.$parent.isSend=true
          try{
            let res=await new HttpResetClass().load("POST", this.$parent.check_type=='年度普检'?'/api/af-safecheck/logic/AddCheckPlanItemTS':'/api/af-safecheck/logic/AddCheckPlanItemCivilTS', {
              data:{
                f_operator:this.userlogin.name,
                f_plan_id:this.selectplan.id,
                f_safecheck_type:this.selectplan.f_safecheck_type,
                f_filialeid:this.userlogin.orgid,
                f_subscribe_date:'',
                condition:this.model.condition,
                switchCheckAll:true,
                checkAll:this.checkAll,
                param:this.checkes,
                f_plan_year:new Date().getFullYear(),
                columnName: "ua.id"
              }
            }, {resolveMsg: null, rejectMsg: null})
            //tag+"---"+res.data.result.length)
            this.$parent.isSend=false
            if(res.data.code==200){
              //alert("添加成功！有"+res.data.result.length+"条用户地址已经存在于其他计划中:  \n"+res.data.result.reduce((c,v)=>{c += v.f_user_name+":"+v.f_address+"\n"}),0)
              let msg=''
              if(this.$parent.check_type=='年度普检'){
                msg = '本次添加成功'+res.data.resultno[0].con+'户！'+(res.data.result.length>0?"另有"+res.data.result.length+"条用户地址已经存在于其他计划中":"")
              }else{
                msg = '本次添加成功'+res.data.resultno[0].con+'户！'
              }
              Vue.showMessage(msg)
              this.$parent.refresh()
            }else{
              if (res.data.msg) {
                Vue.showMessage(res.data.msg)
              } else {
                Vue.showMessage("添加失败！")
              }
            }
          }catch (e) {
            this.$showMessage("添加失败！")
          }
          this.$parent.isSend=false
        }else{
          this.$parent.isSend=false
          this.$showMessage("请先打开一个计划再进行操作")
        }
      }
    },
    events: {
      onFileUpload: function (file, res) {
        //tag)
        //tag)
        let data = {
          filepath: res.f_downloadpath
        }
        new HttpResetClass().load('POST','/api/af-safecheck/logic/safe_GetUserInfoFromExcel', {data: data}, {
          resolveMsg: '导入成功！已生成条件，若要去除导入条件请点击旁边 ‘清空用户编号’ 按钮。',
          rejectMsg: '导入失败'
        }).then((res) => {
          this.uploadCodeCondition=res.data.condition
          this.excelUserCondtion = false
        })
      },

    }
  }
</script>

<style scoped>
  .safe-planfont{
    font-family: MicrosoftYaHei;
    font-size: 15px;
    font-weight: normal;
    font-stretch: normal;
    letter-spacing: 2px;
    color: #333333;
    line-height: 25px;
  }
  .safe-bodyfont{
    font-family: MicrosoftYaHei;
    font-size: 14px;
    font-weight: normal;
    font-stretch: normal;
    letter-spacing: 0px;
    color: #999999;
    line-height: 30px;
  }
  .safe-leftplan{
    height:auto;
    border-bottom:1px solid #ececec;
    padding: 10px 5px
  }
  .leftplan-center{
    border-top:1px solid #ececec;
    border-bottom:1px solid #ececec;
  }
  .safe_p{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .safe-div-p{
    color: #4792de;
    text-align: end;
    padding: 8px 15px;
  }
</style>
<style lang="less">
  .upuserinfo_sel ul{
    width: 150% !important;
  }
</style>
