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.

463 lines
13 KiB

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