猫妈狗爸伴宠师小程序前端代码
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.

607 lines
14 KiB

  1. <template>
  2. <view class="timeline-container">
  3. <!-- 日期和状态标签 -->
  4. <view class="date-header">
  5. <view class="date-box">
  6. <view class="date-box-color" :style="{'background-color': getTopBgColor()}"></view>
  7. <view class="date-month-day">{{ formatDate(date).month }}-{{ formatDate(date).day }}</view>
  8. </view>
  9. <view class="status-tag" :class="{'status-tag-pending': status}">
  10. <image src="/static/images/ydd/icon1.png" mode="aspectFit" class="status-icon"></image>
  11. {{ status ? '待上门' : '已完成' }}{{ orderCount }}
  12. </view>
  13. </view>
  14. <!-- 空状态显示 -->
  15. <view v-if="!processedList || processedList.length === 0" class="empty-state">
  16. <text class="empty-text">暂无订单数据</text>
  17. </view>
  18. <!-- 时间线主体 -->
  19. <view v-else class="timeline-body" v-for="(item, index) in processedList" :key="index">
  20. <view class="timeline-line"></view>
  21. <view class="time-point">
  22. <view class="time-icon">
  23. <image src="/static/images/order/address.png" mode="aspectFit" class="time-image"></image>
  24. </view>
  25. <view class="time-text">{{ item.address }}</view>
  26. <view class="collapse-icon" @click="toggleServiceCard(index)">
  27. {{ serviceCardCollapsed[index] ? '展开' : '收起' }} <text class="arrow" :class="{'arrow-up': !serviceCardCollapsed[index]}"></text>
  28. </view>
  29. </view>
  30. <!-- 服务内容卡片 -->
  31. <view v-if="!serviceCardCollapsed[index]" class="service-card">
  32. <!-- 服务日期 -->
  33. <view class="service-section">
  34. <view class="section-title">
  35. <view class="title-indicator"></view>
  36. <text>服务日期</text>
  37. </view>
  38. <view class="section-content date-content">
  39. {{ item.fullDate }}
  40. </view>
  41. </view>
  42. <!-- 陪伴对象 -->
  43. <view class="service-section">
  44. <view class="section-title">
  45. <view class="title-indicator"></view>
  46. <text>陪伴对象</text>
  47. <view class="collapse-icon" @click="togglePetList(index)">
  48. {{ petListCollapsed[index] ? '展开' : '收起' }} <text class="arrow" :class="{'arrow-up': !petListCollapsed[index]}"></text>
  49. </view>
  50. </view>
  51. <view class="section-content pet-list" v-if="!petListCollapsed[index]">
  52. <view v-for="(pet, i) in item.petList" :key="i" class="pet-item">
  53. <view class="pet-avatar">
  54. <image :src="pet.avatar" mode="aspectFill" class="avatar-image"></image>
  55. </view>
  56. <view class="pet-info">
  57. <view class="pet-name">
  58. {{ pet.name }}
  59. <text class="pet-gender" :class="{'pet-gender-male': pet.gender === 'male', 'pet-gender-female': pet.gender === 'female'}">
  60. {{ pet.gender === 'male' ? '♂' : '♀' }}
  61. </text>
  62. </view>
  63. <view class="pet-description">
  64. {{ pet.breed }}{{ pet.bodyType }} | {{ pet.services.join(',') }}
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <!-- 上门地址 -->
  71. <view class="service-section">
  72. <view class="section-title">
  73. <view class="title-indicator"></view>
  74. <text>上门地址</text>
  75. </view>
  76. <view class="section-content address-content">
  77. {{ item.addressDetail }}
  78. </view>
  79. </view>
  80. <!-- 操作按钮 -->
  81. <view class="action-buttons">
  82. <view class="btn btn-clock" @click="handleClock(item)">打卡</view>
  83. <view class="btn btn-clock" @click="handlePetFile(item)">宠物档案</view>
  84. <view class="btn btn-clock" @click="handleServiceFile(item)">服务档案</view>
  85. </view>
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script setup>
  91. import { ref, computed } from 'vue';
  92. import { getOrderServiceText, getProductNameText } from '@/utils/serviceTime.js';
  93. // 定义组件属性
  94. const props = defineProps({
  95. date: {
  96. type: String,
  97. default: '2024-12-08'
  98. },
  99. orderCount: {
  100. type: Number,
  101. default: 2
  102. },
  103. status : {
  104. type: Boolean,
  105. default: true
  106. },
  107. current: {
  108. type: Number,
  109. default: 0
  110. },
  111. list: {
  112. type: Array,
  113. default: () => []
  114. }
  115. });
  116. // 宠物列表折叠状态 - 使用数组来单独控制每个卡片中的宠物列表
  117. const petListCollapsed = ref([]);
  118. // 服务卡片折叠状态 - 使用数组来单独控制每个卡片
  119. const serviceCardCollapsed = ref([]);
  120. // 切换宠物列表显示状态
  121. const togglePetList = (index) => {
  122. if (petListCollapsed.value[index] === undefined) {
  123. petListCollapsed.value[index] = true;
  124. } else {
  125. petListCollapsed.value[index] = !petListCollapsed.value[index];
  126. }
  127. };
  128. // 切换服务卡片显示状态
  129. const toggleServiceCard = (index) => {
  130. if (serviceCardCollapsed.value[index] === undefined) {
  131. serviceCardCollapsed.value[index] = true;
  132. } else {
  133. serviceCardCollapsed.value[index] = !serviceCardCollapsed.value[index];
  134. }
  135. };
  136. // 格式化日期
  137. const formatDate = (dateString) => {
  138. const date = new Date(dateString);
  139. return {
  140. day: date.getDate().toString().padStart(2, '0'),
  141. month: (date.getMonth() + 1).toString().padStart(2, '0')
  142. };
  143. };
  144. // 处理订单数据,转换为组件所需格式
  145. const processedList = computed(() => {
  146. return props.list.map(order => {
  147. // 获取所有宠物信息
  148. const petList = [];
  149. let orderId = 0
  150. let serviceId = 0
  151. if (order.appletOrderItemDate && order.appletOrderItemDate.length > 0) {
  152. order.appletOrderItemDate.forEach(item => {
  153. if (item.orderServiceList && item.orderServiceList.petVo) {
  154. const pet = item.orderServiceList.petVo;
  155. const services = [];
  156. // 获取服务名称
  157. if (item.orderItemList && item.orderItemList.length > 0) {
  158. item.orderItemList.forEach(orderItem => {
  159. services.push(orderItem.productName);
  160. orderId = orderItem.orderId
  161. });
  162. }
  163. serviceId = item.orderServiceList.id,
  164. petList.push({
  165. name: pet.name,
  166. serviceId : item.orderServiceList.id,
  167. gender: pet.gender === '男生' ? 'male' : 'female',
  168. breed: pet.breed,
  169. bodyType: `(${pet.bodyType})`,
  170. services: services,
  171. avatar: pet.photo || (pet.petType === 'dog' ? '/static/images/ydd/dog.png' : '/static/images/ydd/cat.png')
  172. });
  173. }
  174. });
  175. }
  176. return {
  177. id: order.id,
  178. orderId,
  179. serviceId,
  180. address: order.cityAddress,
  181. addressDetail: order.address,
  182. fullDate: props.date.replace(/-/g, '/'),
  183. petList: petList
  184. };
  185. });
  186. });
  187. // 按钮事件处理函数
  188. const handleClock = (item) => {
  189. // 根据订单状态确定跳转路径
  190. const paths = [
  191. `/otherPages/myOrdersManage/clock/index?id=${item.orderId}&itemID=${item.id}&serviceId=${item.serviceId}`,
  192. `/otherPages/myOrdersManage/clock/index?isRead=true&id=${item.orderId}&itemID=${item.id}`,
  193. ];
  194. uni.navigateTo({
  195. url: props.status ? paths[0] : paths[1]
  196. });
  197. };
  198. const handlePetFile = (item) => {
  199. uni.navigateTo({
  200. url: "/otherPages/orderTakingManage/pet/index?id=" + item.orderId
  201. });
  202. };
  203. const handleServiceFile = (item) => {
  204. uni.navigateTo({
  205. url: "/otherPages/myOrdersManage/service/index?id=" + item.orderId
  206. });
  207. };
  208. function getTopBgColor(){
  209. return props.status ? '#FFAA48' : '#4CD964';
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .timeline-container {
  214. position: relative;
  215. padding: 20rpx;
  216. margin-bottom: 30rpx;
  217. .empty-state {
  218. display: flex;
  219. flex-direction: column;
  220. align-items: center;
  221. justify-content: center;
  222. padding: 80rpx 40rpx;
  223. .empty-image {
  224. width: 200rpx;
  225. height: 200rpx;
  226. margin-bottom: 20rpx;
  227. }
  228. .empty-text {
  229. color: #999;
  230. font-size: 28rpx;
  231. }
  232. }
  233. .date-header {
  234. display: flex;
  235. align-items: center;
  236. margin-bottom: 20rpx;
  237. .date-box {
  238. width: 80rpx;
  239. background-color: #ffffff;
  240. border: 2px solid #333;
  241. border-radius: 0;
  242. display: flex;
  243. flex-direction: column;
  244. justify-content: center;
  245. align-items: center;
  246. margin-right: 20rpx;
  247. box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
  248. border-radius: 14rpx;
  249. .date-box-color{
  250. height: 20rpx;
  251. width: 100%;
  252. border-top-left-radius: 14rpx;
  253. border-top-right-radius: 14rpx;
  254. position: relative;
  255. &::before{
  256. content: '';
  257. display: block;
  258. background-color: #ddd;
  259. width: 100%;
  260. height: 26rpx;
  261. top: 100%;
  262. left: 0;
  263. position: absolute;
  264. }
  265. }
  266. .date-month-day {
  267. position: relative;
  268. font-size: 26rpx;
  269. font-weight: bold;
  270. color: #333;
  271. height: 50rpx;
  272. display: flex;
  273. flex-direction: column;
  274. justify-content: center;
  275. }
  276. }
  277. .status-tag {
  278. background-color: #4CD96422;
  279. color: #4CD964;
  280. border: 4rpx solid #4CD964;
  281. padding: 16rpx 26rpx;
  282. border-radius: 14rpx;
  283. font-size: 26rpx;
  284. display: flex;
  285. align-items: center;
  286. position: relative;
  287. margin-left: 20rpx;
  288. .status-icon {
  289. width: 32rpx;
  290. height: 32rpx;
  291. margin-right: 8rpx;
  292. }
  293. &::after{
  294. content: '';
  295. display: block;
  296. position: absolute;
  297. width: 0;
  298. height: 0;
  299. top: 50%;
  300. transform: translateY(-50%);
  301. left: -16rpx;
  302. border-top: 16rpx solid transparent;
  303. border-bottom: 16rpx solid transparent;
  304. border-right: 16rpx solid #4CD964;
  305. }
  306. &::before{
  307. content: '';
  308. display: block;
  309. position: absolute;
  310. width: 0;
  311. height: 0;
  312. top: 50%;
  313. transform: translateY(-50%);
  314. left: -12rpx;
  315. border-top: 12rpx solid transparent;
  316. border-bottom: 12rpx solid transparent;
  317. border-right: 12rpx solid #4CD96422;
  318. z-index: 1;
  319. }
  320. }
  321. .status-tag-pending {
  322. background-color: #FFAA4822;
  323. color: #FFAA48;
  324. border-color: #FFAA48;
  325. &::after{
  326. border-right-color: #FFAA48;
  327. }
  328. &::before{
  329. border-right-color: #FFAA4822;
  330. }
  331. }
  332. }
  333. .timeline-body {
  334. position: relative;
  335. padding-left: 40rpx;
  336. padding-bottom: 40rpx;
  337. .timeline-line {
  338. position: absolute;
  339. left: 40rpx;
  340. top: 0;
  341. height: 100%;
  342. width: 0;
  343. border-left: 2rpx dashed #707070;
  344. border-left-style: dashed;
  345. border-image: repeating-linear-gradient(to bottom, #707070 0, #707070 8rpx, transparent 8rpx, transparent 20rpx) 1;
  346. z-index: 0;
  347. &::after{
  348. content: '';
  349. display: block;
  350. position: absolute;
  351. width: 8rpx;
  352. height: 8rpx;
  353. background-color: #000;
  354. border: 2rpx solid #707070;
  355. border-radius: 50%;
  356. left: -7rpx;
  357. top: 30rpx;
  358. }
  359. }
  360. .time-point {
  361. display: flex;
  362. align-items: center;
  363. margin-bottom: 20rpx;
  364. position: relative;
  365. z-index: 1;
  366. .time-icon {
  367. width: 60rpx;
  368. height: 60rpx;
  369. background-color: #fff;
  370. border-radius: 50%;
  371. display: flex;
  372. justify-content: center;
  373. align-items: center;
  374. margin-right: 20rpx;
  375. position: relative;
  376. left: 20rpx;
  377. .time-image {
  378. width: 40rpx;
  379. height: 40rpx;
  380. }
  381. }
  382. .time-text {
  383. font-size: 28rpx;
  384. color: #333;
  385. margin-left: 20rpx;
  386. flex: 1;
  387. }
  388. .collapse-icon {
  389. font-size: 24rpx;
  390. color: #999;
  391. padding: 0 20rpx;
  392. .arrow {
  393. transition: transform 0.3s;
  394. display: inline-block;
  395. }
  396. .arrow-up {
  397. transform: rotate(180deg);
  398. }
  399. }
  400. }
  401. .service-card {
  402. background-color: #fff;
  403. border-radius: 12rpx;
  404. padding: 30rpx;
  405. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  406. margin-left: 20rpx;
  407. .service-section {
  408. margin-bottom: 30rpx;
  409. .section-title {
  410. display: flex;
  411. align-items: center;
  412. margin-bottom: 15rpx;
  413. .title-indicator {
  414. width: 6rpx;
  415. height: 30rpx;
  416. background-color: #FFAA48;
  417. margin-right: 15rpx;
  418. }
  419. text {
  420. font-size: 28rpx;
  421. color: #333;
  422. font-weight: bold;
  423. }
  424. .collapse-icon {
  425. margin-left: auto;
  426. font-size: 24rpx;
  427. color: #999;
  428. .arrow {
  429. transition: transform 0.3s;
  430. display: inline-block;
  431. }
  432. .arrow-up {
  433. transform: rotate(180deg);
  434. }
  435. }
  436. }
  437. .section-content {
  438. padding: 0 15rpx;
  439. background-color: #FFF9F0;
  440. }
  441. .date-content {
  442. background-color: #FFF9F0;
  443. padding: 20rpx;
  444. border-radius: 8rpx;
  445. font-size: 28rpx;
  446. color: #333;
  447. }
  448. .pet-list {
  449. padding: 15rpx;
  450. .pet-item {
  451. display: flex;
  452. margin-bottom: 20rpx;
  453. &:last-child {
  454. margin-bottom: 0;
  455. }
  456. .pet-avatar {
  457. width: 80rpx;
  458. height: 80rpx;
  459. border-radius: 50%;
  460. overflow: hidden;
  461. margin-right: 20rpx;
  462. .avatar-image {
  463. width: 100%;
  464. height: 100%;
  465. }
  466. }
  467. .pet-info {
  468. flex: 1;
  469. .pet-name {
  470. font-size: 28rpx;
  471. color: #333;
  472. margin-bottom: 8rpx;
  473. .pet-gender {
  474. display: inline-block;
  475. width: 32rpx;
  476. height: 32rpx;
  477. line-height: 32rpx;
  478. text-align: center;
  479. border-radius: 50%;
  480. color: #fff;
  481. font-size: 20rpx;
  482. margin-left: 10rpx;
  483. }
  484. .pet-gender-male {
  485. background-color: #4A90E2;
  486. }
  487. .pet-gender-female {
  488. background-color: #FF6B9A;
  489. }
  490. }
  491. .pet-description {
  492. font-size: 24rpx;
  493. color: #7D8196;
  494. }
  495. }
  496. }
  497. }
  498. .address-content {
  499. padding: 20rpx;
  500. border-radius: 8rpx;
  501. font-size: 28rpx;
  502. color: #7D8196;
  503. }
  504. }
  505. .action-buttons {
  506. display: flex;
  507. justify-content: space-between;
  508. .btn {
  509. width: 30%;
  510. height: 80rpx;
  511. line-height: 80rpx;
  512. text-align: center;
  513. border-radius: 40rpx;
  514. font-size: 28rpx;
  515. }
  516. .btn-clock {
  517. background-color: #FFAA48;
  518. color: #fff;
  519. }
  520. .btn-pet-file, .btn-service-file {
  521. background-color: #F6F7FB;
  522. color: #333;
  523. border: 1px solid #E5E6EB;
  524. }
  525. }
  526. }
  527. }
  528. }
  529. </style>