addAddress.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <view class="container">
  3. <view class="chooseAddress">
  4. <button class="choose-btn" @click="chooseLocation">
  5. <van-icon name="location-o" />
  6. 选择收货地址
  7. </button>
  8. <view v-if="location" class="location-info">
  9. <text>{{ location.name }}</text>
  10. <text>{{ location.address }}</text>
  11. </view>
  12. </view>
  13. <view class="info">
  14. <view class="detailAddress">
  15. <input placeholder="详细地址,例如101室" v-model="detailAddress" />
  16. </view>
  17. <view class="tag">
  18. <radio-group @change="changeAddressTag">
  19. <label class="tag-label" v-for="tag in addressTags" :key="tag">
  20. <radio :value="tag" :checked="addressTag === tag" />
  21. {{ tag }}
  22. </label>
  23. </radio-group>
  24. </view>
  25. <view class="person-info">
  26. <input
  27. class="person-input"
  28. placeholder="请填写收货人的姓名"
  29. v-model="receiverName"
  30. />
  31. <radio-group class="gender" @change="changeGender">
  32. <label v-for="g in genders" :key="g">
  33. <radio :value="g" :checked="gender === g" />{{ g }}
  34. </label>
  35. </radio-group>
  36. </view>
  37. <view class="phoneNumber">
  38. <input placeholder="请填写收货手机号码" v-model="phoneNumber" />
  39. </view>
  40. </view>
  41. <view class="savaAddress">
  42. <button class="save-btn" @click="saveAddress">保存地址</button>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import { mapMutations ,mapGetters} from 'vuex'
  48. export default {
  49. data() {
  50. return {
  51. detailAddress: '',
  52. addressTag: '家',
  53. addressTags: ['家', '公司', '学校', '公寓'],
  54. receiverName: '',
  55. phoneNumber: '',
  56. gender: '先生',
  57. genders: ['先生', '女士'],
  58. location: null
  59. };
  60. },
  61. methods: {
  62. ...mapMutations('m_addr', ['addAddress']),
  63. chooseLocation() {
  64. uni.chooseLocation({
  65. success: (res) => {
  66. this.location = res;
  67. }
  68. });
  69. },
  70. changeAddressTag(e) {
  71. this.addressTag = e.detail.value;
  72. },
  73. changeGender(e) {
  74. this.gender = e.detail.value;
  75. },
  76. saveAddress() {
  77. let data={
  78. detailAddress: this.detailAddress,
  79. addressTag: this.addressTag,
  80. receiverName: this.receiverName,
  81. phoneNumber: this.phoneNumber,
  82. gender: this.gender,
  83. location: this.location
  84. }
  85. this.addAddress(data)
  86. console.log('详细地址:', this.detailAddress);
  87. console.log('地址标签:', this.addressTag);
  88. console.log('收货人姓名:', this.receiverName);
  89. console.log('手机号码:', this.phoneNumber);
  90. console.log('性别:', this.gender);
  91. console.log('位置:', this.location);
  92. uni.navigateBack();
  93. },
  94. saveAndBack() {
  95. // 返回上一层页面
  96. }
  97. }
  98. }
  99. </script>
  100. <style lang="scss">
  101. .container {
  102. padding: 20rpx;
  103. background-color: #f7f7f7;
  104. }
  105. .chooseAddress {
  106. background-color: #fff;
  107. padding: 20rpx;
  108. border-radius: 10rpx;
  109. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  110. .choose-btn {
  111. display: flex;
  112. align-items: center;
  113. background-color: #ff6600;
  114. color: #fff;
  115. font-size: 28rpx;
  116. padding: 10rpx 20rpx;
  117. border-radius: 30rpx;
  118. .van-icon-location-o {
  119. margin-right: 10rpx;
  120. }
  121. }
  122. .location-info {
  123. margin-top: 20rpx;
  124. color: #666;
  125. font-size: 26rpx;
  126. text {
  127. display: block;
  128. }
  129. }
  130. }
  131. .info {
  132. margin-top: 20rpx;
  133. background-color: #fff;
  134. padding: 20rpx;
  135. border-radius: 10rpx;
  136. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  137. .detailAddress,
  138. .phoneNumber {
  139. input {
  140. border: 1px solid #eee;
  141. border-radius: 5rpx;
  142. padding: 10rpx;
  143. margin-bottom: 20rpx;
  144. }
  145. }
  146. .tag {
  147. display: flex;
  148. flex-wrap: wrap;
  149. margin-bottom: 20rpx;
  150. .tag-label {
  151. background-color: #f7f7f7;
  152. color: #666;
  153. padding: 5rpx 10rpx;
  154. margin-right: 10rpx;
  155. margin-bottom: 10rpx;
  156. border-radius: 5rpx;
  157. radio {
  158. transform: scale(0.8);
  159. }
  160. }
  161. }
  162. .person-info {
  163. display: flex;
  164. align-items: center;
  165. justify-content: space-between;
  166. margin-bottom: 20rpx;
  167. .person-input {
  168. flex: 1;
  169. border: 1px solid #eee;
  170. border-radius: 5rpx;
  171. padding: 10rpx;
  172. }
  173. .gender {
  174. display: flex;
  175. radio {
  176. transform: scale(0.8);
  177. }
  178. }
  179. }
  180. }
  181. .savaAddress {
  182. margin-top: 20rpx;
  183. .save-btn {
  184. background-color: #ff6600;
  185. color: #fff;
  186. font-size: 28rpx;
  187. padding: 10rpx 20rpx;
  188. border-radius: 30rpx;
  189. }
  190. }
  191. </style>