<template>
  <div class="mod-config">
  <el-form :inline="true"  label-position="top" :model="searchData" >
    <el-form-item :label="'计划编码'">
      <el-input v-model="searchData.planID"  style="width: 120px"></el-input>
    </el-form-item>
    <el-form-item :label="'计划描述'">
      <el-input v-model="searchData.planDesc"  style="width: 120px"></el-input>
    </el-form-item>
    <el-form-item :label="'设备编码'">
      <el-input v-model="searchData.objectID"  style="width: 120px"></el-input>
    </el-form-item>
    <el-form-item :label="'计划开始日期：'">
      <el-date-picker
        style="width: 120px"
        v-model="searchData.startDate"
        type="date"
        value-format="yyyy-MM-dd"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item style="margin-top: 23px;">
      <laber style="margin-left: -9px;font-size: 19px">&#10142</laber>
    </el-form-item>
    <el-form-item  :label="' '">
      <el-date-picker
        style="width: 120px"
        v-model="searchData.endDate"
        type="date"
        value-format="yyyy-MM-dd"
        placeholder="选择日期">
      </el-date-picker>
    </el-form-item>
    <el-form-item :label="'状态'">
      <el-select filterable v-model="searchData.status" style="width: 120px">
        <el-option label="全部" value=""></el-option>
        <el-option label="已计划" value="已计划"></el-option>
        <el-option label="进行中" value="进行中"></el-option>
        <el-option label="已结束" value="已结束"></el-option>
        <el-option label="已取消" value="已取消"></el-option>
      </el-select>
    </el-form-item>
    <el-form-item  :label="' '">
      <el-button @click="getDataList()">查询</el-button>
      <el-button  type="primary" @click="addModal()">新增计划</el-button>
      <!--        <el-button  type="danger" @click="deletePlan()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
    </el-form-item>
  </el-form>
  <el-table
    :height="height"
    :data="dataList"
    border
    v-loading="dataListLoading"

    style="width: 100%;">
