addAddress.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. console.log("1324567989");
  65. uni.chooseLocation({
  66. success: (res) => {
  67. this.location = res;
  68. console.log('cg');
  69. },
  70. fail(e) {
  71. console.log("sb",e);
  72. }
  73. });
  74. },
  75. changeAddressTag(e) {
  76. this.addressTag = e.detail.value;
  77. },
  78. changeGender(e) {
  79. this.gender = e.detail.value;
  80. },
  81. saveAddress() {
  82. let data={
  83. detailAddress: this.detailAddress,
  84. addressTag: this.addressTag,
  85. receiverName: this.receiverName,
  86. phoneNumber: this.phoneNumber,
  87. gender: this.gender,
  88. location: this.location
  89. }
  90. this.addAddress(data)
  91. console.log('详细地址:', this.detailAddress);
  92. console.log('地址标签:', this.addressTag);
  93. console.log('收货人姓名:', this.receiverName);
  94. console.log('手机号码:', this.phoneNumber);
  95. console.log('性别:', this.gender);
  96. console.log('位置:', this.location);
  97. uni.navigateBack();
  98. },
  99. saveAndBack() {
  100. // 返回上一层页面
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss">
  106. .container {
  107. padding: 20rpx;
  108. background-color: #f7f7f7;
  109. }
  110. .chooseAddress {
  111. background-color: #fff;
  112. padding: 20rpx;
  113. border-radius: 10rpx;
  114. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  115. .choose-btn {
  116. display: flex;
  117. align-items: center;
  118. background-color: #ff6600;
  119. color: #fff;
  120. font-size: 28rpx;
  121. padding: 10rpx 20rpx;
  122. border-radius: 30rpx;
  123. .van-icon-location-o {
  124. margin-right: 10rpx;
  125. }
  126. }
  127. .location-info {
  128. margin-top: 20rpx;
  129. color: #666;
  130. font-size: 26rpx;
  131. text {
  132. display: block;
  133. }
  134. }
  135. }
  136. .info {
  137. margin-top: 20rpx;
  138. background-color: #fff;
  139. padding: 20rpx;
  140. border-radius: 10rpx;
  141. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
  142. .detailAddress,
  143. .phoneNumber {
  144. input {
  145. border: 1px solid #eee;
  146. border-radius: 5rpx;
  147. padding: 10rpx;
  148. margin-bottom: 20rpx;
  149. }
  150. }
  151. .tag {
  152. display: flex;
  153. flex-wrap: wrap;
  154. margin-bottom: 20rpx;
  155. .tag-label {
  156. background-color: #f7f7f7;
  157. color: #666;
  158. padding: 5rpx 10rpx;
  159. margin-right: 10rpx;
  160. margin-bottom: 10rpx;
  161. border-radius: 5rpx;
  162. radio {
  163. transform: scale(0.8);
  164. }
  165. }
  166. }
  167. .person-info {
  168. display: flex;
  169. align-items: center;
  170. justify-content: space-between;
  171. margin-bottom: 20rpx;
  172. .person-input {
  173. flex: 1;
  174. border: 1px solid #eee;
  175. border-radius: 5rpx;
  176. padding: 10rpx;
  177. }
  178. .gender {
  179. display: flex;
  180. radio {
  181. transform: scale(0.8);
  182. }
  183. }
  184. }
  185. }
  186. .savaAddress {
  187. margin-top: 20rpx;
  188. .save-btn {
  189. background-color: #ff6600;
  190. color: #fff;
  191. font-size: 28rpx;
  192. padding: 10rpx 20rpx;
  193. border-radius: 30rpx;
  194. }
  195. }
  196. </style>