create.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view class="create-page">
  3. <view class="form">
  4. <view class="form-item">
  5. <text class="label">体重(kg)</text>
  6. <input class="input" type="digit" v-model="form.weight" placeholder="请输入体重" />
  7. </view>
  8. <view class="form-item">
  9. <text class="label">体脂率(%)</text>
  10. <input class="input" type="digit" v-model="form.bodyFatPercent" placeholder="选填" />
  11. </view>
  12. <view class="form-item">
  13. <text class="label">腰围(cm)</text>
  14. <input class="input" type="digit" v-model="form.waistCircumference" placeholder="选填" />
  15. </view>
  16. <view class="form-item">
  17. <text class="label">测量日期</text>
  18. <picker mode="date" :value="form.measureDate" @change="onDateChange">
  19. <view class="picker">{{ form.measureDate }}</view>
  20. </picker>
  21. </view>
  22. </view>
  23. <button class="submit-btn" @click="submit">保存</button>
  24. </view>
  25. </template>
  26. <script>
  27. import { createWeightRecord } from '../../utils/api.js'
  28. import { today } from '../../utils/format.js'
  29. export default {
  30. data() {
  31. return {
  32. form: {
  33. weight: '',
  34. bodyFatPercent: '',
  35. waistCircumference: '',
  36. measureDate: today()
  37. }
  38. }
  39. },
  40. methods: {
  41. onDateChange(e) {
  42. this.form.measureDate = e.detail.value
  43. },
  44. submit() {
  45. if (!this.form.weight) {
  46. uni.showToast({ title: '请输入体重', icon: 'none' })
  47. return
  48. }
  49. var data = {
  50. weight: this.form.weight,
  51. measureDate: this.form.measureDate
  52. }
  53. if (this.form.bodyFatPercent) data.bodyFatPercent = this.form.bodyFatPercent
  54. if (this.form.waistCircumference) data.waistCircumference = this.form.waistCircumference
  55. createWeightRecord(data).then(() => {
  56. uni.showToast({ title: '保存成功', icon: 'success' })
  57. setTimeout(() => {
  58. uni.navigateBack()
  59. }, 1000)
  60. })
  61. }
  62. }
  63. }
  64. </script>
  65. <style>
  66. .create-page { padding: 30rpx; }
  67. .form { background: #fff; border-radius: 16rpx; padding: 0 30rpx; margin-bottom: 60rpx; }
  68. .form-item { display: flex; align-items: center; padding: 30rpx 0; border-bottom: 1rpx solid #f5f5f5; }
  69. .label { width: 200rpx; color: #333; }
  70. .input { flex: 1; text-align: right; }
  71. .picker { flex: 1; text-align: right; color: #333; }
  72. .submit-btn { background: #F97316; color: #fff; border-radius: 40rpx; }
  73. </style>