<template>
  <div class="flex-row">
    <div class="basic-main">
      <!--    <button class="btn btn-xs" v-show="!criteriaShow" @click="show()">-->
      <!--      <span class="glyphicon glyphicon-chevron-down" style="color: #000;"></span>-->
      <!--    </button>-->
      <criteria-paged :model="model" v-ref:paged>
        <criteria partial='criteria' class="search_area" @condition-changed='$parent.search' v-ref:criteria>
          <div novalidate class="form-horizontal select-overspread container-fluid auto" partial>
            <div class="row">
              <div class="col-sm-2">
                <label class="font_normal_body">用户编号</label>
                <input type="text" class="input_search" style="width: 60%" v-model="model.f_userinfo_code"
                       id="f_userinfo_code" style="width:60%"
                       placeholder="用户编号" condition="ui.f_userinfo_code like '%{}%'">
              </div>
              <div class="col-sm-2">
                <label class="font_normal_body">用户名称</label>
                <input type="text" class="input_search" style="width: 60%" v-model="model.f_user_name" id="f_user_name"
                       style="width:60%"
                       placeholder="用户名称" condition="ui.f_user_name like '%{}%'">
              </div>
              <div class="col-sm-2 col-md-2 col-lg-2  ">
                <label class="font_normal_body">用户地址</label>
                <input type="text" class="input_search" style="width: 60%" v-model="model.f_address" id="f_address"
                       style="width:60%"
                       placeholder="地址信息" condition="ua.f_address like '%{}%'">
              </div>


              <div class="col-sm-4" style="float: right">
                <div style="float: right; margin-top: 8px" class="button_spacing"
                     :class="{'button_shrink_top':$parent.$parent.criteriaShow,'button_shrink_bottom':!$parent.$parent.criteriaShow}"
                     @click="$parent.$parent.hidden()"></div>
<!--                <button type="button" class="button_export button_spacing" style="float: right;margin-top: 8px"-->
<!--                        @click="$parent.$parent.itemAdd()" v-if="$parent.$parent.checkplan">添加-->
<!--                </button>-->
<!--                <button type="button" class="button_export button_spacing" style="float: right;margin-top: 8px"-->
<!--                        @click="$parent.$parent.itemAddBack()" v-if="$parent.$parent.checkplan">返回-->
<!--                </button>-->
                <button type="button" class="button_export button_spacing" style="float: right;margin-top: 8px"
                        @click="$parent.$parent.AllPlan()" v-if="!$parent.$parent.checkplan">计划生成
                </button>
                <button class="button_search button_spacing" style="float: right;margin-top: 8px" @click="search()">查询
                </button>
              </div>
            </div>
            <modal :show.sync="$parent.$parent.showModal" v-ref:modal 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="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">计划名称</label>
                    <input class="input_search" style="width: 60%" type="text"
                           v-model="$parent.$parent.checkboxModel.f_plan_name" placeholder="计划名称(必填)">
                  </div>
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">是否共享</label>
                    <v-select :value="$parent.$parent.IsShare" style="width:60% "
                              class="select select_list"
                              v-on:change="$parent.$parent.IsShareschange" :value-single="true"
                              :options='$parent.$parent.IsShares' close-on-select clear-button></v-select>
                  </div>
                  <div class="col-sm-6  form-group form-fix-width" v-if="$parent.$parent.IsShare == '否'">
                    <label class="font_normal_body"
                           style="padding-top: 0;line-height: 39px;">安&nbsp;检&nbsp;员&nbsp;</label>
                    <v-select id="checker" :value="$parent.$parent.checker" style="width:60% "
                              class="select select_list"
                              v-on:change="$parent.$parent.checkerchange" :value-single="true"
                              :options='$parent.$parent.checkers' close-on-select clear-button></v-select>
                  </div>
                  <!--<div class="col-sm-6  form-group form-fix-width" v-if="$parent.$parent.IsShare == '是'">-->
                  <!--<label class="control-label">站点</label>-->
                  <!--<v-select id="checker" :value="$parent.$parent. "-->
                  <!--v-on:change="$parent.$parent." :value-single="true"-->
                  <!--:options='$parent.$parent.' close-on-select clear-button> </v-select>-->
                  <!--</div>-->
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">计划年份</label>
                    <v-select id="c_plan_year" :value.sync="$parent.$parent.f_plan_year" style="width:60% "
                              class="select select_list"
                              :options='$parent.$parent.c_year_list' close-on-select clear-button></v-select>
                  </div>
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">计划月份</label>
                    <v-select id="c_plan_month" :value.sync="$parent.$parent.f_plan_month" style="width:60% "
                              class="select select_list"
                              :options='$parent.$parent.c_month_list' close-on-select clear-button></v-select>
                  </div>
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">安检类型</label>
                    <v-select  :value.sync="$parent.$parent.checkboxModel.f_safecheck_type"
                              style="width:60% "
                              class="select select_list"
                              :value-single="true"
                              readonly="readonly"
                              :options='$parent.$parent.c_type_list' close-on-select clear-button></v-select>
                  </div>
