visitor.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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. </template>
  48. </scroll-view>
  49. </template>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. mapGetters
  55. } from 'vuex';
  56. import {
  57. getVisitList
  58. } from '@/config/api.js';
  59. export default {
  60. data() {
  61. return {
  62. user: {},
  63. visitStatus: '0',
  64. visitList: [],
  65. loadMoreStatus: 'loadmore', // loadmore, loading, nomore
  66. params: {
  67. current: 1,
  68. size: 10,
  69. },
  70. hasMore: true
  71. };
  72. },
  73. computed: {
  74. ...mapGetters(['isLogin'])
  75. },
  76. onLoad() {
  77. this.user = uni.getStorageSync("user")
  78. console.log(uni.getStorageSync("user"), "usususuus")
  79. this.getList();
  80. },
  81. onShow() {
  82. },
  83. onPullDownRefresh() {
  84. this.refresh()
  85. uni.stopPullDownRefresh();
  86. },
  87. methods: {
  88. // Refresh list
  89. refresh() {
  90. this.visitList = []
  91. this.params.current = 1
  92. this.hasMore = true
  93. this.loadMoreStatus = 'loadmore'
  94. this.getList()
  95. },
  96. // Handle reaching bottom of scroll
  97. onReachBottom() {
  98. if (!this.hasMore || this.loadMoreStatus === 'loading') return
  99. this.params.current++
  100. this.getList(true)
  101. },
  102. // Get status class for styling
  103. getStatusClass(status) {
  104. const statusMap = {
  105. '待访问': 'status-pending-visit',
  106. '待审核': 'status-pending-review',
  107. '已拒绝': 'status-rejected'
  108. }
  109. return statusMap[status] || 'status-default'
  110. },
  111. // 获取访客列表
  112. async getList(loadMore = false) {
  113. if (!loadMore) {
  114. uni.showLoading({
  115. title: '加载中...'
  116. });
  117. }
  118. this.loadMoreStatus = 'loading'
  119. try {
  120. // 调用接口获取数据
  121. const response = await getVisitList({
  122. userId: 100,
  123. visitStatus: this.visitStatus || '0' // 可以根据需要传递状态参数,空字符串表示获取所有状态
  124. });
  125. console.log('访客列表接口返回:', response);
  126. if (response && response.code === 200) {
  127. // 处理返回的数据
  128. const statusMap = {
  129. '0': '待访问',
  130. '1': '已访问',
  131. '2': '待审核',
  132. '3': '已拒绝'
  133. };
  134. const list = response.rows.map(item => {
  135. // 解析创建时间
  136. const createTime = item.createTime || item.visitDate;
  137. return {
  138. id: item.id,
  139. employeeName: item.empName, // 对接人(员工姓名)
  140. visitReason: item.visitReson, // 访问事由
  141. status: statusMap[item.visitStatus] || '未知', // 状态
  142. visitDate: item.visitDate, // 访问时间
  143. visitorName: item.visitPerson, // 访客姓名
  144. visitorCompany: item.visDept, // 访客单位
  145. visitorPhone: item.visitorTel, // 访客电话
  146. visitorNum: item.visitorNum, // 访客人数
  147. accPerson: item.accPerson, // 随行人员(JSON字符串)
  148. createTime: createTime,
  149. // 格式化显示用的字段
  150. date: this.$u.timeFormat(createTime, 'dd'),
  151. year: this.$u.timeFormat(createTime, 'yyyy/mm'),
  152. time: this.$u.timeFormat(createTime, 'hh:MM')
  153. };
  154. });
  155. if (loadMore) {
  156. this.visitList = [...this.visitList, ...list];
  157. } else {
  158. this.visitList = list;
  159. }
  160. // 根据返回的数据判断是否还有更多数据
  161. // 这里简单处理,如果返回的数据少于每页数量,说明没有更多了
  162. this.hasMore = response.rows.length >= this.params.size;
  163. this.loadMoreStatus = this.hasMore ? 'loadmore' : 'nomore';
  164. } else {
  165. uni.showToast({
  166. title: response.msg || '获取数据失败',
  167. icon: 'none'
  168. });
  169. this.loadMoreStatus = 'nomore';
  170. }
  171. } catch (error) {
  172. console.error('获取访客列表失败:', error);
  173. uni.showToast({
  174. title: '获取数据失败',
  175. icon: 'none'
  176. });
  177. this.loadMoreStatus = 'nomore';
  178. } finally {
  179. if (!loadMore) {
  180. uni.hideLoading();
  181. }
  182. }
  183. },
  184. // 跳转到详情页面
  185. goToDetail(item) {
  186. // 将完整对象数据存储到缓存,用于详情页读取
  187. uni.setStorageSync('visitDetailData', item);
  188. uni.navigateTo({
  189. url: `/pagesA/task/detail?id=${item.id}`
  190. });
  191. },
  192. // 跳转到登录页面
  193. goToLogin() {
  194. uni.navigateTo({
  195. url: '/pagesA/public/login'
  196. });
  197. },
  198. }
  199. };
  200. </script>
  201. <style lang="scss" scoped>
  202. .container {
  203. min-height: 100vh;
  204. background-color: #f5f5f5;
  205. .no-login {
  206. display: flex;
  207. flex-direction: column;
  208. align-items: center;
  209. justify-content: center;
  210. padding-top: 30vh;
  211. .no-login-image {
  212. width: 240rpx;
  213. height: 240rpx;
  214. margin-bottom: 40rpx;
  215. }
  216. .no-login-text {
  217. font-size: 32rpx;
  218. color: #999;
  219. margin-bottom: 60rpx;
  220. }
  221. .login-btn {
  222. width: 320rpx;
  223. height: 88rpx;
  224. background: #FF6B00;
  225. border-radius: 44rpx;
  226. color: #fff;
  227. font-size: 32rpx;
  228. font-weight: 500;
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. }
  233. }
  234. }
  235. .visit-list {
  236. height: 100vh;
  237. }
  238. .visit-item {
  239. background-color: #fff;
  240. margin: 16rpx 20rpx;
  241. border-radius: 16rpx;
  242. padding: 24rpx;
  243. display: flex;
  244. align-items: flex-start;
  245. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  246. }
  247. .visit-date {
  248. display: flex;
  249. flex-direction: column;
  250. align-items: center;
  251. margin-right: 24rpx;
  252. min-width: 80rpx;
  253. .date-num {
  254. font-size: 48rpx;
  255. font-weight: bold;
  256. color: #333;
  257. line-height: 1;
  258. }
  259. .date-month {
  260. font-size: 24rpx;
  261. color: #999;
  262. margin-top: 4rpx;
  263. }
  264. }
  265. .visit-content {
  266. flex: 1;
  267. .visit-header {
  268. display: flex;
  269. justify-content: space-between;
  270. align-items: center;
  271. margin-bottom: 12rpx;
  272. .visitor-info {
  273. display: flex;
  274. align-items: center;
  275. .visitor-label {
  276. margin-right: 10rpx;
  277. font-size: 32rpx;
  278. color: #333;
  279. font-weight: normal;
  280. }
  281. .visitor-name {
  282. font-size: 36rpx;
  283. color: #333;
  284. font-weight: bold;
  285. }
  286. }
  287. .visit-status {
  288. font-size: 28rpx;
  289. padding: 4rpx 12rpx;
  290. border-radius: 12rpx;
  291. &.status-pending-visit {
  292. color: #4CAF50;
  293. background-color: rgba(76, 175, 80, 0.1);
  294. }
  295. &.status-pending-review {
  296. color: #2196F3;
  297. background-color: rgba(33, 150, 243, 0.1);
  298. }
  299. &.status-rejected {
  300. color: #F44336;
  301. background-color: rgba(244, 67, 54, 0.1);
  302. }
  303. }
  304. }
  305. .visit-desc {
  306. color: #666;
  307. font-size: 28rpx;
  308. line-height: 1.4;
  309. margin-bottom: 12rpx;
  310. }
  311. .visit-time {
  312. display: flex;
  313. align-items: center;
  314. gap: 8rpx;
  315. text {
  316. color: #999;
  317. font-size: 24rpx;
  318. }
  319. }
  320. }
  321. </style>