index.vue 12 KB

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