<!--                  <data-grid :model="$parent.$parent.model2" partial='list' v-ref:grid2 class="list_area table_sy">-->
<!--                    <template partial='head'>-->
<!--                      <tr>-->
<!--                        <th>安检员</th>-->
<!--                        <th>计划数</th>-->
<!--                        <th>已检</th>-->
<!--                        <th>未检</th>-->
<!--                      </tr>-->
<!--                    </template>-->
<!--                    <template partial='body'>-->
<!--                      <td style="text-align: center">{{ row.f_checker }}</td>-->
<!--                      <td style="text-align: center">{{ row.c }}</td>-->
<!--                      <td style="text-align: center">{{ row.checked }}</td>-->
<!--                      <td style="text-align: center">{{ row.unchecked }}</td>-->
<!--                    </template>-->
<!--                    <template partial="foot">-->
<!--                    </template>-->
<!--                  </data-grid>-->
                  <!--<div class="col-sm-6  form-group form-fix-width">-->
                  <!--<label class="control-label">有效起始</label>-->
                  <!--<datepicker-->
                  <!--:value.sync="$parent.$parent.f_effective_start_time"-->
                  <!--placeholder='最后安检时间起始'-->
                  <!--:disabled-days-of-week="[]"-->
                  <!--:format="'yyyy-MM-dd'"-->
                  <!--:show-rest-button="reset"-->
                  <!--v-model = "$parent.$parent.f_effective_start_time">-->
                  <!--</datepicker>-->
                  <!--</div>-->
                  <!--<div class="col-sm-6  form-group form-fix-width">-->
                  <!--<label class="control-label">有效结束</label>-->
                  <!--<datepicker-->
                  <!--:value.sync="$parent.$parent.f_effective_end_time"-->
                  <!--placeholder='最后安检时间起始'-->
                  <!--:disabled-days-of-week="[]"-->
                  <!--:format="'yyyy-MM-dd'"-->
                  <!--:show-rest-button="reset"-->
                  <!--v-model = "$parent.$parent.f_effective_end_time">-->
                  <!--</datepicker>-->
                  <!--</div>-->
                </div>
              </div>
              <div slot="modal-footer" class="modal-footer">
