index.vue 11 KB

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