addressManage.vue 5.5 KB

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