<!--    <el-table-column-->
<!--      type="selection"-->
<!--      header-align="center"-->
<!--      align="center"-->
<!--      width="50">-->
<!--    </el-table-column>-->
    <el-table-column
      v-for="(item,index) in columnList" :key="index"
      :sortable="item.columnSortable"
      :prop="item.columnProp"
      :header-align="item.headerAlign"
      :show-overflow-tooltip="item.showOverflowTooltip"
      :align="item.align"
      :fixed="item.fixed==''?false:item.fixed"
      :min-width="item.columnWidth"
      :label="item.columnLabel">
      <template slot-scope="scope">
        <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
        <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                           style="width: 100px; height: 80px"/></span>
      </template>
    </el-table-column>
    <el-table-column
      fixed="right"
      header-align="center"
      align="center"
      width="160"
      label="操作">
      <template slot-scope="scope">
        <a type="text" size="small" v-if="scope.row.status=='已计划'" @click="createOrder(scope.row)">下达</a>
        <a type="text" size="small" v-if="scope.row.status=='进行中'" @click="planOrder(scope.row)">计划</a>
        <a type="text" size="small" v-if="scope.row.status!='已结束'||scope.row.status!='已取消'" @click="cancelPlan(scope.row)">取消</a>
        <a type="text" size="small" v-if="scope.row.status=='已计划'" @click="updateModal(scope.row)">修改</a>
        <a type="text" size="small" v-if="scope.row.status!='进行中'" @click="deletePlan(scope.row)">删除</a>
        <a type="text" size="small" @click="itemModal(scope.row)">维保项目</a>
      </template>
    </el-table-column>
  </el-table>
  <el-pagination
    @size-change="sizeChangeHandle"
    @current-change="currentChangeHandle"
    :current-page="pageIndex"
    :page-sizes="[20, 50, 100, 1000]"
    :page-size="pageSize"
    :total="totalPage"
    layout="total, sizes, prev, pager, next, jumper">
  </el-pagination>

  <el-dialog title="维保计划" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="570px">
    <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
      <el-form-item label="计划编码:">
        <el-input v-model="modalData.planID"  disabled style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="计划描述:">
        <el-input v-model="modalData.planDesc"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item  v-if="this.modalData.flag==2" >
        <span slot="label" style="" @click="getBaseList(200)"><a herf="#">设备编码</a></span>
        <el-input v-model="modalData.objectID" :disabled="modalDisableFlag" @blur="objectIDBlur" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="设备名称:" v-if="this.modalData.flag==2" >
        <el-input v-model="modalData.objectDesc" disabled style="width: 120px"></el-input>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(1032)"><a herf="#">维保模板</a></span>
        <el-input v-model="modalData.propertiesCode" @blur="modalCodeBlur" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="模板名称:">
        <el-input v-model="modalData.propertiesDesc" disabled style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="计划开始日期:">
        <el-date-picker
          style="width: 120px"
          v-model="modalData.planStartDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="必选">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="计划结束日期:">
        <el-date-picker
          style="width: 120px"
          v-model="modalData.planEndDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="必选">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: 0px;">
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(201)"><a herf="#">默认机修人员</a></span>
        <el-input v-model="modalData.operator"  style="width: 120px"></el-input>
      </el-form-item>

      <el-form-item label="维保周期(天):">
        <el-input v-model="modalData.planPeriod" type="number"   onkeyup="value=value.replace(/^[^\d]+/g,'')" style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="备注:">
        <el-input v-model="modalData.remark"  style="width: 254px"></el-input>
      </el-form-item>
    </el-form>
    <div v-if="this.modalData.flag==1">
    <div style="text-align: center ;font-size: 11px">
      <span> ----------------------------------------------------选择设备----------------------------------------------------</span>
    </div>
    <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -8px;">
      <el-form-item label="设备编码">
        <el-input v-model="objectData.objectID"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label="设备名称">
        <el-input v-model="objectData.objectDesc"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item >
        <span slot="label" style="" @click="getBaseList(1027)"><a herf="#">设备分类编码</a></span>
        <el-input v-model="objectData.familyID"  style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item label=" ">
        <el-button @click="getObjectList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :height="200"
      :data="objectList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="objectID"
        header-align="center"
        align="left"
        min-width="30"
        label="设备编码">
      </el-table-column>
      <el-table-column
        prop="objectDesc"
        header-align="center"
        align="left"
        min-width="30"
        label="设备名称">
      </el-table-column>
      <el-table-column
        prop="familyID"
        header-align="center"
        align="left"
        min-width="30"
        label="设备分类">
      </el-table-column>
      <el-table-column
        prop="familyName"
        header-align="center"
        align="left"
        min-width="30"
        label="分类名称">
      </el-table-column>
    </el-table>
    </div>
    <el-footer style="height:40px;margin-top: 10px;text-align:center">
      <el-button type="primary" @click="saveData()">保存</el-button>
      <el-button type="primary" @click="modalFlag = false">关闭</el-button>
    </el-footer>
  </el-dialog>

    <el-dialog title="维保项目清单" :close-on-click-modal="false" v-drag :visible.sync="detailModelFlag" width="830px">
      <el-form :inline="true"  label-position="top"  @keyup.enter.native="getDataList()">
        <el-form-item :label="'维保模板编码'">
          <el-input v-model="detailData.codeNo"  readonly style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'维保模板名称'">
          <el-input v-model="detailData.codeDesc"  readonly style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item  :label="' '">
