<template>
  <div>
    <el-form
      :model="maForm"
      ref="maForm"
      size="small"
      :rules="rules"
      :inline="true"
      label-width="120px"
    >
      <el-form-item label="退料单位" prop="unitName">
        <el-input
          v-model="maForm.unitName"
          placeholder="请输入退料单位"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          disabled
        />
      </el-form-item>
      <el-form-item label="工程名称" prop="projectName">
        <el-input
          v-model="maForm.projectName"
          placeholder="请输入工程名称"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          disabled
        />
      </el-form-item>
      <el-form-item label="维修单号" prop="repairNum">
        <el-input
          v-model="maForm.repairNum"
          placeholder="请输入维修单号"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          disabled
        />
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handlePassAll"
          >合格</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleFailAll"
          >驳回</el-button
        >
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="equipmentList"
      row-key="id"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column
        label="类型名称"
        align="center"
        prop="maTypeName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="规格型号"
        align="center"
        prop="typeName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="计量单位"
        align="center"
        prop="unitName"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="退料数量"
        align="center"
        prop="storageNum"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="已修数量"
        align="center"
        prop="preNum"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="待修数量"
        align="center"
        prop="alNum"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="管理模式"
        align="center"
        prop="alNum"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            style="margin-bottom: 10px"
            type="primary"
            @click="handlePass(scope.row)"
            >通过
          </el-button>

          <el-button size="mini" type="danger" @click="handleFail(scope.row)"
            >驳回
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="maForm.pageNum"
      :limit.sync="maForm.pageSize"
      @pagination="getTaskInfo"
    />
  </div>
</template>

<script>
import { getAuditInfo } from "@/api/repair/testExamine";
import { getToken } from "@/utils/auth";
export default {
  name: "QueryTools",
  components: {
    // UploadImg,
  },
  props: {
    isView: {
      type: Boolean,
      default: () => {
        return false;
      },
    },
    queryTaskId: {
      type: [String, Number],
      default: () => {
        return "";
      },
    },
    queryId: {
      type: [String, Number],
      default: () => {
        return "";
      },
    },
    param: {
      type: Object,
      default: () => {
        return "";
      },
    },
  },
  data() {
    return {
      paramTemp: {},
      //任务ID
      taskId: "",
      // 遮罩层
      loading: true,
      total: 0,
      //租赁单位
      uniteList: [],
      //租赁工程
      projectList: [],
      // 表格数据
      equipmentList: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 是否显示弹出层
      open: false,
      rowData: {},
      maForm: {
        pageNum: 1,
        pageSize: 10,
        unitName: undefined,
        projectName: undefined,
        repairNum: undefined,
      },
    };
  },
  computed: {},
  mounted() {
    this.taskId = this.queryTaskId;
    this.paramTemp = this.param;
    this.getTaskInfo();
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    //获取任务详情-列表数据
    getTaskInfo() {
      this.loading = true;
      getAuditInfo({ taskId: this.taskId }).then((response) => {
        this.maForm = this.paramTemp;
        this.equipmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handlePass(row) {
      this.$modal
        .confirm("是否确认合格所选择的数据项？")
        .then(function () {
          // return applySend(row.id);
        })
        .then(() => {
          this.getTaskInfo();
          this.$modal.msgSuccess("合格成功");
        })
        .catch(() => {});
    },
    handleFail(row) {
      this.$modal
        .confirm("是否确认驳回所选择的数据项？")
        .then(function () {
          // return applySend(row.id);
        })
        .then(() => {
          this.getTaskInfo();
          this.$modal.msgSuccess("驳回成功");
        })
        .catch(() => {});
    },
    handlePassAll() {
      if (this.ids.length == 0) {
        this.$alert("请至少勾选一条审核数据", "提示", {
          type: "warning",
          confirmButtonText: "确定",
        });
        return;
      } else {
        // applySendAll(this.sendTemp).then((response) => {
        //   if (response.code == 200) {
        //     this.$modal.msgSuccess("合格成功");
        //   }
        //  this.getTaskInfo();
        // });
      }
    },
    handleFailAll() {
      if (this.ids.length == 0) {
        this.$alert("请至少勾选一条审核数据", "提示", {
          type: "warning",
          confirmButtonText: "确定",
        });
        return;
      } else {
        // applySendAll(this.sendTemp).then((response) => {
        //   if (response.code == 200) {
        //     this.$modal.msgSuccess("驳回成功");
        //   }
        //  this.getTaskInfo();
        // });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep.el-table .fixed-width .el-button--mini {
  width: 60px !important;
  margin-bottom: 10px;
}
//隐藏图片上传框的css
::v-deep.disabled {
  .el-upload--picture-card {
    display: none;
  }
}
.custom-textarea {
  width: 300px;
  height: 100px;
}
.accept-img {
  color: #409eff;

  .a-two {
    margin-left: 20px;
  }
}

.left-tip {
  font-size: 16px;
  letter-spacing: 1px;
}
</style>
