add.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="add">
  3. <view class="tips">
  4. 提醒:姓名与身份证一致,否则会影响出游
  5. </view>
  6. <view class="card">
  7. <view class="form-item">
  8. <view class="label">姓名</view>
  9. <u--input customStyle="input" placeholder="请输入姓名" v-model="form.userName" border="none"></u--input>
  10. </view>
  11. <view class="form-item" @click="show = true">
  12. <view class="label">证件类型</view>
  13. <u--input customStyle="input" readonly placeholder="请选择证件类型" value="身份证" border="none"></u--input>
  14. </view>
  15. <view class="form-item">
  16. <view class="label">证件号码</view>
  17. <u--input customStyle="input" :maxlength="18" placeholder="请输入证件号码" v-model="form.idCard"
  18. border="none"></u--input>
  19. </view>
  20. <view class="form-item">
  21. <view class="label">手机号码</view>
  22. <u--input customStyle="input" :maxlength="11" placeholder="请输入号码" type="idcard" v-model="form.phone"
  23. border="none"></u--input>
  24. </view>
  25. <view class="form-item" @click="showSex = true">
  26. <view class="label">性别</view>
  27. <u--input customStyle="input" readonly placeholder="请选择性别" v-model="sexLabel" border="none"></u--input>
  28. </view>
  29. </view>
  30. <view class="buy-box">
  31. <button :loading="loading" class="buy-btn" type="default" @click="handleAdd">确定</button>
  32. </view>
  33. <u-action-sheet :closeOnClickOverlay="true" @close="show = false" :closeOnClickAction="true" cancelText="取消"
  34. :actions="option" :show="show"></u-action-sheet>
  35. <u-action-sheet :closeOnClickOverlay="true" @close="showSex = false" :closeOnClickAction="true" cancelText="取消"
  36. :actions="sexOption" @select="select" :show="showSex"></u-action-sheet>
  37. </view>
  38. </template>
  39. <script>
  40. import { saveTraveler } from "@/api/study"
  41. export default {
  42. data() {
  43. return {
  44. option: [
  45. {
  46. name: '身份证',
  47. },
  48. ],
  49. sexOption: [
  50. {
  51. name: '男',
  52. },
  53. {
  54. name: '女',
  55. },
  56. ],
  57. form: {
  58. id: '',
  59. idCard: '',
  60. cardType: '1',
  61. phone: '',
  62. sex: '',
  63. userId: '',
  64. userName: ''
  65. },
  66. sexLabel: '',
  67. show: false,
  68. showSex: false,
  69. loading: false
  70. };
  71. },
  72. methods: {
  73. select({ name }) {
  74. this.sexLabel = name
  75. this.form.sex = name == "男" ? 1 : 2
  76. },
  77. handleAdd() {
  78. this.loading = true
  79. // 表单校验
  80. if (!this.validate()) {
  81. this.loading = false
  82. return
  83. }
  84. saveTraveler(this.form).then(res => {
  85. if (res.state == 'Success') {
  86. uni.showToast({
  87. title: '完成',
  88. icon: 'none'
  89. });
  90. uni.navigateBack({
  91. delta: 1
  92. });
  93. }
  94. })
  95. },
  96. validate() {
  97. if (!this.form.userName) {
  98. uni.showToast({
  99. title: '请输入姓名',
  100. icon: 'none'
  101. });
  102. return
  103. }
  104. if (!this.form.idCard) {
  105. uni.showToast({
  106. title: '请输入证件号码',
  107. icon: 'none'
  108. });
  109. return
  110. }
  111. // 校验身份证合法性
  112. if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(this.form.idCard)) {
  113. uni.showToast({
  114. title: '身份证格式不正确',
  115. icon: 'none'
  116. });
  117. return
  118. }
  119. if (!this.form.phone) {
  120. uni.showToast({
  121. title: '请输入手机号码',
  122. icon: 'none'
  123. });
  124. return
  125. }
  126. // 校验手机合法性
  127. if (!/^1[3456789]\d{9}$/.test(this.form.phone)) {
  128. uni.showToast({
  129. title: '手机号码格式不正确',
  130. icon: 'none'
  131. });
  132. return
  133. }
  134. if (!this.form.sex) {
  135. uni.showToast({
  136. title: '请选择性别',
  137. icon: 'none'
  138. });
  139. return
  140. }
  141. return true
  142. }
  143. },
  144. };
  145. </script>
  146. <style lang="scss" scoped>
  147. .add {
  148. background: #F9F9F9;
  149. min-height: 100vh;
  150. padding: 0 20rpx;
  151. }
  152. .tips {
  153. color: #AAAAAA;
  154. font-size: 28rpx;
  155. padding: 28rpx 0;
  156. }
  157. .card {
  158. padding: 24rpx;
  159. background: #FFFFFF;
  160. border-radius: 16rpx;
  161. .form-item {
  162. border-top: 1px solid #F0F0F0;
  163. display: flex;
  164. &:first-child {
  165. border-top: none;
  166. }
  167. .label {
  168. color: #222222;
  169. font-size: 24rpx;
  170. margin: 24rpx 0;
  171. width: 152rpx;
  172. }
  173. .input {}
  174. }
  175. }
  176. .buy-box {
  177. position: fixed;
  178. bottom: 0%;
  179. left: 0%;
  180. width: 100%;
  181. background: #fff;
  182. padding: 10rpx 24rpx env(safe-area-inset-bottom);
  183. box-sizing: border-box;
  184. .buy-btn {
  185. width: 702rpx;
  186. height: 80rpx;
  187. line-height: 80rpx;
  188. text-align: center;
  189. background: #3B83FF;
  190. border-radius: 40rpx;
  191. font-weight: 600;
  192. font-size: 28rpx;
  193. color: #FFFFFF;
  194. }
  195. }
  196. </style>