<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="操作人" prop="operName">
        <el-input
          v-model="queryParams.operName"
          placeholder="请输入操作人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作时间" prop="operTime">
        <el-date-picker clearable size="small" style="width: 200px"
                        v-model="queryParams.operTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择操作时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="操作类型" prop="operType">
        <el-input
          v-model="queryParams.operType"
          placeholder="请输入操作类型"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('装置')" prop="plantCode" label-width="50">
        <el-input
          v-model="queryParams.plantCode"
          :placeholder="$t('请输入') + $t('装置')"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" ref="deviceTable" :data="ccList" :height="clientHeight" border>

      <el-table-column :label="$t('操作人员')" align="center" fixed="left" prop="operName" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('操作时间')" align="center" fixed="left" prop="operTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作类型')" align="center" fixed="left" prop="operType" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('装置')" align="center"  fixed="left" prop="plantCode" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('单元')" align="center"  fixed="left" prop="unit" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('使用部门')" align="center" fixed="left" prop="useDept" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('装置维修组')" align="center"  fixed="left" prop="plantMaint" :show-overflow-tooltip="true"/>

      <el-table-column :label="$t('装置维护人员')" align="center"  fixed="left" prop="engineer" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('车牌号')" align="center"  fixed="left" prop="carNo" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('档案号')" align="center"  fixed="left" prop="docno" :show-overflow-tooltip="true"/>
      <!--      <el-table-column :label="$t('状态')" align="center" fixed="left"  prop="status" :formatter="statusFormat" />-->
      <!--      <el-table-column :label="$t('申请状态')" align="center" fixed="left"  prop="approveStatus" :formatter="approveStatusFormat" />-->
      <el-table-column :label="$t('发动机号')" align="center" prop="engineNo" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('注册代码')" align="center" prop="regno" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('颜色')" align="center" prop="color" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('工作能力')+'(Ton)'" align="center" prop="capacity" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('设备品种(名称)')" align="center" prop="devname" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('动力形式')" align="center" prop="engineType" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('型号')" align="center" prop="model" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('车架（底盘）编号')" align="center" prop="frameNo" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('产品编号')" align="center" prop="productNo" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('生产厂家')" align="center" prop="createUnit" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('防爆改造厂家')" align="center" prop="exUnit" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('防爆级别')" align="center" prop="exGrade" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('初检日期')" align="center" prop="firstWarnDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstWarnDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('检验策略')" align="center" prop="checkStrategy" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('检验日期')" align="center" prop="warnDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.warnDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('下次检验日期')" align="center" prop="nextWarnDate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextWarnDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('报告编号')" align="center" prop="reportNo" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('定期检验结论')" align="center" prop="perTestConclusion" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('资产归属形式')" align="center" prop="assetOwner" :show-overflow-tooltip="true"/>
      <el-table-column :label="$t('备注')" align="center" prop="remarks" :show-overflow-tooltip="true"/>
    </el-table>

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

<script>
import { listCc, getCc, delCc, addCc, updateCc, exportCc, importTemplate} from "@/api/sems/his/cc";
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";

export default {
  name: "Cc",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 特种设备叉车台账历史表格数据
      ccList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      deptOptions: undefined,
      clientHeight:300,
      // 是否显示弹出层
      open: false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/his/cc/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        plantCode: null,
        carNo: null,
        devname: null,
        devno: null,
        submitdate: null,
        status: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null,
        remarks: null,
        approveStatus: null,
        regno: null,
        useno: null,
        warnDate: null,
        warnCycle: null,
        nextWarnDate: null,
        warnFlag: null,
        createUnit: null,
        checkStrategy: null,
        firstWarnDate: null,
        checkUnit: null,
        docno: null,
        approveTime: null,
        changeTime: null,
        engineNo: null,
        color: null,
        capacity: null,
        model: null,
        engineType: null,
        devClass: null,
        exUnit: null,
        useDept: null,
        engineer: null,
        exGrade: null,
        reportNo: null,
        frameNo: null,
        productNo: null,
        assetOwner: null,
        devId: null,
        hiType: null,
        unit: null,
        plantMaint: null,
        operName: null,
        operTime: null,
        operType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        plantCode: [
          { required: true, message: "装置名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    //设置表格高度对应屏幕高度
    this.$nextTick(() => {
      this.clientHeight = document.body.clientHeight -250
    })
    this.getList();
    this.getTreeselect();
  },
  methods: {
    /** 查询特种设备叉车台账历史列表 */
    getList() {
      this.loading = true;
      listCc(this.queryParams).then(response => {
        this.ccList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 搜索按钮操作 */
    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
    },
  }
};
</script>
