<template>
  <el-container style="padding: 0">
    <el-header style="width: 100%; height: 22px;font-size: 12px;padding-top: 5px">
      <el-form :inline="true" label-width="55px" label-position="right">
        <el-row>
          <el-col :span="20">
            <el-form-item label="船号:">
              <ProjectSelect ref="projectSelectRef" />
            </el-form-item>
            <el-form-item label="批量:">
              <el-input v-model="queryParam.dcPl" type="search" placeholder="批量" />
            </el-form-item>
            <el-form-item label="分段:">
              <el-input v-model="queryParam.dcFd" type="search" placeholder="分段" />
            </el-form-item>
          </el-col>
          <el-col :span="4" style="text-align: right">
            <el-button type="success" @click="wzxjc">零件齐套检查</el-button>
            <el-button type="success" @click="bgong">报工</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-header>
    <el-container style="padding: 0">
      <el-main>
        <VxeGrid ref="bFangRef" v-bind="gridOptions" />
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import tableConfig from "@/views/jhzxgl/components/yppfk";
import ProjectSelect from "@/components/ProjectSelect/index.vue";
import {bgList, yppbg} from "@/api/zyjh";
import {getBFangDwxx} from "@/views/zyjhzx/bfang/comps/api";

export default {
  name:'YppFk',
  components: {ProjectSelect},
  data(){
    return{
      queryParam:{
        dcCh:'',
        dcPl:'',
        dcFd:'',
      },
      list:[],
      gridOptions:{},
      qyData:[],
      qyList:[],
    }
  },
  created(){
    const {options,columns}=tableConfig()
    this.gridOptions=options
    this.gridOptions.columns = columns;
    this.gridOptions.height=window.innerHeight-150
    getBFangDwxx().then((res)=>{
      this.qyData=res.data
      const qyList=[]
      Object.keys(this.qyData).forEach(key=>{
        const qy={label:key,value:key};
        qyList.push(qy)
      })
      this.qyList=qyList
    })
  },
  methods:{
    bgong(){
      const data=this.$refs.bFangRef.getCheckboxRecords()
      if(data.length>0){
        yppbg(data).then(()=>{
          this.$message.success('成功');
          this.wzxjc()
        })
      }
    },
    wzxjc(){
      this.queryParam.dcPl = this.$refs.projectSelectRef.getDcch()
      bgList(this.queryParam).then((res) => {
        res.data.forEach(item=>{
          item.status='已配盘'
          Object.values(this.qyData).forEach(dwList=>{
            dwList.forEach(dwxx=>{
              if (dwxx.id===item.dwxxId){
                item.qy=dwxx.qy
                item.dwh=dwxx.dwh
              }
            })
          })
        })
        this.gridOptions.data=res.data
      })
    },
  }
}
</script>
