home.vue 8.6 KB

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