statisticsList.vue 5.08 KB
<!-- 内容管理统计 -->
<template>
  <d2-container class="container">
    <div class="header" slot="header">
      <d2-search
        ref="showSearch"
        class="show-search"
        :search-form="searchForm"
        :form-data="showFormData"
      >
      </d2-search>
      <div class="up-btns">
        <el-button :id="tableParams.btnId" size="small" type="primary" handle>
          查询
        </el-button>
        <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <!-- <el-button size="mini" @click="exportList()"> 导出 </el-button> -->
        <auth-button category="Button" :show-btn-ids="['9130401']" />
      </d2-table-header>
      <d2-table
        ref="contentTable"
        :search-form="realSearchForm"
        :table-params="tableParams"
        :get-list-api="getListApi"
        :before-search-fn="beforeSearchFn"
      >
      </d2-table>
    </div>
  </d2-container>
</template>

<script>
import { Util, deepClone } from "@/common/util"
import {
  getStatisticsList,
  exportStatisticsList,
  getMerchantList
} from "@api/contentManager"
export default {
  name: "ContentManagerList",
  data() {
    return {
      title: "",
      searchForm: {
        goodsId: "",
        goodsType: 0,
        EnterDate: [],
        merchantId: ""
      },
      realSearchForm: {},
      showFormData: [
        {
          label: "浏览时间",
          name: "EnterDate",
          type: "datePicker",
          isClear: true,
          pickerOptions: "beforeRangePickerOptions"
        },
        {
          label: "可见门店",
          name: "merchantId",
          type: "select",
          optionList: [],
          optionId: "merchantId",
          optionLabel: "merchantName"
        }
      ],
      // 基本数据
      baseData: {
        contentTypeOptions: [],
        sceneOptions: [],
        channelOptions: [],
        statuslOptions: []
      },
      tableSearchForm: {},
      getListApi: getStatisticsList,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: "list",
        tableColumns: [
          {
            label: "用户",
            prop: "customerAccountName"
          },
          {
            label: "手机号",
            prop: "customerMobile"
          },
          {
            label: "浏览时间",
            prop: "enterDate"
          },
          {
            label: "浏览时长/秒",
            prop: "browseDuration"
          },
          {
            label: "所属门店",
            prop: "merchantName"
          }
        ]
      }
    }
  },
  created() {
    // this.title = this.$route.query.title
  },
  mounted() {
    var params = { currentPage: 1, pageSize: 2000, merchantIdName: "" }
    getMerchantList(params)
      .then((res) => {
        this.getBaseData(res)
      })
      .catch(() => {
        this.getBaseData([])
      })
  },

  methods: {
    getBaseData(res) {
      const allOpt = {
        id: "",
        label: "全部"
      }

      this.showFormData.forEach((item, index) => {
        // if (item.type === "select" && this.baseData[item.optionsName]) {
        //   this.baseData[item.optionsName].unshift(allOpt)
        //   this.$set(
        //     this.showFormData[index],
        //     "optionList",
        //     this.baseData[item.optionsName]
        //   )
        // }
        if (item.type === "select" && item.name === "merchantId") {
          res.unshift({
            merchantId: "",
            merchantName: "全部"
          })
          this.$set(this.showFormData[index], "optionList", res)
        }
      })
    },
    handleReset() {
      for (const key in this.searchForm) {
        this.searchForm[key] = ""
      }
      this.searchForm.goodsType = 0
      this.realSearchForm = {}
      this.$refs.contentTable.refreshTable(true, true)
    },
    exportList() {
      const params = this.getParams()
      exportStatisticsList(params).then((res) => {
        console.log(res, "res")
        // window.open(res)
        const tempaa = Util.getExplorer()
        if (tempaa == "QQ") {
          window.open(res)
        } else {
          const iframe = document.createElement("iframe")
          iframe.style.display = "none"
          iframe.src = res
          document.body.appendChild(iframe)
        }
      })
    },
    getParams() {
      const params = deepClone(this.searchForm)
      console.log(params, "params")
      if (params.EnterDate?.length) {
        params.startEnterDate =
          new Date(params.EnterDate[0])
            .toLocaleDateString()
            .replace(/\//g, "-") + " 00:00:00"
        params.endEnterDate =
          new Date(params.EnterDate[1])
            .toLocaleDateString()
            .replace(/\//g, "-") + " 23:59:59"
      }
      delete params.EnterDate
      return params
    },
    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchForm.goodsId = this.$route.query.id
        this.realSearchForm = this.getParams()
        resolve()
      })
    }
  }
}
</script>
<style scoped lang="scss"></style>