addressManage.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="content" >
  3. <view class="row b-b">
  4. <text class="tit">联系人</text>
  5. <input class="input" type="text" v-model="addressData.name" placeholder="收货人姓名" placeholder-class="placeholder" />
  6. </view>
  7. <view class="row b-b">
  8. <text class="tit">手机号</text>
  9. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b" @click="openChoose">
  12. <text class="tit">地址</text>
  13. <!-- <pickerAddress class="input" @change="onCityClick">{{addressDetail||'请选择地址'}}</pickerAddress> -->
  14. <!-- <input class="input" type="text" v-model="address" disabled placeholder="请选择地址" placeholder-class="placeholder" /> -->
  15. <view class="clamp">
  16. {{address}}
  17. </view>
  18. </view>
  19. <view class="row b-b">
  20. <text class="tit">门牌号</text>
  21. <input class="input" type="text" v-model="addressData.area" placeholder="楼号、门牌" placeholder-class="placeholder" />
  22. </view>
  23. <uni-list class="margin-t-20">
  24. <uni-list-item
  25. title="设为默认"
  26. :switch-checked="addressData.default"
  27. :show-switch="true"
  28. :show-arrow="false"
  29. switch-color="#5dbc7c"
  30. @switchChange="switchChange"
  31. ></uni-list-item>
  32. </uni-list>
  33. <uni-popup ref="popup" type="bottom">
  34. <choose-address ref="choose" @chooseEnd="chooseEnd" :lists="cityList"></choose-address>
  35. </uni-popup>
  36. <button class="add-btn" @click="confirm">提交</button>
  37. </view>
  38. </template>
  39. <script>
  40. import chooseAddress from '@/components/chooseAddress/index.vue'
  41. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  42. import { addressEdit,getCity } from '@/api/user.js';
  43. export default {
  44. components: {
  45. pickerAddress,
  46. chooseAddress
  47. },
  48. data() {
  49. return {
  50. addressDetail: '',
  51. cityList: [],
  52. addressData: {
  53. name: '',
  54. mobile: '',
  55. address: {
  56. province: '',
  57. city: '',
  58. district: ''
  59. },
  60. area: '',
  61. default: false
  62. }
  63. };
  64. },
  65. computed: {
  66. address() {
  67. return this.cityList.map(item => {return item.label}).join(' ')
  68. }
  69. },
  70. onLoad(option) {
  71. let title = '新增收货地址';
  72. if (option.type === 'edit') {
  73. title = '编辑收货地址';
  74. let data = JSON.parse(option.data);
  75. console.log(data);
  76. this.addressData = {
  77. name: data.real_name,
  78. mobile: data.phone,
  79. address: {
  80. province: data.province,
  81. city: data.city,
  82. district: data.district
  83. },
  84. area: data.detail,
  85. default: data.is_default == 1,
  86. id: data.id
  87. };
  88. this.addressDetail = data.province + data.city + data.district;
  89. }
  90. this.manageType = option.type;
  91. uni.setNavigationBarTitle({
  92. title
  93. });
  94. },
  95. methods: {
  96. openChoose() {
  97. this.$refs.popup.open()
  98. },
  99. chooseEnd(e) {
  100. this.$refs.popup.close()
  101. console.log(e)
  102. this.cityList = e
  103. },
  104. // 选中城市切换
  105. onCityClick({data}) {
  106. let address = this.addressData.address;
  107. address.province = data[0];
  108. address.city = data[1];
  109. address.district = data[2];
  110. this.addressDetail = data.join('');
  111. },
  112. //地图选择地址
  113. chooseLocation() {
  114. uni.chooseLocation({
  115. success: data => {
  116. console.log(data);
  117. this.addressData.addressName = data.name;
  118. this.addressData.address = data.name;
  119. }
  120. });
  121. },
  122. // 设置是否为默认地址
  123. switchChange(e) {
  124. this.addressData.default = e.value;
  125. },
  126. //提交
  127. confirm() {
  128. let obj = this;
  129. let data = this.addressData;
  130. if (!data.name) {
  131. this.$msg('请填写收货人姓名');
  132. return;
  133. }
  134. if (!data.address) {
  135. this.$msg('请在地图选择所在位置');
  136. return;
  137. }
  138. if (!data.area) {
  139. this.$msg('请填写门牌号信息');
  140. return;
  141. }
  142. //this.$prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  143. addressEdit({
  144. real_name: data.name,
  145. phone: data.mobile,
  146. address: {
  147. province: data.address.province,
  148. city: data.address.city,
  149. district: data.address.district
  150. },
  151. detail: data.area,
  152. is_default: data.default,
  153. id: data.id||"",
  154. type:1
  155. }).then(function(e) {
  156. obj.$prePage().refreshList();
  157. uni.showToast({
  158. title:'提交成功',
  159. duration:2000
  160. });
  161. setTimeout(function() {
  162. uni.navigateBack();
  163. }, 800);
  164. });
  165. }
  166. }
  167. };
  168. </script>
  169. <style lang="scss">
  170. page {
  171. background: $page-color-base;
  172. padding-top: 16rpx;
  173. }
  174. .row {
  175. display: flex;
  176. align-items: center;
  177. position: relative;
  178. padding: 0 30rpx;
  179. height: 110rpx;
  180. background: #fff;
  181. .tit {
  182. flex-shrink: 0;
  183. width: 120rpx;
  184. font-size: 30rpx;
  185. color: $font-color-dark;
  186. }
  187. .input {
  188. flex: 1;
  189. font-size: 30rpx;
  190. color: $font-color-dark;
  191. }
  192. .iconlocation {
  193. font-size: 36rpx;
  194. color: $font-color-light;
  195. }
  196. }
  197. .default-row {
  198. margin-top: 16rpx;
  199. .tit {
  200. flex: 1;
  201. }
  202. switch {
  203. transform: translateX(16rpx) scale(0.9);
  204. }
  205. }
  206. .add-btn {
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. width: 690rpx;
  211. height: 80rpx;
  212. margin: 60rpx auto;
  213. font-size: $font-lg;
  214. color: #fff;
  215. background-color: $base-color;
  216. border-radius: 10rpx;
  217. // box-shadow: 1px 2px 5px rgba(219, 63, 96, 0.4);
  218. }
  219. .alert-box {
  220. background-color: #ffffff;
  221. }
  222. </style>