addressManage.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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">
  12. <text class="tit">所在地区</text>
  13. <pickerAddress class="input" style="text-align: right;" @change="onCityClick">{{addressDetail||'请选择地址'}}</pickerAddress>
  14. <text class="iconfont iconenter"></text>
  15. </view>
  16. <!-- <view class="row b-b">
  17. <text class="tit">街道</text>
  18. <input class="input" type="text" style="text-align: right;" v-model="addressData.area" placeholder="所在街道" placeholder-class="placeholder" />
  19. <text class="iconfont iconenter"></text>
  20. </view> -->
  21. <view class="row b-b">
  22. <input class="input" type="text" v-model="addressData.area" placeholder="详细地址" placeholder-class="placeholder" />
  23. </view>
  24. <uni-list class="margin-t-20">
  25. <uni-list-item
  26. title="设为默认地址"
  27. :switch-checked="addressData.default"
  28. :show-switch="true"
  29. :show-arrow="false"
  30. switch-color="#45A7EB"
  31. @switchChange="switchChange"
  32. ></uni-list-item>
  33. </uni-list>
  34. <!-- <view class="delete b-b" >
  35. 删除地址
  36. </view> -->
  37. <button class="add-btn" @click="confirm">确认添加</button>
  38. </view>
  39. </template>
  40. <script>
  41. import uniList from '@/components/uni-list/uni-list.vue';
  42. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  43. import uniPopup from '@/components/uni-popup/uni-popup.vue';
  44. import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';
  45. import { addressEdit } from '@/api/address.js';
  46. export default {
  47. components: {
  48. uniList,
  49. uniListItem,
  50. pickerAddress,
  51. uniPopup
  52. },
  53. data() {
  54. return {
  55. addressDetail: '',
  56. addressData: {
  57. name: '',
  58. mobile: '',
  59. address: {
  60. province: '',
  61. city: '',
  62. district: '',
  63. detail: '',
  64. },
  65. area: '',
  66. default: false
  67. }
  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. // 显示隐藏弹窗
  97. // 选中城市切换
  98. onCityClick({data}) {
  99. let address = this.addressData.address;
  100. address.province = data[0];
  101. address.city = data[1];
  102. address.district = data[2];
  103. this.addressDetail = data.join('');
  104. },
  105. //地图选择地址
  106. chooseLocation() {
  107. uni.chooseLocation({
  108. success: data => {
  109. console.log(data);
  110. this.addressData.addressName = data.name;
  111. this.addressData.address = data.name;
  112. }
  113. });
  114. },
  115. // 设置是否为默认地址
  116. switchChange(e) {
  117. this.addressData.default = e.value;
  118. },
  119. //提交
  120. confirm() {
  121. let obj = this;
  122. let data = this.addressData;
  123. if (!data.name) {
  124. this.$api.msg('请填写收货人姓名');
  125. return;
  126. }
  127. if (data.mobile.length!=11) {
  128. this.$api.msg('请输入正确的手机号码');
  129. return;
  130. }
  131. if (!data.address) {
  132. this.$api.msg('请在地图选择所在位置');
  133. return;
  134. }
  135. if (!data.area) {
  136. this.$api.msg('请填写门牌号信息');
  137. return;
  138. }
  139. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  140. addressEdit({
  141. real_name: data.name,
  142. phone: data.mobile,
  143. address: {
  144. province: data.address.province,
  145. city: data.address.city,
  146. district: data.address.district
  147. },
  148. detail: data.area,
  149. is_default: data.default,
  150. id: data.id||"",
  151. type:1
  152. }).then(function(e) {
  153. // obj.$api.prePage().refreshList();
  154. uni.showToast({
  155. title:'提交成功',
  156. duration:2000
  157. });
  158. setTimeout(function() {
  159. uni.navigateBack();
  160. }, 800);
  161. });
  162. }
  163. }
  164. };
  165. </script>
  166. <style lang="scss">
  167. page {
  168. background: $page-color-base;
  169. padding-top: 16rpx;
  170. }
  171. .row {
  172. display: flex;
  173. align-items: center;
  174. position: relative;
  175. padding: 0 30rpx;
  176. height: 110rpx;
  177. background: #fff;
  178. .tit {
  179. flex-shrink: 0;
  180. width: 120rpx;
  181. font-size: 30rpx;
  182. color: $font-color-dark;
  183. margin-right: 10rpx;
  184. }
  185. .input {
  186. flex: 1;
  187. font-size: 30rpx;
  188. color: $font-color-dark;
  189. }
  190. .iconenter {
  191. font-size: 36rpx;
  192. color: #cccccc;
  193. }
  194. }
  195. .default-row {
  196. margin-top: 16rpx;
  197. .tit {
  198. flex: 1;
  199. }
  200. switch {
  201. transform: translateX(16rpx) scale(0.9);
  202. }
  203. }
  204. .delete {
  205. display: flex;
  206. align-items: center;
  207. position: relative;
  208. padding: 0 30rpx;
  209. height: 110rpx;
  210. background: #fff;
  211. margin-top: 28rpx;
  212. font-size: 30rpx;
  213. font-weight:500;
  214. color:rgba(250,39,64,1);
  215. }
  216. .add-btn {
  217. display: flex;
  218. align-items: center;
  219. justify-content: center;
  220. width: 560rpx;
  221. height: 80rpx;
  222. margin: 60rpx auto;
  223. font-size: $font-lg;
  224. color: #fff;
  225. background: linear-gradient(0deg, #2E58FF, #32C6FF);
  226. border-radius:40px;
  227. }
  228. .alert-box {
  229. background-color: #ffffff;
  230. }
  231. </style>