index.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="article-manager">
  3. <div class="i-layout-page-header">
  4. <Form ref="formInline" :model="formInline" inline>
  5. <FormItem class="mr20">
  6. 用户渠道:
  7. <Select v-model="channel_type" style="width: 300px" placeholder="用户渠道" @on-change="changeTxt">
  8. <Option value="all">全部</Option>
  9. <Option value="wechat">公众号</Option>
  10. <Option value="routine">小程序</Option>
  11. <Option value="h5">H5</Option>
  12. <Option value="pc">PC</Option>
  13. </Select>
  14. </FormItem>
  15. <FormItem>
  16. 选择时间:
  17. <DatePicker
  18. :editable="false"
  19. :clearable="false"
  20. @on-change="onchangeTime"
  21. :value="timeVal"
  22. format="yyyy/MM/dd"
  23. type="daterange"
  24. placement="bottom-start"
  25. placeholder="请选择时间"
  26. style="width: 300px"
  27. class="mr20"
  28. :options="options"
  29. ></DatePicker>
  30. </FormItem>
  31. <FormItem>
  32. <Button type="primary" @click="handleSubmit('formInline')">查询</Button>
  33. </FormItem>
  34. <FormItem>
  35. <Button type="primary" @click="excel">导出</Button>
  36. </FormItem>
  37. </Form>
  38. </div>
  39. <user-info :formInline="formInline" ref="userInfos" key="1"></user-info>
  40. <wechet-info :formInline="formInline" ref="wechetInfos" v-if="isShow" key="2"></wechet-info>
  41. <user-region :formInline="formInline" ref="userRegions" key="3"></user-region>
  42. </div>
  43. </template>
  44. <script>
  45. import userInfo from './components/userInfo';
  46. import wechetInfo from './components/wechetInfo';
  47. import userRegion from './components/userRegion';
  48. import { statisticUserExcel } from '@/api/statistic';
  49. import { formatDate } from '@/utils/validate';
  50. export default {
  51. name: 'index',
  52. components: {
  53. userInfo,
  54. wechetInfo,
  55. userRegion,
  56. },
  57. data() {
  58. return {
  59. options: this.$timeOptions,
  60. formInline: {
  61. channel_type: '',
  62. data: '',
  63. },
  64. channel_type: 'all',
  65. timeVal: [],
  66. isShow: false,
  67. };
  68. },
  69. created() {
  70. const end = new Date();
  71. const start = new Date();
  72. start.setTime(start.setTime(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate() - 29)));
  73. this.timeVal = [start, end];
  74. this.formInline.data = formatDate(start, 'yyyy/MM/dd') + '-' + formatDate(end, 'yyyy/MM/dd');
  75. },
  76. methods: {
  77. changeTxt() {
  78. this.formInline.channel_type = this.channel_type === 'all' ? '' : this.channel_type;
  79. },
  80. // 导出
  81. excel() {
  82. statisticUserExcel(this.formInline).then(async (res) => {
  83. res.data.url.map((item) => {
  84. window.location.href = item;
  85. });
  86. });
  87. },
  88. // 具体日期
  89. onchangeTime(e) {
  90. this.timeVal = e;
  91. this.formInline.data = this.timeVal.join('-');
  92. },
  93. handleSubmit() {
  94. this.$refs.userInfos.getStatistics();
  95. this.$refs.userInfos.getTrend();
  96. this.$refs.userRegions.getTrend();
  97. this.$refs.userRegions.getSex();
  98. if (this.formInline.channel_type === 'wechat') {
  99. this.isShow = true;
  100. this.$refs.wechetInfos.getStatistics();
  101. this.$refs.wechetInfos.getTrend();
  102. } else {
  103. this.isShow = false;
  104. }
  105. },
  106. },
  107. };
  108. </script>
  109. <style scoped>
  110. .ivu-form-item {
  111. padding-bottom: 10px;
  112. margin-bottom: 0;
  113. }
  114. </style>