import request from '@/utils/request'
import { VXETable } from 'vxe-table'

const 看板数据编辑=()=>{

  const butClick=()=>{
    console.log(data.formData)
    保存钢加公司目标达成率统计(data.formData).then(res=>{
      if(res.success){
        VXETable.modal.message({ content: '成功', status: 'success' })
      }
    })
  }

  const addClick=function (){
    if(data.activeName==='one'){
      console.log(data.options1)
      data.options1.data.push({})
    }

    if(data.activeName==='two'){
      data.options2.data.push({})
    }
  }

  const saveClick=()=>{
    if(data.activeName==='one'){
      保存双周达成率(data.options1.data)
      init双周达成率()
    }

    if(data.activeName==='two'){
      保存配送达成率(data.options2.data)
      init配送达成率()
    }
  }

  const data={
    setActiveName:function (activeName){
      data.activeName=activeName
    },
    activeName:'one',
    formData:{
      ndgc:0,
      jhwc:0,
    },
    formItems:[
      { field: 'ndgc', title: '年度钢材加工', span: 4,
        itemRender: {
          name: '$input', props: {placeholder: '年度钢材加工' }
        }
      },
      { field: 'jhwc', title: '年度计划完成率', span: 4 ,
        itemRender: {
          name: '$input', props: {placeholder: '年度计划完成率' }
        }
      },
      {align:'center',
        itemRender: {
          name: '$button', props: {content:'保存',status:'primary'},events:{click:butClick}
        }
      },
      {span:13,align:'right',
        itemRender: {
          name: '$button', props: {content:'新增',status:'primary'},events:{click:addClick}
        }
      },
      {align:'right',
        itemRender: {
          name: '$button', props: {content:'保存',status:'primary'},events:{click:saveClick}
        }
      },
    ],
    options1:{
      height:700,
      align:'center',
      border: true,
      resizable: true,
      keepSource:true,
      size:'mini',
      showOverflow: true,
      scrollY:{enable:true},
      editConfig:{trigger: 'click', mode: 'cell', showStatus: true},
      highlightCurrentRow:true,
      data:[],
    },
    options2:{
      height:700,
      align:'center',
      border: true,
      resizable: true,
      keepSource:true,
      size:'mini',
      showOverflow: true,
      scrollY:{enable:true},
      editConfig:{trigger: 'click', mode: 'cell', showStatus: true},
      highlightCurrentRow:true,
      data:[],
    },
    columns:[
      { type: 'seq', width: 60, title: '序号' },
      { field: 'ch', title: '船号',
        editRender:{ name: '$input',}
      },
      { field: 'wcl', title: '达成率',
        editRender:{ name: '$input',}
      },
    ],
  }

  // 获取钢加公司目标达成率统计().then(res=>{
  //   data.formData=res.data
  // })

  const init双周达成率=()=>{
    console.log(111)
    获取双周达成率().then(res=>{
      data.options1.data=res.data||[]
    })
  }
  init双周达成率()

  const init配送达成率=()=>{
    获取配送达成率().then(res=>{
      data.options2.data=res.data||[]
    })
  }
  init配送达成率()

  return data
}

export const 获取钢加公司目标达成率统计=()=>{
  return request({
    url: "/YdjhKban/getMbdc",
    method: "get",
  });
}

const 保存钢加公司目标达成率统计=(data)=>{
  return request({
    url: "/YdjhKban/saveMbdc",
    method: "post",
    data,
  });
}

const 获取双周达成率=()=>{
  return request({
    url: "/YdjhKban/getSzdc",
    method: "get",
  });
}

const 保存双周达成率=(data)=>{
  return request({
    url: "/YdjhKban/saveSzdc",
    method: "post",
    data,
  });
}

const 获取配送达成率=()=>{
  return request({
    url: "/YdjhKban/getPsdc",
    method: "get",
  });
}

const 保存配送达成率=(data)=>{
  return request({
    url: "/YdjhKban/savePsdc",
    method: "post",
    data,
  });
}

export default 看板数据编辑
