<template>
  <div class="app-container">
    <el-card style="margin-top: 2px">
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="成品不合格" name="1">
       <el-table
        :data="wproductList.results"
        border
        fit
        stripe
        highlight-current-row
        max-height="600"
      >
        <el-table-column type="index" label="序号" width="50"/>
        <el-table-column label="产品编号">
          <template slot-scope="scope">{{ scope.row.number }}</template>
        </el-table-column>
        <el-table-column label="任务编号">
          <template slot-scope="scope" v-if="scope.row.subproduction_plan_">{{ scope.row.subproduction_plan_.number }}
          </template>
        </el-table-column>
        <el-table-column label="产品名称">
          <template slot-scope="scope" v-if="scope.row.material_">{{ scope.row.material_.name }}</template>
        </el-table-column>
        <el-table-column label="型号规格">
          <template slot-scope="scope" v-if="scope.row.material_">{{ scope.row.material_.specification }}</template>
        </el-table-column>
        <el-table-column label="军检状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.is_mtested==false">未军检</el-tag>
            <el-tag v-if="scope.row.is_mtested==true">已军检</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="军检结论">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.is_mtestok==false">不合格</el-tag>
            <el-tag v-if="scope.row.is_mtestok==true">合格</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="仓库">
          <template slot-scope="scope" v-if="scope.row.warehouse_">{{ scope.row.warehouse_.name }}</template>
        </el-table-column>
        <el-table-column label="检查表">
          <template slot-scope="scope">{{ scope.row.number }}</template>
        </el-table-column>
        <el-table-column label="检查状态">
          <template slot-scope="scope">{{ actstate_[scope.row.act_state]}}</template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="220px">
          <template slot-scope="scope">
            <el-link
              v-if="checkPermission(['warehouse_update'])&&scope.row.act_state==30&&scope.row.is_mtested==false"
              @click="handleMtest(scope)"
            >军检
            </el-link>
            <el-link
              @click="checkRecord(scope)"
            >检验记录
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="wproductList.count > 0"
        :total="wproductList.count"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.page_size"
        @pagination="getList"
      />
        </el-tab-pane>
        <el-tab-pane label="过程不合格品" name="2">
          <el-table
            :data="wproductticket.results"
            border
            fit
            stripe
            highlight-current-row
            height="620"
            v-el-height-adaptive-table="{ bottomOffset: 40 }"
          >
            <el-table-column type="index" width="50" />
            <el-table-column label="玻璃编号">
              <template slot-scope="scope">{{ scope.row.number }}</template>
            </el-table-column>
            <el-table-column label="订单编号">
              <template slot-scope="scope" v-if="scope.row.order_">{{
                scope.row.order_.number
              }}</template>
            </el-table-column>
            <el-table-column label="产品名称">
              <template slot-scope="scope" v-if="scope.row.product_">{{
                scope.row.product_.name
              }}</template>
            </el-table-column>
            <el-table-column label="规格型号">
              <template slot-scope="scope" v-if="scope.row.product_">{{
                scope.row.product_.specification
              }}</template>
            </el-table-column>
            <el-table-column label="责任工序">
              <template slot-scope="scope" v-if="scope.row.resp_process_">{{
                scope.row.resp_process_.name
              }}</template>
            </el-table-column>
            <el-table-column label="处理结果">
              <template slot-scope="scope">{{
                decision_[scope.row.decision]
              }}</template>
            </el-table-column>
            <el-table-column label="创建时间">
              <template slot-scope="scope">{{
                scope.row.create_time
              }}</template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-link
                  v-if="checkPermission(['material_update'])"
                  type="primary"
                  @click="handledetailbhg(scope)"
                  >查看</el-link
                >
              </template>
            </el-table-column>
          </el-table>
          <pagination
            v-show="wproductticket.count > 0"
            :total="wproductticket.count"
            :page.sync="listQuery2.page"
            :limit.sync="listQuery2.page_size"
            @pagination="getList2"
          />
       
        </el-tab-pane>
         <el-tab-pane label="入场不合格" name="4">
       <el-table
        v-loading="listLoading"
        :data="fifodetailList4.results"
        border
        fit
        stripe
        highlight-current-row
       height="620"
         v-el-height-adaptive-table="{bottomOffset: 40}"
      >
        <el-table-column type="index" width="50" />
         <el-table-column label="物料批次">
          <template slot-scope="scope">{{ scope.row.batch }}</template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">{{ scope.row.material_.name }}</template>
        </el-table-column>
  <el-table-column label="规格型号">
          <template slot-scope="scope">{{
            scope.row.material_.specification
          }}</template>
        </el-table-column>
         <el-table-column label="物料单位">
          <template slot-scope="scope">{{ scope.row.material_.unit }}</template>
        </el-table-column>
    
  <el-table-column label="创建时间">
          <template slot-scope="scope">{{ scope.row.create_time }}</template>
        </el-table-column>
      
      </el-table>
      <pagination
        v-show="fifodetailList4.count > 0"
        :total="fifodetailList4.count"
        :page.sync="listQuery4.page"
        :limit.sync="listQuery4.page_size"
        @pagination="getList4"
      />
    </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>
<script>
import { getProductionplanList } from "@/api/pm";
import { getwproductticketList,getwproductList } from "@/api/wpm";
import { ticketread } from "@/api/workflow";
import {  getfifodetailList} from "@/api/inm";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination

export default {
  components: { Pagination },
  data() {
    return {
     wproductList: {
        count: 0,
      },
       actstate_: {
          6: "待复检",
          10: "操作进行中",
          20: "待检验",
          30: "已合格",
          40: "库存中",
          50: "不合格",
          60: "待成品检验",
          8: "操作准备中",
          26: "待夹层检验",
          70: "报废",
        },
       listQuery: {
        page: 1,
        page_size: 20,
      },
        wproductticket: {
        count: 0,
      },
    
      listQuery2: {
        page: 1,
        page_size: 20,
      },
       customfieldList: [],
         activeName: "1",
        decision_: {
        10: "返工",
        20: "返修",
        30: "报废",
        40: "让步接受",
        50: "偏离许可",
        60: "降级使用",
        70: "退回供方",
        80: "召回",
      },
       listQuery4: {
        page: 1,
        page_size: 20,
      },
       fifodetailList4:{
        count: 0,
      },
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getList(); //成品不合格
    this.getList2(); //过程
    this.getList4();//入场不合格
  },
  methods: {
    checkPermission,
    //不合格成品
   
     getList() {
      this.listLoading = true;
     
     
        this.listQuery.material__type = 1;
         this.listQuery.tag='ok';
        getwproductList(this.listQuery).then((response) => {
          if (response.data) {
            this.wproductList = response.data;
          }
        });
   
    },

    //不合格玻璃审批工单列表
    getList2() {
      getwproductticketList(this.listQuery2).then((response) => {
        if (response.data) {
          this.wproductticket = response.data;
        }
      });
    },
    //不合格玻璃审理单查看
    handledetailbhg(scope)
    {
      
        this.$router.push({name:"ticketDetail",params:{ticketId:scope.row.ticket}})
    },
    //入场检验不合格
     //不合格物料
      getList4() {
      this.listLoading = true;
       this.listQuery4.fifo__type = 3;
      this.listQuery4.is_testok = false;
      this.listQuery4.is_tested = true;
      getfifodetailList(this.listQuery4).then((response) => {
        if (response.data) {
          this.fifodetailList4 = response.data;
        }
        this.listLoading = false;
      });
    },
  },
};
</script>
