detail.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <page-meta :page-style="loading? 'overflow: hidden;' : ''" />
  3. <!-- <scroll-view scroll-y="true" :scroll-into-view="scrollViewId" upper-threshold="10" @scrolltoupper="onScrollTop" style="height: 100vh;"> -->
  4. <view class="list">
  5. <view class="item" v-for="(item,index) in list" :key="index" :id="`msg${item.report_id}${item.activity_id}`" >
  6. <view class="msg-time">{{formatMsgTime(item.time)}}</view>
  7. <view class="content" @click="goDetail(item)">
  8. <view class="top-img" :style="'background-image:url('+item.img_url+')'">
  9. <text class="name">{{item.top_name}}</text>
  10. </view>
  11. <view class="title">{{formatTitle(item)}}</view>
  12. <view :class="['intro',item.content.substr(0,1)=='【'?'text-indent':'']">{{item.content}}</view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="report-empty-box" v-if="finished&&list.length==0">
  17. <image :src="globalImgUrls.chartEmpty" mode="widthFix" />
  18. <view>暂无数据</view>
  19. </view>
  20. <!-- </scroll-view> -->
  21. </template>
  22. <script>
  23. const dayjs=require('@/utils/dayjs.min')
  24. dayjs.locale('zh-cn')
  25. import {apiBuyDetail} from '@/api/buy'
  26. export default {
  27. data () {
  28. return {
  29. scrollViewId:'',
  30. classify_id_first:0,
  31. activity_id:0,
  32. page:1,
  33. pageSize:20,
  34. list:[],
  35. finished:false,
  36. loading:false
  37. }
  38. },
  39. onLoad(options) {
  40. this.classify_id_first=options.classify_id_first
  41. this.activity_id=options.activity_id
  42. uni.setNavigationBarTitle({
  43. title: options.activity_id!=0?'电话会':options.name
  44. })
  45. this.getList()
  46. },
  47. methods: {
  48. async getList(){
  49. this.loading=true
  50. const res=await apiBuyDetail({
  51. classify_id_first:Number(this.classify_id_first),
  52. activity_id:Number(this.activity_id),
  53. current_index:this.page,
  54. page_size:this.pageSize
  55. })
  56. setTimeout(() => {
  57. this.loading=false
  58. }, 500);
  59. if(res.code===200){
  60. let arr=res.data.list||[]
  61. let temarr=JSON.parse(JSON.stringify(arr))
  62. this.list=[...temarr.reverse(),...this.list]
  63. if(res.data.paging.is_end){
  64. this.finished=true
  65. }
  66. this.$nextTick(()=>{
  67. if(arr[0]){
  68. this.scrollViewId=`msg${res.data.list[0].report_id}${res.data.list[0].activity_id}`
  69. uni.pageScrollTo({ selector:'#'+this.scrollViewId,duration:0 })
  70. }
  71. })
  72. }
  73. },
  74. // onScrollTop(){
  75. // if(this.finished) return
  76. // this.page++
  77. // this.getList()
  78. // },
  79. // 格式化消息时间
  80. formatMsgTime(e){
  81. const hour=dayjs(e).hour()//获取小时
  82. const dayTime=dayjs(e).format('hh:mm')
  83. let dayStr=''
  84. if(hour>=0&&hour<5){
  85. dayStr=`凌晨 ${dayjs(e).format('HH:mm')}`
  86. }else if(hour>=5&&hour<7){
  87. dayStr=`清晨 ${dayTime}`
  88. }else if(hour>=7&&hour<9){
  89. dayStr=`早上 ${dayTime}`
  90. }else if(hour>=9&&hour<11){
  91. dayStr=`上午 ${dayTime}`
  92. }else if(hour>=11&&hour<13){
  93. dayStr=`中午 ${dayTime}`
  94. }else if(hour>=13&&hour<17){
  95. dayStr=`下午 ${dayTime}`
  96. }else if(hour>=17&&hour<19){
  97. dayStr=`傍晚 ${dayTime}`
  98. }else if(hour>=19&&hour<23){
  99. dayStr=`晚上 ${dayTime}`
  100. }else if(hour>=23&&hour<24){
  101. dayStr=`午夜 ${dayTime}`
  102. }
  103. // 判断是否为今天
  104. if(dayjs(new Date()).isSame(e, 'day')){
  105. return dayStr
  106. }
  107. // 判断昨天
  108. if(dayjs(dayjs().subtract(1, 'day')).isSame(e,'day')){
  109. return `昨天 ${dayStr}`
  110. }
  111. // 前天
  112. if(dayjs(dayjs().subtract(2, 'day')).isSame(e,'day')){
  113. return `前天 ${dayStr}`
  114. }
  115. // 周内
  116. if(dayjs(new Date()).isSame(e, 'week')){
  117. return `${dayjs(e).format('ddd')} ${dayStr}`
  118. }
  119. //年内
  120. if(dayjs(new Date()).isSame(e, 'year')){
  121. return `${dayjs(e).format('MM月DD日')} ${dayStr}`
  122. }
  123. return `${dayjs(e).format('YYYY年MM月DD日')} ${dayStr}`
  124. },
  125. goDetail(item){
  126. if(item.activity_id){
  127. uni.navigateTo({url: '/pages-activity/detail?id=' + item.activity_id })
  128. }else{
  129. uni.navigateTo({url:'/pages-report/reportDetail?reportId='+item.report_id})
  130. }
  131. },
  132. onPageScroll({ scrollTop }) {
  133. if(this.loading||this.finished) return
  134. if(scrollTop<20){
  135. this.page++
  136. this.getList()
  137. }
  138. },
  139. //格式化标题
  140. formatTitle(item){
  141. let t=dayjs(item.time).format('MMDD')
  142. if(item.activity_id){
  143. return `${item.title}`
  144. }else{
  145. return `${item.title}(${t})`
  146. }
  147. }
  148. }
  149. }
  150. </script>
  151. <style>
  152. page{
  153. min-height: 100vh;
  154. padding-bottom: 0;
  155. background-color: #F5F6FA;
  156. }
  157. </style>
  158. <style lang="scss" scoped>
  159. .list{
  160. .item{
  161. padding: 34rpx;
  162. .msg-time{
  163. text-align: center;
  164. padding: 20rpx;
  165. }
  166. .content{
  167. background: #FFFFFF;
  168. box-shadow: 3rpx 3rpx 12rpx 0px rgba(161,161,161,0.14);
  169. border-radius: 16rpx;
  170. overflow: hidden;
  171. .top-img{
  172. width: 100%;
  173. height: 230rpx;
  174. background-color: #a1a1a1;
  175. background-size: cover;
  176. position: relative;
  177. .name{
  178. display: block;
  179. width: 90%;
  180. text-align: center;
  181. color: #CFC09F;
  182. font-size: 50rpx;
  183. font-weight: 600;
  184. position: absolute;
  185. top: 50%;
  186. left: 50%;
  187. transform: translate(-50%,-50%);
  188. }
  189. }
  190. .title{
  191. padding: 20rpx 30rpx 10rpx 30rpx;
  192. font-weight: bold;
  193. font-size: 32rpx;
  194. }
  195. .intro{
  196. padding: 0 30rpx 24rpx 30rpx;
  197. color: $global-text-color-grey;
  198. }
  199. .text-indent{
  200. margin-left: -12rpx;
  201. }
  202. }
  203. }
  204. }
  205. </style>