detail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <template>
  2. <!-- 任务详情 -->
  3. <view class="container">
  4. <!-- 状态标签 -->
  5. <view class="status-bar" :class="getStatusBarClass(visitDetail.status)">
  6. <text class="status-text">{{ visitDetail.status }}</text>
  7. </view>
  8. <!-- 详情内容 -->
  9. <view class="detail-container">
  10. <!-- 对接信息 -->
  11. <view class="section">
  12. <view class="section-title">
  13. <image class="title-icon" src="/static/images/person.png" mode="aspectFit"></image>
  14. <view class="title">
  15. 对接信息
  16. </view>
  17. </view>
  18. <view class="info-item">
  19. <text class="label">所属部门</text>
  20. <text class="value">{{visitDetail.department}}</text>
  21. </view>
  22. <view class="info-item">
  23. <text class="label">员工姓名</text>
  24. <text class="value">{{visitDetail.employeeName}}</text>
  25. </view>
  26. </view>
  27. <!-- 访问信息 -->
  28. <view class="section">
  29. <view class="section-title">
  30. <image class="title-icon" src="/static/images/calendar.png" mode="aspectFit"></image>
  31. <view class="title">
  32. 访问信息
  33. </view>
  34. </view>
  35. <view class="info-item">
  36. <text class="label">访问事由</text>
  37. <text class="value">{{visitDetail.visitReason}}</text>
  38. </view>
  39. <view class="info-item">
  40. <text class="label">到访时间</text>
  41. <text class="value">{{visitDetail.visitTime}}</text>
  42. </view>
  43. <view class="info-item">
  44. <text class="label">访客姓名</text>
  45. <text class="value">{{visitDetail.visitorName}}</text>
  46. </view>
  47. <view class="info-item">
  48. <text class="label">访客单位</text>
  49. <text class="value">{{visitDetail.visitorCompany}}</text>
  50. </view>
  51. <view class="info-item">
  52. <text class="label">手机号</text>
  53. <text class="value">{{visitDetail.visitorPhone}}</text>
  54. </view>
  55. </view>
  56. <!-- 随行人员 -->
  57. <view class="section" v-if="visitDetail.accompanyPersons && visitDetail.accompanyPersons.length > 0">
  58. <view class="section-title">
  59. <image class="title-icon" src="/static/images/person.png" mode="aspectFit"></image>
  60. <view class="title">
  61. 随行人员
  62. </view>
  63. </view>
  64. <view class="accompany-list">
  65. <view class="info-item" v-for="(person, index) in visitDetail.accompanyPersons" :key="index">
  66. <text class="label">随行人员{{index + 1}}</text>
  67. <view class="accompany-info">
  68. <text class="value">{{person.name}}</text>
  69. <text class="phone">{{person.phone}}</text>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. <!-- 使用车辆 -->
  75. <view class="section" v-if="visitDetail.useVehicle">
  76. <view class="section-title">
  77. <image class="title-icon" src="/static/images/cart.png" mode="aspectFit"></image>
  78. <view class="title">
  79. 车辆信息
  80. </view>
  81. <text class="vehicle-number">{{visitDetail.vehicleNumber}}</text>
  82. </view>
  83. <view class="info-item">
  84. <text class="label">接客时间</text>
  85. <text class="value">{{visitDetail.pickupTime}}</text>
  86. </view>
  87. <view class="info-item">
  88. <text class="label">接客地点</text>
  89. <text class="value">{{visitDetail.pickupLocation}}</text>
  90. </view>
  91. </view>
  92. </view>
  93. <!-- 操作按钮 - 仅待审核状态显示 -->
  94. <view class="action-container" v-if="visitDetail.status === '待审核'">
  95. <!-- <view class="action-container">-->
  96. <button class="reject-btn" @click="handleReject">拒绝</button>
  97. <button class="approve-btn" @click="handleApprove">通过</button>
  98. </view>
  99. <!-- 确认弹框 -->
  100. <uni-popup ref="confirmPopup" type="center">
  101. <view class="confirm-popup">
  102. <view class="popup-content">
  103. <view class="popup-title">{{confirmAction === 'approve' ? '确认通过' : '确认拒绝'}}</view>
  104. <view class="popup-message">
  105. {{confirmAction === 'approve' ? '确定要通过这个访问申请吗?' : '确定要拒绝这个访问申请吗?'}}
  106. </view>
  107. <view class="popup-buttons">
  108. <button class="cancel-btn" @click="cancelAction">取消</button>
  109. <button class="confirm-btn"
  110. @click="confirmAction === 'approve' ? approveVisit() : rejectVisit()">
  111. 确定
  112. </button>
  113. </view>
  114. </view>
  115. </view>
  116. </uni-popup>
  117. <!-- 结果提示弹框 -->
  118. <uni-popup ref="resultPopup" type="center">
  119. <view class="result-popup">
  120. <view class="popup-content">
  121. <view class="result-icon" :class="resultType">
  122. <uni-icons :type="resultType === 'success' ? 'checkmarkempty' : 'closeempty'" size="60"
  123. :color="resultType === 'success' ? '#52c41a' : '#ff4757'"></uni-icons>
  124. </view>
  125. <view class="popup-title">{{resultTitle}}</view>
  126. <view class="popup-message">{{resultMessage}}</view>
  127. <button class="close-btn" @click="closeResultPopup">确定</button>
  128. </view>
  129. </view>
  130. </uni-popup>
  131. </view>
  132. </template>
  133. <script>
  134. import {
  135. updateVisitInfo
  136. } from '@/config/api.js';
  137. export default {
  138. data() {
  139. return {
  140. visitId: '',
  141. visitDetail: {
  142. id: '',
  143. department: '',
  144. employeeName: '',
  145. visitReason: '',
  146. visitTime: '',
  147. visitorName: '',
  148. visitorCompany: '',
  149. visitorPhone: '',
  150. status: '',
  151. useVehicle: false,
  152. vehicleNumber: '',
  153. pickupTime: '',
  154. pickupLocation: '',
  155. accompanyPersons: []
  156. },
  157. confirmAction: '', // 'approve' 或 'reject'
  158. resultType: '', // 'success' 或 'error'
  159. resultTitle: '',
  160. resultMessage: ''
  161. }
  162. },
  163. onLoad(options) {
  164. if (options.id) {
  165. this.visitId = options.id;
  166. this.getVisitDetail();
  167. }
  168. },
  169. methods: {
  170. // 获取状态栏样式类
  171. getStatusBarClass(status) {
  172. const statusClassMap = {
  173. '待访问': 'status-bar-pending-visit',
  174. '已访问': 'status-bar-visited',
  175. '待审核': 'status-bar-pending-review',
  176. '已拒绝': 'status-bar-rejected'
  177. };
  178. return statusClassMap[status] || 'status-bar-default';
  179. },
  180. // 获取访问详情
  181. getVisitDetail() {
  182. // 从缓存中获取数据
  183. const visitData = uni.getStorageSync('visitDetailData');
  184. if (visitData) {
  185. // 解析随行人员数据
  186. let accompanyPersons = [];
  187. if (visitData.accPerson) {
  188. try {
  189. const accPersonData = typeof visitData.accPerson === 'string' ? JSON.parse(visitData.accPerson) : visitData.accPerson;
  190. if (Array.isArray(accPersonData)) {
  191. accompanyPersons = accPersonData.map(person => ({
  192. name: person.name || person.accName || '',
  193. phone: person.phone || person.accTel || ''
  194. }));
  195. }
  196. } catch (error) {
  197. console.error('解析随行人员数据失败:', error);
  198. }
  199. }
  200. // 设置详情数据
  201. this.visitDetail = {
  202. id: visitData.id,
  203. department: visitData.visDept || '', // 访客单位作为部门
  204. employeeName: visitData.employeeName,
  205. visitReason: visitData.visitReason,
  206. visitTime: visitData.visitDate,
  207. visitorName: visitData.visitorName,
  208. visitorCompany: visitData.visitorCompany,
  209. visitorPhone: visitData.visitorPhone,
  210. status: visitData.status,
  211. useVehicle: visitData.useVehicle || false,
  212. vehicleNumber: visitData.vehicleNumber || '',
  213. pickupTime: visitData.pickupTime || '',
  214. pickupLocation: visitData.pickupLocation || '',
  215. accompanyPersons: accompanyPersons
  216. };
  217. // 清除缓存
  218. uni.removeStorageSync('visitDetailData');
  219. }
  220. },
  221. // 处理拒绝
  222. handleReject() {
  223. this.confirmAction = 'reject';
  224. this.$refs.confirmPopup.open();
  225. },
  226. // 处理通过
  227. handleApprove() {
  228. this.confirmAction = 'approve';
  229. this.$refs.confirmPopup.open();
  230. },
  231. // 取消操作
  232. cancelAction() {
  233. this.$refs.confirmPopup.close();
  234. this.confirmAction = '';
  235. },
  236. // 确认通过
  237. async approveVisit() {
  238. this.$refs.confirmPopup.close();
  239. uni.showLoading({
  240. title: '处理中...'
  241. });
  242. try {
  243. // 调用接口,状态改为 0=待访问(通过)
  244. const response = await updateVisitInfo({
  245. id: this.visitDetail.id,
  246. visitStatus: '0'
  247. });
  248. uni.hideLoading();
  249. if (response && response.code === 200) {
  250. // 实时更新本地状态
  251. this.visitDetail.status = '待访问';
  252. // 强制页面刷新
  253. this.$forceUpdate();
  254. // 显示成功提示
  255. this.resultType = 'success';
  256. this.resultTitle = '审核通过';
  257. this.resultMessage = '访问申请已通过,访客将收到通知';
  258. this.$refs.resultPopup.open();
  259. // 通知 visitor.vue 刷新列表
  260. uni.$emit('refreshVisitList');
  261. console.log('审核通过,状态已更新为:', this.visitDetail.status);
  262. } else {
  263. uni.showToast({
  264. title: response.msg || '操作失败',
  265. icon: 'none'
  266. });
  267. }
  268. } catch (error) {
  269. uni.hideLoading();
  270. console.error('审核通过失败:', error);
  271. uni.showToast({
  272. title: '操作失败,请重试',
  273. icon: 'none'
  274. });
  275. }
  276. },
  277. // 确认拒绝
  278. async rejectVisit() {
  279. this.$refs.confirmPopup.close();
  280. uni.showLoading({
  281. title: '处理中...'
  282. });
  283. try {
  284. // 调用接口,状态改为 3=已拒绝
  285. const response = await updateVisitInfo({
  286. id: this.visitDetail.id,
  287. visitStatus: '3'
  288. });
  289. uni.hideLoading();
  290. if (response && response.code === 200) {
  291. // 实时更新本地状态
  292. this.visitDetail.status = '已拒绝';
  293. // 强制页面刷新
  294. this.$forceUpdate();
  295. // 显示成功提示
  296. this.resultType = 'success';
  297. this.resultTitle = '审核完成';
  298. this.resultMessage = '访问申请已拒绝,访客将收到通知';
  299. this.$refs.resultPopup.open();
  300. // 通知 visitor.vue 刷新列表
  301. uni.$emit('refreshVisitList');
  302. console.log('审核拒绝,状态已更新为:', this.visitDetail.status);
  303. } else {
  304. uni.showToast({
  305. title: response.msg || '操作失败',
  306. icon: 'none'
  307. });
  308. }
  309. } catch (error) {
  310. uni.hideLoading();
  311. console.error('拒绝访问失败:', error);
  312. uni.showToast({
  313. title: '操作失败,请重试',
  314. icon: 'none'
  315. });
  316. }
  317. },
  318. // 关闭结果弹框
  319. closeResultPopup() {
  320. this.$refs.resultPopup.close();
  321. // 返回上一页
  322. uni.navigateBack();
  323. }
  324. }
  325. }
  326. </script>
  327. <style lang="scss" scoped>
  328. .container {
  329. min-height: 100vh;
  330. background-color: #f5f5f5;
  331. padding-bottom: 140rpx;
  332. }
  333. // 状态栏样式
  334. .status-bar {
  335. margin: 20rpx;
  336. padding: 20rpx 30rpx;
  337. border-radius: 12rpx;
  338. text-align: center;
  339. .status-text {
  340. font-size: 32rpx;
  341. font-weight: 600;
  342. }
  343. &.status-bar-pending-visit {
  344. background: linear-gradient(135deg, rgba(76, 175, 80, 0.1) 0%, rgba(76, 175, 80, 0.2) 100%);
  345. border: 2rpx solid rgba(76, 175, 80, 0.3);
  346. .status-text {
  347. color: #4CAF50;
  348. }
  349. }
  350. &.status-bar-visited {
  351. background: linear-gradient(135deg, rgba(33, 150, 243, 0.1) 0%, rgba(33, 150, 243, 0.2) 100%);
  352. border: 2rpx solid rgba(33, 150, 243, 0.3);
  353. .status-text {
  354. color: #2196F3;
  355. }
  356. }
  357. &.status-bar-pending-review {
  358. background: linear-gradient(135deg, rgba(255, 152, 0, 0.1) 0%, rgba(255, 152, 0, 0.2) 100%);
  359. border: 2rpx solid rgba(255, 152, 0, 0.3);
  360. .status-text {
  361. color: #FF9800;
  362. }
  363. }
  364. &.status-bar-rejected {
  365. background: linear-gradient(135deg, rgba(244, 67, 54, 0.1) 0%, rgba(244, 67, 54, 0.2) 100%);
  366. border: 2rpx solid rgba(244, 67, 54, 0.3);
  367. .status-text {
  368. color: #F44336;
  369. }
  370. }
  371. &.status-bar-default {
  372. background: linear-gradient(135deg, rgba(158, 158, 158, 0.1) 0%, rgba(158, 158, 158, 0.2) 100%);
  373. border: 2rpx solid rgba(158, 158, 158, 0.3);
  374. .status-text {
  375. color: #999;
  376. }
  377. }
  378. }
  379. .detail-container {
  380. padding: 20rpx;
  381. }
  382. .section {
  383. background-color: #fff;
  384. border-radius: 16rpx;
  385. margin-bottom: 20rpx;
  386. padding: 30rpx;
  387. }
  388. .section-title {
  389. margin-bottom: 30rpx;
  390. display: flex;
  391. align-items: center;
  392. }
  393. .title {
  394. font-size: 32rpx;
  395. font-weight: 600;
  396. color: #333;
  397. }
  398. .title-icon {
  399. width: 40rpx;
  400. height: 40rpx;
  401. margin-right: 15rpx;
  402. }
  403. .vehicle-number {
  404. font-size: 28rpx;
  405. color: #666;
  406. font-weight: normal;
  407. margin-left: auto;
  408. }
  409. .info-item {
  410. display: flex;
  411. align-items: flex-start;
  412. margin-bottom: 24rpx;
  413. &:last-child {
  414. margin-bottom: 0;
  415. }
  416. }
  417. .label {
  418. width: 160rpx;
  419. font-size: 28rpx;
  420. color: #666;
  421. flex-shrink: 0;
  422. line-height: 1.5;
  423. }
  424. .value {
  425. flex: 1;
  426. font-size: 28rpx;
  427. color: #333;
  428. line-height: 1.5;
  429. word-break: break-all;
  430. }
  431. .accompany-info {
  432. flex: 1;
  433. display: flex;
  434. flex-direction: column;
  435. gap: 8rpx;
  436. .value {
  437. font-size: 28rpx;
  438. color: #333;
  439. }
  440. .phone {
  441. font-size: 24rpx;
  442. color: #666;
  443. }
  444. }
  445. .action-container {
  446. position: fixed;
  447. bottom: 0;
  448. left: 0;
  449. right: 0;
  450. padding: 20rpx;
  451. background-color: #fff;
  452. box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.1);
  453. display: flex;
  454. gap: 20rpx;
  455. }
  456. .reject-btn,
  457. .approve-btn {
  458. flex: 1;
  459. height: 88rpx;
  460. border-radius: 44rpx;
  461. border: none;
  462. font-size: 32rpx;
  463. font-weight: 600;
  464. }
  465. .reject-btn {
  466. background-color: #fff;
  467. color: #ff4757;
  468. border: 2rpx solid #ff4757;
  469. }
  470. .approve-btn {
  471. background: #39833b;
  472. color: #fff;
  473. }
  474. // 弹框样式
  475. .confirm-popup,
  476. .result-popup {
  477. .popup-content {
  478. background-color: #fff;
  479. border-radius: 20rpx;
  480. padding: 60rpx 40rpx 40rpx;
  481. width: 560rpx;
  482. text-align: center;
  483. }
  484. .popup-title {
  485. font-size: 36rpx;
  486. font-weight: 600;
  487. color: #333;
  488. margin-bottom: 20rpx;
  489. }
  490. .popup-message {
  491. font-size: 28rpx;
  492. color: #666;
  493. line-height: 1.6;
  494. margin-bottom: 40rpx;
  495. }
  496. }
  497. .popup-buttons {
  498. display: flex;
  499. gap: 20rpx;
  500. .cancel-btn,
  501. .confirm-btn {
  502. flex: 1;
  503. height: 80rpx;
  504. border-radius: 40rpx;
  505. font-size: 28rpx;
  506. border: none;
  507. }
  508. .cancel-btn {
  509. background-color: #f5f5f5;
  510. color: #666;
  511. }
  512. .confirm-btn {
  513. background: linear-gradient(135deg, #ff6b35 0%, #ff9500 100%);
  514. color: #fff;
  515. }
  516. }
  517. .result-icon {
  518. margin-bottom: 30rpx;
  519. &.success {
  520. // success icon styling handled by uni-icons color
  521. }
  522. &.error {
  523. // error icon styling handled by uni-icons color
  524. }
  525. }
  526. .close-btn {
  527. width: 100%;
  528. height: 80rpx;
  529. background: linear-gradient(135deg, #ff6b35 0%, #ff9500 100%);
  530. border-radius: 40rpx;
  531. color: #fff;
  532. font-size: 28rpx;
  533. border: none;
  534. }
  535. </style>