visitor.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <!-- 访客记录 -->
  3. <view class="container">
  4. <template v-if="!isLogin">
  5. <!-- 未登录状态 -->
  6. <view class="no-login">
  7. <image src="/static/images/no-login.png" mode="aspectFit" class="no-login-image"></image>
  8. <text class="no-login-text">登录后查看更多内容</text>
  9. <button class="login-btn" @click="goToLogin">去登录</button>
  10. </view>
  11. </template>
  12. <template v-else>
  13. <!-- Visit list -->
  14. <scroll-view scroll-y class="visit-list" @scrolltolower="onReachBottom">
  15. <template v-if="visitList.length > 0">
  16. <view class="visit-item" v-for="(item, index) in visitList" :key="index" @click="goToDetail(item)">
  17. <view class="visit-date">
  18. <text class="date-num">{{item.date}}</text>
  19. <text class="date-month">{{item.year}}</text>
  20. </view>
  21. <view class="visit-content">
  22. <view class="visit-header">
  23. <view class="visitor-info">
  24. <text class="visitor-label">对接人 </text>
  25. <text class="visitor-name">{{item.employeeName}}</text>
  26. </view>
  27. <text class="visit-status" :class="getStatusClass(item.status)">{{item.status}}</text>
  28. </view>
  29. <view class="visit-desc">{{item.visitReason}}</view>
  30. <view class="visit-time">
  31. <u-icon name="clock" size="12" color="#999"></u-icon>
  32. <text>{{item.time}}</text>
  33. </view>
  34. </view>
  35. </view>
  36. <!-- Loading more -->
  37. <u-loadmore :status="loadMoreStatus" />
  38. </template>
  39. <template v-else>
  40. <!-- 暂无数据 -->
  41. <view class="flex-items-plus">
  42. <image src="../../static/images/empty.png" class="empty "></image>
  43. </view>
  44. <view class="font28 font-gray flex-items-plus">
  45. 数据为空
  46. </view>
  47. <no-data text="暂无访问记录" mode="list"></no-data>
  48. </template>
  49. </scroll-view>
  50. </template>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. mapGetters
  56. } from 'vuex';
  57. export default {
  58. data() {
  59. return {
  60. visitList: [],
  61. loadMoreStatus: 'loadmore', // loadmore, loading, nomore
  62. params: {
  63. current: 1,
  64. size: 10,
  65. },
  66. hasMore: true
  67. };
  68. },
  69. computed: {
  70. ...mapGetters(['isLogin'])
  71. },
  72. onLoad() {
  73. this.getList();
  74. },
  75. onShow() {
  76. },
  77. onPullDownRefresh() {
  78. this.refresh()
  79. uni.stopPullDownRefresh();
  80. },
  81. methods: {
  82. // Refresh list
  83. refresh() {
  84. this.visitList = []
  85. this.params.current = 1
  86. this.hasMore = true
  87. this.loadMoreStatus = 'loadmore'
  88. this.getList()
  89. },
  90. // Handle reaching bottom of scroll
  91. onReachBottom() {
  92. if (!this.hasMore || this.loadMoreStatus === 'loading') return
  93. this.params.current++
  94. this.getList(true)
  95. },
  96. // Get status class for styling
  97. getStatusClass(status) {
  98. const statusMap = {
  99. '待访问': 'status-pending-visit',
  100. '待审核': 'status-pending-review',
  101. '已拒绝': 'status-rejected'
  102. }
  103. return statusMap[status] || 'status-default'
  104. },
  105. // Get visit list with mock data
  106. getList(loadMore = false) {
  107. if (!loadMore) {
  108. uni.showLoading({
  109. title: '加载中...'
  110. });
  111. }
  112. this.loadMoreStatus = 'loading'
  113. // 模拟接口延迟
  114. setTimeout(() => {
  115. // 模拟数据
  116. const mockData = Array(10).fill(0).map((_, index) => {
  117. const currentIndex = (this.params.current - 1) * 10 + index;
  118. const date = new Date();
  119. date.setDate(date.getDate() - currentIndex); // 每条数据日期递减
  120. const statusList = ['待访问', '待审核', '已拒绝'];
  121. const contactPersons = ['范海洋', '张河嘉', '李明', '王芳'];
  122. const descList = [
  123. '我是访问事由我是访问事由我是访问事由...',
  124. '需要进行业务对接商谈...',
  125. '产品展示与技术交流...',
  126. '项目合作洽谈...'
  127. ];
  128. return {
  129. id: currentIndex,
  130. contactPerson: contactPersons[Math.floor(Math.random() * contactPersons
  131. .length)],
  132. createTime: date,
  133. status: statusList[Math.floor(Math.random() * statusList.length)],
  134. visitReason: descList[Math.floor(Math.random() * descList.length)]
  135. };
  136. });
  137. const list = mockData.map(item => ({
  138. ...item,
  139. date: this.$u.timeFormat(item.createTime, 'DD'),
  140. year: this.$u.timeFormat(item.createTime, 'YYYY/MM'),
  141. time: this.$u.timeFormat(item.createTime, 'hh:mm')
  142. }));
  143. if (loadMore) {
  144. this.visitList = [...this.visitList, ...list];
  145. } else {
  146. this.visitList = list;
  147. }
  148. // 模拟总共有5页数据
  149. this.hasMore = this.params.current < 5;
  150. this.loadMoreStatus = this.hasMore ? 'loadmore' : 'nomore';
  151. if (!loadMore) {
  152. uni.hideLoading();
  153. }
  154. }, 500); // 增加500ms延迟模拟网络请求
  155. },
  156. // 跳转到详情页面
  157. goToDetail(item) {
  158. uni.navigateTo({
  159. url: `/pagesA/task/detail?id=${item.id}&status=${item.status}`
  160. });
  161. },
  162. // 跳转到登录页面
  163. goToLogin() {
  164. uni.navigateTo({
  165. url: '/pagesA/public/login'
  166. });
  167. },
  168. }
  169. };
  170. </script>
  171. <style lang="scss" scoped>
  172. .container {
  173. min-height: 100vh;
  174. background-color: #f5f5f5;
  175. .no-login {
  176. display: flex;
  177. flex-direction: column;
  178. align-items: center;
  179. justify-content: center;
  180. padding-top: 30vh;
  181. .no-login-image {
  182. width: 240rpx;
  183. height: 240rpx;
  184. margin-bottom: 40rpx;
  185. }
  186. .no-login-text {
  187. font-size: 32rpx;
  188. color: #999;
  189. margin-bottom: 60rpx;
  190. }
  191. .login-btn {
  192. width: 320rpx;
  193. height: 88rpx;
  194. background: #FF6B00;
  195. border-radius: 44rpx;
  196. color: #fff;
  197. font-size: 32rpx;
  198. font-weight: 500;
  199. display: flex;
  200. align-items: center;
  201. justify-content: center;
  202. }
  203. }
  204. }
  205. .visit-list {
  206. height: 100vh;
  207. }
  208. .visit-item {
  209. background-color: #fff;
  210. margin: 16rpx 20rpx;
  211. border-radius: 16rpx;
  212. padding: 24rpx;
  213. display: flex;
  214. align-items: flex-start;
  215. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  216. }
  217. .visit-date {
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. margin-right: 24rpx;
  222. min-width: 80rpx;
  223. .date-num {
  224. font-size: 48rpx;
  225. font-weight: bold;
  226. color: #333;
  227. line-height: 1;
  228. }
  229. .date-month {
  230. font-size: 24rpx;
  231. color: #999;
  232. margin-top: 4rpx;
  233. }
  234. }
  235. .visit-content {
  236. flex: 1;
  237. .visit-header {
  238. display: flex;
  239. justify-content: space-between;
  240. align-items: center;
  241. margin-bottom: 12rpx;
  242. .visitor-info {
  243. display: flex;
  244. align-items: center;
  245. .visitor-label {
  246. margin-right: 10rpx;
  247. font-size: 32rpx;
  248. color: #333;
  249. font-weight: normal;
  250. }
  251. .visitor-name {
  252. font-size: 36rpx;
  253. color: #333;
  254. font-weight: bold;
  255. }
  256. }
  257. .visit-status {
  258. font-size: 28rpx;
  259. padding: 4rpx 12rpx;
  260. border-radius: 12rpx;
  261. &.status-pending-visit {
  262. color: #4CAF50;
  263. background-color: rgba(76, 175, 80, 0.1);
  264. }
  265. &.status-pending-review {
  266. color: #2196F3;
  267. background-color: rgba(33, 150, 243, 0.1);
  268. }
  269. &.status-rejected {
  270. color: #F44336;
  271. background-color: rgba(244, 67, 54, 0.1);
  272. }
  273. }
  274. }
  275. .visit-desc {
  276. color: #666;
  277. font-size: 28rpx;
  278. line-height: 1.4;
  279. margin-bottom: 12rpx;
  280. }
  281. .visit-time {
  282. display: flex;
  283. align-items: center;
  284. gap: 8rpx;
  285. text {
  286. color: #999;
  287. font-size: 24rpx;
  288. }
  289. }
  290. }
  291. </style>