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.

551 lines
20 KiB

5 months ago
2 weeks ago
5 months ago
5 months ago
5 months ago
5 months ago
2 weeks ago
2 weeks ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
  1. <template>
  2. <view class="personal-pet">
  3. <view v-if="petList.length > 0" class="personal-pet-list">
  4. <view v-for="(item, index) in petList" :key="index">
  5. <view
  6. :class="['personal-pet-list-item', item.gender == '男生' ? '.personal-pet-list-item_backgroud_m' : '.personal-pet-list-item_backgroud_f']">
  7. <view class="personal-pet-info">
  8. <view>
  9. <u-avatar :src="item.photo ? item.photo : defaultPhoto" size="60" shape="circle"></u-avatar>
  10. </view>
  11. <view class="personal-pet-info-1" style="width: calc(100% - 120px);">
  12. <view class="personal-pet-info-2">
  13. <view class="personal-pet-name ellipsis">
  14. {{ item.name }}
  15. </view>
  16. <view class="personal-pet-sex">
  17. <img :src="item.gender == '男生' ? '../../static/images/details/boy.svg' : '../../static/images/details/girl.svg'"
  18. alt="sex" style="width: 16px;height: 16px;" />
  19. </view>
  20. </view>
  21. <view class="personal-pet-info-3" style="width: 100%;">
  22. <view class="ellipsis" style="max-width: 25%;">
  23. {{ item.breed || '未知' }}
  24. </view>
  25. <view class="personal-pet-info-age" style="max-width: 90px;">
  26. {{ item.birthDate || '未知' }}
  27. </view>
  28. <view class="ellipsis" style="max-width: 25%;">
  29. {{ item.bodyType || '未知' }}
  30. </view>
  31. </view>
  32. </view>
  33. <view style="margin-left: auto; width: 20px;">
  34. <u-checkbox-group v-model="item.checked">
  35. <u-checkbox shape="circle" :name="true" activeColor="#ffbf60"></u-checkbox>
  36. </u-checkbox-group>
  37. </view>
  38. </view>
  39. <view class="personal-pet-info-disposition ellipsis">
  40. 性格 {{ item.personality }}
  41. </view>
  42. <view class="personal-pet-info-btns">
  43. <view style="display: flex; align-items: center;">
  44. <u-button v-if="item.selectedDate.length == 0" color="#FFBF60" size="mini"
  45. iconPlacement="right" shape="circle" plain @click="selectDate(item)">
  46. <view style="font-size: 14px;">请选择服务日期</view>
  47. <u-icon name="arrow-right" color="#FFBF60" size="14"
  48. style="margin-right: 5px;"></u-icon>
  49. </u-button>
  50. <u-button v-else color="#FFBF60" type="primary" size="mini" iconPlacement="right"
  51. shape="circle" @click="selectDate(item)">
  52. <view style="font-size: 14px;">{{ showSelectedDate(item.selectedDate) }}</view>
  53. <u-icon name="arrow-right" color="#ffffff" size="14"
  54. style="margin-right: 5px;"></u-icon>
  55. </u-button>
  56. </view>
  57. <view style="display: flex; align-items: center; justify-content: flex-end;">
  58. <view class="personal-pet-info-btn" @click="editPet(item)">
  59. <u-icon name="edit-pen" color="#7d8196" size="16" style="margin-right: 5px;"></u-icon>
  60. <view style="margin-left: 5px;">
  61. 编辑
  62. </view>
  63. </view>
  64. <view class="personal-pet-info-btn" @click="deletePet(item)">
  65. <u-icon name="trash" color="#7d8196" size="16"></u-icon>
  66. <view style="margin-left: 5px;">
  67. 删除
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view v-else class="personal-pet-none">
  76. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" alt="pet"
  77. style="width: 149px;height: 124px;" mode="widthFix" />
  78. <view class="personal-pet-none-text">这里还没有您的宠物,请点击添加吧~</view>
  79. </view>
  80. <view class="personal-pet-add">
  81. <view style="width: 45%;">
  82. <u-button class="personal-pet-add-btn" color="#FFF4E4" @click="addPet">
  83. <view style="font-size: 32rpx;font-weight: 500;color: #FFAA48;">
  84. 新增宠物
  85. </view>
  86. </u-button>
  87. </view>
  88. <view style="width: 45%;">
  89. <u-button class="personal-pet-add-btn" color="#FFBF60" @click="confirm">
  90. <view style="font-size: 32rpx;font-weight: 500;color: #fff;">
  91. 确定
  92. </view>
  93. </u-button>
  94. </view>
  95. </view>
  96. <view class="">
  97. <u-picker :showToolbar='false' :show="show" :columns="petTypes" @change="petTypeChange" @cancel="cancel"
  98. @confirm="confirmPetType"></u-picker>
  99. </view>
  100. <u-modal :show="showDel" @confirm="confirmDel" @cancel="cancelDel" ref="uModal" showCancelButton
  101. :asyncClose="true" :content='delContent'>
  102. </u-modal>
  103. <view v-if="showCalendar" class="calendar-popup">
  104. <view class="calendar-mask"></view>
  105. <view class="calendar-content">
  106. <uni-calendar class="uni-calendar--hook"
  107. :disabledDay="outDateList"
  108. :holidayDate="holidayDate"
  109. :holidayPrice="holidayPrice"
  110. :normalPrice="normalPrice"
  111. :selected="selectedDate" :startDate="startDate"
  112. :endDate="endDate" @change="change" :showMonth="false" />
  113. <u-button color="#FFBF60" type="primary" @click="confirmCanlendar">确定</u-button>
  114. </view>
  115. </view>
  116. </view>
  117. </template>
  118. <script>
  119. import { getDictList } from "@/api/system/user.js"
  120. import { getPetList, delPet } from "@/api/system/pet"
  121. import positionMixin from '../../mixins/position';
  122. import {
  123. getTeacherAddressList,
  124. } from "@/api/order/order"
  125. import { mapState } from 'vuex'
  126. export default {
  127. mixins: [positionMixin],
  128. data() {
  129. return {
  130. defaultPhoto: 'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png',
  131. petList: [],
  132. show: false,
  133. showDel: false,
  134. petTypes: [],
  135. delContent: '',
  136. deleteId: '',
  137. petType: '',
  138. startDate: '',
  139. endDate: '',
  140. showCalendar: false,
  141. selectedDate: [],
  142. currentPets: [],
  143. //当前技师不接单日期
  144. outDateList : ['2025-6-20'],
  145. holidayDate: [],
  146. holidayPrice: 75,
  147. normalPrice : 75,
  148. }
  149. },
  150. computed: {
  151. ...mapState(['price_config', 'buyInfo'])
  152. },
  153. onShow() {
  154. this.getPetList();
  155. this.getOutDateList()
  156. let priceConfig = this.$store.state.price_config
  157. console.log(priceConfig)
  158. // 获取已保存的伴宠师等级价格和城市倍率
  159. let companionPrice = this.$globalData.newOrderData.companionLevelPrice || 0
  160. let cityPriceRate = this.$globalData.newOrderData.cityPriceRate || 1
  161. if(priceConfig.basePrice && priceConfig.basePrice.holiday){
  162. this.holidayPrice = ((priceConfig.basePrice.holiday * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2)
  163. }
  164. if(priceConfig.basePrice && priceConfig.basePrice.normal){
  165. this.normalPrice = ((priceConfig.basePrice.normal * this.$store.state.memberRate * cityPriceRate) + companionPrice).toFixed(2)
  166. }
  167. if(priceConfig.holidays && priceConfig.holidays.length > 0){
  168. this.holidayDate = priceConfig.holidays
  169. }else{
  170. this.holidayDate = []
  171. }
  172. this.$store.commit('getUserInfo')
  173. },
  174. onPullDownRefresh() {
  175. this.getPetList();
  176. },
  177. mounted() {
  178. this.getPetTypeList();
  179. this.getPetList();
  180. this.getCalendarDate();
  181. },
  182. methods: {
  183. getPetList() {
  184. this.petList = []
  185. getPetList().then(res => {
  186. let currentPets = this.$globalData.newOrderData.currentPets
  187. if (res && res.content) {
  188. this.petList = res.content.map(e => {
  189. const currentPet = currentPets.find(item => item.id === e.id)
  190. if (currentPet) {
  191. e.selectedDate = currentPet.selectedDate
  192. e.checked = [!!currentPet.checked]
  193. } else {
  194. e.selectedDate = []
  195. e.checked = false
  196. }
  197. return e
  198. })
  199. this.showDel = false;
  200. }
  201. })
  202. },
  203. //获取当前技师不接单日期
  204. getOutDateList(){
  205. if(!this.buyInfo.teacher || !this.buyInfo.teacher.userId){
  206. return
  207. }
  208. console.log('this.buyInfo', this.buyInfo);
  209. getTeacherAddressList({
  210. userId : this.buyInfo.teacher.userId
  211. }).then(response => {
  212. if (response.code == 200) {
  213. let addressList = this.calculateDistanceAddressList(response.data)
  214. if(addressList && addressList[0] && addressList[0].appletOutDate){
  215. this.outDateList = addressList[0].appletOutDate.map(n => n.date)
  216. }
  217. console.log(addressList, this.outDateList);
  218. }
  219. })
  220. },
  221. getPetTypeList() {
  222. getDictList('pet_type').then(res => {
  223. if (res.code == 200) {
  224. let petType = res.data.map(e => e.dictLabel)
  225. this.petTypes = [petType]
  226. console.log(this.petTypes)
  227. } else {
  228. this.$modal.showToast('获取pet type失败')
  229. }
  230. })
  231. },
  232. addPet() {
  233. this.show = true;
  234. },
  235. cancel() {
  236. this.show = false
  237. },
  238. petTypeChange(e) {
  239. console.log(e)
  240. this.petType = e.value[0]
  241. },
  242. confirmPetType(e) {
  243. console.log(e)
  244. this.show = false
  245. // 获取宠物类型,优先使用已选择的petType,否则使用e.value[0]
  246. const type = this.petType || e.value[0]
  247. // 根据宠物类型映射到英文类型
  248. const petTypeMap = {
  249. '猫猫': 'cat',
  250. '狗狗': 'dog'
  251. }
  252. const petType = petTypeMap[type]
  253. if (petType) {
  254. uni.navigateTo({
  255. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=add&isNewOrder=true`
  256. });
  257. }
  258. },
  259. editPet(item) {
  260. const petTypeMap = {
  261. '猫猫': 'cat',
  262. 'cat': 'cat',
  263. '狗狗': 'dog',
  264. 'dog': 'dog'
  265. }
  266. const petType = petTypeMap[item.petType]
  267. if (petType) {
  268. uni.navigateTo({
  269. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=edit&petId=${item.id}&isNewOrder=true`
  270. });
  271. }
  272. },
  273. deletePet(item) {
  274. this.delContent = "确定要删除" + item.name + '?';
  275. this.showDel = true;
  276. this.deleteId = item.id;
  277. },
  278. confirmDel() {
  279. delPet(this.deleteId).then(res => {
  280. console.log(res);
  281. this.$modal.showToast('删除成功');
  282. this.getPetList()
  283. })
  284. },
  285. cancelDel() {
  286. this.showDel = false;
  287. this.deleteId = '';
  288. },
  289. getCalendarDate() {
  290. let tomorrow = new Date()
  291. tomorrow.setDate(tomorrow.getDate() + 2);
  292. this.startDate = this.formatDate(tomorrow);
  293. // 获取三个月后的日期
  294. let threeMonthsLater = new Date();
  295. threeMonthsLater.setMonth(threeMonthsLater.getMonth() + 3);
  296. this.endDate = this.formatDate(threeMonthsLater);
  297. },
  298. formatDate(date) {
  299. let year = date.getFullYear();
  300. let month = (date.getMonth() + 1).toString().padStart(2, '0');
  301. let day = date.getDate().toString().padStart(2, '0');
  302. return year + '-' + month + '-' + day;
  303. },
  304. selectDate(item) {
  305. this.currentId = item.id
  306. this.selectedDate = item.selectedDate
  307. this.showCalendar = true;
  308. },
  309. confirmCanlendar() {
  310. const currentPet = this.petList.find(e => e.id == this.currentId);
  311. currentPet.selectedDate = this.selectedDate.sort((a, b) => new Date(a.date) - new Date(b.date));
  312. // 选择日期后自动勾选该宠物
  313. if (this.selectedDate.length > 0) {
  314. currentPet.checked = [true];
  315. }
  316. this.selectedDate = [];
  317. this.showCalendar = false;
  318. },
  319. change(e) {
  320. const selectedValue = this.selectedDate.find(item => item.date === e.fulldate)
  321. if (selectedValue) {
  322. // 存在则移除
  323. this.selectedDate = this.selectedDate.filter(item => item.date !== e.fulldate);
  324. } else {
  325. this.selectedDate.push({
  326. date: e.fulldate,
  327. info: '预定'
  328. })
  329. }
  330. },
  331. confirm() {
  332. const selectedPets = this.petList.filter(e => e.checked)
  333. const unselectedDatePets = selectedPets.filter(pet => !pet.selectedDate || pet.selectedDate.length === 0)
  334. if (unselectedDatePets.length > 0) {
  335. const petNames = unselectedDatePets.map(pet => pet.name).join('、')
  336. this.$modal.showToast(`请为${petNames}选择服务时间`)
  337. return
  338. }
  339. this.$globalData.newOrderData.currentPets = selectedPets
  340. uni.redirectTo({
  341. url: '/pages/newOrder/serviceNew'
  342. })
  343. },
  344. showSelectedDate(selectedDate) {
  345. // 显示格式:首日...最后一日 共几天
  346. // 日期格式只需要月份和日期 例如:01/01...01/07
  347. const firstDate = selectedDate[0].date.substring(5).replace('-', '/')
  348. const lastDate = selectedDate[selectedDate.length - 1].date.substring(5).replace('-', '/')
  349. const days = selectedDate.length
  350. return `${firstDate}${days > 2 ? '...' : ''}${days == 2 ? ',' : ''}${days > 1 ? lastDate : ''}${days}`
  351. }
  352. }
  353. }
  354. </script>
  355. <style lang="scss" scoped>
  356. .personal-pet {
  357. position: relative;
  358. height: 100%;
  359. padding-bottom: 90px;
  360. .personal-pet-add {
  361. background-color: #FFFFFF;
  362. padding: 10px 20px 40px;
  363. width: 100%;
  364. height: 90px;
  365. position: fixed;
  366. bottom: 0;
  367. z-index: 100;
  368. display: flex;
  369. justify-content: space-between;
  370. .personal-pet-add-btn {
  371. width: 100%;
  372. border-radius: 6px;
  373. font-size: 16px;
  374. }
  375. }
  376. .personal-pet-list {
  377. .personal-pet-list-add {
  378. width: 100%;
  379. height: 44px;
  380. background-color: #FFFFFF;
  381. display: flex;
  382. justify-content: space-between;
  383. align-items: center;
  384. padding: 0 15px;
  385. .personal-pet-list-add-btn {
  386. font-size: 14px;
  387. color: #AAA;
  388. display: flex;
  389. align-items: center;
  390. }
  391. }
  392. .personal-pet-list-item_backgroud_m {
  393. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  394. }
  395. .personal-pet-list-item_backgroud_f {
  396. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  397. }
  398. .personal-pet-list-item {
  399. margin: 10px 10px 0 10px;
  400. border-radius: 5px;
  401. padding: 20px 10px 10px;
  402. .personal-pet-info {
  403. display: flex;
  404. align-items: center;
  405. justify-content: flex-start;
  406. .personal-pet-info-1 {
  407. margin-left: 10px;
  408. .personal-pet-info-2 {
  409. display: flex;
  410. flex-wrap: wrap;
  411. .personal-pet-name {
  412. color: #333;
  413. font-size: 16px;
  414. margin-right: 10px;
  415. }
  416. }
  417. .personal-pet-info-3 {
  418. display: flex;
  419. align-items: baseline;
  420. font-size: 14px;
  421. margin-top: 5px;
  422. color: #7D8196;
  423. .personal-pet-info-age {
  424. padding: 0 10px;
  425. margin: 0 10px;
  426. border-left: solid 2px #7D8196;
  427. border-right: solid 2px #7D8196;
  428. }
  429. }
  430. }
  431. }
  432. .personal-pet-info-disposition {
  433. padding: 10px;
  434. color: #7D8196;
  435. font-size: 14px;
  436. background: #f9f9f9;
  437. border-radius: 5px;
  438. margin-top: 10px;
  439. }
  440. .personal-pet-info-btns {
  441. display: flex;
  442. justify-content: space-between;
  443. margin-top: 10px;
  444. .personal-pet-info-btn {
  445. display: flex;
  446. font-size: 14px;
  447. color: #7D8196;
  448. margin-left: 20px;
  449. }
  450. }
  451. }
  452. }
  453. .personal-pet-none {
  454. display: flex;
  455. justify-content: center;
  456. align-items: center;
  457. flex-wrap: wrap;
  458. margin-top: 40%;
  459. .personal-pet-none-text {
  460. color: #666;
  461. text-align: center;
  462. font-size: 14px;
  463. width: 100%;
  464. margin-top: 10px;
  465. }
  466. }
  467. .calendar-popup {
  468. position: fixed;
  469. bottom: 0;
  470. left: 0;
  471. right: 0;
  472. z-index: 999;
  473. .calendar-content {
  474. background: #fff;
  475. border-radius: 16px 16px 0 0;
  476. padding: 0 20px 20px;
  477. }
  478. }
  479. .calendar-mask {
  480. position: fixed;
  481. top: 0;
  482. left: 0;
  483. right: 0;
  484. bottom: 0;
  485. background: rgba(0, 0, 0, 0.5);
  486. /* 半透明黑色 */
  487. z-index: 998;
  488. /* 确保在内容下方 */
  489. pointer-events: none;
  490. /* 使遮罩层不阻止点击事件 */
  491. }
  492. .calendar-content {
  493. position: relative;
  494. /* 确保内容在遮罩层之上 */
  495. z-index: 999;
  496. /* 确保内容在遮罩层之上 */
  497. }
  498. }
  499. </style>