<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="关键字" prop="keyword">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入关键字"
          clearable
          maxlength="50"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="状态" prop="taskStatus">
        <el-select
          v-model="queryParams.taskStatus"
          placeholder="请选择状态"
          clearable
          filterable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.repair_end_task_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          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">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          >导出
        </el-button>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="testedList"
      ref="multipleTable"
      row-key="teamId"
    >
      <el-table-column label="序号" align="center" width="80" type="index">
        <template slot-scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="维修单号" align="center" prop="repairCode"  />
      <el-table-column label="物资类型" align="center" prop="maTypeName"  />
      <el-table-column label="工程名称" align="center" prop="projectName"  />
      <el-table-column label="单位名称" align="center" prop="unitName"  />
      <el-table-column label="维修人员" align="center" prop="wxName"  />
      <el-table-column label="维修时间" align="center" prop="wxTime"  />
      <el-table-column label="状态" align="center" prop="taskStatus" >
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.repair_end_task_status"
            :value="scope.row.taskStatus"
          />
        </template>
      </el-table-column>
     
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            style="margin-bottom: 10px"
            type="normal"
            @click="handleView(scope.row)"
            >查看
          </el-button>
          <el-button
            size="mini"
            style="margin-bottom: 10px"
            type="primary"
  
            @click="handleUpdate(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
      :title="title"
      :visible.sync="showView"
      width="1100px"
      append-to-body
    >
      <el-form
        :model="queryInBoundInfo"
        ref="queryFormOutInfo"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item prop="typeId">
          <el-input
            v-model="queryInBoundInfo.typeId"
            placeholder="请输入规格型号"
            clearable
            @keyup.enter.native="handleQueryView"
            maxlength="20"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQueryView"
            >查询</el-button
          >
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="resetQueryView"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            size="mini"
            @click="handleSuccessAll"
            v-if="title=='审核'"
            >批量通过
          </el-button>
        </el-col>
       <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            size="mini"
            @click="handleFailAll"
            v-if="title=='审核'"
            >批量不通过
          </el-button>
        </el-col>
      </el-row>

      <el-table :data="getInBoundInfo" width="600px" height="450" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"  :selectable="selectable"/>
        <el-table-column label="类型名称" align="center" prop="typeName2" :show-overflow-tooltip="true"/>
        <el-table-column label="规格型号" align="center" prop="typeName" :show-overflow-tooltip="true"/>
        <el-table-column label="数量" align="center" prop="repairNum" :show-overflow-tooltip="true" />
        <el-table-column label="编号" align="center" prop="maCode" :show-overflow-tooltip="true" />
        <el-table-column label="提交人" align="center" prop="updateBy" :show-overflow-tooltip="true" />
        <el-table-column label="提交时间" align="center" prop="updateTime" :show-overflow-tooltip="true" />
        <el-table-column label="状态" align="center" prop="status" >
        <!-- <template slot-scope="scope">
          <dict-tag
            :options="dict.type.repair_end_task_status"
            :value="scope.row.taskStatus"
          />
        </template> -->
      </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="200px"
          v-if="title=='审核'"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="success"
              @click="InBoundSuccess(scope.row)"
              v-if="scope.row.status != '已入库' "
            >
              通过
            </el-button>
            <el-button
              size="mini"
              type="danger"
              v-if="scope.row.status != '已入库' "
              @click="InBoundFail(scope.row)"
            >
              不通过
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="totalView > 0"
        :total="totalView"
        :page.sync="queryInBoundInfo.pageNum"
        :limit.sync="queryInBoundInfo.pageSize"
        @pagination="getListView"
      />
    </el-dialog>
  </div>
</template> 
  
  <script>
import {
  getTestedListApi,
  getTestedDetailListApi
} from "@/api/repair/testedInBound";
import { downloadFile } from "@/utils/download";
export default {
  name: "testedInBound",
  dicts: ["repair_end_task_status"],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,

      // 显示搜索条件
      showSearch: true,
      // 查看页面
      showView: false,

      // 总条数
      total: 0,
      //二级页面总条数
      totalView:0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyWord: undefined,
      },
      queryInBoundInfo:{
        pageNum: 1,
        pageSize: 10,
      },

      //修试入库列表
      testedList:[],
      //审核入库列表
      getInBoundInfo:[]
    };
  },
  created() {
    this.getList();
  },
  components: {},
  methods: {
    //是否可用勾选框
    selectable(row) {
      if (row.taskStatus == "1" && this.title=="审核") {
        return false;
      } else {
        return true;
      }
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 查询修试入库列表 */
    getList() {
      this.loading = true;
      getTestedListApi(this.queryParams).then((response) => {
        this.testedList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.keyWord = null;
      this.handleQuery();
    },
    
    //一级页面查看按钮
    handleView(row){
      // this.getListView()
      this.title = "查看"
      getTestedDetailListApi(row.id).then((response) => {
        this.getInBoundInfo = response.rows;
        this.totalView = response.total;
        this.loading = false;
      });
      // this.getInBoundInfo = [
      //   {'typeName':'p1','taskStatus':0},
      //   {'typeName':'p2','taskStatus':1}
      // ]
      this.showView = true;
    },

    getListView(){

    },

    //一级页面审核按钮
    handleUpdate(row){
      // this.getListView()
      this.title = "审核"
      getTestedDetailListApi(row.id).then((response) => {
        this.getInBoundInfo = response.rows;
        this.totalView = response.total;
        this.loading = false;
      });
      // this.getInBoundInfo = [
      //   {'typeName':'p1','taskStatus':0},
      //   {'typeName':'p2','taskStatus':1}
      // ]
      // this.totalView = 2
      this.showView = true;
    },

    //通过
    InBoundSuccess(row){

    },

    //不通过
    InBoundFail(row){

    },

    //批量通过
    handleSuccessAll(){

    },
    
    //批量不通过
    handleFailAll(){

    },

    //二级页面查询
    handleQueryView(){
      
    },

    //二级页面表单重置
    resetQueryView(){
      this.queryInBoundInfo = {};
      this.resetForm("queryInBoundInfo");
    },

    //** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.houseId != undefined) {
            editHouse(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.showHouse = false;
              this.getList();
            });
          } else {
            addHouse(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.showHouse = false;
              this.getList();
            });
          }
        }
      });
    },

    // 取消按钮
    cancel() {
      this.showHouse = false;
      this.reset();
    },


    handleExport() {
      // this.download(
      //   "/material/wh_house_info/export",
      //   {
      //     ...this.queryParams,
      //   },
      //   `修饰入库_${new Date().getTime()}.xlsx`
      // );
    },

  },
};
</script>
  <style lang="scss" scoped>
.uploadImg {
  padding-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.deviceCode {
  margin-top: 10px;
  padding-bottom: 20px;
  font-size: 18px;
}
::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;
  }
}
</style>