<!--                <span style="color:red;float: left"-->
<!--                      v-show="$parent.$parent.repeated > 0">此次下发共有{{ $parent.$parent.repeated }}单重复</span>-->
<!--                <button type="button" v-show="$parent.$parent.repeated > 0" class="button_spacing button_search"-->
<!--                        @click="$parent.$parent.confirm('override')">覆盖下发-->
<!--                </button>-->
<!--                <button type="button" v-show="$parent.$parent.repeated > 0" class="button_spacing button_search"-->
<!--                        @click="$parent.$parent.confirm('skip')">跳过下发-->
<!--                </button>-->
                <button type="button"  class="button_spacing button_search"
                        @click="$parent.$parent.confirm('create')">生成
                </button>
                <button type="button" class="button_spacing button_clear" @click="$parent.$parent.cancel">取消</button>
              </div>
            </modal>

















            <modal :show.sync="$parent.$parent.showAddModal" v-ref:addModal 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="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">计划名称</label>
                    <input class="input_search" style="width: 60%;" disabled="true" type="text"
                           v-model="$parent.$parent.checkboxModel.f_plan_name">
                  </div>
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">是否共享</label>
                    <input class="input_search" style="width: 60%;" disabled="true" type="text"
                           v-model="$parent.$parent.checkboxModel.IsShare">
                  </div>
                  <div class="col-sm-6  form-group form-fix-width" v-if="$parent.$parent.checkboxModel.IsShare == '否'">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">安&nbsp;检&nbsp;员</label>
                    <input class="input_search" style="width: 60%;" disabled="true" type="text"
                           v-model="$parent.$parent.checkboxModel.checker">
                  </div>
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">计划年份</label>
                    <input class="input_search" style="width: 60%;" disabled="true" type="text"
                           v-model="$parent.$parent.checkboxModel.f_plan_year">
                  </div>
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">计划月份</label>
                    <input class="input_search" style="width: 60%;" disabled="true" type="text"
                           v-model="$parent.$parent.checkboxModel.f_plan_month">
                  </div>
                  <div class="col-sm-6  form-group form-fix-width">
                    <label class="font_normal_body" style="padding-top: 0;line-height: 39px;">安检类型</label>
                    <input class="input_search" style="width: 60%;" disabled="true" type="text"
                           v-model="$parent.$parent.checkboxModel.f_safecheck_type">
                  </div>
                </div>
              </div>
              <div slot="modal-footer" class="modal-footer">
                <span style="color:red;float: left"
                      v-show="$parent.$parent.repeated > 0">此次下发共有{{ $parent.$parent.repeated }}单重复</span>
                <button type="button" v-show="$parent.$parent.repeated > 0" class="button_spacing button_search"
                        @click="$parent.$parent.confirm('override')">覆盖下发
                </button>
                <button type="button" v-show="$parent.$parent.repeated > 0" class="button_spacing button_search"
                        @click="$parent.$parent.confirm('skip')">跳过下发
                </button>
                <button type="button" v-show="$parent.$parent.repeated == 0" class="button_spacing button_search"
                        @click="$parent.$parent.confirm('create')">添加
                </button>
                <button type="button" class="button_spacing button_clear" @click="$parent.$parent.cancel">取消</button>
              </div>
            </modal>
          </div>
        </criteria>
        <data-grid :model="model" class="list_area table_sy" style="overflow: hidden" partial='list'>
          <template partial='head'>
            <tr>
              <!--<th><nobr>全选<input type="checkbox" @click='$parent.$parent.$parent.changeStates'  v-model='$parent.$parent.$parent.checkedAll'></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>
                <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>-->
            </tr>
          </template>
          <template partial='body'>
            <!--          <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center"><nobr><input type="checkbox" v-model="row.checked" v-bind:checked="row.checked"  @click="$parent.$parent.$parent.addChecked(row)"></nobr></td>-->
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center;">
              {{ row.f_userinfo_code }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center;">
              {{ row.f_user_name }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center;">
              {{ row.f_user_phone }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">
              {{ row.f_user_type }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">
              {{ row.f_residential_area }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">
              {{ row.f_building }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">
              {{ row.f_unit }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">
              {{ row.f_floor }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">
              {{ row.f_room }}
            </td>
            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">
              {{ row.f_address }}
            </td>
            <!--            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">-->
            <!--              <div v-if="row.danger"><div v-if="row.danger.result=='有隐患'"><a @click="$parent.$parent.$parent.gotodanger(row.danger)">{{row.danger.result}}</a></div>-->
            <!--                <div v-if="row.danger.result!='有隐患'"></div></div>-->
            <!--            </td>-->
            <!--          <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">{{row.f_user_family_remarks}}</td>-->
            <!--            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">{{row.f_last_check_date}}</td>-->
            <!--            <td :class="[ row.color ==='red' ? 'p1' : row.color === 'yellow'? 'p':''  ]" style="text-align: center">{{row.f_last_check_state}}</td>-->
          </template>
        </data-grid>
      </criteria-paged>
    </div>
  </div>


  <modal :show.sync="showdanger" v-ref:modal backdrop="false">
    <header slot="modal-header" class="modal-header">
      <button type="button" class="close" @click="colsedanger"><span>&times;</span></button>
      <h4 style="text-align: center" class="modal-title">隐患内容</h4>
    </header>
    <article slot="modal-body" class="modal-body">
      <div class="form-group">
        <center>
          <div v-html="dangerinfo"></div>
        </center>

      </div>
    </article>
    <div slot="modal-footer" class="modal-footer">
      <button type="button" class="button_spacing button_search" @click="colsedanger()">关闭</button>
    </div>
  </modal>


</template>

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

let AddItem = function* (self) {
  self.checkboxModel.f_filialeid = self.$login.f.orgid
  self.checkboxModel.f_orgstr = self.$login.f.orgpathstr
  self.checkboxModel.planid = self.checkplan.id
  self.checkboxModel.rows = self.checkrows
  self.checkboxModel.model = self.model
  self.checkboxModel.sqlname = self.sqlname
  self.checkboxModel.f_filialeids = self.model.f_filialeids
  self.checkboxModel.createWay = self.createWay
  self.checkboxModel.repeated = self.repeated
  //tag
  self.checkboxModel.planWay = 'add'
  yield self.$resetpost('rs/logic/GenCallInAllPlan', {data: self.checkboxModel}, {
    resolveMsg: null,
    rejectMsg: null
  }).then((res) => {
    //tag
    if (res.data.code == 200) {
      self.$showMessage(`添加成功！现在${self.checkplan.f_plan_name}共有${res.data.countItem}个计划！`)
      self.$emit('finish')
    } else {
      self.$showMessage("计划添加失败!")
    }
    self.isBusy = false
  })
}

let saveGen = function* (self) {



  self.checkboxModel.f_create_time = self.$login.toStandardTimeString()
  self.checkboxModel.f_plan_type = '预约计划'
  self.checkboxModel.f_issued = '否'
  self.checkboxModel.f_filialeid = self.$login.f.orgid
  self.checkboxModel.f_filialeids = self.model.f_filialeids
  self.checkboxModel.f_orgstr = self.$login.f.orgpathstr
  self.checkboxModel.f_plan_year = self.f_plan_year[0]
  self.checkboxModel.f_plan_month = self.f_plan_month[0]
  self.checkboxModel.f_subcompany = self.$login.f.f_fengongsi
  self.checkboxModel.f_create_operator = self.$login.f.name
  self.checkboxModel.f_effective_start_time = self.f_effective_start_time
  self.checkboxModel.f_effective_end_time = self.f_effective_end_time
  self.checkboxModel.model = self.model
  self.checkboxModel.sqlname = self.sqlname
  self.checkboxModel.planWay = 'create'
  self.checkboxModel.createWay = self.createWay
  self.checkboxModel.repeated = self.repeated
  yield self.$resetpost('rs/logic/GenCallInAllPlan', {data: self.checkboxModel}, {resolveMsg: null, rejectMsg: null})
    .then((respanse) => {
      //tag
      self.showModal = false
      if (respanse.data.code == 200) {
        self.$showMessage("预约计划生成成功!")
        self.checkrows = []
        self.creatPlanWay = ''
        self.checker = {}
        self.IsShare = '否'
        self.checkboxModel = {}
        self.$refs.paged.$refs.criteria.search()
        self.createWay = ''
      } else {
        self.$showMessage("预约计划生成失败!")
      }
      self.isBusy = false
    })
}

let checkItems = function* (self) {
  let data = {}
  self.repeated = -1
  let checkIdArray = []
  data = self.model.params
  //tag)
  yield self.$resetpost('rs/sql/getExistCheckItem/n', {data: data}, {resolveMsg: null, rejectMsg: null})
    .then((res) => {
      //tag
      self.repeated = res.data.n
    })
}

let seachData = function* (self) {
  let getParams = yield self.$resetpost('rs/logic/getSaleInitData', {data: {f_orgid: self.$login.f.orgid}}, {
    resolveMsg: null,
    rejectMsg: '获取营收参数出错！！！'
  })
  //tag
  if (getParams.data) {
    let arr = []
    getParams.data.adjustable.forEach((item, index) => {
      let temp = {}
      temp.label = `[${item.f_adjustable_id}]-${item.f_adjustable_name}`
      temp.value = `${item.id}`
      arr.push(temp)
    })
    self.adjustables = [{label: '全部', value: ''}, ...arr]
  }
}
let select = function* (self) {
  //tag
  let http = new HttpResetClass()
  let getGasman = yield http.load('POST', '/rs/search', {
    source: 'tool.getChildrenOfResName($安检员$)',
    userid: self.$login.f.id
  }, {resolveMsg: null, rejectMsg: null})
  //tag
  //tag
  getGasman.data.forEach((checker) => {
    self.checkers.push({label: checker.name, value: checker})
  })
}

let searchSafeCycle = function* (self) {
  //tag
  let http = new HttpResetClass()
  yield http.load('POST', 'rs/logic/getSafeCheckCycle', {}, {resolveMsg: null, rejectMsg: null}).then((res) => {
    //tag
    if (res.data.code == 200) {
      self.civil = res.data.civil.value
      self.civilian = res.data.civilian.value
      self.model.safeCycle = self.civil
    } else {
      self.$showMessage(res.data.msg)
    }
  })
}
export default {
  title: '计划生成',
  data() {
    let options = []
    let year = (new Date()).getFullYear()
    for (let i = year; i <= year + 3; i++)
      options.push({label: i + '', value: i + ''})
    let moptions = []
    for (let i = 1; i <= 12; i++)
      moptions.push({label: i + '', value: i + ''})
    let model1 = new PagedList('rs/sql/根据安检员查询用户档案', 50, null)
    let model = new PagedList('rs/sql/FetchUserFileByOrgNoRuHuSXQ', 50, {
      SafeCheckCQ: "",
      SafeCheckSX: {f_check_start: "''", f_check_end: "''"},
      checkAll: false,
      checkes: [],
      columnName: "''",
      endday: "''",
      f_usertype: "''",
      month: "''",
      orderitem: "'f_residential_area,f_building,f_unit,f_floor,f_room'",
      startday: "''",
      switchCheckAll: true
    })
    // 默认搜索12个月
    model.timetype = 'mm'
    model.f_filialeids = '(' + this.$login.f.orgid + ')'
    let model2 = new PagedList('rs/sql/planCount', 50, {
      f_filialeids: 'this.f_filialeids'
    })
    model2.f_filialeids = '(' + this.$login.f.orgid + ')'
    return {
      isBusy: false,
      civil: '',   //民用安检周期
      civilian: '',      //非民用安检周期
      SafeCheckXZs: [{label: '未安检', value: '未安检'}, {label: '已安检', value: '已安检'}, {
        label: '应安检',
        value: '应安检'
      }, {label: '超期安检', value: '超期安检'}], // 安检筛选选项
      SafeCheckSXs: [{label: '是', value: '是'}, {label: '否', value: '否'}, {label: '全部', value: ''},],
      IsShares: [{label: '是', value: '是'}, {label: '否', value: '否'}],
      IsShare: '否',
      checker: {},
      criteriaShow: false,
      model: model,
      model1: model,
      model2: model2,
      checkers: [],
      chosenOrg: {id: 0},
      showModal: false,
      showAddModal: false,
      checkedAll: false,
      checkrows: [],
      adjustables: [],
      checkStates: this.$appdata.getParam('安检状态'),
      f_plan_year: year + '',
      f_plan_month: moptions[new Date().getMonth()].value,
      f_effective_start_time: '',  //计划有效起始时间
      f_effective_end_time: '',    //计划有效结束时间
      checkboxModel: {
        f_plan_name: '',
        f_plan_year: '',
        f_plan_month: '',
        f_safecheck_type: '设备维护',
        IsShare: '',
        checker: ''
      },
      plancondition:'1=1',
      c_year_list: options,
      c_month_list: moptions,
      c_type_list: [{label:'设备维护',value:'设备维护'}],
      areas: this.areas(),
      areaslist: [],
      checkstatus: this.checkstatus(),
      usertypes: this.usertypes(),
      timetypes: this.timetypes(),
      userstates: this.userstates(),
      sqlname: '',
      creatPlanWay: '',
      showdanger: false,
      dangerinfo: null,
      repeated: 0, //下发时重复的安检单条数
      createWay: ''
    }
  },
  props: {
    checkplan: { // 传入一条安检计划信息
      type: Object
    },
    rowsdata: [],
    additemshow: {
      type: Boolean,
      default: false
    }
  },
  ready() {
    let gen  = select(this);
    co(gen)
    //tag
  },
  methods: {

    itemAddBack() {
      this.$emit('finish')
    },
    itemAdd(val) {
      if (this.model.rows.length == 0) {
        this.$showMessage("暂无可添加的计划！")
        return
      }
      this.checkExist()
      this.showAddModal = true
    },
    // 选择安检员
    IsShareschange(val) {
      this.IsShare = val
      if (val == '是') {
        this.checker = null
      }
    },
    checkerchange(val) {
      this.checkboxModel.f_checker = val.name
      this.checkboxModel.f_checker_id = val.id
    },
    async search(args) {
      args.condition+=" and uf.f_usetype='设备维护'"
      this.plancondition=args.condition
     this.model.search(args.condition, args.model)

    },

    gotodanger(val) {
      let a = ''
      for (let row of val.data) {
        let str = JSON.stringify(row)
        a = a + str + '<br/>'
      }
      this.dangerinfo = a
      this.showdanger = true

    },
    checkstatus() {
      return this.$appdata.getParam('安检状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('安检状态')] : [{label: '全部', value: ''}]
    },
    usertypes() {
      return this.$appdata.getParam('用户类型') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('用户类型')] : [{label: '全部', value: ''}]
    },
    userstates() {
      return this.$appdata.getParam('用户状态') ? [{
        label: '全部',
        value: ''
      }, ...this.$appdata.getParam('用户状态')] : [{label: '全部', value: ''}]
    },
    timetypes() {
      // return [{label: '天', value: 'dd'},{label: '月',value: 'mm'},{label:'年',value:'yy'}]
      return [{label: '天', value: 'dd'}, {label: '月', value: 'mm'}]
    },
    show() {
      this.criteriaShow = true
    },
    hidden() {
      this.criteriaShow = !this.criteriaShow
    },
    confirm(createWay) {
      if (!this.checkboxModel.f_plan_name) {
        this.$showMessage('请填写安检计划名称!')
        return
      }
      // if(this.f_effective_start_time == ''){
      //   this.$showMessage('请选择有效起始日期！')
      //   return
      // }
      // if(this.f_effective_end_time == ''){
      //   this.$showMessage('请选择有效结束日期！')
      //   return
      // }
      if (this.IsShare == '否' && !this.checkplan) {
        if (!this.checkboxModel.f_checker_id) {
          this.$showMessage('请选择安检员！')
          return
        }
      }
      this.createWay = createWay
      if (this.isBusy === false) {
        this.isBusy = true
        this.$showMessage('正在下发中，请稍等...')
        // if (!this.checkplan) {
        //   let gen = saveGen(this)
        //   co(gen)
        // } else {
        //   let _gen = AddItem(this)
        //   co(_gen)
        // }
        let savedate={
          plan:{
            name:this.checkboxModel.f_plan_name,
            year:this.f_plan_year[0],
            month:this.f_plan_month[0],
            f_filialeid:this.$login.f.orgid,
            f_create_operator:this.$login.f.name,
            f_safecheck_type:this.checkboxModel.f_safecheck_type,
            isshare:this.IsShare,
            condition:this.plancondition,
            f_checker:this.checkboxModel.f_checker?this.checkboxModel.f_checker:"",
            f_checker_id:this.checkboxModel.f_checker_id?this.checkboxModel.f_checker_id:""
          }

        }
        //tag
        //tag
        //tag)
        new HttpResetClass().load('post','rs/logic/CreatePlanThenAdd',savedate).then(res=>{
          //tag)
          if (res.data.code=='200'){
            this.showModal=false
            this.checkrows = []
            this.creatPlanWay = ''
            this.checker = {}
            this.IsShare = '否'
            this.checkboxModel = {}
            this.$refs.paged.$refs.criteria.search()
            this.createWay = ''
            this.$showMessage('计划创建成功')
          }else{
            this.$showMessage('计划创建失败')
          }
        })
        this.isBusy = false
      } else {
        this.$showMessage('正在下发中，请稍等...')
      }

    },
    changeStates() {
      if (this.checkedAll) {//实现反选/
        this.checkrows = [];
        for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
          this.$set('$refs.paged.model.rows[' + i + '].checked', false)
        }
      } else {//实现全选
        for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
          this.$set('$refs.paged.model.rows[' + i + '].checked', true)
        }
        let _this = this
        let condition = this.$refs.paged.$refs.criteria.condition
        let url = this.model.url
        this.$resetpost(`${url}?pageSize=9999999`, {
          data: {
            condition: condition,
            groupitem: '',
            orderitem: 'f_residential_area',
            f_usertype: this.model.f_usertype,
            f_filialeids: this.model.f_filialeids,
            month: this.model.month,
            safeCycle: this.model.safeCycle,
            f_checktime_start: this.model.f_checktime_start,
            f_checktime_end: this.model.f_checktime_end,
            SafeCheckSX: this.model.SafeCheckSX,
            f_last_check_state: this.model.f_last_check_state
          },
        }, {resolveMsg: null, rejectMsg: null}, -1).then(
          (respanse) => {
            if (respanse.data.length >= 5000) {
              this.$showMessage("数据量太大，请重新选择")
            } else {
              _this.checkrows = []
              for (let j = 0; j < respanse.data.length; j++) {
                _this.checkrows.push(respanse.data[j])
              }
              //tag;
            }
          })
      }
    },
    addChecked(item) {
      //tag;
      if (!item.checked) {
        this.checkrows.push(item);
        //tag;
      } else {
        for (let i = 0; i < this.checkrows.length; i++) {
          if (item.f_userinfo_id == this.checkrows[i].f_userinfo_id) {
            this.checkrows.splice(i, 1)
          }
        }
      }
    },
    ToshowModal() {
      this.creatPlanWay = 'single'
      if (this.checkrows.length > 0) {
        this.checkExist()
        this.showModal = true
      } else {
        this.$showMessage("请选择需要安检的用户!")
      }
    },
    FiltrationPlan() {
      if (this.model.rows.length == 0) {
        this.$showMessage("暂无可生成的计划！")
        return
      }
      this.creatPlanWay = 'filtration'
      this.checkExist()
      this.showModal = true
    },
    AllPlan(orgs) {
      if (this.model.rows.length == 0) {
        this.$showMessage("暂无可生成的计划！")
        return
      }
      this.creatPlanWay = 'all'
      this.checkExist()
      this.showModal = true
      this.getCheckerInfo(orgs)
    },
    // 安检员任务完成情况
    getCheckerInfo(orgs) {
      this.model2.search(`1=1`)
    },
    cancel() {
      this.showModal = false
      this.showAddModal = false
    },
    areas() {
      let rs = []
      for (let i = 0; i < this.$login.f.f_allArea.length; i++) {
        let temp = {
          label: this.$login.f.f_allArea[i].label,
          value: this.$login.f.f_allArea[i].label
        }
        rs.push(temp)
      }
      return [{label: '全部', value: ''}, ...rs]
    },
    initAdjustables() {
      //tag
      let arr = []
      let filter = this.$login.f.orgid
      this.$GetSaleParam.getAdjustable(filter).forEach((item) => {
        let temp = {}
        temp.label = `[${item.value.f_adjustable_id}]-${item.label}`
        temp.value = `${item.value.id}`
        arr.push(temp)
      })
      this.adjustables = [{label: '全部', value: ''}, ...arr]
    },
    getRes(obj) {
      this.model.f_filialeids = this.$login.convertToIn(obj.resids);
      //tag
    },
    checkExist() {
      co(checkItems(this))
    }
  },

  watch: {
    'model.f_usertype'(val) {
      if (val == '民用') {
        this.model.safeCycle = this.civil
      } else if (val == '非民用') {
        this.model.safeCycle = this.civilian
      }
    },
    'model.SafeCheckXZ'(val) {
      if (val == '已安检') {
        this.model.SafeCheckCQ = ''
        this.model.SafeCheckSX = {
          f_check_end: '', // 安检时间  查询起始条件
          f_check_start: ''// 安检时间  查询终止条件
        }
      } else {
        // 当使用筛选条件时，清空不需要的条件选项
        this.$refs.paged.$refs.criteria.model.f_check_start = ''
        this.$refs.paged.$refs.criteria.model.f_check_end = ''
        this.$refs.paged.$refs.criteria.model.f_last_check_state = ''
        this.model.month = ''
        if (val == '应安检') {
          this.model.f_shouldcheck_start = Util.toStartDateString()
          this.model.f_shouldcheck_end = Util.toStandardDateString()
        }
        // this.model.f_checktime_start = ''
        // this.model.f_checktime_end = ''
      }
    },
    // 'checker'(val){
    //   //tag
    //   if(val){
    //     this.checkboxModel.f_checker = this.checker[0].name
    //     this.checkboxModel.f_checker_id = this.checker[0].id
    //   }
    // },
    'model.rows'() {
      // if (!this.checkedAll) {//实现反选/
      // this.checkrows = [];
      for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
        var k = false
        for (let j = 0; j < this.checkrows.length; j++) {
          if (this.$refs.paged.model.rows[i].f_userinfo_id == this.checkrows[j].f_userinfo_id) {
            this.$set('$refs.paged.model.rows[' + i + '].checked', true)
            k = true
            continue
          }
        }
        if (!k) {
          this.$set('$refs.paged.model.rows[' + i + '].checked', false)
        }
      }
      // } else {//实现全选
      //   // this.checkboxModel = {};
      //   for (let i = 0; i < this.$refs.paged.model.rows.length; i++) {
      //     this.$set('$refs.paged.model.rows[' + i + '].checked', true)
      //   }
      // }
    }
  },
  computed: {
    getCondition() {
      //tag
      return {
        condition: `${this.$refs.paged.$refs.criteria.condition}`,
        orderitem: `${this.model.orderitem}`,
        f_filialeid: this.model.f_filialeid,
        month: this.model.month,
        SafeCheckSX: this.model.SafeCheckSX,
        f_usertype: this.model.f_usertype,
        f_last_check_state: this.model.f_last_check_state,
        f_new_account: this.model.f_new_account,
        safeCycle: this.model.safeCycle,
        SafeCheckCQ: this.model.SafeCheckCQ,
        SafeCheckXZ: this.model.SafeCheckXZ,
        f_shouldcheck_start: this.model.f_shouldcheck_start,
        f_shouldcheck_end: this.model.f_shouldcheck_end
      }
    },
    getfield() {
      let data = {}
      this.bodyData.forEach((value, index) => {
        data[this.bodyData[index]] = this.headData[index]
      })
      return data
    },
    selected() {
      return this.$refs.paged.$refs.grid.selected
    }
  }
}
</script>
<style scoped>
.newcolor {
  color: red;
}

.table th {
  background-color: #f2f6fa;
  color: black;
}

.p {
  color: #fff922;
  font-weight: bold
}

.p1 {
  color: #ff252f;
}
</style>
