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.

335 lines
8.2 KiB

1 week ago
  1. <template>
  2. <view class="personal-pet">
  3. <view v-if="petList.length>0" class="personal-pet-list">
  4. <!-- <view class="personal-pet-list-add">
  5. <view style="font-size: 14px;color:#333;">
  6. 全部宠物
  7. </view>
  8. <view class="personal-pet-list-add-btn" @click="addPet">
  9. <uni-icons type="plus" size="18" color="#AAA" style="margin-right: 5px;"></uni-icons>
  10. </view>
  11. </view> -->
  12. <view v-for="(item,index) in petList" :key="index">
  13. <view :class="['personal-pet-list-item',item.gender=='男生'?'.personal-pet-list-item_backgroud_m':'.personal-pet-list-item_backgroud_f' ]">
  14. <view class="personal-pet-info">
  15. <view>
  16. <u-avatar :src="item.photo?item.photo:defaultPhoto" size="60" shape="circle"></u-avatar>
  17. </view>
  18. <view class="personal-pet-info-1">
  19. <view class="personal-pet-info-2">
  20. <view class="personal-pet-name">
  21. {{item.name}}
  22. </view>
  23. <view class="personal-pet-sex">
  24. <img :src="item.gender=='男生'?'../../static/images/details/boy.svg':'../../static/images/details/girl.svg'" alt="sex"
  25. style="width: 16px;height: 16px;"/>
  26. </view>
  27. </view>
  28. <view class="personal-pet-info-3" style="width: 100%;">
  29. <view class="ellipsis" style="max-width: 25%;" >
  30. {{item.breed || '未知'}}
  31. </view>
  32. <view class="personal-pet-info-age" style="max-width: 90px;">
  33. {{item.birthDate || '未知'}}
  34. </view>
  35. <view class="ellipsis" style="max-width: 25%;">
  36. {{item.bodyType || '未知'}}
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="personal-pet-info-disposition ellipsis">
  42. 性格 {{item.personality}}
  43. </view>
  44. <view class="personal-pet-info-btns">
  45. <view class="personal-pet-info-btn" @click="editPet(item)">
  46. <u-icon name="edit-pen" color="#7d8196" size="16" style="margin-right: 5px;"></u-icon>
  47. <view style="margin-left: 5px;">
  48. 编辑
  49. </view>
  50. </view>
  51. <view class="personal-pet-info-btn" @click="deletePet(item)">
  52. <u-icon name="trash" color="#7d8196" size="16"></u-icon>
  53. <view style="margin-left: 5px;">
  54. 删除
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view v-else class="personal-pet-none">
  62. <img src="https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png" alt="pet"
  63. style="width: 149px;height: 124px;" mode="widthFix"/>
  64. <view class="personal-pet-none-text">这里还没有您的宠物,请点击添加吧~</view>
  65. </view>
  66. <view class="personal-pet-add">
  67. <button class="personal-pet-add-btn" @click="addPet">
  68. <view style="font-size: 16px;font-weight: 500;">
  69. 添加宠物
  70. </view>
  71. </button>
  72. </view>
  73. <view class="">
  74. <u-picker
  75. :showToolbar='false'
  76. :show="show"
  77. :columns="petTypes"
  78. @change="petTypeChange"
  79. @cancel="cancel"
  80. @confirm="confirm"
  81. ></u-picker>
  82. </view>
  83. <u-modal :show="showDel"
  84. @confirm="confirmDel"
  85. @cancel="cancelDel"
  86. ref="uModal"
  87. showCancelButton
  88. :asyncClose="true"
  89. :content='delContent'></u-modal>
  90. </view>
  91. </template>
  92. <script>
  93. import { getDictList } from "@/api/system/user.js"
  94. import { getPetList,delPet } from "@/api/system/pet"
  95. export default{
  96. data(){
  97. return{
  98. defaultPhoto:'https://catmdogf.oss-cn-shanghai.aliyuncs.com/CMDF/front/personal/pet/catdog.png',
  99. petList:[],
  100. show:false,
  101. showDel:false,
  102. petTypes:[],
  103. delContent:'',
  104. deleteId:'',
  105. petType:''
  106. }
  107. },
  108. onShow(options) {
  109. this.getPetList();
  110. },
  111. onPullDownRefresh() {
  112. this.getPetList();
  113. },
  114. mounted() {
  115. this.getPetTypeList();
  116. this.getPetList();
  117. },
  118. methods:{
  119. getPetList(){
  120. this.petList=[]
  121. getPetList().then(res=>{
  122. if(res&&res.content){
  123. this.petList=res.content
  124. this.showDel = false;
  125. }
  126. })
  127. },
  128. getPetTypeList(){
  129. getDictList('pet_type').then(res=>{
  130. if (res.code == 200) {
  131. let petType = res.data.map(e=>e.dictLabel)
  132. this.petTypes=[petType]
  133. console.log(this.petTypes)
  134. } else {
  135. this.$modal.showToast('获取pet type失败')
  136. }
  137. })
  138. },
  139. addPet(){
  140. this.show = true;
  141. },
  142. cancel() {
  143. this.show = false
  144. },
  145. petTypeChange(e){
  146. console.log(e)
  147. this.petType=e.value[0]
  148. },
  149. confirm(e) {
  150. this.show = false
  151. console.log(this.petType)
  152. if(this.petType==='猫猫'){
  153. uni.navigateTo({
  154. url: `/pages/personalCenter/petInfo?petType=cat&optionType=add`
  155. });
  156. }
  157. if(this.petType==='狗狗'){
  158. uni.navigateTo({
  159. url: `/pages/personalCenter/petInfo?petType=dog&optionType=add`
  160. });
  161. }
  162. if(!this.petType){
  163. if(e.value[0]==='猫猫'){
  164. uni.navigateTo({
  165. url: `/pages/personalCenter/petInfo?petType=cat&optionType=add`
  166. });
  167. }
  168. if(e.value[0]==='狗狗'){
  169. uni.navigateTo({
  170. url: `/pages/personalCenter/petInfo?petType=dog&optionType=add`
  171. });
  172. }
  173. }
  174. },
  175. editPet(item){
  176. if(item.petType=='猫猫' || item.petType=='cat'){
  177. uni.navigateTo({
  178. url: `/pages/personalCenter/petInfo?petType=cat&optionType=edit&petId=${item.id}`
  179. });
  180. }
  181. if(item.petType=='狗狗'|| item.petType=='dog'){
  182. uni.navigateTo({
  183. url: `/pages/personalCenter/petInfo?petType=dog&optionType=edit&petId=${item.id}`
  184. });
  185. }
  186. },
  187. deletePet(item){
  188. this.delContent = "确定要删除"+item.name+'?';
  189. this.showDel = true;
  190. this.deleteId=item.id;
  191. },
  192. confirmDel(){
  193. delPet(this.deleteId).then(res=>{
  194. console.log(res);
  195. this.$modal.showToast('删除成功');
  196. this.getPetList()
  197. })
  198. },
  199. cancelDel(){
  200. this.showDel = false;
  201. this.deleteId='';
  202. }
  203. }
  204. }
  205. </script>
  206. <style lang="scss">
  207. .personal-pet{
  208. position: relative;
  209. height: 100%;
  210. padding-bottom: 90px;
  211. .personal-pet-add{
  212. background-color: #FFFFFF;
  213. padding:10px 20px 40px;
  214. width: 100%;
  215. height: 90px;
  216. position: fixed;
  217. bottom: 0;
  218. z-index: 100;
  219. display: flex;
  220. .personal-pet-add-btn{
  221. width: 100%;
  222. border-radius: 6px;
  223. background: #FFB13F;
  224. font-size: 16px;
  225. color: #FFFFFF;
  226. }
  227. }
  228. .personal-pet-list{
  229. .personal-pet-list-add{
  230. width: 100%;
  231. height: 44px;
  232. background-color: #FFFFFF;
  233. display: flex;
  234. justify-content: space-between;
  235. align-items: center;
  236. padding: 0 15px;
  237. .personal-pet-list-add-btn{
  238. font-size: 14px;
  239. color:#AAA;
  240. display: flex;
  241. align-items: center;
  242. }
  243. }
  244. .personal-pet-list-item_backgroud_m{
  245. background: linear-gradient(179deg, #EDF5FE 0.75%, #FFF 34.11%);
  246. }
  247. .personal-pet-list-item_backgroud_f{
  248. background: linear-gradient(179deg, #FFF4F6 0.75%, #FFF 34.11%);
  249. }
  250. .personal-pet-list-item{
  251. margin: 10px 10px 0 10px;
  252. border-radius: 5px;
  253. padding: 20px 10px 10px;
  254. .personal-pet-info{
  255. display: flex;
  256. align-items: center;
  257. justify-content: flex-start;
  258. .personal-pet-info-1{
  259. margin-left: 10px;
  260. .personal-pet-info-2{
  261. display: flex;
  262. flex-wrap: wrap;
  263. .personal-pet-name{
  264. color: #333;
  265. font-size: 16px;
  266. margin-right: 10px;
  267. }
  268. }
  269. .personal-pet-info-3 {
  270. display: flex;
  271. align-items: baseline;
  272. font-size: 14px;
  273. margin-top: 5px;
  274. color: #7D8196;
  275. .personal-pet-info-age{
  276. padding: 0 10px;
  277. margin: 0 10px;
  278. border-left: solid 2px #7D8196;
  279. border-right: solid 2px #7D8196;
  280. }
  281. }
  282. }
  283. }
  284. .personal-pet-info-disposition{
  285. padding: 10px;
  286. color: #7D8196;
  287. font-size: 14px;
  288. background: #f9f9f9;
  289. border-radius: 5px;
  290. margin-top: 10px;
  291. }
  292. .personal-pet-info-btns{
  293. display: flex;
  294. justify-content: flex-end;
  295. margin-top: 10px;
  296. .personal-pet-info-btn{
  297. display: flex;
  298. font-size: 14px;
  299. color: #7D8196;
  300. margin-left: 20px;
  301. }
  302. }
  303. }
  304. }
  305. .personal-pet-none{
  306. display:flex;
  307. justify-content: center;
  308. align-items: center;
  309. flex-wrap: wrap;
  310. margin-top: 40%;
  311. .personal-pet-none-text{
  312. color: #666;
  313. text-align: center;
  314. font-size: 14px;
  315. width: 100%;
  316. margin-top: 10px;
  317. }
  318. }
  319. }
  320. </style>