<template>
  <div>
    <el-form
      :model="maForm"
      ref="maForm"
      size="small"
      :inline="true"
      label-width="120px"
    >
      <el-form-item label="退料单位" prop="backUnit">
        <el-input
          v-model="maForm.backUnit"
          placeholder="请输入退料单位"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          disabled
        />
      </el-form-item>
      <el-form-item label="退料工程" prop="backPro">
        <el-input
          v-model="maForm.backPro"
          placeholder="请输入退料工程"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          disabled
        />
      </el-form-item>
      <el-form-item label="报废单号" prop="scrapCode">
        <el-input
          v-model="maForm.scrapCode"
          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-check"
          size="mini"
          :disabled="multiple"
          @click="handlePassAll"
          >通过</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-close"
          size="mini"
          :disabled="multiple"
          @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"
        :selectable="selectable"
      /> -->
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column
        label="类型名称"
        align="center"
        prop="typeName"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="规格型号"
        align="center"
        prop="typeModelName"
        :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="repairNum"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="已修数量"
        align="center"
        prop="repairedNum"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="报废数量"
        align="center"
        prop="scrapNum"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="设备编码"
        align="center"
        prop="code"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="费用合计(元)"
        align="center"
        prop="totalCost"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="报废原因"
        align="center"
        prop="scrapReason"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="附件"
        align="center"
        prop="fileList" width="300"
      >
        <template slot-scope="scope">
          <img v-for="(item,index) in scope.row.fileList" :key="index" width="100px" height="100px" :src="item.url.replaceAll('#','%23')"  />
              <!-- <div v-if="scope.row.manageType==0">编码管理</div>
              <div v-if="scope.row.manageType==1">数量管理</div> -->
        </template>
      </el-table-column>
      <el-table-column
        label="审核状态"
        align="center"
        prop="status"
        :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.status == '0'" style="color: #e6a23c">
            {{ "未审核" }}
          </div>
          <div v-if="scope.row.status == '1'" style="color: #67c23a">
            {{ "已审核" }}
          </div>
          <div v-if="scope.row.status == '2'" style="color: #f56c6c">
            {{ "驳回" }}
          </div>
          <!-- <div v-else style="color: red;"></div> -->
        </template>
      </el-table-column>
      <!-- <el-table-column label="操作" align="center" width="300">
        <template slot-scope="scope">
          <el-button
            size="mini"
            style="margin-bottom: 10px"
            type="success"
            v-if="scope.row.status == '0'"
            @click="handlePass(scope.row)"
            >通过
          </el-button>

          <el-button
            size="mini"
            type="danger"
            @click="handleFail(scope.row)"
            v-if="scope.row.status == '0'"
            >驳回
          </el-button>
          <div v-if="scope.row.status != '0'">-</div>
        </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 { getScrapDetailListApi,batchRejectApi, batchPassApi } from "@/api/repair/scrapManage";
import { getToken } from "@/utils/auth";
export default {
  name: "AddTools",
  components: {
    // UploadImg,
  },
  props: {
    isEdit: {
      type: Boolean,
      default: () => {
        return false;
      },
    },
    queryTaskId: {
      type: [String, Number],
      default: () => {
        return "";
      },
    },
    queryId: {
      type: [String, Number],
      default: () => {
        return "";
      },
    },
    agreementId: {
      type: [String, Number],
      default: () => {
        return "";
      },
    },
    param: {
      type: Object,
      default: () => {
        return "";
      },
    },
  },
  data() {
    return {
      paramTemp: {},
      //任务ID
      taskId: "",
      // 遮罩层
      loading: true,
      total: 0,
      //租赁单位
      uniteList: [],
      //租赁工程
      projectList: [],
      // 表格数据
      equipmentList: [],
      passTemp: [],
      faliTemp: [],
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 是否显示弹出层
      open: false,
      rowData: {},
      maForm: {
        backUnit: undefined,
        backPro: undefined,
        scrapCode: undefined,
      },
    };
  },
  computed: {},
  mounted() {
    this.taskId = this.queryTaskId;
    this.paramTemp = this.param;
    this.maForm = this.paramTemp;
    this.getTaskInfo();
  },
  methods: {
    //获取任务详情-列表数据
    getTaskInfo() {
      this.loading = true;
      getScrapDetailListApi({ taskId: this.taskId }).then((response) => {
        this.maForm = this.paramTemp;
        this.equipmentList = response.data;
        // this.total = response.total;
        this.loading = false;
      });
    },
    //单个通过
    handlePass(row) {
      const param = [];
      param.push({ id: row.id, status: "1",specificationType: row.specificationType,machineTypeName:row.machineTypeName,
        unitName:row.unitName,repairNum:row.repairNum,repairedNum:row.repairedNum,typeId:row.typeId,taskId:row.taskId,
        auditId:row.id,repairId:row.repairId,maId:row.maId, });
      this.$modal
        .confirm("是否确认通过所选择的数据项？")
        .then(function () {
          // return auditPass(param);
        })
        .then(() => {
          // this.getTaskInfo();
          // this.$modal.msgSuccess("通过成功");
        })
        .catch(() => {});
    },
    //单个驳回
    handleFail(row) {
      const param = [];
      param.push({ id: row.id, status: "2",specificationType: row.specificationType,machineTypeName:row.machineTypeName,
        unitName:row.unitName,repairNum:row.repairNum,repairedNum:row.repairedNum,typeId:row.typeId,taskId:row.taskId,
        auditId:row.id,repairId:row.repairId,maId:row.maId,
       });
      this.$modal
        .confirm("是否确认驳回所选择的数据项？")
        .then(function () {
          // return auditPass(param);
        })
        .then(() => {
          // this.getTaskInfo();
          // this.$modal.msgSuccess("驳回成功");
        })
        .catch(() => {});
    },
    //是否可用勾选框
    selectable(row) {
      if (row.status == "0") {
        return true;
      } else {
        return false;
      }
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.passTemp = [];
      this.failTemp = [];
      this.ids = selection.map((item) => item.id);
      selection.forEach((item) => {
        this.passTemp.push({ id: item.id});
      });
      console.log(this.agreementId)
      selection.forEach((item) => {
        let obj=item;
        obj.agreementId=this.agreementId
        this.failTemp.push(obj);
      });
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    //多个通过
    handlePassAll() {
      if (this.ids.length == 0) {
        this.$alert("请至少勾选一条审核数据", "提示", {
          type: "warning",
          confirmButtonText: "确定",
        });
        return;
      } else {
        batchPassApi({'scrapApplyDetailsList':this.passTemp}).then((response) => {
          if (response.code == 200) {
            this.$modal.msgSuccess("通过成功");
          }
          this.getTaskInfo();
        });
      }
    },
    //多个驳回
    handleFailAll() {
      if (this.ids.length == 0) {
        this.$alert("请至少勾选一条审核数据", "提示", {
          type: "warning",
          confirmButtonText: "确定",
        });
        return;
      } else {
        batchRejectApi({'scrapApplyDetailsList':this.failTemp}).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>
