<template>
  <div class="app-container">
  
    <el-card style="margin-top: 2px">
      <el-descriptions title="基本信息" direction="vertical" :column="8" border>
  <el-descriptions-item label="客户名称" v-if="salesdetail.customer">  {{salesdetail.customer_.name}}</el-descriptions-item>
  <el-descriptions-item label="产品名称" v-if="salesdetail.product">  {{salesdetail.product_.name}}</el-descriptions-item>
  <el-descriptions-item label="产品型号" :span="2" v-if="salesdetail.product">  {{salesdetail.product_.specification}}</el-descriptions-item>
  <el-descriptions-item label="订单编号" v-if="salesdetail.order">  {{salesdetail.order_.number}} </el-descriptions-item>
  <el-descriptions-item label="合同名称" v-if="salesdetail.order"> {{salesdetail.order_.contract_.name}}</el-descriptions-item>
</el-descriptions>
<el-card class="box-card">
  <div slot="header" class="clearfix">
    <span>关联产品信息</span>
  </div>
<el-table
    ref="singleTable"
    :data="saleproduct"
    highlight-current-row
    style="width: 100%">
   
  
      <el-table-column type="index" width="50" />
        <el-table-column label="产品编号"   show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.number }}</template>
        </el-table-column>
       
        <el-table-column label="产品名称"  show-overflow-tooltip>
          <template slot-scope="scope" >{{ scope.row.iproduct_.material_.name }}</template>
        </el-table-column>
         <el-table-column label="批次" >
          <template slot-scope="scope" >{{ scope.row.iproduct_.batch }}</template>
        </el-table-column>
         <el-table-column label="仓库">
          <template slot-scope="scope">{{ scope.row.iproduct_.warehouse_.name }}</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-else>已军检</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-else>合格</el-tag></template>

        </el-table-column>

        
          <el-table-column
          align="center"
          label="操作"
          width="220px"
        >
          <template slot-scope="scope">
           
          
            <el-link
              v-if="checkPermission(['warehouse_delete'])"
              type="danger"
              @click="handleDelete(scope)"
              >删除</el-link
            >
          </template>
        </el-table-column>
        
  </el-table>
  </el-card>
  
     </el-card>
  </div>
</template>
<script>
import {getSale,getSaleproductList,deleteSaleproduct} from "@/api/sam";
import checkPermission from "@/utils/permission";


import { genTree } from "@/utils";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination

export default {
  components: { Pagination },
  data() {
    return {
   
     salesdetail:"",
     saleproduct:"",
   
    };
  },
  computed: {},
  watch: {},
  created() {
     this.id = this.$route.params.id; 
    this.getList();
    this.getSaleproductLists();


  },
  methods: {
    checkPermission,
    //详情
    getList() {
     
      getSale(this.id).then((response) => {
        if (response.data) {
          this.salesdetail = response.data;
        }
      
      });
    },
   
    getSaleproductLists()
    {
       getSaleproductList({sale:this.id,page:0}).then((response) => {
        if (response.data) {
          this.saleproduct = response.data;
        }
      
      });
    },
     handleDelete(scope) {
      this.$confirm("确认删除?", "警告", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "error",
      })
        .then(async () => {
          await deleteSaleproduct(scope.row.id);
          this.getSaleproductLists();
          this.$message.success("成功");
        })
        .catch((err) => {
          console.error(err);
        });
    },
   
  },
};
</script>
