<template>
  <div class="name">
    <el-card class="mt10 box-card">
      <div class="lcl-title">设备校准</div>
      <el-button type="primary" icon="el-icon-plus" @click="handleAdd"
        >新增</el-button
      >
      <div class="mt10" id=" radar-table">
        <!-- <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="68px"
          class="mt10"
        >
          <el-form-item label="审核状态" prop="status">
            <el-select
              v-model="queryParams.status"
              placeholder="审核状态"
              clearable
              style="width: 240px"
            >
              <el-option
                v-for="item in statusList"
                :key="item.val"
                :label="item.lable"
                :value="item.val"
              />
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="getList"
              >搜索</el-button
            >
          </el-form-item>
        </el-form> -->
        <el-table
          :data="dataList"
          border
          stripe
          style="width: 100%"
          :header-cell-style="{
            textAlign: 'center',
            height: '1.25rem',
          }"
          :row-style="{ height: '1.25rem' }"
        >
          <el-table-column
            align="center"
            prop="calibrationAuditName"
            label="校准人"
          >
          </el-table-column>
          <el-table-column align="center" prop="creatTime" label="校准时间">
          </el-table-column>
          <el-table-column
            align="center"
            prop="calibrationType"
            label="校准类型"
          >
            <template slot-scope="scope">
              <span v-if="scope.row.calibrationType == 1">年度校准</span>
              <span v-if="scope.row.calibrationType == 2">局部校准</span>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="insStatus" label="审核状态">
            <template slot-scope="scope">
              <el-tag
                class="subject-btn"
                type="warning"
                v-if="scope.row.status == 0"
                >等待审核</el-tag
              >
              <el-tag
                class="subject-btn"
                type="success"
                v-if="scope.row.status == 1"
                >审核通过</el-tag
              >
              <el-tag
                class="subject-btn"
                type="danger"
                v-if="scope.row.status == 2"
                >审核未通过</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            class-name="small-padding fixed-width"
            label="操作"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleEdit(scope.row)"
                v-if="scope.row.status != 0"
                >查看</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleEdit(scope.row)"
                v-if="scope.row.status == 0"
                >修改</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDel(scope.row)"
                >删除</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
          width="30%"
          :inline="true"
          :title="title"
          :visible.sync="watchDialog"
          :close-on-press-escape="false"
          :close-on-click-modal="false"
        >
          <el-dialog
            width="30%"
            title="审核"
            :visible.sync="innerCheckVisible"
            append-to-body
            :close-on-press-escape="false"
            :close-on-click-modal="false"
          >
            <!-- <el-form :model="form" :rules="checkRules">
              <el-form-item label="理由" prop="remark">
                <el-input
                  v-model="form.remark"
                  autocomplete="off"
                ></el-input>
              </el-form-item>
            </el-form> -->
            <div slot="footer" class="dialog-footer" v-if="form.status == 0">
              <el-button type="danger" @click="checkResult(2)"
                >不通过</el-button
              >
              <el-button type="success" @click="checkResult(1)"
                >通 过</el-button
              >
            </div>
          </el-dialog>
          <el-button
            type="primary"
            size="medium"
            @click="checkDia"
            v-if="checkStatus && form.status == 0"
            >审核</el-button
          >
          <el-form label-width="80px" style="overflow: hidden">
            <el-col :span="12">
              <el-form-item label="校准人" required>
                <el-input
                  style="width: 100%"
                  v-model="form.calibrationAuditName"
                  placeholder="请填写校准人"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="校准日期" required>
                <el-form-item prop="form.creatTime">
                  <el-date-picker
                    type="date"
                    placeholder="选择校准日期"
                    v-model="form.creatTime"
                    value-format="yyyy-MM-dd"
                    style="width: 100%"
                  ></el-date-picker>
                </el-form-item>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="校准类型" required>
                <el-select
                  v-model="form.calibrationType"
                  placeholder="请选校准类型"
                  style="width: 100%"
                >
                  <el-option label="年度校准" value="1"></el-option>
                  <el-option label="局部校准" value="2"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="校准设备" required>
                <el-checkbox-group v-model="form.ids">
                  <el-checkbox
                    v-for="item in calibrationOptions"
                    :key="item.dictSort"
                    :label="item.dictCode"
                    >{{ item.dictLabel }}</el-checkbox
                  >
                </el-checkbox-group>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="校准记录">
                <el-input type="textarea" v-model="form.remark"></el-input>
              </el-form-item>
            </el-col>
          </el-form>
          <span v-if="form.status != 0 && form.id"
            >审核人：{{ form.auditPerson }}</span
          >

          <div class="shenhe shenhe1" v-if="form.status == 1 && form.id">
            <span>审核通过</span>
          </div>
          <div class="shenhe shenhe2" v-if="form.status == 2 && form.id">
            <span>审核未通过</span>
          </div>

          <div slot="footer" class="dialog-footer">
            <el-button @click="watchDialog = false">取 消</el-button>
            <el-button
              type="primary"
              @click="submitForm"
              v-if="form.status == 0"
              >提 交</el-button
            >
          </div>
        </el-dialog>
      </div>
    </el-card>
  </div>
