home.vue 8.8 KB

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