addressManage.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <view class="content">
  3. <hx-navbar title="收货地址" backTabbarUrl="/pages/user/center/center" :backgroundColor="[241,241,241]"></hx-navbar>
  4. <view class="bb15">
  5. </view>
  6. <view class="list-box">
  7. <view class="row b-b">
  8. <text class="tit">联系人</text>
  9. <input class="input" type="text" v-model="addressData.name" placeholder="收货人姓名" placeholder-class="placeholder" />
  10. </view>
  11. <view class="row b-b">
  12. <text class="tit">手机号</text>
  13. <input class="input" type="number" v-model="addressData.mobile" placeholder="收货人手机号码" placeholder-class="placeholder" />
  14. </view>
  15. <view class="row b-b">
  16. <text class="tit">地址</text>
  17. <text @click="chooseLocation" class="input">
  18. {{addressData.addressName}}
  19. </text>
  20. <text class="hxicon-locationfill"></text>
  21. </view>
  22. <view class="row b-b">
  23. <text class="tit">门牌号</text>
  24. <input class="input" type="text" v-model="addressData.area" placeholder="楼号、门牌" placeholder-class="placeholder" />
  25. </view>
  26. <view class="row default-row">
  27. <text class="tit">设为默认</text>
  28. <switch :checked="addressData.defaule" color="#ffc107" @change="switchChange" />
  29. </view>
  30. </view>
  31. <view class="add-btn" @click="confirm">
  32. <text>提交</text>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. export default {
  38. data() {
  39. return {
  40. addressData: {
  41. name: '',
  42. mobile: '',
  43. addressName: '在地图选择',
  44. address: '',
  45. area: '',
  46. default: false
  47. }
  48. }
  49. },
  50. onLoad(option){
  51. let title = '新增收货地址';
  52. if(option.type==='edit'){
  53. title = '编辑收货地址'
  54. this.addressData = JSON.parse(option.data)
  55. }
  56. this.manageType = option.type;
  57. uni.setNavigationBarTitle({
  58. title
  59. })
  60. },
  61. methods: {
  62. switchChange(e){
  63. this.addressData.default = e.detail;
  64. },
  65. //地图选择地址
  66. chooseLocation(){
  67. uni.chooseLocation({
  68. success: (data)=> {
  69. this.addressData.addressName = data.name;
  70. this.addressData.address = data.name;
  71. }
  72. })
  73. },
  74. //提交
  75. confirm(){
  76. let data = this.addressData;
  77. if(!data.name){
  78. this.$api.msg('请填写收货人姓名');
  79. return;
  80. }
  81. if(!/(^1[3|4|5|7|8][0-9]{9}$)/.test(data.mobile)){
  82. this.$api.msg('请输入正确的手机号码');
  83. return;
  84. }
  85. if(!data.address){
  86. this.$api.msg('请在地图选择所在位置');
  87. return;
  88. }
  89. if(!data.area){
  90. this.$api.msg('请填写门牌号信息');
  91. return;
  92. }
  93. //this.$api.prePage()获取上一页实例,可直接调用上页所有数据和方法,在App.vue定义
  94. this.$api.prePage().refreshList(data, this.manageType);
  95. this.$api.msg(`地址${this.manageType=='edit' ? '修改': '添加'}成功`);
  96. setTimeout(()=>{
  97. uni.navigateBack()
  98. }, 800)
  99. },
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. .bb15{
  105. background: #f1f1f1;
  106. padding-top: 40upx;
  107. }
  108. .list-box{
  109. display: flex;
  110. flex-direction: column;
  111. background-color: #fff;
  112. border-radius: 10px;
  113. overflow: hidden;
  114. margin: 0 15px;
  115. }
  116. .row{
  117. display: flex;
  118. align-items: center;
  119. position: relative;
  120. padding:0 30upx;
  121. height: 110upx;
  122. background: #fff;
  123. .tit{
  124. flex-shrink: 0;
  125. width: 120upx;
  126. font-size: 30upx;
  127. color: $font-color-dark;
  128. }
  129. .input{
  130. flex: 1;
  131. font-size: 30upx;
  132. color: $font-color-dark;
  133. }
  134. .icon-locationfill{
  135. font-size: 36upx;
  136. color: $font-color-light;
  137. }
  138. }
  139. .default-row{
  140. margin-top: 16upx;
  141. .tit{
  142. flex: 1;
  143. }
  144. switch{
  145. transform: translateX(16upx) scale(.9);
  146. }
  147. }
  148. .add-btn{
  149. position: fixed;
  150. display: flex;
  151. flex-direction: row;
  152. justify-content: center;
  153. align-items: center;
  154. border-radius: 10px;
  155. overflow: hidden;
  156. bottom: 15px;
  157. left: 15px;
  158. right: 15px;
  159. height: 45px;
  160. font-size: 16px;
  161. font-weight: bold;
  162. color: #333;
  163. background: linear-gradient(45deg, #ffd900, #ffc107);
  164. }
  165. </style>