addressadd.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="addressadd">
  3. <custom-nav :title="pageTitle"></custom-nav>
  4. <custom-toast ref='toast'></custom-toast>
  5. <view class="content">
  6. <view class="form">
  7. <view class="name item">
  8. <text>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</text>
  9. <input type="text" maxlength="12" placeholder="请输入姓名" v-model="name"/>
  10. <text v-if="name" class="cuIcon-roundclosefill" @tap="clearName"></text>
  11. </view>
  12. <view class="line"></view>
  13. <view class="tel item">
  14. <text>联系电话:</text>
  15. <input type="text" maxlength="11" placeholder="请输入联系电话" v-model="tel"/>
  16. <text v-if="tel" class="cuIcon-roundclosefill" @tap="clearTel"></text>
  17. </view>
  18. <view class="line"></view>
  19. <view class="address1 item">
  20. <text>所在地区:</text>
  21. <picker mode="region" @change="RegionChange" :value="region">
  22. <view class="picker">
  23. {{region[0]}} {{region[1]}} {{region[2]}}
  24. </view>
  25. </picker>
  26. <text class="cuIcon-right"></text>
  27. </view>
  28. <view class="line"></view>
  29. <view class="address2 item">
  30. <text>详细地址:</text>
  31. <input type="text" placeholder="请输入详细地址" v-model="address"/>
  32. <text v-if="address" class="cuIcon-roundclosefill" @tap="clearAddress"></text>
  33. </view>
  34. </view>
  35. <label class="default item" for="checkoutbox">
  36. <text>设为默认</text>
  37. <switch class="base" id="checkoutbox" @change="Switch" :class="setDefault ? 'checked' : '' " :checked="setDefault ? true : false" color="#FA6342"></switch>
  38. </label>
  39. <view class="save" @tap="save">保存地址</view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import { api_addAddress } from '../../api.js'
  45. export default {
  46. data() {
  47. return {
  48. pageTitle: '新增地址',
  49. region: ['河南省', '郑州市', '金水区'],
  50. setDefault: true,
  51. name: '',
  52. tel: '',
  53. address: ''
  54. };
  55. },
  56. methods: {
  57. RegionChange(e) {
  58. this.region = e.detail.value
  59. },
  60. Switch(e) {
  61. this.setDefault = e.detail.value
  62. },
  63. clearName () {
  64. this.name = ''
  65. },
  66. clearTel () {
  67. this.tel = ''
  68. },
  69. clearAddress () {
  70. this.address = ''
  71. },
  72. save () {
  73. if (this.name && this.tel && this.address) { //首先所有的input 不能为空
  74. if (this.tel.match(/^1\d{10}$/)) { //校验手机号
  75. let address = ''
  76. this.region.forEach(e => { //取出piacker 中的地址
  77. address = address + e + ' '
  78. })
  79. this.$ajax.post(api_addAddress, {
  80. name: this.name,
  81. tel: this.tel,
  82. address: address + '-' +this.address,
  83. status: this.setDefault ? 1 : 0
  84. }).then(([ , { data: res }]) => {
  85. if (+res.code === 200) {
  86. uni.$emit('MESSAGE', '地址添加成功')
  87. uni.navigateBack()
  88. } else {
  89. this.$refs.toast.hover('添加失败')
  90. }
  91. })
  92. } else {
  93. this.$refs.toast.hover('手机号格式不正确,请重新输入')
  94. }
  95. } else {
  96. this.$refs.toast.hover('请将个人信息填写完整')
  97. }
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .addressadd {
  104. @include page();
  105. .content {
  106. background: $custom-nav-borderbot-color;
  107. .form {
  108. .item {
  109. display: flex;
  110. align-items: center;
  111. justify-content: space-between;
  112. position: relative;
  113. input {
  114. flex: 1;
  115. height: 100%;
  116. box-sizing: border-box;
  117. text-align: left;
  118. }
  119. .cuIcon-roundclosefill {
  120. font-size: 40rpx;
  121. color: #AAAAAA;
  122. }
  123. picker {
  124. position: absolute;
  125. width: 100%;
  126. height: 100%;
  127. z-index: 1;
  128. line-height: 90rpx;
  129. text-align: center;
  130. }
  131. }
  132. border-top: 10rpx solid $custom-nav-borderbot-color;
  133. box-sizing: border-box;
  134. padding: 0 30rpx;
  135. background: #FFFFFF;
  136. view {
  137. height: 90rpx;
  138. &.line {
  139. height: 2rpx;
  140. background: $custom-nav-borderbot-color;
  141. }
  142. }
  143. }
  144. .default {
  145. display: flex;
  146. align-items: center;
  147. justify-content: space-between;
  148. position: relative;
  149. margin-top: 20rpx;
  150. background: #FFFFFF;
  151. height: 90rpx;
  152. box-sizing: border-box;
  153. padding: 0 30rpx;
  154. }
  155. .save {
  156. width: 400rpx;
  157. height: 70rpx;
  158. line-height: 70rpx;
  159. text-align: center;
  160. background: rgba(250,99,66,1);
  161. color: #FFFFFF;
  162. margin: 138rpx auto 0;
  163. box-shadow: 0px 2rpx 4rpx 0px rgba(51,51,51,0.15);
  164. border-radius: 35rpx;
  165. }
  166. }
  167. }
  168. </style>