visitor.vue 8.8 KB

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