index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <!-- 订单详情 -->
  2. <template>
  3. <view class="order-detail">
  4. <view class="user-info order-card">
  5. <view class="font-title">基本信息</view>
  6. <view class="user-box">
  7. <view class="info-list">
  8. <view>被服务人员:{{ detaile.clientName }}</view>
  9. <view style="display: flex;">服务类别:{{ detaile.businessTireName }}</view>
  10. <view @click="onPhone">电话号码:<label class="phone">{{ detaile.clientPhoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') }}</label></view>
  11. <view>地址:{{ detaile.address }}</view>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="service-info order-card">
  16. <view class="font-title ">备注信息</view>
  17. <view class="info-list">
  18. {{ detaile.remark || '暂无备注信息'}}
  19. </view>
  20. </view>
  21. <view class="service-info order-card" v-if="isStatus">
  22. <view class="font-title ">反馈信息</view>
  23. <view class="info-list">
  24. <up-textarea v-model="detaile.volunteerReview" placeholder="请输入内容"></up-textarea>
  25. </view>
  26. </view>
  27. <view v-if="detaile.orderStatus !== '3'">
  28. <view class="user-info order-card">
  29. <view class="font-title">志愿者反馈信息</view>
  30. <view class="user-box">
  31. <view class="info-list">
  32. <view class="info-item">{{ detaile.volunteerReview || '暂无志愿者反馈信息'}}</view>
  33. </view>
  34. </view>
  35. <view class="upload-box-see">
  36. <view class="upload-img-item" v-for="(item) in volunteerPicture" :key="item.url">
  37. <up-image class="upload-img-see" :show-loading="true" :src="item.url"
  38. :alt="item.fileName" mode="widthFix"></up-image>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="user-info order-card">
  43. <view class="font-title">用户评价信息</view>
  44. <view class="user-box">
  45. <view class="info-list">
  46. <view class="info-item">{{ detaile.userReview || '用户未完成评价' }}</view>
  47. </view>
  48. </view>
  49. <view class="upload-box-see">
  50. <view class="upload-img-item" v-for="(item) in userPicture" :key="item.url">
  51. <up-image class="upload-img-see" :show-loading="true" :src="item.url"
  52. :alt="item.fileName"></up-image>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="service-info order-card" v-if="isStatus">
  58. <view class="font-title">图片上传</view>
  59. <view class="upload-box">
  60. <view class="upload-img-item" v-for="(item, index) in fileList" :key="item.url">
  61. <view class="delete-icon" @click="deletePic(index)"><up-icon name="close-circle-fill"
  62. color="#f64a1f" size="18" v-if="isStatus"></up-icon></view>
  63. <img class="upload-img" :src="item.url" :alt="item.fileName" srcset="">
  64. </view>
  65. <img src="/static/img/upload.png" alt="" class="upload-img" @click="uploadClick('img')"
  66. v-if="fileList.length < 10 && isStatus">
  67. </view>
  68. </view>
  69. <view class=" footer-g" v-if="isStatus">
  70. <view class="status-btn" @click="submit">确定结束</view>
  71. </view>
  72. </view>
  73. </template>
  74. <script setup>
  75. import { ref, toRaw, computed } from 'vue';
  76. import { onLoad } from '@dcloudio/uni-app';
  77. import { getVolunteerOrderInfo, getVolunteerFinishSecondOrder } from '@/api/volunteer.js'
  78. import { getAddress } from '@/api/address.js'
  79. import { wxUploadFile, wxMakePhoneCall } from '@/utils/wxRequest.js'
  80. import { useDict } from '@/utils/dict.js';
  81. import DictTag from '@/components/DictTag/index.vue'
  82. import { getLatLong } from '@/utils/adress'
  83. const fileList = ref([]);
  84. const secondOrderId = ref('');
  85. const detaile = ref({
  86. volunteerReview: ''
  87. });
  88. const {
  89. lrr_service_category
  90. } = useDict('lrr_service_category');
  91. const isEnd = ref(false);//详情、结束服务
  92. const isStatus = computed(() => {
  93. console.log('isEnd.value',isEnd.value,detaile.value.orderStatus);
  94. return isEnd.value ? !isEnd.value : (detaile.value.orderStatus === '3')
  95. })
  96. // 删除图片
  97. const deletePic = (index) => {
  98. fileList.value.splice(index, 1);
  99. };
  100. const uploadClick = async (type) => {
  101. const res = await wxUploadFile(type);
  102. fileList.value = [...fileList.value, ...res];
  103. console.log('xxxxres', res, fileList.value);
  104. }
  105. const onPhone = (phone) => {
  106. wxMakePhoneCall(phone)
  107. }
  108. //志愿者图片反馈
  109. const volunteerPicture = computed(() => {
  110. if (detaile.value.volunteerPicture) {
  111. return detaile.value.volunteerPicture.split(',').map(item => {
  112. return { url: item }
  113. });
  114. }
  115. return [];
  116. })
  117. //用户图片评价
  118. const userPicture = computed(() => {
  119. if (detaile.value.userPicture) {
  120. return detaile.value.userPicture.split(',').map(item => {
  121. return { url: item }
  122. });
  123. }
  124. return [];
  125. })
  126. const getOrderDetail = async () => {
  127. try {
  128. // uni.showLoading({
  129. // title: '数据加载中...'
  130. // });
  131. const res = await getVolunteerOrderInfo({ secondOrderId: secondOrderId.value });
  132. console.log('API response:', res);
  133. // Check if the response was successful
  134. if (res.code === 200) {
  135. // Directly assign the data from response
  136. detaile.value = res.data;
  137. // Check if volunteer pictures exist and process them
  138. if (res.data.volunteerPicture) {
  139. fileList.value = res.data.volunteerPicture.split(',').map(item => {
  140. return { url: item }
  141. });
  142. }
  143. } else {
  144. uni.showToast({
  145. title: res.msg || '获取数据失败',
  146. icon: 'error',
  147. });
  148. }
  149. console.log('detaile.value after assignment:', detaile.value);
  150. } catch (error) {
  151. console.log('error', error);
  152. uni.showToast({
  153. title: error.msg || '获取数据失败',
  154. icon: 'error',
  155. })
  156. } finally {
  157. // uni.hideLoading();
  158. }
  159. }
  160. // 获取当前位置信息
  161. const getCurrentLocation = () => {
  162. return new Promise((resolve, reject) => {
  163. // 先检查用户是否授权了位置权限
  164. uni.getSetting({
  165. success: (res) => {
  166. if (!res.authSetting['scope.userLocation']) {
  167. // 如果用户未授权,先请求授权
  168. uni.authorize({
  169. scope: 'scope.userLocation',
  170. success: () => {
  171. // 授权成功后获取位置
  172. getLocation(resolve, reject);
  173. },
  174. fail: (err) => {
  175. console.error('位置授权失败:', err);
  176. uni.showModal({
  177. title: '提示',
  178. content: '需要获取您的位置信息,请在设置中打开位置权限',
  179. confirmText: '去设置',
  180. success: (res) => {
  181. if (res.confirm) {
  182. uni.openSetting();
  183. }
  184. }
  185. });
  186. reject(err);
  187. }
  188. });
  189. } else {
  190. // 已授权,直接获取位置
  191. getLocation(resolve, reject);
  192. }
  193. },
  194. fail: (err) => {
  195. console.error('获取设置失败:', err);
  196. reject(err);
  197. }
  198. });
  199. });
  200. }
  201. // 获取位置的具体实现
  202. const getLocation = (resolve, reject) => {
  203. // 删除开发环境模拟位置的代码,始终获取真实位置
  204. uni.getFuzzyLocation({
  205. type: 'gcj02',
  206. // isHighAccuracy: true, // 高精度
  207. // highAccuracyExpireTime: 3000, // 高精度过期时间
  208. success: (res) => {
  209. const { longitude, latitude } = res;
  210. console.log('当前位置 - 经度:', longitude);
  211. console.log('当前位置 - 纬度:', latitude);
  212. resolve({
  213. longitude,
  214. latitude
  215. });
  216. },
  217. fail: (err) => {
  218. console.error('获取位置失败:', err);
  219. // 获取位置失败时向用户提示
  220. uni.showToast({
  221. title: '获取位置失败,请确保已开启位置权限',
  222. icon: 'none',
  223. duration: 2000
  224. });
  225. reject(err);
  226. }
  227. });
  228. }
  229. const submit = () => {
  230. uni.$u.debounce(onSubmit, 300)
  231. }
  232. const onSubmit = async () => {
  233. try {
  234. // 调用结束服务接口,通过URL查询参数传递位置信息
  235. // uni.showLoading({
  236. // title: '正在结束服务...',
  237. // })
  238. const img_urls = fileList.value.map(item => item.url).join(',');
  239. console.log('submit', fileList.value, img_urls);
  240. // 获取结束服务时的位置
  241. // const locationData = await getCurrentLocation().catch(err => {
  242. // // uni.hideLoading()
  243. // verify.value.initialization()
  244. // throw new Error('无法获取位置信息,请确保已开启位置权限')
  245. // })
  246. const locationData =await getLatLong()
  247. // 构建参数字符串
  248. const params = `volunteerPicture=${img_urls}&volunteerReview=${detaile.value.volunteerReview}&secondOrderId=${secondOrderId.value}&serviceFinishLongitude=${locationData.longitude.toString()}&serviceFinishLatitude=${locationData.latitude.toString()}`
  249. const res = await getVolunteerFinishSecondOrder(params);
  250. if (res.code === 200) {
  251. uni.showToast({
  252. title: '服务结束',
  253. icon: 'success',
  254. success: () => {
  255. setTimeout(() => {
  256. uni.switchTab({
  257. url: '/pages/classify'
  258. });
  259. }, 800)
  260. }
  261. })
  262. } else {
  263. uni.showToast({
  264. title: res.data,
  265. icon: 'error',
  266. })
  267. }
  268. } catch (error) {
  269. console.log("TCL: onSubmit -> error", error)
  270. } finally {
  271. // uni.hideLoading()
  272. }
  273. }
  274. onLoad((options) => {
  275. console.log('options received:', options);
  276. secondOrderId.value = options.secondOrderId;
  277. isEnd.value = options.type && options.type ==='details';
  278. console.log('secondOrderId set to:', secondOrderId.value);
  279. // orderId.value = '1911685346559660034';
  280. getOrderDetail();
  281. })
  282. </script>
  283. <style lang="scss" scoped>
  284. .order-detail {
  285. position: fixed;
  286. top: 0;
  287. left: 0;
  288. right: 0;
  289. bottom: 0;
  290. padding: 12px 12px 24px;
  291. background: rgba(245, 245, 245, 1);
  292. overflow-y: auto;
  293. .order-card {
  294. border-radius: 8px;
  295. background: rgba(255, 255, 255, 1);
  296. padding: 12px;
  297. margin-bottom: 12px;
  298. }
  299. .font-title {
  300. margin-bottom: 12px;
  301. }
  302. .user-box {
  303. display: flex;
  304. .user-img {
  305. width: 65.8px;
  306. height: 65.8px;
  307. margin-right: 12px;
  308. }
  309. }
  310. .register-box {
  311. display: flex;
  312. margin-bottom: 12px;
  313. .register-img {
  314. width: 90px;
  315. height: 90px;
  316. margin-right: 12px;
  317. }
  318. }
  319. .info-list {
  320. flex: 1;
  321. font-size: 14px;
  322. font-weight: 500;
  323. letter-spacing: 0px;
  324. line-height: 23.27px;
  325. color: rgba(51, 51, 51, 1);
  326. }
  327. .price {
  328. font-size: 18px;
  329. font-weight: 500;
  330. color: rgba(246, 74, 31, 1);
  331. .price-yuan {
  332. font-size: 13px;
  333. font-weight: 700;
  334. color: rgba(246, 74, 31, 1);
  335. }
  336. }
  337. .footer-g {
  338. padding: 12px;
  339. position: absolute;
  340. bottom: 18px;
  341. left: 0px;
  342. right: 0px;
  343. }
  344. .upload-img {
  345. height: 68px;
  346. width: 68px;
  347. margin-right: 12px;
  348. margin-bottom: 12px;
  349. }
  350. .upload-box {
  351. display: flex;
  352. flex-wrap: wrap;
  353. // display: flex;
  354. // flex-direction: column;
  355. // align-items: center;
  356. // justify-content: center;
  357. .upload-img-item {
  358. position: relative;
  359. .delete-icon {
  360. position: absolute;
  361. top: -7px;
  362. right: 7px;
  363. z-index: 1;
  364. }
  365. }
  366. }
  367. .upload-box-see {
  368. display: flex;
  369. flex-direction: column;
  370. align-items: center;
  371. justify-content: center;
  372. .upload-img-see {
  373. margin-bottom: 12px;
  374. }
  375. }
  376. .phone {
  377. color: #3c9cff;
  378. }
  379. .info-item {
  380. margin-bottom: 12px;
  381. }
  382. }
  383. .status-btn {
  384. // width: 716rpx;
  385. height: 96rpx;
  386. border-radius: 16rpx;
  387. background: rgba(221, 94, 69, 1);
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. font-size: 32rpx;
  392. font-weight: 400;
  393. color: rgba(255, 255, 255, 1);
  394. margin-bottom: 88rpx;
  395. }
  396. </style>