index.vue.备份 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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="taskList.length > 0">
  16. <view class="visit-item" v-for="(item, index) in taskList" :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. <!-- Floating button -->
  50. <view class="floating-button" @click="showApplyPopup">
  51. <text class="floating-text">申请<br>访问</text>
  52. </view>
  53. </template>
  54. <!-- Application method popup -->
  55. <uni-popup ref="popup" type="center" border-radius="16rpx">
  56. <view class="popup-content">
  57. <view class="popup-title">
  58. 选择申请方式
  59. <text class="close-icon" @click="closePopup">×</text>
  60. </view>
  61. <view class="apply-methods">
  62. <view class="method-item" @click="handleApply('self')">
  63. <view class="method-icon green-bg">
  64. <image src="/static/images/apply.png" mode="aspectFit"></image>
  65. </view>
  66. <text class="font-bold">发起申请</text>
  67. </view>
  68. <view class="method-item" @click="handleApply('proxy')">
  69. <view class="method-icon orange-bg">
  70. <image src="/static/images/behalf.png" mode="aspectFit"></image>
  71. </view>
  72. <text class="font-bold">代客申请</text>
  73. </view>
  74. </view>
  75. </view>
  76. </uni-popup>
  77. </view>
  78. </template>
  79. <script>
  80. import {
  81. orderList,
  82. userLogin
  83. } from '@/config/api.js';
  84. import {
  85. mapGetters
  86. } from 'vuex';
  87. import {
  88. shareImg
  89. } from '@/common/config.js'
  90. export default {
  91. data() {
  92. return {
  93. taskList: [],
  94. loadMoreStatus: 'loadmore', // loadmore, loading, nomore
  95. params: {
  96. current: 1,
  97. size: 10,
  98. },
  99. hasMore: true
  100. }
  101. },
  102. computed: {
  103. ...mapGetters(['isLogin'])
  104. },
  105. onLoad(options) {
  106. this.getList();
  107. },
  108. // 微信小程序分享配置
  109. onShareAppMessage() {
  110. return {
  111. title: `邀请您加入知己访客`,
  112. path: `/pages/index/index`,
  113. imageUrl: shareImg // 分享图片,需要添加
  114. }
  115. },
  116. onShareTimeline(res) {
  117. let that = this;
  118. let shareInfo = store.state.vuex_shareInfo;
  119. let query = shareInfo.query;
  120. //携带当前页面资源ID参数
  121. let currentPage = getCurrentPages()[getCurrentPages().length - 1];
  122. let options = currentPage.options;
  123. if (JSON.stringify(options) != '{}' && options.id) {
  124. query += `&id=${options.id}`;
  125. }
  126. return {
  127. title: shareInfo.title,
  128. query: query,
  129. imageUrl: shareImg,
  130. success(res) {
  131. uni.showToast({
  132. title: '分享成功'
  133. })
  134. },
  135. fail(res) {
  136. uni.showToast({
  137. title: '分享失败',
  138. icon: 'none'
  139. })
  140. },
  141. }
  142. },
  143. onShow() {
  144. // #ifdef H5
  145. this.login()
  146. // #endif
  147. },
  148. onPullDownRefresh() {
  149. this.refresh()
  150. uni.stopPullDownRefresh();
  151. },
  152. methods: {
  153. // Refresh list
  154. refresh() {
  155. this.taskList = []
  156. this.params.current = 1
  157. this.hasMore = true
  158. this.loadMoreStatus = 'loadmore'
  159. this.getList()
  160. },
  161. // Handle reaching bottom of scroll
  162. onReachBottom() {
  163. if (!this.hasMore || this.loadMoreStatus === 'loading') return
  164. this.params.current++
  165. this.getList(true)
  166. },
  167. // Show apply popup
  168. showApplyPopup() {
  169. console.log('显示申请弹窗');
  170. this.$refs.popup.open()
  171. },
  172. // Close popup
  173. closePopup() {
  174. this.$refs.popup.close()
  175. },
  176. // Handle apply method selection
  177. handleApply(type) {
  178. if (!this.isLogin) {
  179. uni.navigateTo({
  180. url: '/pagesA/public/login'
  181. });
  182. return
  183. }
  184. console.log('选择申请方式:', type);
  185. this.$refs.popup.close()
  186. if (type === 'self') {
  187. uni.navigateTo({
  188. url: '/pagesA/task/edit?type=1'
  189. })
  190. } else {
  191. uni.navigateTo({
  192. url: '/pagesA/task/edit?type=2'
  193. })
  194. }
  195. },
  196. // Login method
  197. login() {
  198. let params = {
  199. username: "USER082927",
  200. grant_type: "web",
  201. memberId: "1957060037088083973"
  202. }
  203. userLogin(params).then((loginData) => {
  204. uni.setStorageSync('access_token', loginData.access_token);
  205. uni.setStorageSync('refresh_token', loginData.refresh_token);
  206. uni.setStorageSync('user', loginData);
  207. this.$store.commit('isLogin', true);
  208. this.$store.commit('refresh_token', loginData.refresh_token);
  209. })
  210. },
  211. // Get visit list with mock data
  212. getList(loadMore = false) {
  213. if (!loadMore) {
  214. uni.showLoading({
  215. title: '加载中...'
  216. });
  217. }
  218. this.loadMoreStatus = 'loading'
  219. // 模拟接口延迟
  220. setTimeout(() => {
  221. // 模拟数据
  222. const mockData = Array(10).fill(0).map((_, index) => {
  223. const currentIndex = (this.params.current - 1) * 10 + index;
  224. const date = new Date();
  225. date.setDate(date.getDate() - currentIndex); // 每条数据日期递减
  226. const statusList = ['待访问', '待审核', '已拒绝'];
  227. const descList = [
  228. '我是访问事由我是访问事由我是访问事由...',
  229. '需要进行业务对接商谈...',
  230. '产品展示与技术交流...',
  231. '项目合作洽谈...'
  232. ];
  233. return {
  234. id: currentIndex,
  235. employeeName: `范海洋${currentIndex + 1}`,
  236. createTime: date,
  237. status: statusList[Math.floor(Math.random() * statusList.length)],
  238. visitReason: descList[Math.floor(Math.random() * descList.length)]
  239. };
  240. });
  241. const list = mockData.map(item => ({
  242. ...item,
  243. date: this.$u.timeFormat(item.createTime, 'DD'),
  244. year: this.$u.timeFormat(item.createTime, 'YYYY/MM'),
  245. time: this.$u.timeFormat(item.createTime, 'hh:mm')
  246. }));
  247. if (loadMore) {
  248. this.taskList = [...this.taskList, ...list];
  249. } else {
  250. this.taskList = list;
  251. }
  252. // 模拟总共有5页数据
  253. this.hasMore = this.params.current < 5;
  254. this.loadMoreStatus = this.hasMore ? 'loadmore' : 'nomore';
  255. if (!loadMore) {
  256. uni.hideLoading();
  257. }
  258. }, 500); // 增加500ms延迟模拟网络请求
  259. },
  260. // Get status class for styling
  261. getStatusClass(status) {
  262. const statusMap = {
  263. '待访问': 'status-pending-visit',
  264. '待审核': 'status-pending-review',
  265. '已拒绝': 'status-rejected'
  266. }
  267. return statusMap[status] || 'status-default'
  268. },
  269. // 跳转到详情页面
  270. goToDetail(item) {
  271. uni.navigateTo({
  272. url: `/pagesA/task/detail?id=${item.id}&status=${item.status}`
  273. });
  274. },
  275. // 跳转到登录页面
  276. goToLogin() {
  277. uni.navigateTo({
  278. url: '/pagesA/public/login'
  279. });
  280. },
  281. },
  282. }
  283. </script>
  284. <style lang="scss" scoped>
  285. .container {
  286. min-height: 100vh;
  287. background-color: #f5f5f5;
  288. .no-login {
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. justify-content: center;
  293. padding-top: 30vh;
  294. .no-login-image {
  295. width: 240rpx;
  296. height: 240rpx;
  297. margin-bottom: 40rpx;
  298. }
  299. .no-login-text {
  300. font-size: 32rpx;
  301. color: #999;
  302. margin-bottom: 60rpx;
  303. }
  304. .login-btn {
  305. width: 320rpx;
  306. height: 88rpx;
  307. background: #FF6B00;
  308. border-radius: 44rpx;
  309. color: #fff;
  310. font-size: 32rpx;
  311. font-weight: 500;
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. }
  316. }
  317. }
  318. .visit-list {
  319. height: 100vh;
  320. }
  321. .visit-item {
  322. background-color: #fff;
  323. margin: 16rpx 20rpx;
  324. border-radius: 16rpx;
  325. padding: 24rpx;
  326. display: flex;
  327. align-items: flex-start;
  328. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  329. }
  330. .visit-date {
  331. display: flex;
  332. flex-direction: column;
  333. align-items: center;
  334. margin-right: 24rpx;
  335. min-width: 80rpx;
  336. .date-num {
  337. font-size: 48rpx;
  338. font-weight: bold;
  339. color: #333;
  340. line-height: 1;
  341. }
  342. .date-month {
  343. font-size: 24rpx;
  344. color: #999;
  345. margin-top: 4rpx;
  346. }
  347. }
  348. .visit-content {
  349. flex: 1;
  350. .visit-header {
  351. display: flex;
  352. justify-content: space-between;
  353. align-items: center;
  354. margin-bottom: 12rpx;
  355. .visitor-info {
  356. display: flex;
  357. align-items: center;
  358. .visitor-label {
  359. margin-right: 10rpx;
  360. font-size: 32rpx;
  361. color: #333;
  362. font-weight: normal;
  363. }
  364. .visitor-name {
  365. font-size: 36rpx;
  366. color: #333;
  367. font-weight: bold;
  368. }
  369. }
  370. .visit-status {
  371. font-size: 28rpx;
  372. padding: 4rpx 12rpx;
  373. border-radius: 12rpx;
  374. &.status-pending-visit {
  375. color: #4CAF50;
  376. background-color: rgba(76, 175, 80, 0.1);
  377. }
  378. &.status-pending-review {
  379. color: #2196F3;
  380. background-color: rgba(33, 150, 243, 0.1);
  381. }
  382. &.status-rejected {
  383. color: #F44336;
  384. background-color: rgba(244, 67, 54, 0.1);
  385. }
  386. }
  387. }
  388. .visit-desc {
  389. color: #666;
  390. font-size: 28rpx;
  391. line-height: 1.4;
  392. margin-bottom: 12rpx;
  393. }
  394. .visit-time {
  395. display: flex;
  396. align-items: center;
  397. gap: 8rpx;
  398. text {
  399. color: #999;
  400. font-size: 24rpx;
  401. }
  402. }
  403. }
  404. .floating-button {
  405. position: fixed;
  406. bottom: 120rpx;
  407. right: 40rpx;
  408. width: 120rpx;
  409. height: 120rpx;
  410. background-color: #FF6B00;
  411. border-radius: 16rpx;
  412. display: flex;
  413. align-items: center;
  414. justify-content: center;
  415. box-shadow: 0 8rpx 20rpx rgba(255, 107, 0, 0.3);
  416. z-index: 999;
  417. .floating-text {
  418. color: #fff;
  419. font-size: 28rpx;
  420. text-align: center;
  421. line-height: 1.2;
  422. }
  423. }
  424. .popup-content {
  425. width: 600rpx;
  426. padding: 70rpx 40rpx;
  427. background-color: #fff;
  428. border-radius: 16rpx;
  429. .popup-title {
  430. font-size: 36rpx;
  431. color: #333;
  432. text-align: center;
  433. position: relative;
  434. margin-bottom: 60rpx;
  435. font-weight: 500;
  436. .close-icon {
  437. position: absolute;
  438. right: 0;
  439. top: 50%;
  440. transform: translateY(-50%);
  441. font-size: 50rpx;
  442. color: #999;
  443. width: 60rpx;
  444. height: 60rpx;
  445. display: flex;
  446. align-items: center;
  447. justify-content: center;
  448. }
  449. }
  450. .apply-methods {
  451. display: flex;
  452. justify-content: space-around;
  453. padding: 0 20rpx;
  454. .method-item {
  455. display: flex;
  456. flex-direction: column;
  457. align-items: center;
  458. gap: 30rpx;
  459. cursor: pointer;
  460. .method-icon {
  461. width: 120rpx;
  462. height: 120rpx;
  463. border-radius: 20rpx;
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. image {
  468. width: 80rpx;
  469. height: 80rpx;
  470. }
  471. &.green-bg {
  472. background-color: #39833b;
  473. }
  474. &.orange-bg {
  475. background-color: #FF6B00;
  476. }
  477. }
  478. text {
  479. font-size: 32rpx;
  480. color: #333;
  481. font-weight: 500;
  482. }
  483. }
  484. }
  485. }
  486. </style>