廖井涛
2024-05-28 f866d4c98e2f69a8f4ba6a12bf492b02e734d488
north-glass-erp/northglass-erp/src/views/pp/report/WorkInProgress.vue
@@ -269,9 +269,12 @@
    // buttons: [{
    //
    // }],
    import: false,
    export: true,
    print: true,
    slots: {
      tools: 'toolbar_buttons'
    },
    // import: false,
    // export: true,
    // print: true,
    zoom: true,
    custom: true
  },
@@ -294,7 +297,57 @@
})
function exportExcel(url, fileName,date) {
  let processes = value.value
  let inputVal = form.orderId
  if (inputVal == '') {
    inputVal = null
  }
  let inputProject = form.project
  if (inputProject == '') {
    inputProject = null
  }
  if(date===null){
    ElMessage.warning("请先选择日期")
    return
  }
  if(processes===null){
    ElMessage.warning("请先选择工序")
    return
  }
  const date1 = new Date(date[0]);
  const date2 = new Date(date[1]);
  const timeDiff = Math.abs(date2.getTime() - date1.getTime());
  const daysDiff = timeDiff / (1000 * 3600 * 24);
  if(Math.floor(daysDiff)>180){
    ElMessage.warning("导出的筛选时间不能超过180天")
    return
  }
  let dataMp = ref({
    date: date,
    processes: processes,
    orderId: inputVal,
    project: inputProject
  })
  request.post(url,dataMp.value,{responseType :'blob'}).then(res => {
    const blob = new Blob([res])
    if ('download' in document.createElement('a')) { // 非IE下载
      const elink = document.createElement('a')
      elink.download = `${fileName}.xlsx`
      elink.style.display = 'none'
      elink.href = URL.createObjectURL(blob)
      document.body.appendChild(elink)
      elink.click()
      URL.revokeObjectURL(elink.href) // 释放URL 对象
      document.body.removeChild(elink)
    } else { // IE10+下载
      navigator.msSaveBlob(blob, fileName)
    }
  })
}
</script>
<template>
@@ -358,11 +411,17 @@
      <template #num1_filter="{ column, $panel }">
        <div>
          <div v-for="(option, index) in column.filters" :key="index">
            <input v-model="option.data" type="type" @input="changeFilterEvent($event, option, $panel)"/>
            <input v-model="option.data" type="text" @input="changeFilterEvent($event, option, $panel)"/>
          </div>
        </div>
      </template>
      <template #toolbar_buttons>
        <vxe-button style="margin-right: 0.5rem"
                    @click="exportExcel('/report/exportWorkInProgress',
                                          '在制品报表',
                                          form.date1)">
          导出</vxe-button>
      </template>
    </vxe-grid>
  </div>