<!--          <el-button  type="primary" @click="addDetailModal()">新增</el-button>-->
        </el-form-item>
      </el-form>
      <el-table
        :height="300"
        :data="detailList"
        border
        v-loading="dataListLoading"

        style="width: 100%;">
        <el-table-column
          v-for="(item,index) in columnDetailList" :key="index"
          :sortable="item.columnSortable"
          :prop="item.columnProp"
          :header-align="item.headerAlign"
          :show-overflow-tooltip="item.showOverflowTooltip"
          :align="item.align"
          :fixed="item.fixed==''?false:item.fixed"
          :min-width="item.columnWidth"
          :label="item.columnLabel">
          <template slot-scope="scope">
            <span v-if="!item.columnHidden"> {{ scope.row[item.columnProp] }}</span>
            <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                               style="width: 100px; height: 80px"/></span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          width="130"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" v-if="scope.row.valueChooseFlag=='Y'" @click="chooseModal(scope.row)">可选值</a>
            <a type="text" size="small"  @click="updateItemModal(scope.row)">编辑</a>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="detailModelFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="维保项目" :close-on-click-modal="false" v-drag :visible.sync="itemModalFlag" width="430px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="维保项目编码:">
          <el-input v-model="itemModalData.itemNo" :disabled="itemModalDisableFlag" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="维保项目名称:">
          <el-input v-model="itemModalData.itemDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'检测值类型'">
          <el-select filterable v-model="itemModalData.valueTypeDb" style="width: 120px">
            <el-option label="文本" value="T"></el-option>
            <el-option label="数字" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="维保方法说明:">
          <el-input v-model="itemModalData.itemRemark"  style="width: 254px"></el-input>
        </el-form-item>
        <el-form-item :label="'是否值可选'">
          <el-select filterable v-model="itemModalData.valueChooseFlag" style="width: 120px">
            <el-option label="是" value="Y"></el-option>
            <el-option label="否" value="N"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="参照值:">
          <el-input v-model="itemModalData.defaultValue"  style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="最大值:">
          <el-input v-model="itemModalData.maxValue" type="number" style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="最小值:">
          <el-input v-model="itemModalData.minValue"  type="number" style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="itemSaveData()">保存</el-button>
        <el-button type="primary" @click="itemModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="可选值" :close-on-click-modal="false" v-drag :visible.sync="chooseModalFlag" width="430px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="维保项目名称:">
          <el-input v-model="chooseModalData.itemDesc"  disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item :label="'检测值类型'">
          <el-select filterable v-model="chooseModalData.valueTypeDb" disabled style="width: 120px">
            <el-option label="文本" value="T"></el-option>
            <el-option label="数字" value="N"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="' '">
          <el-button  type="primary" @click="addChooseModal()">新增</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="300"
        :data="chooseTableData"
        border
        style="width: 100%">
        <el-table-column
          prop="availableValue"
          header-align="center"
          align="left"
          min-width="200"
          label="属性值">
        </el-table-column>
        <el-table-column
          prop=""
          header-align="center"
          align="center"
          min-width="100"
          label="操作">
          <template slot-scope="scope">
            <a type="text" size="small" @click="updateChooseModal(scope.row)">修改</a>
            <a type="text" size="small" @click="deleteItemAvailable(scope.row)">删除</a>
          </template>
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="chooseModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <el-dialog title="可选值维护" :close-on-click-modal="false" v-drag :visible.sync="itemAddModalFlag" width="215px" >
      <el-form :inline="true" label-position="top" style="margin-left: 22px;margin-top: -5px;" @submit.native.prevent>
        <el-form-item :label="'可选值：'">
          <el-input v-model="itemData.availableValue"  :type="itemFlag" style="width: 130px;"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 20px;text-align:center">
        <el-button type="primary" @click="saveItemAvailable()">保存</el-button>
        <el-button type="primary" @click="itemAddModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>
    <Chooselist ref="baseList"  @getBaseData="getBaseData"></Chooselist>

  </div>
</template>

