adddetailsList.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="container">
  3. <view class=" padding" >
  4. <view class="title">乘客类型</view>
  5. <view style="display: flex; margin-top: 20rpx;">
  6. <view :class="{ selected: falong === 1, }" @click="tablist(1)" style="border: 1px solid #ccc; padding: 10rpx 15rpx; background: #fff; margin-left: 20rpx; border-radius: 10rpx;">
  7. 成人
  8. </view>
  9. <view :class="{ selected: falong === 2, }" @click="tablist(2)" style="border: 1px solid #ccc; padding: 10rpx 15rpx; background: #fff; margin-left: 20rpx; border-radius: 10rpx;">
  10. 儿童
  11. </view>
  12. </view>
  13. </view>
  14. <view class="padding" >
  15. <view class="title">乘客姓名</view>
  16. <view style="margin-top: 20rpx;">
  17. <input class="uni-input" v-model="name" style="width: 90%;" placeholder="请输入乘客姓名" />
  18. </view>
  19. </view>
  20. <view class=" padding" v-if="falong === 1" >
  21. <view class="title">乘客身份证</view>
  22. <view style="margin-top: 20rpx;">
  23. <input class="uni-input" v-model="idCard" style="width: 90%;" placeholder="请输入乘客身份证号码" />
  24. </view>
  25. </view>
  26. <view class=" padding" v-if="falong === 2" >
  27. <view class="title">温馨提示</view>
  28. <view style="margin-top: 20rpx; font-size: 23rpx; color: #999;">
  29. 儿童需要全价购票,暂时不支持半价票或免票,必须有一名成人跟随
  30. </view>
  31. </view>
  32. <view class="footer">
  33. <button class="submit-btn" @tap="insertsubmit()">确认</button>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. falong: 1,
  42. name: '',
  43. idCard: '',
  44. isEdit: false,
  45. id: null,
  46. }
  47. },
  48. onLoad(options) {
  49. this.mode = options.type;
  50. if (this.mode === 'edit' && options.data) {
  51. try {
  52. const detail = JSON.parse(decodeURIComponent(options.data));
  53. this.editId = detail.id;
  54. this.name = detail.name;
  55. this.idCard = '';
  56. this.falong = detail.type;
  57. } catch (e) {
  58. console.error('解析传参失败', e);
  59. }
  60. }
  61. },
  62. methods: {
  63. tablist(valie) {
  64. this.falong = valie
  65. },
  66. validateIdCard(idCard) {
  67. const reg =
  68. /(^\d{15}$)|(^\d{17}([0-9Xx])$)/;
  69. return reg.test(idCard);
  70. },
  71. insertsubmit() {
  72. if (!this.name.trim()) {
  73. uni.showToast({
  74. title: '请填写乘客姓名',
  75. icon: 'none'
  76. });
  77. return;
  78. }
  79. if (this.falong === 1) {
  80. // 成人:校验身份证
  81. if (!this.idCard.trim()) {
  82. uni.showToast({
  83. title: '请填写身份证号',
  84. icon: 'none'
  85. });
  86. return;
  87. }
  88. if (!this.validateIdCard(this.idCard)) {
  89. uni.showToast({
  90. title: '身份证格式不正确',
  91. icon: 'none'
  92. });
  93. return;
  94. }
  95. }
  96. const data = {
  97. name: this.name,
  98. idCard: this.falong === 1 ? this.idCard : '',
  99. type: this.falong,
  100. }
  101. // 如果是编辑模式,加上 id 字段,并改为调用更新接口
  102. const api = this.isEdit ? '/app/passenger/update' : '/app/passenger/insert';
  103. if (this.isEdit) {
  104. data.id = this.id;
  105. }
  106. this.$Request.postT(api, data).then(res => {
  107. if (res.code === 0) {
  108. uni.showToast({ title: '操作成功' });
  109. uni.$emit('refreshPassengerList'); // 通知列表页刷新
  110. uni.navigateBack();
  111. } else {
  112. uni.showModal({ showCancel: false, title: '操作失败', content: res.msg });
  113. }
  114. });
  115. }
  116. }
  117. }
  118. </script>
  119. <style scoped>
  120. .container {
  121. width: 100%;
  122. height: 100%;
  123. /* padding: 0 30rpx; */
  124. /* background: #fff; */
  125. }
  126. .title {
  127. font-size: 33rpx;
  128. font-family: PingFang SC;
  129. color: #333333;
  130. }
  131. .selected {
  132. background: #f76801 !important;
  133. color: #fff !important;
  134. border: #f76801 1rpx solid !important;
  135. }
  136. .footer {
  137. position: fixed;
  138. bottom: 0;
  139. left: 0;
  140. right: 0;
  141. background: #fff;
  142. padding: 20rpx 30rpx;
  143. box-shadow: 0 -4rpx 10rpx rgba(0, 0, 0, 0.05);
  144. }
  145. .submit-btn {
  146. background: #fe6b01;
  147. color: #fff;
  148. border-radius: 50rpx;
  149. font-size: 32rpx;
  150. height: 80rpx;
  151. line-height: 80rpx;
  152. }
  153. </style>