ck_page.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="box">
  3. <u-navbar title="添加乘客" autoBack :placeholder="true" bgColor="#fee1b9"></u-navbar>
  4. <view class="ban">
  5. <view class="form-group" v-for="(item, index) in passengers" :key="index">
  6. <text>成员 {{ index + 1 }}</text>
  7. <u-input placeholder="请输入姓名" v-model="item.name" border="surround" />
  8. <u-input placeholder="请输入手机号" v-model="item.mobile" border="surround" />
  9. <u-input placeholder="请输入年龄" v-model="item.age" border="surround" />
  10. <button type="default" @click="removePassenger(index)" v-if="passengers.length > 0">删除乘客</button>
  11. </view>
  12. <view @click="addPassenger" class="tjbm_btn">添加乘客</view>
  13. <view @click="submit" class="tjbm_btn">提交</view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. passengers: [
  22. { name: '', mobile: '', age: '' }
  23. ]
  24. };
  25. },
  26. onLoad() {
  27. // 从本地存储中获取乘客信息
  28. const storedPassengers = uni.getStorageSync('passengers');
  29. if (storedPassengers) {
  30. this.passengers = storedPassengers;
  31. } else {
  32. // 如果没有存储的乘客信息,则初始化一个空的乘客对象
  33. this.passengers = [{ name: '', mobile: '', age: '' }];
  34. }
  35. },
  36. methods: {
  37. addPassenger() {
  38. this.passengers.push({ name: '', mobile: '', age: '' });
  39. },
  40. removePassenger(index) {
  41. this.passengers.splice(index, 1);
  42. // 更新本地存储
  43. uni.setStorageSync('passengers', this.passengers);
  44. },
  45. submit() {
  46. console.log('提交的乘客信息:', this.passengers);
  47. // 将乘客信息保存到本地存储中
  48. uni.setStorageSync('passengers', this.passengers);
  49. // 返回上一个页面
  50. uni.navigateBack({
  51. delta: 1
  52. });
  53. }
  54. }
  55. };
  56. </script>
  57. <style scoped>
  58. .box {
  59. min-height: 100%;
  60. height: auto;
  61. width: 100%;
  62. padding-bottom: 50rpx;
  63. background-image: url('https://huli-app.wenlvti.net/app_static/minnanhun/image/gj_bg.png');
  64. background-repeat: repeat-y;
  65. background-size: 100%;
  66. }
  67. .ban {
  68. width: 92%;
  69. margin: auto;
  70. }
  71. .form-group {
  72. margin-bottom: 20px;
  73. border: 1px solid #ccc;
  74. padding: 10px;
  75. border-radius: 5px;
  76. }
  77. button {
  78. margin-top: 10px;
  79. }
  80. .u-input.data-v-113bc24f {
  81. background-color: #fee1b9 !important;
  82. margin-top: 20rpx;
  83. }
  84. .tjbm_btn {
  85. width: 100%;
  86. height: 80rpx;
  87. font-size: 30rpx;
  88. line-height: 80rpx;
  89. text-align: center;
  90. color: #ffffff;
  91. border-radius: 10rpx;
  92. background-color: #fb5a02;
  93. margin-top: 50rpx;
  94. }
  95. </style>