<template>
  <div class="app-container">
   
    <el-card style="margin-top: 2px">
      <el-table
        v-loading="listLoading"
        :data="iproductData.results"
        border
        fit
        stripe
        highlight-current-row
         max-height="700"
         height="100"
        v-el-height-adaptive-table="{bottomOffset: 50}"
      >
        <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.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.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-if="scope.row.is_mtestok == true">合格</el-tag></template>

        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          width="220px"
        >
          <template slot-scope="scope">
           
            <el-link
              v-if="scope.row.is_mtested == false"
              @click="handleMtest(scope)"
              >军检</el-link
            >
           
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="iproductData.count > 0"
        :total="iproductData.count"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.page_size"
        @pagination="getList"
      />
       <el-dialog
      :visible.sync="dialogVisible"
       :close-on-click-modal="false"
       title="军检" 
    >
      <el-form
        ref="Form"
        :model="mtest"
        label-width="150px"
        label-position="right"
       
      >
          <el-form-item label="军检是否合格">
   
      <el-radio   v-model="mtest.is_mtestok" label=True  >合格</el-radio>
      <el-radio  v-model="mtest.is_mtestok" label=False >不合格</el-radio>
    
  </el-form-item>
         <el-form-item label="备注" prop="remark">
          <el-input v-model="mtest.remark" placeholder="备注" />
        </el-form-item>
        
      </el-form>
      <div style="text-align: right">
        <el-button type="danger" @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="smtconfirm('Form')">确认</el-button>
      </div>
    </el-dialog>
    </el-card>
  
  </div>
</template>
<script>
import {  getiproductList,saleMtest} from "@/api/inm";
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 {
     
      iproductData: {
        count: 0,
      },
       listQuery: {
        page: 1,
        page_size: 20,
      },
       mtest: {},
     salesdetail:"",
     saleproduct:"",
     dialogVisible:false,
     
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getList();
  },
  methods: {
    checkPermission,
    //半成品列表
    getList() {
      this.listLoading = true;
      getiproductList(this.listQuery).then((response) => {
        if (response.data) {
          this.iproductData= response.data;
        }
        this.listLoading = false;
      });
    },
      handleMtest(scope){
      this.saleproduct=scope.row.id;
      this.dialogVisible=true;
    },
    smtconfirm(){
   
       saleMtest(this.saleproduct,this.mtest).then((res) => {
        
        if (res.code >= 200) {
              this.getList();
                 this.dialogVisible = false;
                this.$message.success("成功");
              }
      
      });
    }
  },
};
</script>
