index.vue 11 KB

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