index.vue 12 KB

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