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.

576 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. //判断当前选中的地址是否加价
  184. isAddPrice(){
  185. let currentAddress = this.$globalData.newOrderData.currentAddress || {}
  186. let defaultPrice = 1
  187. try{
  188. defaultPrice = this.price_config.cityConfig.priceRates.default
  189. }catch(e){
  190. defaultPrice = 1
  191. }
  192. if(!this.price_config.cityConfig || !currentAddress.province || !currentAddress.city){
  193. return defaultPrice
  194. }
  195. let addressList = this.price_config.cityConfig.priceRates || []
  196. for(let key in addressList){
  197. if((currentAddress.province + currentAddress.city).includes(key)){
  198. return addressList[key]
  199. }
  200. }
  201. return defaultPrice
  202. },
  203. getPetList() {
  204. this.petList = []
  205. getPetList().then(res => {
  206. let currentPets = this.$globalData.newOrderData.currentPets
  207. if (res && res.content) {
  208. this.petList = res.content.map(e => {
  209. const currentPet = currentPets.find(item => item.id === e.id)
  210. if (currentPet) {
  211. e.selectedDate = currentPet.selectedDate
  212. e.checked = [!!currentPet.checked]
  213. } else {
  214. e.selectedDate = []
  215. e.checked = false
  216. }
  217. return e
  218. })
  219. this.showDel = false;
  220. }
  221. })
  222. },
  223. //获取当前技师不接单日期
  224. getOutDateList(){
  225. if(!this.buyInfo.teacher || !this.buyInfo.teacher.userId){
  226. return
  227. }
  228. console.log('this.buyInfo', this.buyInfo);
  229. getTeacherAddressList({
  230. userId : this.buyInfo.teacher.userId
  231. }).then(response => {
  232. if (response.code == 200) {
  233. let addressList = this.calculateDistanceAddressList(response.data)
  234. if(addressList && addressList[0] && addressList[0].appletOutDate){
  235. this.outDateList = addressList[0].appletOutDate.map(n => n.date)
  236. }
  237. console.log(addressList, this.outDateList);
  238. }
  239. })
  240. },
  241. getPetTypeList() {
  242. getDictList('pet_type').then(res => {
  243. if (res.code == 200) {
  244. let petType = res.data.map(e => e.dictLabel)
  245. this.petTypes = [petType]
  246. console.log(this.petTypes)
  247. } else {
  248. this.$modal.showToast('获取pet type失败')
  249. }
  250. })
  251. },
  252. addPet() {
  253. this.show = true;
  254. },
  255. cancel() {
  256. this.show = false
  257. },
  258. petTypeChange(e) {
  259. console.log(e)
  260. this.petType = e.value[0]
  261. },
  262. confirmPetType(e) {
  263. console.log(e)
  264. this.show = false
  265. // 获取宠物类型,优先使用已选择的petType,否则使用e.value[0]
  266. const type = this.petType || e.value[0]
  267. // 根据宠物类型映射到英文类型
  268. const petTypeMap = {
  269. '猫猫': 'cat',
  270. '狗狗': 'dog'
  271. }
  272. const petType = petTypeMap[type]
  273. if (petType) {
  274. uni.navigateTo({
  275. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=add&isNewOrder=true`
  276. });
  277. }
  278. },
  279. editPet(item) {
  280. const petTypeMap = {
  281. '猫猫': 'cat',
  282. 'cat': 'cat',
  283. '狗狗': 'dog',
  284. 'dog': 'dog'
  285. }
  286. const petType = petTypeMap[item.petType]
  287. if (petType) {
  288. uni.navigateTo({
  289. url: `/pages/personalCenter/petInfo?petType=${petType}&optionType=edit&petId=${item.id}&isNewOrder=true`
  290. });
  291. }
  292. },
  293. deletePet(item) {
  294. this.delContent = "确定要删除" + item.name + '?';
  295. this.showDel = true;
  296. this.deleteId = item.id;
  297. },
  298. confirmDel() {
  299. delPet(this.deleteId).then(res => {
  300. console.log(res);
  301. this.$modal.showToast('删除成功');
  302. this.getPetList()
  303. })
  304. },
  305. cancelDel() {
  306. this.showDel = false;
  307. this.deleteId = '';
  308. },
  309. getCalendarDate() {
  310. let tomorrow = new Date()
  311. tomorrow.setDate(tomorrow.getDate() + 2);
  312. this.startDate = this.formatDate(tomorrow);
  313. // 获取三个月后的日期
  314. let threeMonthsLater = new Date();
  315. threeMonthsLater.setMonth(threeMonthsLater.getMonth() + 3);
  316. this.endDate = this.formatDate(threeMonthsLater);
  317. },
  318. formatDate(date) {
  319. let year = date.getFullYear();
  320. let month = (date.getMonth() + 1).toString().padStart(2, '0');
  321. let day = date.getDate().toString().padStart(2, '0');
  322. return year + '-' + month + '-' + day;
  323. },
  324. selectDate(item) {
  325. this.currentId = item.id
  326. this.selectedDate = item.selectedDate
  327. this.showCalendar = true;
  328. },
  329. confirmCanlendar() {
  330. const currentPet = this.petList.find(e => e.id == this.currentId);
  331. currentPet.selectedDate = this.selectedDate.sort((a, b) => new Date(a.date) - new Date(b.date));
  332. // 选择日期后自动勾选该宠物
  333. if (this.selectedDate.length > 0) {
  334. currentPet.checked = [true];
  335. }
  336. this.selectedDate = [];
  337. this.showCalendar = false;
  338. },
  339. change(e) {
  340. const selectedValue = this.selectedDate.find(item => item.date === e.fulldate)
  341. if (selectedValue) {
  342. // 存在则移除
  343. this.selectedDate = this.selectedDate.filter(item => item.date !== e.fulldate);
  344. } else {
  345. this.selectedDate.push({
  346. date: e.fulldate,
  347. info: '预定'
  348. })
  349. }
  350. },
  351. confirm() {
  352. const selectedPets = this.petList.filter(e => e.checked)
  353. const unselectedDatePets = selectedPets.filter(pet => !pet.selectedDate || pet.selectedDate.length === 0)
  354. if (unselectedDatePets.length > 0) {
  355. const petNames = unselectedDatePets.map(pet => pet.name).join('、')
  356. this.$modal.showToast(`请为${petNames}选择服务时间`)
  357. return
  358. }
  359. this.$globalData.newOrderData.currentPets = selectedPets
  360. uni.redirectTo({
  361. url: '/pages/newOrder/serviceNew'
  362. })
  363. },
  364. showSelectedDate(selectedDate) {
  365. // 显示格式:首日...最后一日 共几天
  366. // 日期格式只需要月份和日期 例如:01/01...01/07
  367. const firstDate = selectedDate[0].date.substring(5).replace('-', '/')
  368. const lastDate = selectedDate[selectedDate.length - 1].date.substring(5).replace('-', '/')
  369. const days = selectedDate.length
  370. return `${firstDate}${days > 2 ? '...' : ''}${days == 2 ? ',' : ''}${days > 1 ? lastDate : ''}${days}`
  371. }
  372. }
  373. }
  374. </script>
  375. <style lang="scss" scoped>
  376. .personal-pet {
  377. position: relative;
  378. height: 100%;
  379. padding-bottom: 90px;
  380. .personal-pet-add {
  381. background-color: #FFFFFF;
  382. padding: 10px 20px 40px;
  383. width: 100%;
  384. height: 90px;
  385. position: fixed;
  386. bottom: 0;
  387. z-index: 100;
  388. display: flex;
  389. justify-content: space-between;
  390. .personal-pet-add-btn {
  391. width: 100%;
  392. border-radius: 6px;
  393. font-size: 16px;
  394. }
  395. }
  396. .personal-pet-list {
  397. .personal-pet-list-add {
  398. width: 100%;
  399. height: 44px;
  400. background-color: #FFFFFF;
  401. display: flex;
  402. justify-content: space-between;
  403. align-items: center;
  404. padding: 0 15px;
  405. .personal-pet-list-add-btn {
  406. font-size: 14px;
  407. color: #AAA;
  408. display: flex;
  409. align-items: center;
  410. }
  411. }
  412. .personal-pet-list-item_backgroud_m {
  413. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  414. }
  415. .personal-pet-list-item_backgroud_f {
  416. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  417. }
  418. .personal-pet-list-item {
  419. margin: 10px 10px 0 10px;
  420. border-radius: 5px;
  421. padding: 20px 10px 10px;
  422. .personal-pet-info {
  423. display: flex;
  424. align-items: center;
  425. justify-content: flex-start;
  426. .personal-pet-info-1 {
  427. margin-left: 10px;
  428. .personal-pet-info-2 {
  429. display: flex;
  430. flex-wrap: wrap;
  431. .personal-pet-name {
  432. color: #333;
  433. font-size: 16px;
  434. margin-right: 10px;
  435. }
  436. }
  437. .personal-pet-info-3 {
  438. display: flex;
  439. align-items: baseline;
  440. font-size: 14px;
  441. margin-top: 5px;
  442. color: #7D8196;
  443. .personal-pet-info-age {
  444. padding: 0 10px;
  445. margin: 0 10px;
  446. border-left: solid 2px #7D8196;
  447. border-right: solid 2px #7D8196;
  448. }
  449. }
  450. }
  451. }
  452. .personal-pet-info-disposition {
  453. padding: 10px;
  454. color: #7D8196;
  455. font-size: 14px;
  456. background: #f9f9f9;
  457. border-radius: 5px;
  458. margin-top: 10px;
  459. }
  460. .personal-pet-info-btns {
  461. display: flex;
  462. justify-content: space-between;
  463. margin-top: 10px;
  464. .personal-pet-info-btn {
  465. display: flex;
  466. font-size: 14px;
  467. color: #7D8196;
  468. margin-left: 20px;
  469. }
  470. }
  471. }
  472. }
  473. .personal-pet-none {
  474. display: flex;
  475. justify-content: center;
  476. align-items: center;
  477. flex-wrap: wrap;
  478. margin-top: 40%;
  479. .personal-pet-none-text {
  480. color: #666;
  481. text-align: center;
  482. font-size: 14px;
  483. width: 100%;
  484. margin-top: 10px;
  485. }
  486. }
  487. .calendar-popup {
  488. position: fixed;
  489. bottom: 0;
  490. left: 0;
  491. right: 0;
  492. z-index: 999;
  493. .calendar-content {
  494. background: #fff;
  495. border-radius: 16px 16px 0 0;
  496. padding: 0 20px 20px;
  497. }
  498. }
  499. .calendar-mask {
  500. position: fixed;
  501. top: 0;
  502. left: 0;
  503. right: 0;
  504. bottom: 0;
  505. background: rgba(0, 0, 0, 0.5);
  506. /* 半透明黑色 */
  507. z-index: 998;
  508. /* 确保在内容下方 */
  509. pointer-events: none;
  510. /* 使遮罩层不阻止点击事件 */
  511. }
  512. .calendar-content {
  513. position: relative;
  514. /* 确保内容在遮罩层之上 */
  515. z-index: 999;
  516. /* 确保内容在遮罩层之上 */
  517. }
  518. }
  519. </style>