index.vue 12 KB

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