<template>
  <VxeGrid ref="ljpgd" v-bind="gridOptions" @cell-click="cellClick" @current-change="getCurrentData"
           @checkbox-change="checkboxChange" @checkbox-all="checkboxAll" />
</template>

<script>
import paoWanPgdConfig from './pgdTable'
import {ljpg} from "@/api/jhzxgl/pgd";
import {endLoading, startLoading} from "@/utils";

export default {
  name:'LjianPgd',
  props:{
    worker:{
      type:Object,
      default: {}
    },
    workers:{
      type:Array,
      default:[]
    },
  },
  data(){
    return{
      gridOptions:{},
      list:{},
      setExt:null,
      checkedList:[],
    }
  },
  created(){
    const {options,columns,setExt}=paoWanPgdConfig()
    this.setExt=setExt
    this.gridOptions=options
    this.gridOptions.columns=columns
    console.log(this.$props.workers)
    this.setExt("workers",this.$props.workers)
  },
  methods:{
    plGylx(gylx,worker){
      if (!gylx){
        this.$message.warning('请选择工艺路线')
        return;
      }
      const data=this.checkedList
      if (data.length===0){
        this.$message.warning('工单未选择')
        return;
      }
      data.forEach(item=>{
        item.pkbs='N'
        item.qbs='N'
        item.dmbs='N'
        gylx.forEach(gy=>{
          item[gy]='Y'
        })

        item.pkbs==='Y'&&(item.pscry=worker.pscry)
        item.qbs==='Y'&&(item.qscry=worker.qscry)
        item.dmbs&&(item.dscry=worker.dscry)
      })
    },
    paigong(){
      const data=this.checkedList
      if (data.length===0){
        this.$message.warning('请选择需要派工的工单')
        return;
      }
      for (const item of data) {
        if (item.pkbs&&item.pscry==='Y'){
          this.$message.warning('坡口施工人员未安排')
          return
        }
        if (item.qbs&&item.qscry==='Y'){
          this.$message.warning('曲面施工人员未安排')
          return
        }
        if (item.dmbs&&item.dscry==='Y'){
          this.$message.warning('打磨施工人员未安排')
          return
        }
      }
      const pgData=data//.filter(item=>this.isAllNotEmpty(item.dmry,item.pkry,item.qjgry,item.pkbs,item.qbs,item.dmbs))
        .map(item=>{
          const data={
            id:item.id,
            dscry:item.dscry,pscry:item.pscry,qscry:item.qscry,
            pkbs:item.pkbs,qbs:item.qbs,dmbs:item.dmbs,
          }
          item.pkbs==='Y'&&(data.pkZt='02')
          item.qbs==='Y'&&(data.qjgZt='02')
          item.dmbs==='Y'&&(data.dmZt='02')
          return data
        })
      startLoading()
      ljpg(pgData).then(res=>{
        if (res.success){
          this.$message.warning('成功')
          this.$emit('search',this.worker)
        }
      })
    },
    checkboxAll() {
      this.checkedList = this.$refs.ljpgd.getCheckboxRecords();
    },
    checkboxChange() {
      this.checkedList = this.$refs.ljpgd.getCheckboxRecords();
    },
    initData(data){
      // this.gridOptions.data=data
      this.$refs.ljpgd.reloadData(data)
      setTimeout(()=>{
        endLoading()
      },2000)
    },
    getCurrentData(){
      const data= this.checkedList
      window.localStorage.setItem("ljfk",JSON.stringify(data))
    },
    cellClick({row}){
      this.$emit('initPgd',row)
    }
  }
}
</script>
