<template>
  <div class="app-container">
    <el-card style="margin-top: 2px">
      <el-descriptions title="任务详情" :column="5" border  style="margin-bottom: 20px">
  <el-descriptions-item label="任务编号">{{productionplan.number}}</el-descriptions-item>
  <el-descriptions-item label="产品名称" v-if="productionplan.product_">{{productionplan.product_.name}}</el-descriptions-item>
  <el-descriptions-item label="规格型号" v-if="productionplan.product_">{{productionplan.product_.specification}}</el-descriptions-item>
  <el-descriptions-item label="生产状态">{{state_[productionplan.state]}}</el-descriptions-item>
   <el-descriptions-item label="不合格品数量">不合格数没有</el-descriptions-item>
</el-descriptions>
     
      <el-tabs v-model="activeName" type="card"  >
    <el-tab-pane label="玻璃" name="1" >
        <el-table
                :data="wproduct"
                border
                fit
                stripe
                style="width: 100%"
               height="500"
              >
               
                <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"  >{{
                    scope.row.step_.name
                  }}</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(['material_delete'])"
              type="primary"
              @click="handleoption(scope)"
              >查看</el-link
            >
          </template>
        </el-table-column>
              
               
              </el-table>

    </el-tab-pane>
     <el-tab-pane label="工序" name="2" >
         <el-table
                :data="process_json"
                border
                fit
                stripe
                style="width: 100%"
               height="500"
              >
               
                <el-table-column type="index" width="50" />
              

                <el-table-column label="工序名称" >
                  <template slot-scope="scope" >{{ scope.row.process_name }}</template>
                </el-table-column>
                 <el-table-column label="玻璃数量" >
                  <template slot-scope="scope" >{{ scope.row.count_real }}</template>
                </el-table-column>
                
                 <el-table-column label="合格数量" >
                  <template slot-scope="scope" >{{ scope.row.count_ok }}</template>
                </el-table-column>
                
                 <el-table-column label="不合格数量" >
                  <template slot-scope="scope" >{{ scope.row.count_notok }}</template>
                </el-table-column>
                
                  
               <el-table-column
          align="center"
          label="过程记录"
          width="220px"
        >
          <template slot-scope="scope">
          
            <el-link
              v-if="checkPermission(['material_delete'])"
              type="primary"
              @click="handleprocess(scope)"
              >查看</el-link
            >
          </template>
        </el-table-column>
              
               
              </el-table>
    </el-tab-pane>
      </el-tabs>
    </el-card>

  

    
  </div>
</template>
<script>

import { getProductionplan,getsubproductionplanList } from "@/api/pm";
import {  getwproductList} from "@/api/wpm";
import checkPermission from "@/utils/permission";

import {getTestRecord} from "@/api/qm";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination

export default {
  components: { Pagination },
  data() {
    return {
     productionplan:{
       number:""
     },
     activeName:"1",
     wproduct:[],
      subproductionplanList: "",
      listQuery: {
        page: 1,
        page_size: 20,
      },
     state_:{
        10:'制定中',
        20:'已下达',
        30:'已接受',
        40:'生产中',
        50:'已完成',
         60:'军检完成'},
       actstate_: {
        6: "待复检",
        10: "操作进行中",
        20: "待检验",
        30: "已合格",
        40: "库存中",
        50: "不合格",
        60: "待成品检验",
        8: "操作准备中",
        26: "待夹层检验",
        70: "报废",
      },
      process_json:null,
      productionplanID:null,
    };
  },
  computed: {},
  watch: {},
  created() {
     this.id = this.$route.params.id;
     this.getList();
     this.getspList();
     this.getwproductList();
     
  },
  methods: {
    checkPermission,

     getList() {
      getProductionplan(this.id).then((response) => {
        if (response.data) {
          this.productionplan = response.data;
          this.productionplanID=response.data.id;
         
          let process_json = [];
          for(let item in response.data.process_json){
            let obj = new Object();
            obj = response.data.process_json[item];
            process_json.push(obj)
          }
          
         
          this.process_json= process_json;
        }
        
      });
    },
     getspList() {
     
      getsubproductionplanList({page:0,production_plan:this.id}).then((response) => {
        if (response.data) {
          this.subproductionplanList = response.data;
        }
      
      });
      
    },
    getwproductList()
    {
      getwproductList({production_plan:this.id,page:0,}).then((response) => {
        if (response.data) {
          this.wproduct = response.data;
        }
        
      });
    },
    //查看该玻璃检验记录表
    handleoption(scope){

        this.$router.push({name: "taskrecordfrom", params: { id: scope.row.id ,productionplanid:this.id ,number:scope.row.number,process:scope.row.step_.name}, })
    
    },
    //查看工序对应的玻璃
    handleprocess (scope){

        this.$router.push({name: "wproduct", params: { id: scope.row.process,productionplanid:this.id} })
    
    }
  },
};
</script>
