<template>
  <div class="app-container-PRE">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['reliability:preventivemaintenance:add']"
        >{{ $t('新增') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['reliability:preventivemaintenance:edit']"
        >{{ $t('修改') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['reliability:preventivemaintenance:remove']"
        >{{ $t('删除') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['reliability:preventivemaintenance:edit']"
        >{{ $t('导入') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['reliability:preventivemaintenance:export']"
        >{{ $t('导出') }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-s-data"
          size="mini"
          @click="handleData"
        >{{ $t('数据分析') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="preventivemaintenanceList" @selection-change="handleSelectionChange" :cell-class-name="tableCellClassName" :height="clientHeight" border>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column :label="$t('年份')" align="center" prop="year" :show-overflow-tooltip="true"/>
      <el-table-column label="ITEM" align="center" prop="itemtag" width="250" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('一月')" align="center" prop="jan" :formatter="janFormat" />
      <el-table-column :label="$t('二月')" align="center" prop="feb" :formatter="febFormat" />
      <el-table-column :label="$t('三月')" align="center" prop="mar" :formatter="marFormat" />
      <el-table-column :label="$t('四月')" align="center" prop="apr" :formatter="aprFormat" />
      <el-table-column :label="$t('五月')" align="center" prop="may" :formatter="mayFormat" />
      <el-table-column :label="$t('六月')" align="center" prop="jun" :formatter="junFormat" />
      <el-table-column :label="$t('七月')" align="center" prop="jul" :formatter="julFormat" />
      <el-table-column :label="$t('八月')" align="center" prop="aug" :formatter="augFormat" />
      <el-table-column :label="$t('九月')" align="center" prop="sep" :formatter="sepFormat" />
      <el-table-column :label="$t('十月')" align="center" prop="oct" :formatter="octFormat" />
      <el-table-column :label="$t('十一月')" align="center" prop="nov" :formatter="novFormat" />
      <el-table-column :label="$t('十二月')" align="center" prop="dec" :formatter="decFormat" />
      <el-table-column label="PART" align="center" prop="part" width="150" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('位号')" align="center" prop="tagno" width="120" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('维护检修内容')" align="center" prop="maintcontents"width="200" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('维护周期')" align="center" prop="maintperiod" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('责任人')" align="center" prop="responsibleby" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('执行人')" align="center" prop="executor" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('确认人')" align="center" prop="confirmedby" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('实施结果')" align="center" prop="executionresult" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('数量')" align="center" prop="quantity" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('备注')" align="center" prop="remarks" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('操作')" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['reliability:preventivemaintenance:edit']"
          >{{ $t('修改') }}</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['reliability:preventivemaintenance:remove']"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改预防性管理对话框 -->
    <el-dialog  :close-on-click-modal="false" v-dialogDrag :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item :label="$t('装置名称')" prop="plantCode">
          <el-select v-model="form.plantCode" :placeholder="$t('请选择') + $t('装置名称')">
            <el-option
              v-for="dict in plantCodeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="PART" prop="part">
          <el-input v-model="form.part" :placeholder="$t('请输入') + 'PART'" />
        </el-form-item>
        <el-form-item label="ITEM" prop="itemtag">
          <el-input v-model="form.itemtag" :placeholder="$t('请输入') + 'ITEM'" />
        </el-form-item>
        <el-form-item :label="$t('PRE类型')" prop="item">
          <el-select v-model="form.item" :placeholder="$t('请选择') + $t('PRE类型')">
            <el-option
              v-for="dict in itemOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('位号')" prop="tagno">
          <el-input v-model="form.tagno" :placeholder="$t('请输入') + $t('位号')" />
        </el-form-item>
        <el-form-item :label="$t('维护检修内容')" prop="maintcontents">
          <el-input v-model="form.maintcontents" :placeholder="$t('请输入') + $t('维护检修内容')" />
        </el-form-item>
        <el-form-item :label="$t('维护周期')" prop="maintperiod">
          <el-input v-model="form.maintperiod" :placeholder="$t('请输入') + $t('维护周期')" />
        </el-form-item>
        <el-form-item :label="$t('责任人')" prop="responsibleby">
          <el-input v-model="form.responsibleby" :placeholder="$t('请输入') + $t('责任人')" />
        </el-form-item>
        <el-form-item :label="$t('执行人')" prop="executor">
          <el-input v-model="form.executor" :placeholder="$t('请输入') + $t('执行人')" />
        </el-form-item>
        <el-form-item :label="$t('确认人')" prop="confirmedby">
          <el-input v-model="form.confirmedby" :placeholder="$t('请输入') + $t('确认人')" />
        </el-form-item>
        <el-form-item :label="$t('实施结果')" prop="executionresult">
          <el-input v-model="form.executionresult" :placeholder="$t('请输入') + $t('实施结果')" />
        </el-form-item>
        <el-form-item :label="$t('数量')" prop="quantity">
          <el-input v-model="form.quantity" :placeholder="$t('请输入') + $t('数量')" />
        </el-form-item>
        <el-form-item :label="$t('年份')" prop="year">
          <el-input v-model="form.year" :placeholder="$t('请输入') + $t('年份')" />
        </el-form-item>
        <el-form-item :label="$t('一月')" prop="jan">
          <el-select v-model="form.jan" :placeholder="$t('请选择') + $t('一月')">
            <el-option
              v-for="dict in janOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('二月')" prop="feb">
          <el-select v-model="form.feb" :placeholder="$t('请选择') + $t('二月')">
            <el-option
              v-for="dict in febOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('三月')" prop="mar">
          <el-select v-model="form.mar" :placeholder="$t('请选择') + $t('三月')">
            <el-option
              v-for="dict in marOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('四月')" prop="apr">
          <el-select v-model="form.apr" :placeholder="$t('请选择') + $t('四月')">
            <el-option
              v-for="dict in aprOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('五月')" prop="may">
          <el-select v-model="form.may" :placeholder="$t('请选择') + $t('五月')">
            <el-option
              v-for="dict in mayOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('六月')" prop="jun">
          <el-select v-model="form.jun" :placeholder="$t('请选择') + $t('六月')">
            <el-option
              v-for="dict in junOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('七月')" prop="jul">
          <el-select v-model="form.jul" :placeholder="$t('请选择') + $t('七月')">
            <el-option
              v-for="dict in julOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('八月')" prop="aug">
          <el-select v-model="form.aug" :placeholder="$t('请选择') + $t('八月')">
            <el-option
              v-for="dict in augOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('九月')" prop="sep">
          <el-select v-model="form.sep" :placeholder="$t('请选择') + $t('九月')">
            <el-option
              v-for="dict in sepOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('十月')" prop="oct">
          <el-select v-model="form.oct" :placeholder="$t('请选择') + $t('十月')">
            <el-option
              v-for="dict in octOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('十一月')" prop="nov">
          <el-select v-model="form.nov" :placeholder="$t('请选择') + $t('十一月')">
            <el-option
              v-for="dict in novOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('十二月')" prop="dec">
          <el-select v-model="form.dec" :placeholder="$t('请选择') + $t('十二月')">
            <el-option
              v-for="dict in decOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('备注')" prop="remarks">
          <el-input v-model="form.remarks" :placeholder="$t('请输入') + $t('备注')" />
        </el-form-item>
        <el-form-item :label="$t('归属部门')" prop="deptId">
          <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" :placeholder="$t('请选择') + $t('归属部门')" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{ $t('确 定') }}</el-button>
        <el-button @click="cancel">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog  :close-on-click-modal="false" v-dialogDrag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ $t('将文件拖到此处，或') }}
          <em>{{ $t('点击上传') }}</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
          <el-link type="info" style="font-size:12px" @click="importTemplate">{{ $t('下载模板') }}</el-link>
        </div>
        <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
          <input name="type" :value="upload.type" hidden />
        </form>
        <div class="el-upload__tip" style="color:red" slot="tip">{{ $t('提示：仅允许导入“xls”或“xlsx”格式文件！') }}</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>
        <el-button @click="upload.open = false">{{ $t('取 消') }}</el-button>
      </div>
    </el-dialog>
    <el-drawer
      :title="$t('数据分析')"
      size="600px"
      :visible.sync="drawer"
      :direction="direction">
      <el-row>
        <el-col>
          <el-card class="box-card" shadow="hover">
            <div slot="header" class="clearfix">
              <span>{{ $t('完成情况统计') }}</span>
            </div>
            <div class="text item">
              <pm-status-data :item = this.item v-if="sonRefresh"></pm-status-data>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </el-drawer>
  </div>
</template>

<script>
  import {
    addPreventivemaintenance,
    delPreventivemaintenance,
    exportPreventivemaintenance,
    getPreventivemaintenance,
    listPreventivemaintenance,
    updatePreventivemaintenance
  } from "@/api/reliability/preventivemaintenance";
  import {treeselect} from "@/api/system/dept";
  import {getToken} from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import PmStatusData from "./pmStatusData";

  export default {
    name: "preventivemaintenance",
    components: {PmStatusData, Treeselect },
    props: ['item'],
    data() {
      return {
        drawer: false,
        direction: 'rtl',
        sonRefresh: true,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,
        // 预防性管理表格数据
        preventivemaintenanceList: [],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        clientHeight:300,
        // 是否显示弹出层
        open: false,
        // 装置名称字典
        plantCodeOptions: [],
        // 用户导入参数
        upload: {
          //下载模板请求地址
          downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
          //下载模板类型
          type: "preventivemaintenance",
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/reliability/preventivemaintenance/importData"
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          item: this.item
        },
        // 表单参数
        form: {},
        // 类型 1：CBPC 2：CTAB 3：CTMB字典
        itemOptions: [],
        // 一月字典
        janOptions: [],
        // 二月字典
        febOptions: [],
        // 三月字典
        marOptions: [],
        // 四月字典
        aprOptions: [],
        // 五月字典
        mayOptions: [],
        // 六月字典
        junOptions: [],
        // 七月字典
        julOptions: [],
        // 八月字典
        augOptions: [],
        // 九月字典
        sepOptions: [],
        // 十月字典
        octOptions: [],
        // 十一月字典
        novOptions: [],
        // 十二月字典
        decOptions: [],
        // 表单校验
        rules: {
          plantCode: [
            { required: true, message: this.$t('装置名称') + this.$t('不能为空'), trigger: "change" }
          ],
          item: [
            { required: true, message: this.$t('类型') + this.$t('不能为空'), trigger: "change" }
          ],
          deptId: [
            { required: true, message: this.$t('部门编号') + this.$t('不能为空'), trigger: "blur" }
          ]
        }
      };
    },
    watch: {
      // 根据名称筛选部门树
      deptName(val) {
        this.$refs.tree.filter(val);
      }
    },
    created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
        this.clientHeight = (document.body.clientHeight - 80) * 0.8
      })
      this.getList();
      this.getTreeselect();
      this.getDicts("PLANT_DIVIDE").then(response => {
        this.plantCodeOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.janOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.febOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.marOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.aprOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.mayOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.junOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.julOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.augOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.sepOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.octOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.novOptions = response.data;
      });
      this.getDicts("PRE_STATUS").then(response => {
        this.decOptions = response.data;
      });
      this.getDicts("PREVENTIVEMAINTENANCE_ITEM").then(response => {
        this.itemOptions = response.data;
      });
    },
    methods: {
      /** 查询预防性管理列表 */
      getList() {
        this.loading = true;
        listPreventivemaintenance(this.queryParams).then(response => {
          this.preventivemaintenanceList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      //根据分数显示颜色提示
      tableCellClassName({ row, column, rowIndex, columnIndex }) {
        if (columnIndex == 3){
          return this.changeColor(row.jan)
        }
        if (columnIndex == 4){
          return this.changeColor(row.feb)
        }
        if (columnIndex == 5){
          return this.changeColor(row.mar)
        }
        if (columnIndex == 6){
          return this.changeColor(row.apr)
        }
        if (columnIndex == 7){
          return this.changeColor(row.may)
        }
        if (columnIndex == 8){
          return this.changeColor(row.jun)
        }
        if (columnIndex == 9){
          return this.changeColor(row.jul)
        }
        if (columnIndex == 10){
          return this.changeColor(row.aug)
        }
        if (columnIndex == 11){
          return this.changeColor(row.sep)
        }
        if (columnIndex == 12){
          return this.changeColor(row.oct)
        }
        if (columnIndex == 13){
          return this.changeColor(row.nov)
        }
        if (columnIndex == 14){
          return this.changeColor(row.dec)
        }
      },
      changeColor (value) {
        if (value == 10){
          return 'cellCare'
        }else if( value == 12) {
          return 'cellFinish'
        }else if( value == 14) {
          return 'cellUrgent'
        }
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      // 装置名称字典翻译
      plantCodeFormat(row, column) {
        return this.selectDictLabel(this.plantCodeOptions, row.plantCode);
      },
      // 一月字典翻译
      janFormat(row, column) {
        return this.selectDictLabel(this.janOptions, row.jan);
      },
      // 二月字典翻译
      febFormat(row, column) {
        return this.selectDictLabel(this.febOptions, row.feb);
      },
      // 三月字典翻译
      marFormat(row, column) {
        return this.selectDictLabel(this.marOptions, row.mar);
      },
      // 四月字典翻译
      aprFormat(row, column) {
        return this.selectDictLabel(this.aprOptions, row.apr);
      },
      // 五月字典翻译
      mayFormat(row, column) {
        return this.selectDictLabel(this.mayOptions, row.may);
      },
      // 六月字典翻译
      junFormat(row, column) {
        return this.selectDictLabel(this.junOptions, row.jun);
      },
      // 七月字典翻译
      julFormat(row, column) {
        return this.selectDictLabel(this.julOptions, row.jul);
      },
      // 八月字典翻译
      augFormat(row, column) {
        return this.selectDictLabel(this.augOptions, row.aug);
      },
      // 九月字典翻译
      sepFormat(row, column) {
        return this.selectDictLabel(this.sepOptions, row.sep);
      },
      // 十月字典翻译
      octFormat(row, column) {
        return this.selectDictLabel(this.octOptions, row.oct);
      },
      // 十一月字典翻译
      novFormat(row, column) {
        return this.selectDictLabel(this.novOptions, row.nov);
      },
      // 十二月字典翻译
      decFormat(row, column) {
        return this.selectDictLabel(this.decOptions, row.dec);
      },
      // 类型 1：CBPC 2：CTAB 3：CTMB字典翻译
      itemFormat(row, column) {
        return this.selectDictLabel(this.itemOptions, row.item);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          plantCode: null,
          part: null,
          itemtag: null,
          tagno: null,
          maintcontents: null,
          maintperiod: null,
          responsibleby: null,
          executor: null,
          confirmedby: null,
          executionresult: null,
          quantity: null,
          year: null,
          jan: null,
          feb: null,
          mar: null,
          apr: null,
          may: null,
          jun: null,
          jul: null,
          aug: null,
          sep: null,
          oct: null,
          nov: null,
          dec: null,
          item: this.item,
          delFlag: null,
          createrCode: null,
          createdate: null,
          updaterCode: null,
          updatedate: null,
          remarks: null,
          deptId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.form.item = "";
        this.open = true;
        this.title = this.$t('新增') + " " + this.$t('预防性管理');
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getPreventivemaintenance(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = this.$t('修改') + this.$t('预防性管理');
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updatePreventivemaintenance(this.form).then(response => {
                this.msgSuccess(this.$t('修改成功'));
                this.open = false;
                this.getList();
              });
            } else {
              addPreventivemaintenance(this.form).then(response => {
                this.msgSuccess(this.$t('新增成功'));
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return delPreventivemaintenance(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess(this.$t('删除成功'));
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm(this.$t('是否确认导出所有预防性管理数据项?'), this.$t('警告'), {
          confirmButtonText: this.$t('确定'),
          cancelButtonText: this.$t('取消'),
          type: "warning"
        }).then(function() {
          return exportPreventivemaintenance(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = this.$t('用户导入');
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        this.$refs['downloadFileForm'].submit()
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        if (response.data[0] != null) {
          this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据') + "，" + this.$t('第') + response.data + this.$t('行数据出现错误导入失败')+"。", this.$t('导入结果'), { dangerouslyUseHTMLString: true });
        }else {
          this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据'), this.$t('导入结果'), { dangerouslyUseHTMLString: true });
        }
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      },
      //数据分析
      handleData(){
        this.sonRefresh= false;
        this.$nextTick(() => {
          this.sonRefresh= true;
        });
        this.drawer = true
      }
    }
  }
</script>
