index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class="weight-page">
  3. <view class="header">
  4. <text class="title">体重记录</text>
  5. <button class="add-btn" size="mini" @click="goCreate">+ 记录</button>
  6. </view>
  7. <view class="list">
  8. <view class="item" v-for="item in list" :key="item.id">
  9. <view class="left">
  10. <text class="date">{{ format(item.measureDate || item.createTime) }}</text>
  11. </view>
  12. <view class="right">
  13. <text class="weight">{{ item.weight }} kg</text>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="empty" v-if="list.length === 0">
  18. <text>暂无体重记录</text>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import { getWeightList, deleteWeightRecord } from '../../utils/api.js'
  24. import { formatDate } from '../../utils/format.js'
  25. export default {
  26. data() {
  27. return {
  28. list: []
  29. }
  30. },
  31. onShow() {
  32. this.loadList()
  33. },
  34. methods: {
  35. loadList() {
  36. getWeightList().then(res => {
  37. if (res.data) this.list = res.data
  38. })
  39. },
  40. goCreate() {
  41. uni.navigateTo({ url: '/pages/weight/create' })
  42. },
  43. format(date) {
  44. return formatDate(date)
  45. },
  46. deleteItem(id) {
  47. uni.showModal({
  48. title: '提示',
  49. content: '确定删除该记录吗?',
  50. success: (res) => {
  51. if (res.confirm) {
  52. deleteWeightRecord(id).then(() => {
  53. this.loadList()
  54. })
  55. }
  56. }
  57. })
  58. }
  59. }
  60. }
  61. </script>
  62. <style>
  63. .weight-page { padding: 30rpx; }
  64. .header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 30rpx; }
  65. .title { font-size: 36rpx; font-weight: 600; }
  66. .add-btn { background: #F97316; color: #fff; border-radius: 40rpx; }
  67. .list { background: #fff; border-radius: 16rpx; overflow: hidden; }
  68. .item { display: flex; justify-content: space-between; padding: 30rpx; border-bottom: 1rpx solid #f5f5f5; }
  69. .date { color: #666; }
  70. .weight { font-size: 32rpx; font-weight: 600; color: #F97316; }
  71. .empty { text-align: center; color: #999; padding: 60rpx; }
  72. </style>