You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

415 lines
13 KiB

  1. <template>
  2. <view class="companion-select-page">
  3. <!-- 顶部警告提示 -->
  4. <view class="warning-tip">
  5. <view class="warning-icon">
  6. <uni-icons type="info" size="16" color="#A94F20"></uni-icons>
  7. </view>
  8. <view class="warning-text">
  9. <text>指定之前服务过的伴宠师需要额外收10元哦可多选最终由系统根据伴宠师的接单时间安排为您安排您喜欢的伴宠师</text>
  10. </view>
  11. </view>
  12. <!-- 伴宠师列表 -->
  13. <scroll-view scroll-y class="companion-scroll">
  14. <view class="companion-list">
  15. <view v-for="(item, index) in companionList" :key="index" class="companion-wrapper"
  16. :class="{ 'selected': selectedCompanionIds.includes(item.userId) }">
  17. <!-- 左侧选中标记 -->
  18. <view class="select-icon" @click="selectCompanion(item)">
  19. <view class="checkbox-circle" :class="{ 'checked': selectedCompanionIds.includes(item.userId) }">
  20. <view class="checkbox-inner" v-if="selectedCompanionIds.includes(item.userId)"></view>
  21. </view>
  22. </view>
  23. <!-- 使用CompanionItem组件 -->
  24. <view class="companion-item-wrapper">
  25. <companion-item :item="item" @click="handleItemClick" @like="handleItemLike">
  26. </companion-item>
  27. </view>
  28. </view>
  29. <!-- 无数据提示 -->
  30. <view class="no-data" v-if="companionList.length === 0">
  31. <image src="/static/images/personal/no-data.png" mode="aspectFit"></image>
  32. <text>暂无伴宠师数据</text>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. <!-- 底部按钮 -->
  37. <view class="footer-buttons">
  38. <view class="cancel-btn" @click="cancel">
  39. <text>取消</text>
  40. </view>
  41. <view class="confirm-btn" @click="confirm">
  42. <text>确定{{ selectedCompanionIds.length > 0 ? `(${selectedCompanionIds.length})` : '' }}</text>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import CompanionItem from '@/components/CompanionItem/CompanionItem.vue'
  49. import { getTecByUser, getOrderDetail, getTeacherDetail } from '@/api/order/order.js'
  50. import { getOpenIdKey } from '@/utils/auth'
  51. import { getAddressDetails } from '@/api/system/address.js'
  52. import { mapState } from 'vuex'
  53. import positionMixin from '@/mixins/position'
  54. export default {
  55. mixins: [positionMixin],
  56. components: {
  57. CompanionItem
  58. },
  59. data() {
  60. return {
  61. companionList: [],
  62. selectedCompanionIds: [],
  63. defaultTeacherId: null, // 默认选中的技师ID(用于再来一单)
  64. originalOrderData: null, // 原始订单数据
  65. orderId: null, // 订单ID
  66. };
  67. },
  68. computed: {
  69. ...mapState(['teacherLevelList']),
  70. // 获取当前选中的伴宠师列表
  71. selectedCompanions() {
  72. if (this.selectedCompanionIds.length === 0) return [];
  73. return this.companionList.filter(item => this.selectedCompanionIds.includes(item.userId));
  74. }
  75. },
  76. onLoad(options) {
  77. // 获取传递的技师ID(用于再来一单时默认选中)
  78. if (options.teacherId) {
  79. this.defaultTeacherId = options.teacherId;
  80. }
  81. // 获取订单ID(用于再来一单时获取订单详情)
  82. if (options.orderId) {
  83. this.orderId = options.orderId;
  84. this.loadOrderData();
  85. }
  86. // 获取选择过的伴宠师列表
  87. this.getServicedCompanions();
  88. },
  89. onPullDownRefresh() {
  90. this.getServicedCompanions()
  91. },
  92. methods: {
  93. // 获取服务过的伴宠师
  94. getServicedCompanions() {
  95. console.log(getOpenIdKey())
  96. getTecByUser({
  97. openId: getOpenIdKey()
  98. }).then(res => {
  99. uni.stopPullDownRefresh()
  100. if (res && res.code == 200) {
  101. this.companionList = res.data || [];
  102. // 如果有默认技师ID,自动选中该技师
  103. if (this.defaultTeacherId) {
  104. const defaultCompanion = this.companionList.find(item => item.userId == this.defaultTeacherId);
  105. if (defaultCompanion && !this.selectedCompanionIds.includes(this.defaultTeacherId)) {
  106. this.selectedCompanionIds.push(this.defaultTeacherId);
  107. }
  108. }
  109. }
  110. }).catch(err => {
  111. uni.stopPullDownRefresh()
  112. console.error('获取服务过的伴宠师失败', err);
  113. });
  114. },
  115. // 加载订单数据
  116. async loadOrderData() {
  117. if (!this.orderId) return;
  118. const params = {
  119. openId: getOpenIdKey(),
  120. orderId: this.orderId
  121. };
  122. try {
  123. const res = await getOrderDetail(params);
  124. if (res) {
  125. this.originalOrderData = res;
  126. } else {
  127. console.error('获取订单详情失败');
  128. }
  129. } catch (error) {
  130. console.error('获取订单数据失败', error);
  131. }
  132. },
  133. // 选择伴宠师(多选)
  134. selectCompanion(companion) {
  135. const userId = companion.userId;
  136. const index = this.selectedCompanionIds.indexOf(userId);
  137. if (index > -1) {
  138. // 如果已选中,则取消选中
  139. this.selectedCompanionIds.splice(index, 1);
  140. } else {
  141. // 如果未选中,则添加到选中列表
  142. this.selectedCompanionIds.push(userId);
  143. }
  144. },
  145. // 处理伴宠师列表项点击事件
  146. handleItemClick(item) {
  147. // 点击伴宠师项时选中该伴宠师
  148. this.selectCompanion(item);
  149. },
  150. // 处理伴宠师列表项点赞事件
  151. handleItemLike(item) {
  152. // 这里可以添加点赞的业务逻辑
  153. console.log('点赞伴宠师:', item);
  154. },
  155. // 取消选择
  156. cancel() {
  157. uni.navigateBack();
  158. },
  159. // 确认选择
  160. confirm() {
  161. if (this.selectedCompanionIds.length === 0) {
  162. uni.showToast({
  163. title: '请至少选择一个伴宠师',
  164. icon: 'none'
  165. });
  166. return;
  167. }
  168. this.submit()
  169. },
  170. async submit() {
  171. let order = this.originalOrderData
  172. this.$globalData.newOrderData.originalOrderData = order
  173. this.$globalData.newOrderData.moreOrderPrice = 10
  174. // 验证地址是否存在
  175. if (order.addressId) {
  176. try {
  177. const addressRes = await getAddressDetails(order.addressId);
  178. if (addressRes && addressRes.id) {
  179. // 地址存在,设置地址信息
  180. this.$globalData.newOrderData.currentAddress = {
  181. id: order.addressId,
  182. name: order.receiverName,
  183. phone: order.receiverPhone,
  184. province: order.receiverProvince,
  185. city: order.receiverCity,
  186. district: order.receiverDistrict,
  187. detailAddress: order.receiverDetailAddress,
  188. latitude: order.latitude,
  189. longitude: order.longitude,
  190. }
  191. } else {
  192. // 地址不存在,不设置地址信息
  193. console.log('地址不存在,addressId:', order.addressId);
  194. this.$globalData.newOrderData.currentAddress = {};
  195. }
  196. } catch (error) {
  197. console.error('验证地址失败:', error);
  198. // 验证失败时也不设置地址信息
  199. this.$globalData.newOrderData.currentAddress = {};
  200. }
  201. } else {
  202. // 没有地址ID,不设置地址信息
  203. this.$globalData.newOrderData.currentAddress = {};
  204. }
  205. if (order.teacherId) {
  206. getTeacherDetail({
  207. userId: order.teacherId
  208. }).then(response => {
  209. if (response) {
  210. let companionInfo = response
  211. companionInfo.distanceText = this.calculateDistanceAddress(response.appletAddresseList)
  212. this.buyInfo.teacher = companionInfo
  213. }
  214. })
  215. }
  216. if (order.companionLevel) {
  217. this.$globalData.newOrderData.companionLevel =
  218. this.teacherLevelList.find(item => item.paramValueNum == order.companionLevel);
  219. }
  220. // 处理提前熟悉相关数据
  221. if (order.needPreFamiliarize) {
  222. this.$globalData.newOrderData.needPreFamiliarize = ['是否提前熟悉']
  223. }
  224. // 组装宠物数据
  225. if (order.petVOList && order.petVOList.length > 0) {
  226. this.$globalData.newOrderData.currentPets = order.petVOList.map(pet => {
  227. // 获取该宠物的服务日期
  228. const petServices = order.orderServiceList.filter(service => service.petId === pet.id);
  229. const selectedDate = petServices.map(service => ({
  230. date: service.serviceDate,
  231. info: "预定"
  232. }));
  233. return {
  234. ...pet,
  235. checked: ['checked'], // 默认选中
  236. selectedDate,
  237. };
  238. });
  239. }
  240. uni.navigateTo({
  241. url: `/pages/newOrder/serviceNew`
  242. });
  243. },
  244. // 查看伴宠师详情
  245. viewCompanionDetail(companionId) {
  246. // 跳转到伴宠师详情页面
  247. uni.navigateTo({
  248. url: `/pages_order/companionPetList/companionPetInfo?id=${companionId}`
  249. });
  250. }
  251. }
  252. }
  253. </script>
  254. <style lang="scss" scoped>
  255. .companion-select-page {
  256. background-color: #F5F5F5;
  257. min-height: 100vh;
  258. display: flex;
  259. flex-direction: column;
  260. padding-bottom: 120rpx;
  261. }
  262. .warning-tip {
  263. background-color: #FFF4E5;
  264. padding: 20rpx 30rpx;
  265. display: flex;
  266. align-items: center;
  267. margin: 20rpx;
  268. .warning-icon {
  269. margin-right: 10rpx;
  270. }
  271. .warning-text {
  272. flex: 1;
  273. font-size: 24rpx;
  274. color: #A94F20;
  275. line-height: 1.4;
  276. }
  277. }
  278. .companion-scroll {
  279. flex: 1;
  280. height: calc(100vh - 250rpx);
  281. }
  282. .companion-list {
  283. padding: 10rpx;
  284. padding-right: 0;
  285. }
  286. .companion-wrapper {
  287. display: flex;
  288. align-items: flex-start;
  289. margin-bottom: 20rpx;
  290. border-radius: 16rpx;
  291. padding: 10rpx;
  292. display: flex;
  293. align-items: center;
  294. .select-icon {
  295. margin-right: 10rpx;
  296. .checkbox-circle {
  297. width: 45rpx;
  298. height: 45rpx;
  299. border: 2rpx solid #DDDDDD;
  300. background-color: #fff;
  301. border-radius: 50%;
  302. display: flex;
  303. align-items: center;
  304. justify-content: center;
  305. &.checked {
  306. border-color: #FFAA48;
  307. background-color: #FFAA48;
  308. }
  309. .checkbox-inner {
  310. width: 16rpx;
  311. height: 10rpx;
  312. border: 2rpx solid #FFFFFF;
  313. border-top: none;
  314. border-right: none;
  315. transform: rotate(-45deg);
  316. margin-top: -4rpx;
  317. }
  318. }
  319. }
  320. .companion-item-wrapper {
  321. flex: 1;
  322. }
  323. }
  324. .no-data {
  325. text-align: center;
  326. image {
  327. width: 200rpx;
  328. height: 200rpx;
  329. margin-bottom: 20rpx;
  330. }
  331. text {
  332. font-size: 28rpx;
  333. color: #999;
  334. }
  335. }
  336. .footer-buttons {
  337. position: fixed;
  338. bottom: 0;
  339. left: 0;
  340. right: 0;
  341. display: flex;
  342. padding: 20rpx 30rpx;
  343. background-color: #FFFFFF;
  344. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  345. .cancel-btn,
  346. .confirm-btn {
  347. flex: 1;
  348. height: 88rpx;
  349. line-height: 88rpx;
  350. text-align: center;
  351. border-radius: 44rpx;
  352. font-size: 30rpx;
  353. }
  354. .cancel-btn {
  355. background-color: #FFFFFF;
  356. color: #666;
  357. border: 1px solid #DDDDDD;
  358. margin-right: 20rpx;
  359. }
  360. .confirm-btn {
  361. background-color: #FFAA48;
  362. color: #FFFFFF;
  363. box-shadow: 0 4rpx 8rpx rgba(255, 170, 72, 0.3);
  364. }
  365. }
  366. </style>