index.vue 7.25 KB
<!-- 下载报表 - 列表 -->
<template>
  <div>
    <!-- class="order-detail" -->
    <d2-container>
      <!-- <div class="offline-account"> -->
      <div class="header" slot="header" style="padding: 10px 20px">
        <d2-search
          ref="showSearch"
          class="show-search"
          :search-form="searchForm"
          :label-width="labelWidth"
          :form-data="showFormData"
        />
        <div class="up-btns">
          <el-button @click="handleSearch" size="small" type="primary">
            查询
          </el-button>
          <el-button size="small" @click="handleReset"> 重置 </el-button>
        </div>
      </div>
      <!-- </d2-container>
          <d2-container> -->
      <div class="d2-container-content">
        <d2-table-header>
          <auth-button category="Button" />
        </d2-table-header>
        <d2-table
          ref="recordTable"
          :get-list-api="getListApi"
          :search-form="searchFormSearch"
          :table-params="tableParams"
          :before-search-fn="beforeSearchFn"
        >
          <div
            slot="auth-button"
            slot-scope="scope"
            v-if="scope.scope.status != -1"
          >
            <auth-button :data="scope.scope" />
          </div>
          <div v-else>
            <span class="list-span">正在生成中</span>
          </div>
        </d2-table>
      </div>
    </d2-container>
  </div>
</template>

<script>
import { Util, deepClone } from "@/common/util"
import {
  downloadReportManage_reportType,
  downloadReportManage_businessType
} from "@/common/constants.js"
import {
  queryAllExcel,
  reportExport_download,
  rebuild
} from "@api/downloadReportManage"
export default {
  name: "DownloadReportList",
  components: {},
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      labelWidth: "100px",
      searchForm: {
        filename: "",
        business_type: "",
        report_type: "",
        key: ""
      },
      searchFormSearch: {},
      showFormData: [
        {
          label: "文件标题",
          name: "filename",
          type: "input",
          maxlength: "50",
          isClear: true
        },
        {
          label: "报表类型",
          name: "report_type",
          type: "select",
          optionList: [],
          optionId: "confId",
          optionLabel: "confValue",
          optionsName: "downloadReportManage_reportType"
        },
        {
          label: "业务类型",
          name: "business_type",
          type: "select",
          optionList: [],
          optionId: "confId",
          optionLabel: "confValue",
          optionsName: "downloadReportManage_businessType"
        }
      ],
      getListApi: queryAllExcel,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        // tableOption: { width: '200px' },
        tableOption: true,
        tableColumns: [
          {
            label: "文件标题",
            prop: "filename",
            width: "400px"
          },
          {
            label: "报表类型",
            prop: "report_type"
            // formatter: (cellValue) => {
            //   return downloadReportManage_reportType.find(el => el.confId == cellValue.report_type)?.confValue
            // }
          },
          {
            label: "业务类型",
            prop: "business_type"
            // formatter: (cellValue) => {
            //   return downloadReportManage_businessType.find(el => el.confId == cellValue.business_type)?.confValue
            // }
          },
          {
            label: "统计周期",
            prop: "statperiod"
            // formatter: (cellValue) => {
            //   return sceneForInStore.find(el => el.confId == o)?.confValue
            // }
          },
          {
            label: "创建时间",
            prop: "created_date"
            // formatter: (cellValue) => {
            //   return sceneForInStore.find(el => el.confId == o)?.confValue
            // }
          }
        ]
      },
      baseData: {
        downloadReportManage_reportType: deepClone(
          downloadReportManage_reportType
        ),
        downloadReportManage_businessType: deepClone(
          downloadReportManage_businessType
        )
      }
    }
  },
  computed: {
    // ...mapState({
    //   dowloadList: (state) => state.d2admin.user.dowloadList
    // })
  },
  mounted() {
    this.getBaseData()
  },

  methods: {
    // ...mapActions({
    //   get: 'd2admin/base/get',
    //   close: 'd2admin/page/close'
    // }),
    // ...mapActions('d2admin/user', ['actionSetDownloadList']),

    async getBaseData() {
      this.getOptionsList()
    },

    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchFormSearch = deepClone(this.searchForm)
        resolve()
      })
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === "select") {
          if (
            this.baseData[item.optionsName].length &&
            this.baseData[item.optionsName][0][
              this.showFormData[index].optionLabel
            ] !== "全部"
          ) {
            const temp = {}
            temp[this.showFormData[index].optionId] = ""
            temp[this.showFormData[index].optionLabel] = "全部"
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(
            this.showFormData[index],
            "optionList",
            this.baseData[item.optionsName]
          )
        }
      })
    },

    handleSearch() {
      this.$refs.recordTable.refreshTable(false, true)
    },
    handleReset() {
      this.searchForm = {
        filename: "",
        business_type: "",
        report_type: ""
      }
      this.$refs.recordTable.refreshTable(false, true)
    },

    // 下载
    handleDownload(row) {
      reportExport_download({ key: row.key }).then((result) => {
        console.log(result, "result")
        result && this.downLoadFile(result.list[0].url)
      })
    },

    /**
     * url下载文件
     *
     */
    downLoadFile: function (url) {
      const Temp = document.createElement("a")
      // url = url + `${url.includes('?') ? '&' : '?'}` + "timestamp=" + new Date().getTime()
      Temp.href = url
      document.body.append(Temp)
      Temp.click()
      document.body.removeChild(Temp)
    },

    // 重新生成
    handleGenerate(row) {
      this.$confirm(
        "系统将自动按照对应的报表及统计时间重新生成,生成过程中不可下载,请耐心等待。是否确认重新生成?",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          closeOnClickModal: false
        }
      )
        .then(() => {
          rebuild({ key: row.key }).then((res) => {
            this.notice.okTips()
            this.$refs.recordTable.refreshTable()
          })
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}
</script>
<style scoped>
.count-txt {
  font-weight: 700;
  color: #2a58ad;
  margin: 0 2px;
}

.leftSpan {
  display: inline-block;
  box-sizing: border-box;
  margin-right: 10px;
}
.list-span {
  font-family: PingFangSC-Regular;
  font-weight: 400;
  font-size: 14px;
  color: #999999;
}
</style>