indexss.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <view>
  3. <view class="hedtop" @click="openMap">
  4. <view class="cs">
  5. {{city}}
  6. <image src="../static/up.png" style="width:20rpx;height: 17rpx;margin-left: 5rpx;"></image>
  7. </view>
  8. <view class="seach">
  9. <u-search v-model="keyword" placeholder="搜索地址" shape="square" :clearabled="false" :animation="true"
  10. bg-color="#F5F5F5" height="75"></u-search>
  11. </view>
  12. </view>
  13. <view class="addlist">
  14. <view class="box" v-for="(item,index) in list" :key="index" :class="listIndex==index?'active':''"
  15. @click="changetan(index,item)">
  16. <view>
  17. <view>{{item.address}}</view>
  18. <view class="add">{{item.addressDetail}}</view>
  19. </view>
  20. <view v-if="listIndex==index">
  21. <image src="../static/duigou.png" style="width: 40rpx;height: 34rpx;"></image>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="tabber">
  26. <!-- <view class="btn" @click="goadd()">添加地址</view> -->
  27. <view class="btn" @click="openMap()">添加地址</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. city: '',
  36. keyword: '',
  37. list: [],
  38. listIndex: '-1',
  39. index:0
  40. }
  41. },
  42. onLoad(option) {
  43. if(option.index){
  44. this.index = option.index
  45. }
  46. this.getAddlist()
  47. },
  48. onShow() {
  49. this.city = uni.getStorageSync('city')
  50. },
  51. methods: {
  52. openMap() { //打开地图选择位置
  53. let that = this
  54. uni.chooseLocation({
  55. success: function(res) {
  56. console.log('位置名称:' + res.name);
  57. console.log('详细地址:' + res.address);
  58. console.log('纬度:' + res.latitude);
  59. console.log('经度:' + res.longitude);
  60. let data = {
  61. address: res.name, //地址
  62. addressDetail: res.address,
  63. addressLongitude: res.longitude, //地址经度
  64. addressLatitude: res.latitude, //地址维度
  65. addressId: '',
  66. addressDefault: '',
  67. }
  68. that.$Request.postJson('/app/indent/addUserAddress', data).then(res => {
  69. if (res.code === 0) {
  70. that.getAddlist()
  71. }
  72. });
  73. }
  74. });
  75. },
  76. getAddlist() {
  77. this.$Request.getT('/app/indent/findUserAddress').then(res => {
  78. if (res.code === 0) {
  79. this.list = res.data
  80. }
  81. });
  82. },
  83. changetan(index, item) {
  84. if(this.index==1){
  85. uni.setStorageSync('addressId', item.addressId)
  86. this.listIndex = index
  87. uni.navigateBack()
  88. }else if(this.index==2){
  89. uni.setStorageSync('addressIds', item.addressId)
  90. this.listIndex = index
  91. uni.navigateBack()
  92. }
  93. }
  94. }
  95. }
  96. </script>
  97. <style lang="less">
  98. page {
  99. background: #FFFFFF;
  100. }
  101. .hedtop {
  102. display: flex;
  103. align-items: center;
  104. padding: 0 30rpx;
  105. position: fixed;
  106. /* #ifdef H5 */
  107. top: 85rpx;
  108. /* #endif */
  109. /* #ifndef H5 */
  110. top: 0rpx;
  111. /* #endif */
  112. left: 0;
  113. right: 0;
  114. z-index: 99;
  115. background: #FFFFFF;
  116. .cs {
  117. width: 20%;
  118. }
  119. .seach {
  120. width: 80%;
  121. }
  122. }
  123. .tabber {
  124. position: fixed;
  125. bottom: 0rpx;
  126. left: 0;
  127. right: 0;
  128. // background: #FFFFFF;
  129. }
  130. .btn {
  131. background: #346EF6;
  132. border-radius: 24rpx;
  133. margin: 32rpx;
  134. padding: 20rpx 0;
  135. text-align: center;
  136. color: #FFFFFF;
  137. }
  138. .addlist {
  139. /* #ifdef H5 */
  140. margin-top: 120rpx;
  141. /* #endif */
  142. /* #ifndef H5 */
  143. margin-top: 120rpx;
  144. /* #endif */
  145. .box {
  146. // width: 100%;
  147. margin: 20rpx 30rpx;
  148. background: #F7F7F7;
  149. border-radius: 8rpx;
  150. padding: 30rpx;
  151. font-size: 28rpx;
  152. font-family: PingFang SC;
  153. font-weight: bold;
  154. color: #333333;
  155. display: flex;
  156. justify-content: space-between;
  157. align-items: center;
  158. .add {
  159. font-size: 24rpx;
  160. font-family: PingFang SC;
  161. font-weight: 500;
  162. color: #999999;
  163. margin-top: 6rpx;
  164. }
  165. }
  166. .active {
  167. border: 2rpx solid #45AEFF;
  168. border-radius: 8rpx;
  169. background: #FFFFFF;
  170. }
  171. }
  172. </style>