index.vue 10 KB

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