home.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="pageHome">
  3. <yx-navbar :isBack="false" title="企业看板"></yx-navbar>
  4. <view class="pageIndex">
  5. <view class="tabs">
  6. <view class="tab" :class="tabIndex === 0 ? 'active' : ''" @click="onClickTab(0)">可视化大屏</view>
  7. <view class="tab" :class="tabIndex === 1 ? 'active' : ''" @click="onClickTab(1)">自助报表</view>
  8. </view>
  9. <view class="search">
  10. <u-icon name="list" size='35' @click="showCategory=true"></u-icon>
  11. <u-search
  12. :placeholder="placeholder" v-model="params.title" :show-action="false"
  13. search-icon-color='#eb5a10' bg-color="#fff" @change="onSearch"
  14. ></u-search>
  15. </view>
  16. <scroll-view class="content" scroll-y @scrolltolower="getData(false)">
  17. <view class="main" v-if="dataList.length > 0">
  18. <view class="infoList" v-for="(item, index) in dataList" :key="index" @click="goDetail(item)">
  19. <img v-if="item.backgroundUrl" class="infoImg" :src="item.backgroundUrl" alt="">
  20. <img v-else class="infoImg" src="../../static/img/no-bg-img.jpg" alt="">
  21. <view class="infoRight">
  22. <view class="name">{{ item.title }}</view>
  23. <view class="describe">所属分类:{{ item.categoryName }}</view>
  24. <view class="infoBottom">
  25. <view class="num"><i class="el-icon-view"></i> 访问量:{{ item.count }}</view>
  26. <view class="dateTime">{{ item.date }}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. <template v-if="!loading&&!dataList.length">
  32. <image v-if="params.title" src="../../static/img/no-search.png" style="width: 100%" mode="aspectFit"></image>
  33. <image v-else src="../../static/img/no-data.png" style="width: 100%" mode="aspectFit"></image>
  34. </template>
  35. </scroll-view>
  36. </view>
  37. <u-picker :show="showCategory" :columns="categoryList" confirmColor="#eb5a10" @cancel="showCategory=false"
  38. closeOnClickOverlay @close="showCategory=false" key-name="categoryValue" @change="onCategoryChange"
  39. @confirm="onSelectCategory"
  40. ></u-picker>
  41. <tab-bar tabbarValue='企业看板'></tab-bar>
  42. </view>
  43. </template>
  44. <script>
  45. import {bigdataList, reportList, classifyList, reportClassList, getPv} from '@/common/api.js'
  46. import moment from 'moment'
  47. export default {
  48. data() {
  49. return {
  50. placeholder: "请输入大屏名称",
  51. tabIndex: 0,
  52. params: {
  53. size: 10,
  54. current: 1,
  55. title: "",
  56. isMobile: 1,
  57. category: ''
  58. },
  59. dataList: [],
  60. visualCategoryPlain: [],
  61. reportCategoryPlain: [],
  62. categoryList: [[], [], []],
  63. showCategory: false,
  64. propsShow: false,
  65. loading: true,
  66. lastCreateTime: '',
  67. }
  68. },
  69. onShow() {
  70. if (this.$store.state.$userInfo.isSingle) {
  71. uni.switchTab({url: '/pages/home/me'});
  72. return
  73. }
  74. this.getCategory().then(() => {
  75. this.getData(true)
  76. })
  77. },
  78. methods: {
  79. getCount(data, type) {
  80. return new Promise((resolve, reject) => {
  81. if (!data.length) {
  82. resolve()
  83. } else {
  84. let visualIds = data.map(i => i.id)
  85. getPv({type, visualIds}).then(rr => {
  86. let counts = rr.data.reduce((r, i) => ({...r, [i.visualId]: i.viewCount}), {})
  87. data.forEach(item => item.count = counts[item.id] || 0)
  88. resolve()
  89. })
  90. }
  91. })
  92. },
  93. getData(reload) {
  94. if (reload) {
  95. this.params.current = 1
  96. this.lastCreateTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  97. }
  98. let data = {...this.params, createTimeIndex: this.lastCreateTime}
  99. this.loading = true
  100. if (this.tabIndex === 0) {
  101. bigdataList(data).then(res => {
  102. let data = res.data
  103. this.getCount(data, 0).then(() => {
  104. data.forEach(item => {
  105. item.categoryName = this.visualCategoryPlain.find(i => i.id === item.category)?.categoryValue || ''
  106. item.date = moment(item.createTime).format('YYYY-MM-DD')
  107. })
  108. if (data.length) this.params.current++
  109. if (reload) {
  110. this.dataList = data
  111. } else {
  112. this.dataList = this.dataList.concat(data)
  113. }
  114. this.lastCreateTime = this.dataList[this.dataList.length - 1]?.createTime || ''
  115. })
  116. }).finally(() => this.loading = false)
  117. }
  118. if (this.tabIndex === 1) {
  119. reportList(data).then(res => {
  120. let data = res.data
  121. this.getCount(data, 1).then(() => {
  122. data.forEach(item => {
  123. item.categoryName = this.reportCategoryPlain.find(i => i.id === item.category)?.categoryValue || ''
  124. item.date = moment(item.createTime).format('YYYY-MM-DD')
  125. })
  126. if (data.length) this.params.current++
  127. if (reload) {
  128. this.dataList = data
  129. } else {
  130. this.dataList = this.dataList.concat(data)
  131. }
  132. this.lastCreateTime = this.dataList[this.dataList.length - 1]?.createTime || ''
  133. })
  134. }).finally(() => this.loading = false)
  135. }
  136. },
  137. onSelectCategory({value}) {
  138. this.params.category = value[2]?.id || ''
  139. this.getData(true)
  140. this.showCategory = false
  141. },
  142. onClickTab(index) {
  143. this.placeholder = index ? '请输入报表名称' : '请输入大屏名称'
  144. this.tabIndex = index
  145. this.params.category = ''
  146. this.params.title = ''
  147. this.countDefaultCategory()
  148. this.getData(true)
  149. },
  150. onSearch(e) {
  151. this.getData(true)
  152. },
  153. goDetail(item) {
  154. uni.navigateTo({url: '/pages/detail/bigdata?id=' + item.id + '&title=' + item.title})
  155. },
  156. getCategory() {
  157. return new Promise((resolve, reject) => {
  158. let task1 = classifyList()
  159. task1.then(res => {
  160. this.visualCategoryPlain = res.data
  161. this.visualCategoryPlain.unshift({id: '', categoryValue: '全部分类'})
  162. })
  163. let task2 = reportClassList()
  164. task2.then(res => {
  165. this.reportCategoryPlain = res.data
  166. this.reportCategoryPlain.unshift({id: '', categoryValue: '全部分类'})
  167. })
  168. Promise.all([task1, task2]).then(() => {
  169. this.countDefaultCategory()
  170. resolve()
  171. })
  172. })
  173. },
  174. countDefaultCategory() {
  175. let categories = this.tabIndex ? this.reportCategoryPlain : this.visualCategoryPlain
  176. let categories1 = categories.filter(i => !i.parentId)
  177. let categories2 = [{id: '', categoryValue: '全部'}]
  178. let categories3 = [{id: '', categoryValue: '全部'}]
  179. this.categoryList = [categories1, categories2, categories3]
  180. },
  181. onCategoryChange({columnIndex, index, picker, values}) {
  182. let now = values[columnIndex][index]
  183. let categories = this.tabIndex ? this.reportCategoryPlain : this.visualCategoryPlain
  184. if (columnIndex === 0) {
  185. if (!now.id) {
  186. picker.setColumnValues(1, [{id: '', categoryValue: '全部'}])
  187. picker.setColumnValues(2, [{id: '', categoryValue: '全部'}])
  188. } else {
  189. let column2 = categories.filter(i => i.parentId === now.id)
  190. column2.unshift({id: now.id, categoryValue: '全部', vir: true})
  191. picker.setColumnValues(1, column2)
  192. picker.setColumnValues(2, [{id: now.id, categoryValue: '全部'}])
  193. }
  194. }
  195. if (columnIndex === 1) {
  196. if (!now.id) {
  197. picker.setColumnValues(2, [{id: '', categoryValue: '全部'}])
  198. } else {
  199. if (now.vir) {
  200. picker.setColumnValues(2, [{id: now.id, categoryValue: '全部'}])
  201. } else {
  202. let column3 = categories.filter(i => i.parentId === now.id)
  203. column3.unshift({id: now.id, categoryValue: '全部'})
  204. picker.setColumnValues(2, column3)
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="less">
  213. @import "./home.less";
  214. </style>