</template>
<script>
// import { api } from '@vue/api'
import {
  calibrationList,
  calibrationAdd,
  pointList,
  calibrationAdult,
  calibrationEdit,
  calibrationDel,
} from "@/api/lclApi/lclapi";
import { getDicts } from "@/api/system/dict/data";
export default {
  name: "name",
  components: {},
  props: [],
  data() {
    return {
      buttonIcon: "edit",
      watchDialog: false,
      innerCheckVisible: false,
      checkStatus: false,
      statusList: [
        { lable: "全部", val: 4 },
        { lable: "未审核", val: 0 },
        { lable: "审核通过", val: 1 },
        { lable: "审核未通过", val: 2 },
      ],
      //审核规则
      checkRules: {
        remark: [{ required: true, message: "请输入理由", trigger: "blur" }],
      },
      title: null,
      form: {},
      formview: {
        ren: "钟志新",
        time: "2023-03-25",
        watchSub: null,
        val: null,
        type: "年度校准",
        ids: ["智能监测机器人", "爆破振动监测"],
        mark: "表面位移监测9#设备校准精度无法满足监测要求，需更换。地下水位监测2#设备校准精度无法满足监测要求，需更换。其他设备均校准完成",
      },
      dataList: [
        { ren: "钟志新", time: "2023-03-25", type: "年度校准", shen: "张文涛" },
      ],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
      },
      calibrationOptions: [],
    };
  },
  watch: {},
  created() {
    this.$nextTick(function () {
      getDicts("slope_calibration_name").then((response) => {
        this.calibrationOptions = response.data;
      });
    });
  },
  mounted() {
    this.$nextTick(function () {
      this.getList();
    });
  },
  methods: {
    formreset() {
      this.form = {
        id: null,
        calibrationAuditName: null,
        creatTime: null,
        watchSub: null,
        calibrationType: null,
        ids: [],
        remark: null,
        status: 0,
      };
    },
    //审核窗口
    checkDia() {
      this.innerCheckVisible = true;
    },
    //通不通过你说了算
    checkResult(val) {
      // if (!this.form.remark && val === 2) {
      //   this.$message({
      //     message: "请填写不通过的理由",
      //     type: "error",
      //   });
      //   return;
      // }
      let data = {
        status: val,
        id: this.form.id,
      };
      calibrationAdult(data).then((res) => {
        console.log(res);
        if (res && res.code === 200) {
          this.getList();
          this.innerCheckVisible = false;
          this.watchDialog = false;
          this.$message({
            message: "提交成功",
            type: "success",
          });
        }
      });
    },
    //设备校准列表
    getList() {
      calibrationList(this.queryParams).then((res) => {
        if (res && res.code === 200 && res.rows) {
          this.dataList = res.rows;
          this.total = res.total;
        }
      });
    },

    handleView(row) {
      console.log(row);
      this.watchDialog1 = true;
    },
    handleAdd() {
      this.title = "新增设备校准";
      this.formreset();
      this.watchDialog = true;
    },
    handleEdit(row) {
      if (row.status == 0) {
        this.checkStatus = true;
        this.title = "修改设备校准";
      } else {
        this.checkStatus = false;
        this.title = "查看设备校准";
      }
      this.formreset();
      this.form = row;
      this.watchDialog = true;
    },
    submitForm() {
      console.log(this.form, "form");
      if (this.form.id) {
        calibrationEdit(this.form).then((res) => {
          if (res && res.code === 200) {
            this.getList();
            this.$message({
              message: "修改成功",
              type: "success",
            });
            this.watchDialog = false;
          }
        });
      } else {
        calibrationAdd(this.form).then((res) => {
          if (res && res.code === 200) {
            this.getList();
            this.$message({
              message: "新增成功",
              type: "success",
            });
            this.watchDialog = false;
          }
        });
      }
    },
    handleDel(row) {
      let that = this;
      const id = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除？")
        .then(function () {
          calibrationDel(id).then((res) => {
            if (res.code === 200) {
              that.getList();
              that.$modal.msgSuccess("删除成功");
            }
          });
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.name {
  width: 100%;
  min-height: 100%;
  .box-card {
    width: 100%;
    .lcl-title {
      font-size: 22px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #333333;
      line-height: 30px;
      position: relative;
      padding-left: 10px;
      &:before {
        content: "";
        position: absolute;
        left: 0;
        top: 4px;
        width: 4px;
        height: 22px;
        background: #0d85f4;
      }
    }
  }
}
.cb {
  clear: both;
}
.shenhe {
  border: 3px solid #db1316;
  width: 270px;
  height: 86px;
  border-radius: 5px;
  padding: 5px;
  box-sizing: border-box;
  overflow: hidden;
  position: absolute;
  right: 10px;
  bottom: 40px;
  z-index: 100;
  transform: rotate(-10deg);
  pointer-events: none;
  span {
    display: inline-block;
    width: 100%;
    height: 70px;
    text-align: center;
    color: #fff;
    border-radius: 5px;
    background-color: #db1316;
    font-size: 40px;
    line-height: 70px;
    font-weight: bold;
  }
}
.shenhe0 {
  border: 3px solid #e6a23c;
  span {
    background-color: #e6a23c;
  }
}
.shenhe1 {
  border: 3px solid #67c23a;
  span {
    background-color: #67c23a;
  }
}
.shenhe2 {
  border: 3px solid #f56c6c;
  span {
    background-color: #f56c6c;
  }
}
</style>