<script>
  import {
    eamWorkPlanSearch,
    eamWorkPlanSave,
    eamWorkPlanEdit,
    eamWorkPlanDelete,
    searchPlanItems,
    updatePlanItems,
    searchPlanItemAvailable,
    savePlanItemAvailable,
    deletePlanItemAvailable,
    createEamWorkOrder,
    objectIDBlur,
    modalCodeBlur,
    getObjectList,
    planOrder,
    cancelPlan,
  } from "@/api/eam/eam.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  export default {
    components: {
      Chooselist
    },
    watch: {
      searchData: {
        deep: true,
        handler: function (newV, oldV) {
          this.searchData.planID = this.searchData.planID.toUpperCase()
          this.searchData.objectID = this.searchData.objectID.toUpperCase()
        }
      },
      modalData: {
        deep: true,
        handler: function (newV, oldV) {
          this.modalData.planID = this.modalData.planID.toUpperCase()
          this.modalData.objectID = this.modalData.objectID.toUpperCase()
          this.modalData.propertiesCode = this.modalData.propertiesCode.toUpperCase()
          this.modalData.operator = this.modalData.operator.toUpperCase()
        }
      },
      detailData: {
        deep: true,
        handler: function (newV, oldV) {
          this.modalData.planID = this.modalData.planID.toUpperCase()
          this.modalData.itemNo = this.modalData.itemNo.toUpperCase()
          this.modalData.codeNo = this.modalData.codeNo.toUpperCase()
        }
      }
    },
    data () {
      return {
        tagNo:'',
        searchData: {
          site: this.$store.state.user.site,
          planID: '',
          planDesc: '',
          objectID: '',
          status: '',
          startDate: new Date(),
          endDate:'',
          functionType:'B',
          page: 1,
          limit: 10,
        },
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        height: 200,
        dataList: [],
        dataListLoading: false,
        dataListSelections: [],
        modalFlag:false,
        modalDisableFlag:false,
        modalData:{
          objectList:[],
          flag:'',
          functionType:'B',
          site: this.$store.state.user.site,
          planID:'',
          planDesc:'',
          objectID:'',
          propertiesCode:'',
          propertiesDesc:'',
          operator:'',
          planPeriod:'',
          status:'',
          planStartDate:'',
          planEndDate:'',
          userId:'',
          remark:'',
        },
        objectData:{
          site: this.$store.state.user.site,
          objectID:'',
          objectDesc:'',
          familyID:'',
        },
        objectList:[],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TableSite',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'site',
            headerAlign: "center",
            align: "left",
            columnLabel: '工厂编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TablePlanID',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'planID',
            headerAlign: "center",
            align: "left",
            columnLabel: '计划编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TablePlanDesc',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'planDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '计划描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TableObjectID',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'objectID',
            headerAlign: "center",
            align: "left",
            columnLabel: '设备编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TablePropertiesCode',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'propertiesCode',
            headerAlign: "center",
            align: "left",
            columnLabel: '维保模板编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TableStatus',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'status',
            headerAlign: "center",
            align: "left",
            columnLabel: '状态',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TablePlanStartDate',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'planStartDate',
            headerAlign: "center",
            align: "left",
            columnLabel: '计划开始日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TablePlanEndDate',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'planEndDate',
            headerAlign: "center",
            align: "left",
            columnLabel: '计划结束日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TableNextWorkDate',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'nextWorkDate',
            headerAlign: "center",
            align: "left",
            columnLabel: '下次执行日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101013,
            serialNumber: '101013TableOperator',
            tableId: "101013Table",
            tableName: "点检计划表",
            columnProp: 'operator',
            headerAlign: "center",
            align: "left",
            columnLabel: '计划操作员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TablePlanPeriod',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'planPeriod',
            headerAlign: "center",
            align: "right",
            columnLabel: '维保周期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TableCreatedDate',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'createdDate',
            headerAlign: "center",
            align: "left",
            columnLabel: '创建时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 140,
          },

          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TableCreatedBy',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'createdBy',
            headerAlign: "center",
            align: "left",
            columnLabel: '创建人',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101017,
            serialNumber: '101017TableRemark',
            tableId: "101017Table",
            tableName: "维保计划表",
            columnProp: 'remark',
            headerAlign: "center",
            align: "left",
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150,
          },
        ],
        //项目清单
        addDetailModalFlag:false,
        detailData:{
          site:'',
          planID:'',
          codeNo:'',
          codeDesc:'',
          functionType:'B',
          itemNo:'',
          itemDesc:'',
          itemType:'B',
          userId:this.$store.state.user.name
        },
        detailModelFlag:false,
        detailList: [],
        columnDetailList: [
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009Table2EamPropertiesItemID',
            tableId: "101009Table2",
            tableName: "维保项目表",
            columnProp: 'itemNo',
            headerAlign: "center",
            align: "left",
            columnLabel: '维保项目编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009Table2EamPropertiesItemDesc',
            tableId: "101009Table2",
            tableName: "维保项目表",
            columnProp: 'itemDesc',
            headerAlign: "center",
            align: "left",
            columnLabel: '维保项目名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 90,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009Table2EamPropertiesItemRemark',
            tableId: "101009Table2",
            tableName: "维保项目表",
            columnProp: 'itemRemark',
            headerAlign: "center",
            align: "left",
            columnLabel: '维保方法说明',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009Table2ValueType',
            tableId: "101009Table2",
            tableName: "维保项目表",
            columnProp: 'valueType',
            headerAlign: "center",
            align: "left",
            columnLabel: '检测值类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009Table2DefaultValue',
            tableId: "101009Table2",
            tableName: "维保项目表",
            columnProp: 'defaultValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '参照值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009Table2MaxValue',
            tableId: "101009Table2",
            tableName: "维保项目表",
            columnProp: 'maxValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '最大值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009Table2MinValue',
            tableId: "101009Table2",
            tableName: "维保项目表",
            columnProp: 'minValue',
            headerAlign: "center",
            align: "left",
            columnLabel: '最小值',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101009,
            serialNumber: '101009TableValueChooseFlag',
            tableId: "101009Table",
            tableName: "common",
            columnProp: 'valueChooseFlag',
            headerAlign: "center",
            align: "left",
            columnLabel: '是否值可选',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 70,
          },
        ],

        itemModalData:{
          site:'',
          planID:'',
          flag:'',
          itemNo:'',
          itemDesc:'',
          valueTypeDb:'',
          defaultValue:'',
          valueChooseFlag:'',
          createdBy:this.$store.state.user.name,
          maxValue:'',
          minValue:'',
          itemRemark:'',
          itemType:'B',
        },
        itemModalFlag:false,
        itemModalDisableFlag:false,

        itemFlag:'text',
        chooseModalFlag:false,
        chooseModalData:{
          site:'',
          planID:'',
          itemNo: '',
          itemDesc: '',
          itemType:'B',
          valueTypeDb:'',
        },
        chooseTableData:[],
        itemData:{
          site:'',
          planID:'',
          itemNo:'',
          valueNo:'',
          availableValue:'',
          itemType:'B',
          createdBy: this.$store.state.user.name
        },
        itemAddModalFlag:false,
      }
    },
    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },
    created () {
      this.getDataList()
    },
    methods: {
      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          if (val === 200 && this.modalDisableFlag!=true) {
            strVal = this.modalData.objectID
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1032) {
            strVal = this.modalData.propertiesCode
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 201) {
            strVal = this.modalData.operator
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 1027) {
            strVal = this.objectData.familyID
            this.$refs.baseList.init(val, strVal)
          }
        })
      },
      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 200) {
          this.modalData.objectID = val.ObjectID
          this.modalData.objectDesc = val.ObjectDesc
        }
        if (this.tagNo === 1032) {
          this.modalData.propertiesCode = val.Code_No
          this.modalData.propertiesDesc = val.Code_Desc
        }
        if (this.tagNo === 201) {
          this.modalData.operator = val.AdminID
        }
        if (this.tagNo === 1027) {
          this.objectData.familyID = val.FamilyID
        }
      },
      // 获取数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        eamWorkPlanSearch(this.searchData).then(({data}) => {
          if (data.code == 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      addModal(){
        this.modalData={
          flag:'1',
          objectList:[],
          functionType:'B',
          site: this.$store.state.user.site,
          planID:'',
          planDesc:'',
          objectID:'',
          objectDesc:'',
          propertiesCode:'',
          propertiesDesc:'',
          operator:'',
          planPeriod:'',
          status:'',
          planStartDate:'',
          planEndDate:'',
          userId:this.$store.state.user.name,
          remark:'',
        };
        this.modalDisableFlag=false;
        this.objectList=[];
        this.modalFlag=true;
      },
      updateModal(row){
        this.modalData={
          flag:'2',
          objectList:[],
          functionType:'B',
          site:row.site,
          planID:row.planID,
          planDesc:row.planDesc,
          objectID:row.objectID,
          objectDesc:row.objectID,
          propertiesCode:row.propertiesCode,
          propertiesDesc:row.codeDesc,
          operator:row.operator,
          planPeriod:row.planPeriod,
          status:row.status,
          planStartDate:row.planStartDate,
          planEndDate:row.planEndDate,
          userId:this.$store.state.user.name,
          remark:row.remark,
        };
        this.modalDisableFlag=true;
        this.modalFlag=true;
      },

      deletePlan (row) {
        this.$confirm(`是否删除这个维保计划?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'

        }).then(() => {
          eamWorkPlanDelete(row).then(({data}) => {
            if (data && data.code ==0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      saveData(){
        if (this.modalData.planDesc == '' || this.modalData.planDesc == null) {
          this.$alert('请输入计划描述 ！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.propertiesCode == '' || this.modalData.propertiesCode == null) {
          this.$alert('请选择维保模板！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.planPeriod == '' || this.modalData.planPeriod == null) {
          this.$alert('选择维保周期！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.planStartDate == '' || this.modalData.planStartDate == null) {
          this.$alert('请选择开始日期！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.planStartDate < this.dayjs().format("YYYY-MM-DD")) {
          this.$alert('计划开始日期不能小于今天！', '错误', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.modalData.planEndDate == '' || this.modalData.planEndDate == null) {
          this.$alert('请选择结束日期！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.modalData.planEndDate < this.dayjs().format("YYYY-MM-DD")) {
          this.$alert('计划结束日期不能小于今天！', '错误', {
            confirmButtonText: '确定'
          })
          return
        }
        if (this.modalData.planStartDate > this.modalData.planEndDate) {
          this.$alert('计划开始日期不能小于结束日期！', '错误', {
            confirmButtonText: '确定'
          })
          return
        }
        if(this.modalData.flag=='1'){
          if(this.dataListSelections.length==0){
            this.$alert('请勾选设备！', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
          this.modalData.objectList=this.dataListSelections
          eamWorkPlanSave(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.modalFlag=false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }else {
          eamWorkPlanEdit(this.modalData).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.modalFlag=false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },



      //----------项目清单----------------start
      //打开项目清单
      itemModal(row){
        this.detailData.site=row.site
        this.detailData.planID=row.planID
        this.detailData.codeNo=row.propertiesCode
        this.detailData.codeDesc=row.codeDesc
        searchPlanItems(this.detailData).then(({data}) => {
          this.detailList = data.rows
        })
        this.detailModelFlag=true;
      },
      updateItemModal(row){
        this.itemModalData={
          flag:'2',
          site:row.site,
          planID:row.planID,
          itemNo:row.itemNo,
          itemDesc:row.itemDesc,
          valueTypeDb:row.valueTypeDb,
          defaultValue:row.defaultValue,
          valueChooseFlag:row.valueChooseFlag,
          createdBy:this.$store.state.user.name,
          maxValue:row.maxValue,
          minValue:row.minValue,
          itemRemark:row.itemRemark,
          itemType:'B',

        };
        this.itemModalDisableFlag=true;
        this.itemModalFlag=true;
      },
      itemSaveData(){
        if (this.itemModalData.itemNo == '' || this.itemModalData.itemNo == null) {
          this.$alert('请输入维保项目编码！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if (this.itemModalData.itemDesc == '' || this.itemModalData.itemDesc == null) {
          this.$alert('请输入维保项目名称！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }

        if(this.itemModalData.flag=='1'){
          // eamPropertiesItemSave(this.itemModalData).then(({data}) => {
          //   if (data && data.code == '0') {
          //          searchPlanItems(this.detailData).then(({data}) => {
        //   this.detailList = data.rows
        // })
          //     this.itemModalFlag=false
          //     this.$message({
          //       message: '操作成功',
          //       type: 'success',
          //       duration: 1500,
          //       onClose: () => {
          //       }
          //     })
          //   } else {
          //     this.$alert(data.msg, '错误', {
          //       confirmButtonText: '确定'
          //     })
          //   }
          // })
        }else {
          updatePlanItems(this.itemModalData).then(({data}) => {
            if (data && data.code == '0') {
              searchPlanItems(this.detailData).then(({data}) => {
                this.detailList = data.rows
              })
              this.itemModalFlag=false
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }
      },
      //----------项目清单----------------end
      //----------项目可选值----------------start
      chooseModal(row){
        this.chooseModalData.site=row.site;
        this.chooseModalData.planID=row.planID;
        this.chooseModalData.itemNo=row.itemNo;
        this.chooseModalData.itemDesc=row.itemDesc;
        this.chooseModalData.valueTypeDb=row.valueTypeDb;
        searchPlanItemAvailable(this.chooseModalData).then(({data}) => {
          this.chooseTableData = data.rows
        })
        this.chooseModalFlag=true;
      },
      addChooseModal(){
        this.itemFlag= this.chooseModalData.valueTypeDb=='T'?'text':'number';
        this.itemData={
          site:this.chooseModalData.site,
          planID:this.chooseModalData.planID,
          itemNo:this.chooseModalData.itemNo,
          valueNo:0,
          availableValue:'',
          itemType:'B',
          createdBy: this.$store.state.user.name
        }
        this.itemAddModalFlag=true;
      },
      updateChooseModal(row){
        this.itemFlag= this.chooseModalData.valueTypeDb=='T'?'text':'number';
        this.itemData={
          site:this.chooseModalData.site,
          planID:this.chooseModalData.planID,
          itemNo:this.chooseModalData.itemNo,
          valueNo:row.valueNo,
          availableValue:row.availableValue,
          itemType:'B',
          createdBy: this.$store.state.user.name
        }
        this.itemAddModalFlag=true;
      },
      saveItemAvailable(){
        if(this.itemData.availableValue==''||this.itemData.availableValue==null){
          this.$alert("请输入可选值！",'错误', {
            confirmButtonText: '确定'
          })
          return false;
        }
        savePlanItemAvailable(this.itemData).then(({data}) => {
          if (data && data.code == 0) {
            searchPlanItemAvailable(this.chooseModalData).then(({data}) => {
              this.chooseTableData = data.rows
            })
            this.itemAddModalFlag=false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
              }
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
      deleteItemAvailable(row){
        this.$confirm(`是否删除这个可选值?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'

        }).then(() => {
          deletePlanItemAvailable(row).then(({data}) => {
            if (data && data.code === 0) {
              searchPlanItemAvailable(this.chooseModalData).then(({data}) => {
                this.chooseTableData = data.rows
              })
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      //----------项目可选值----------------end

      createOrder(row){
          if(row.planStartDate < this.dayjs().format("YYYY-MM-DD")){
            this.$alert('计划开始日期小于今天！请修改开始日期', '错误', {
              confirmButtonText: '确定'
            })
            return false
          }
        row.userId=this.$store.state.user.name
        this.$confirm(`是创建日期为`+row.planStartDate+`的维保工单?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'

        }).then(() => {
          createEamWorkOrder(row).then(({data}) => {
            if (data && data.code ==0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      objectIDBlur(){
        let inData={
          site:this.$store.state.user.site,
          objectID:this.modalData.objectID
        }
        objectIDBlur(inData).then(({data}) => {
          if(data.rows.length>0){
            this.modalData.objectDesc=data.rows[0].objectDesc
          }else {
            this.modalData.objectDesc=''
          }
        })
      },
      modalCodeBlur(){
        let inData={
          functionType:'B',
          codeNo:this.modalData.propertiesCode
        }
        modalCodeBlur(inData).then(({data}) => {
          if(data.rows.length>0){
            this.modalData.propertiesDesc=data.rows[0].codeDesc
          }else {
            this.modalData.propertiesDesc=''
          }
        })
      },
      getObjectList(){
        getObjectList(this.objectData).then(({data}) => {
          this.objectList = data.rows
        })
      },
      planOrder(row){
        row.userId=this.$store.state.user.name;
        this.$confirm(`是否把进行中的计划变为已计划并取消未完成的工单?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'

        }).then(() => {
          planOrder(row).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
      cancelPlan(row){
        row.userId=this.$store.state.user.name;
        this.$confirm(`是否取消计划?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'

        }).then(() => {
          cancelPlan(row).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                }
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },
    }
  }
</script>

<style scoped>

</style>
