index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. <!-- 订单详情 -->
  2. <template>
  3. <view>
  4. <view class="order-detail">
  5. <view class="service-info">
  6. <PositioningMap :address="detaile.address" />
  7. </view>
  8. <view class="user-info order-card">
  9. <view class="handle-user">
  10. <view class="handle-user-left">
  11. <img :src="detaile.avatar" alt=""
  12. style="width: 96rpx; height: 96rpx; margin-right: 32rpx" />
  13. <view class="handle-user-info">
  14. <view class="user-name">{{ detaile.clientName }}</view>
  15. <view class="user-id" style="display: flex">服务类别:{{ detaile.businessTireName }}</view>
  16. </view>
  17. </view>
  18. <view class="user-phone" @click="onPhone(detaile.clientPhoneNumber)">
  19. <up-icon name="phone" color="#fff" size="25"></up-icon>
  20. </view>
  21. </view>
  22. <view class="handle-adress">
  23. <up-icon name="map" color="rgba(156, 163, 175, 1)" size="20"></up-icon>
  24. <view class="adress-text">{{ detaile.address }}</view>
  25. <!-- <up-icon name="pushpin" color="rgba(221, 94, 69, 1)" size="25"></up-icon> -->
  26. </view>
  27. <view>
  28. <view class="handle-remark">
  29. <text class="remark-title">服务次数:{{detaile.singleQuantity }}次</text>
  30. </view>
  31. <view class="handle-remark">
  32. <text class="remark-title">服务时间: {{ detaile.workDate + ' '+ detaile.workStartTime }}</text>
  33. </view>
  34. </view>
  35. <view class="handle-remark">
  36. <view class="remark-title">备注</view>
  37. <view class="remark-text">{{ detaile.remark || '暂无备注' }}</view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="footer-g">
  42. <view class="handle-start" v-if="orderStatus && detaile.serviceStartTime && dateData">
  43. 服务已开始:<text class="handle-time">{{ dateData }}</text>
  44. </view>
  45. <Slide ref="verify" @change="change" :sliderText="slideData" />
  46. </view>
  47. </view>
  48. </template>
  49. <script setup>
  50. import { ref } from 'vue'
  51. import { onLoad, onUnload } from '@dcloudio/uni-app'
  52. import { getVolunteerOrderInfo, getTimesByDate, getVolunteerFinishSecondOrder } from '@/api/volunteer.js'
  53. import PositioningMap from '@/pages_classify/components/PositioningMap/index.vue'
  54. import Slide from '@/pages_classify/components/Slide/index.vue'
  55. import { useDict } from '@/utils/dict.js'
  56. import DictTag from '@/components/DictTag/index.vue'
  57. import { wxMakePhoneCall } from '@/utils/wxRequest.js'
  58. import { computed } from 'vue'
  59. const secondOrderId = ref('')
  60. const detaile = ref({})
  61. const verify = ref(null)
  62. const { lrr_service_category } = useDict('lrr_service_category')
  63. const orderStatus = ref(false) //false:未开始服务 true:服务已开始,待上传图片
  64. const onPhone = (phone) => {
  65. if (phone) {
  66. wxMakePhoneCall(phone)
  67. }
  68. }
  69. const dateData = ref('00:00:00')
  70. let timer = null
  71. // 获取当前位置信息
  72. const getCurrentLocation = () => {
  73. return new Promise((resolve, reject) => {
  74. // 先检查用户是否授权了位置权限
  75. uni.getSetting({
  76. success: (res) => {
  77. if (!res.authSetting['scope.userLocation']) {
  78. // 如果用户未授权,先请求授权
  79. uni.authorize({
  80. scope: 'scope.userLocation',
  81. success: () => {
  82. // 授权成功后获取位置
  83. getLocation(resolve, reject);
  84. },
  85. fail: (err) => {
  86. console.error('位置授权失败:', err);
  87. uni.showModal({
  88. title: '提示',
  89. content: '需要获取您的位置信息,请在设置中打开位置权限',
  90. confirmText: '去设置',
  91. success: (res) => {
  92. if (res.confirm) {
  93. uni.openSetting();
  94. }
  95. }
  96. });
  97. reject(err);
  98. }
  99. });
  100. } else {
  101. // 已授权,直接获取位置
  102. getLocation(resolve, reject);
  103. }
  104. },
  105. fail: (err) => {
  106. console.error('获取设置失败:', err);
  107. reject(err);
  108. }
  109. });
  110. });
  111. }
  112. // 获取位置的具体实现
  113. const getLocation = (resolve, reject) => {
  114. // 删除开发环境模拟位置的代码,始终获取真实位置
  115. uni.getLocation({
  116. type: 'gcj02',
  117. isHighAccuracy: true, // 高精度
  118. highAccuracyExpireTime: 3000, // 高精度过期时间
  119. success: (res) => {
  120. const { longitude, latitude } = res;
  121. console.log('当前位置 - 经度:', longitude);
  122. console.log('当前位置 - 纬度:', latitude);
  123. resolve({
  124. longitude,
  125. latitude
  126. });
  127. },
  128. fail: (err) => {
  129. console.error('获取位置失败:', err);
  130. // 获取位置失败时向用户提示
  131. uni.showToast({
  132. title: '获取位置失败,请确保已开启位置权限',
  133. icon: 'none',
  134. duration: 2000
  135. });
  136. reject(err);
  137. }
  138. });
  139. }
  140. const slideData = computed(() => {
  141. //服务已开始,待上传图片
  142. if (orderStatus.value) {
  143. return {
  144. successText: '服务已完成',
  145. startText: '拖动滑块结束服务',
  146. successColor: '#f64a1f',
  147. btnText: '上传照片',
  148. }
  149. }
  150. return {
  151. successText: '服务已开始',
  152. startText: '拖动滑块开始服务',
  153. successColor: '#72c13f',
  154. btnText: '开始',
  155. }
  156. })
  157. const getOrderDetail = async () => {
  158. try {
  159. // uni.showLoading({
  160. // title: '数据加载中...',
  161. // })
  162. const res = await getVolunteerOrderInfo({
  163. secondOrderId: secondOrderId.value,
  164. })
  165. detaile.value = res.data
  166. if (res.data.orderStatus === '3') {
  167. orderStatus.value = true
  168. }
  169. if (res.data.serviceStartTime) {
  170. timer = setInterval(() => {
  171. const timeDiff = Math.abs(new Date() - new Date(res.data.serviceStartTime))
  172. const units = {
  173. day: Math.floor(timeDiff / (1000 * 60 * 60 * 24)),
  174. hour: Math.floor(timeDiff / (1000 * 60 * 60)),
  175. minute: Math.floor(timeDiff / (1000 * 60)),
  176. second: Math.floor(timeDiff / 1000),
  177. }
  178. // 默认返回完整格式
  179. const hours = units.hour % 24
  180. const minutes = units.minute % 60
  181. const seconds = units.second % 60
  182. dateData.value = `${hours}小时${minutes}分钟${seconds}秒`
  183. }, 1000)
  184. }
  185. } catch (error) {
  186. console.log('error', error)
  187. uni.showToast({
  188. title: error.msg,
  189. icon: 'error',
  190. })
  191. } finally {
  192. // uni.hideLoading()
  193. }
  194. }
  195. const change = async (e) => {
  196. if (e.state && !orderStatus.value) {
  197. try {
  198. // uni.showLoading({
  199. // title: '获取位置信息...'
  200. // })
  201. // 获取开始服务时的位置
  202. const locationData = await getCurrentLocation().catch(err => {
  203. // uni.hideLoading()
  204. verify.value.initialization()
  205. throw new Error('无法获取位置信息,请确保已开启位置权限')
  206. })
  207. // 构建参数字符串
  208. const params = `secondOrderId=${secondOrderId.value}&serviceStartLongitude=${locationData.longitude.toString()}&serviceStartLatitude=${locationData.latitude.toString()}`
  209. // 调用开始服务接口,通过URL查询参数传递位置信息
  210. const res = await getTimesByDate(params)
  211. if (res.code === 200) {
  212. uni.showToast({
  213. title: '已开始服务',
  214. icon: 'success',
  215. success: () => {
  216. verify.value.initialization()
  217. // 验证成功
  218. orderStatus.value = true
  219. },
  220. })
  221. }
  222. } catch (error) {
  223. console.error('开始服务失败', error)
  224. uni.showToast({
  225. title: error.message || '开始服务失败',
  226. icon: 'none'
  227. })
  228. } finally {
  229. // uni.hideLoading()
  230. }
  231. }
  232. if (e.state && orderStatus.value) {
  233. try {
  234. // uni.showLoading({
  235. // title: '获取位置信息...'
  236. // })
  237. uni.showToast({
  238. title: '操作成功',
  239. icon: 'success',
  240. success: () => {
  241. setTimeout(() => {
  242. uni.redirectTo({
  243. url: `/pages_classify/pages/order/index?secondOrderId=${secondOrderId.value}`,
  244. })
  245. }, 800)
  246. },
  247. })
  248. } catch (error) {
  249. console.error('结束服务失败', error)
  250. uni.showToast({
  251. title: error.message || '结束服务失败',
  252. icon: 'none'
  253. })
  254. verify.value.initialization()
  255. } finally {
  256. // uni.hideLoading()
  257. }
  258. }
  259. }
  260. onLoad((options) => {
  261. secondOrderId.value = options.secondOrderId
  262. getOrderDetail()
  263. // 初始检查位置权限
  264. getCurrentLocation().then(location => {
  265. console.log('位置权限正常,可以获取位置');
  266. }).catch(err => {
  267. console.error('位置权限检查失败', err);
  268. uni.showModal({
  269. title: '位置权限提示',
  270. content: '服务需要获取您的位置信息,请确保已开启位置权限',
  271. confirmText: '去设置',
  272. cancelText: '知道了',
  273. success: (res) => {
  274. if (res.confirm) {
  275. uni.openSetting();
  276. }
  277. }
  278. });
  279. });
  280. })
  281. onUnload(() => {
  282. clearInterval(timer)
  283. timer = null
  284. })
  285. </script>
  286. <style lang="scss" scoped>
  287. .order-detail {
  288. position: fixed;
  289. top: 0;
  290. left: 0;
  291. right: 0;
  292. bottom: 280rpx;
  293. overflow-y: auto;
  294. .service-info {
  295. // height: 360px;
  296. }
  297. .order-card {
  298. border-radius: 8px;
  299. background: rgba(255, 255, 255, 1);
  300. padding: 12px;
  301. margin-bottom: 12px;
  302. }
  303. .font-title {
  304. margin-bottom: 12px;
  305. }
  306. .user-box {
  307. display: flex;
  308. .user-img {
  309. width: 65.8px;
  310. height: 65.8px;
  311. margin-right: 12px;
  312. }
  313. }
  314. .register-box {
  315. display: flex;
  316. margin-bottom: 12px;
  317. .register-img {
  318. width: 90px;
  319. height: 90px;
  320. margin-right: 12px;
  321. }
  322. }
  323. .info-list {
  324. flex: 1;
  325. font-size: 14px;
  326. font-weight: 500;
  327. letter-spacing: 0px;
  328. line-height: 23.27px;
  329. color: rgba(51, 51, 51, 1);
  330. }
  331. .price {
  332. font-size: 18px;
  333. font-weight: 500;
  334. color: rgba(246, 74, 31, 1);
  335. .price-yuan {
  336. font-size: 13px;
  337. font-weight: 700;
  338. color: rgba(246, 74, 31, 1);
  339. }
  340. }
  341. .upload-img {
  342. height: 68px;
  343. width: 68px;
  344. margin-right: 12px;
  345. margin-bottom: 12px;
  346. }
  347. .upload-box {
  348. display: flex;
  349. flex-wrap: wrap;
  350. .upload-img-item {
  351. position: relative;
  352. .delete-icon {
  353. position: absolute;
  354. top: -7px;
  355. right: 7px;
  356. z-index: 1;
  357. }
  358. }
  359. }
  360. .phone {
  361. color: #3c9cff;
  362. }
  363. }
  364. .handle-user {
  365. display: flex;
  366. align-items: center;
  367. justify-content: space-between;
  368. .handle-user-left {
  369. display: flex;
  370. align-items: center;
  371. .handle-user-info {
  372. .user-name {
  373. font-size: 32rpx;
  374. font-weight: 400;
  375. color: rgba(17, 24, 39, 1);
  376. }
  377. .user-id {
  378. font-size: 28rpx;
  379. font-weight: 400;
  380. color: rgba(107, 114, 128, 1);
  381. }
  382. }
  383. }
  384. .user-phone {
  385. display: flex;
  386. align-items: center;
  387. justify-content: center;
  388. width: 80rpx;
  389. height: 80rpx;
  390. border-radius: 50%;
  391. background: rgba(221, 94, 69, 1);
  392. }
  393. }
  394. .handle-adress {
  395. display: flex;
  396. align-items: center;
  397. justify-content: space-between;
  398. margin-top: 38rpx;
  399. .adress-text {
  400. flex: 1;
  401. text-align: left;
  402. padding-left: 24rpx;
  403. font-size: 32rpx;
  404. font-weight: 400;
  405. color: rgba(75, 85, 99, 1);
  406. }
  407. }
  408. .handle-remark {
  409. margin-top: 30rpx;
  410. .remark-title {
  411. font-size: 28rpx;
  412. font-weight: 400;
  413. color: rgba(17, 24, 39, 1);
  414. margin-bottom: 20rpx;
  415. }
  416. .remark-text {
  417. border-radius: 16rpx;
  418. background: rgba(249, 250, 251, 1);
  419. padding: 32rpx;
  420. font-size: 32rpx;
  421. font-weight: 400;
  422. color: rgba(75, 85, 99, 1);
  423. }
  424. }
  425. .handle-start {
  426. margin-bottom: 30rpx;
  427. font-size: 32rpx;
  428. font-weight: 400;
  429. color: rgba(75, 85, 99, 1);
  430. text-align: center;
  431. .handle-time {
  432. font-size: 32rpx;
  433. font-weight: 400;
  434. color: rgba(17, 24, 39, 1);
  435. }
  436. }
  437. .footer-g {
  438. padding: 12px;
  439. position: absolute;
  440. bottom: 18px;
  441. left: 0px;
  442. right: 0px;
  443. background: rgba(255, 255, 255, 1);
  444. }
  445. </style>