index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="cardIndex">
  3. <uni-menubar title="数据分析" />
  4. <tm-tabs @change='tabClick' color="bg-gradient-blue-accent" v-model="active" range-key="name"
  5. :list="[{name:'客户轨迹',id:0},{name:'名片分析',id:1},{name:'文章分析',id:2}]">
  6. </tm-tabs>
  7. <tm-sheet :shadow="0">
  8. <tm-tabs model="rect" @change='tabsdataChange' :height="60" v-model="dataTabVal" range-key="name"
  9. color="blue"
  10. :list="[{name:'近1天',id:0},{name:'近7天',id:1},{name:'近30天',id:2},{name:'本年',id:3},{name:'自定义',id:4}]">
  11. </tm-tabs>
  12. </tm-sheet>
  13. <tm-sheet :shadow="0">
  14. <view class="flex flex-between text-align-center">
  15. <view v-for="(item,index) in total_list" :key="index">
  16. <!-- <tm-icons :size="70" :color="item.color" :name="item.icon"></tm-icons> -->
  17. <view class="text-size-s pt-10">{{item.title}}</view>
  18. <view class="text-size-xl pt-10 text-weight-b">{{item.count}}</view>
  19. </view>
  20. </view>
  21. </tm-sheet>
  22. <tm-sheet :padding="[0,0]">
  23. <view class="px-50 pt-30 text-weight-b text-size-n">
  24. 访问类型
  25. </view>
  26. <view class="charts-box">
  27. <qiun-data-charts canvas2d type="pie" :opts="baropts" :chartData="piechart" />
  28. </view>
  29. </tm-sheet>
  30. <tm-sheet :padding="[0,0]">
  31. <view class="px-50 pt-30 text-weight-b text-size-n">
  32. 访问趋势
  33. </view>
  34. <view class="charts-box">
  35. <qiun-data-charts canvas2d type="area" :opts="opts" :chartData="chart" />
  36. </view>
  37. </tm-sheet>
  38. <view>
  39. <tm-sheet :padding="[32,0]" color="transparent">
  40. <view style="font-size: 35rpx;">
  41. 详细数据
  42. </view>
  43. </tm-sheet>
  44. <view v-if="group.length>0">
  45. <tm-sheet v-for="(item,index) in group" :key="index" @click="custDetail(item)">
  46. <tm-col :grid="3">
  47. <view style="display: flex;align-items: center;">
  48. <tm-avatar :src="item.avatar" :size="120"></tm-avatar>
  49. </view>
  50. </tm-col>
  51. <tm-col :grid="9">
  52. <view style="font-size: 34rpx; font-weight:bloder;text-align: start;">{{item.nickname}}
  53. </view>
  54. <view class="mt-15" style="font-size: 24rpx; color:#cccccc;text-align: start;">
  55. {{item.label}}
  56. </view>
  57. </tm-col>
  58. </tm-sheet>
  59. </view>
  60. <view v-else class="">
  61. <tm-empty icon="icon-cry-fill" label="还没有详细数据~"></tm-empty>
  62. </view>
  63. </view>
  64. <tm-calendar v-if="showDetail" mode="rang" :value.sync="showDetail" @confirm="dateClick"
  65. color="bg-gradient-blue-accent"></tm-calendar>
  66. <uni-tabBar />
  67. <uni-suspension />
  68. </view>
  69. </template>
  70. <script>
  71. import qiunDataCharts from '@/subpages/components/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue';
  72. export default {
  73. components: {
  74. qiunDataCharts
  75. },
  76. data() {
  77. return {
  78. chart: {},
  79. piechart: {},
  80. opts: {
  81. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  82. "#ea7ccc"
  83. ],
  84. padding: [15, 15, 0, 15],
  85. legend: {
  86. show: false
  87. },
  88. xAxis: {
  89. disableGrid: true
  90. },
  91. yAxis: {
  92. gridType: "dash",
  93. dashLength: 2
  94. },
  95. extra: {
  96. area: {
  97. type: "curve",
  98. opacity: 0.4,
  99. addLine: true,
  100. width: 2,
  101. gradient: true
  102. }
  103. }
  104. },
  105. baropts: {
  106. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4",
  107. "#ea7ccc"
  108. ],
  109. padding: [5, 5, 5, 5],
  110. extra: {
  111. pie: {
  112. activeOpacity: 0.5,
  113. activeRadius: 10,
  114. offsetAngle: 0,
  115. labelWidth: 15,
  116. border: true,
  117. borderWidth: 3,
  118. borderColor: "#FFFFFF",
  119. linearType: "custom"
  120. }
  121. }
  122. },
  123. active: 1,
  124. dataTabVal: 0,
  125. params: {
  126. form: "card",
  127. time: "",
  128. date: "day",
  129. type: 0
  130. },
  131. datasList: {},
  132. echarts: [],
  133. showDetail: false,
  134. group: [],
  135. total_list: [],
  136. title: "查看名片",
  137. color: "#2196F3"
  138. }
  139. },
  140. mounted() {
  141. this.getEchart()
  142. },
  143. methods: {
  144. tabClick(e) {
  145. this.active = e
  146. if (e < 1) {
  147. uni.redirectTo({
  148. url: "/subpages/pages/radar/index"
  149. })
  150. return false
  151. }
  152. if (e == 1) {
  153. this.params = {
  154. form: "card",
  155. time: "",
  156. date: "day",
  157. type: 0
  158. },
  159. this.title = "查看名片"
  160. this.getEchart()
  161. } else if (e == 2) {
  162. this.params = {
  163. form: "art",
  164. time: "",
  165. date: "day",
  166. type: 0
  167. }
  168. this.title = "浏览文章"
  169. this.getEchart()
  170. }
  171. },
  172. //重新渲染echarts
  173. getEchart() {
  174. this.$tm.request.post('card/trackdata', this.params).then(res => {
  175. this.group = res.data.list
  176. this.total_list = res.data.total_list
  177. let charts = res.data.echarts
  178. let barcharts = res.data.bar_echarts
  179. let xDate = charts.map(val => val.months)
  180. let series = charts.map(val => val.count)
  181. res = {
  182. categories: xDate,
  183. series: [{
  184. name: "访问量",
  185. data: series
  186. }]
  187. };
  188. this.chart = JSON.parse(JSON.stringify(res));
  189. let piechart = {
  190. series: [{
  191. data: barcharts
  192. }]
  193. };
  194. this.piechart = JSON.parse(JSON.stringify(piechart));
  195. })
  196. },
  197. dateClick(selected) {
  198. let start = selected[0]
  199. let end = selected[1]
  200. this.params.date = ''
  201. this.params.time = [`${start.year}-${start.month}-${start.day}`, `${end.year}-${end.month}-${end.day}`]
  202. this.getEchart()
  203. },
  204. tabsdataChange(e) {
  205. this.dataTabVal = e
  206. if (e == 0) {
  207. this.params.date = "day"
  208. } else if (e == 1) {
  209. this.params.date = "week"
  210. } else if (e == 2) {
  211. this.params.date = "month"
  212. } else if (e == 3) {
  213. this.params.date = "year"
  214. } else(
  215. this.showDetail = true
  216. )
  217. if (e < 4) {
  218. this.getEchart()
  219. }
  220. },
  221. chatClick() {
  222. uni.navigateTo({
  223. url: "cardChat"
  224. })
  225. },
  226. lineInit(res) {
  227. // 初始化成功后返回的数据如下:
  228. const {
  229. width,
  230. height,
  231. chart
  232. } = res;
  233. //显示图表数据。
  234. this.$tm.request.post('card/trackdata', this.params).then(res => {
  235. this.group = res.data.list
  236. this.$nextTick(() => {
  237. chart.setOption(this.rOpts('bar', res.data.echarts));
  238. })
  239. })
  240. },
  241. custDetail(item){
  242. uni.navigateTo({
  243. url:"/subpages/pages/radar/drawPage?id="+item.uid
  244. })
  245. },
  246. }
  247. }
  248. </script>
  249. <style scoped lang="scss">
  250. </style>