index.vue 12 KB

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