list.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="app-container">
  3. <view class="congxindingwei">
  4. <view class="header-container">
  5. <view class="left">
  6. <image src="@/static/home/location.png"></image>
  7. <text>{{websitData.address}}</text>
  8. </view>
  9. <view class="right" style="min-width: 120rpx;" @tap="getLocation">
  10. <view class="item" style="min-width: 200rpx;">
  11. 重新定位
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. <view class="wodeshouhuodiz">我的收货地址</view>
  17. <view class="list-container">
  18. <block v-for="(item, index) in addressList" :key="index">
  19. <view class="item" @tap="chooseAddress(item)">
  20. <view class="top">
  21. <view class="left">
  22. <view class="name">{{ item.name }}</view>
  23. <view class="phone">{{ item.phone }}</view>
  24. <view class="default" v-if="item.defaultAddr">默认</view>
  25. </view>
  26. </view>
  27. <view class="bottom">{{ item.province }}{{ item.city }}{{ item.area }}{{ item.street
  28. }}{{ item.address }}{{ item.houseNo }}</view>
  29. </view>
  30. </block>
  31. </view>
  32. <no-data v-if="!addressList.length" :showText="'暂无收货地址'"></no-data>
  33. </view>
  34. </template>
  35. <script>
  36. import {
  37. mapState
  38. } from 'vuex';
  39. import EventBus from '@/utils/eventbus.js';
  40. import {
  41. getArea
  42. } from '@/utils/utils.js';
  43. export default {
  44. data() {
  45. return {
  46. addressList: [], // 收货地址列表
  47. isChoose: false, // 是否进来选择地址
  48. };
  49. },
  50. computed: {
  51. ...mapState(['userInfo', 'isLogin', 'userId', 'websitData']),
  52. },
  53. onShow() {
  54. this.getAddressList();
  55. },
  56. onLoad({
  57. isChoose
  58. }) {
  59. this.isChoose = isChoose;
  60. },
  61. methods: {
  62. // 获取收货地址列表
  63. getAddressList() {
  64. this.$axios({
  65. url: '/user/address/list',
  66. method: 'get',
  67. params: {
  68. pageNum: 1,
  69. pageSize: 100,
  70. userId: this.userId,
  71. },
  72. }).then((res) => {
  73. this.addressList = res.data.records;
  74. });
  75. },
  76. getLocation() {
  77. let that = this;
  78. uni.chooseLocation({
  79. success: (res) => {
  80. this.$axios({
  81. url: '/user/userWebsit',
  82. method: 'post',
  83. params: {
  84. lat: res.latitude,
  85. lng: res.longitude,
  86. },
  87. }).then((res) => {
  88. if (res?.data) {
  89. this.$store.commit('changeWebsitObj', res?.data);
  90. uni.setStorageSync('websitData', res?.data);
  91. uni.setStorageSync("websitIdSj", res?.data.websitId);
  92. uni.reLaunch({
  93. url: "/pages/index/index"
  94. })
  95. } else {
  96. uni.showModal({
  97. title: '提示',
  98. content: '当前定位附件暂无门店,请重新选择定位地址!',
  99. success: (res) => {
  100. if (res.confirm) {
  101. this.getLocation()
  102. } else if (res.cancel) {
  103. console.log('用户点击取消');
  104. }
  105. }
  106. });
  107. }
  108. });
  109. },
  110. fail: (res) => {
  111. uni.getSetting({
  112. success: function(res) {
  113. if (!res.authSetting['scope.userLocation']) {
  114. uni.showModal({
  115. title: '是否授权当前位置',
  116. content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
  117. success(tip) {
  118. if (tip.confirm) {
  119. uni.openSetting({
  120. success: function(data) {
  121. if (data.authSetting[
  122. "scope.userLocation"
  123. ] === true) {
  124. that.$successToast(
  125. '授权成功');
  126. setTimeout(() => {
  127. that
  128. .getLocation();
  129. }, 1000)
  130. }
  131. }
  132. })
  133. }
  134. }
  135. })
  136. }
  137. }
  138. })
  139. }
  140. });
  141. },
  142. // 选择地址
  143. chooseAddress(item) {
  144. this.$axios({
  145. url: '/user/userWebsit',
  146. method: 'post',
  147. params: {
  148. lat: item.lat,
  149. lng: item.lng,
  150. },
  151. }).then((res) => {
  152. if (res?.data) {
  153. this.$store.commit('changeWebsitObj', res?.data);
  154. uni.setStorageSync('websitData', res?.data);
  155. uni.setStorageSync("websitIdSj", res?.data.websitId);
  156. uni.reLaunch({
  157. url: "/pages/index/index"
  158. })
  159. } else {
  160. uni.showModal({
  161. title: '提示',
  162. content: '当前收货地址暂无门店,请重新选择收货地址!',
  163. success: (res) => {
  164. if (res.confirm) {} else if (res.cancel) {}
  165. }
  166. });
  167. }
  168. });
  169. },
  170. },
  171. };
  172. </script>
  173. <style lang="scss">
  174. .wodeshouhuodiz {
  175. font-size: 32rpx;
  176. font-weight: bold;
  177. box-sizing: border-box;
  178. padding: 30rpx 16rpx;
  179. }
  180. .congxindingwei {}
  181. .header-container {
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. padding: 0 10rpx 10rpx;
  186. .left {
  187. display: flex;
  188. align-items: center;
  189. image {
  190. width: 48rpx;
  191. height: 48rpx;
  192. }
  193. }
  194. .right {
  195. display: flex;
  196. .item {
  197. margin-left: 40rpx;
  198. position: relative;
  199. color: blue;
  200. }
  201. }
  202. }
  203. .app-container {
  204. background: #f4f2f2;
  205. padding: 20rpx;
  206. padding-bottom: 250rpx;
  207. box-sizing: border-box;
  208. }
  209. .list-container {
  210. .item {
  211. background: #ffffff;
  212. border-radius: 20rpx;
  213. margin-bottom: 20rpx;
  214. padding: 20rpx;
  215. .top {
  216. display: flex;
  217. justify-content: space-between;
  218. align-items: center;
  219. .left {
  220. display: flex;
  221. align-items: flex-end;
  222. .name {
  223. font-size: 32rpx;
  224. color: #333333;
  225. line-height: 32rpx;
  226. }
  227. .phone {
  228. font-size: 28rpx;
  229. color: #666666;
  230. margin-left: 20rpx;
  231. line-height: 28rpx;
  232. }
  233. .default {
  234. font-size: 22rpx;
  235. color: #ffffff;
  236. background: #fe781f;
  237. padding: 6rpx 8rpx;
  238. line-height: 20rpx;
  239. margin-left: 20rpx;
  240. }
  241. }
  242. .right {
  243. width: 32rpx;
  244. height: 32rpx;
  245. }
  246. }
  247. .bottom {
  248. font-size: 28rpx;
  249. color: #333333;
  250. line-height: 38rpx;
  251. margin-top: 20rpx;
  252. }
  253. }
  254. }
  255. .bottom-container {
  256. position: fixed;
  257. bottom: 0;
  258. left: 0;
  259. width: 100%;
  260. box-sizing: border-box;
  261. padding: 20rpx 20rpx 60rpx;
  262. background: #f4f2f2;
  263. .button {
  264. width: 100%;
  265. height: 72rpx;
  266. border-radius: 72rpx;
  267. text-align: center;
  268. line-height: 72rpx;
  269. &.red {
  270. background: #ff3f42;
  271. color: #ffffff;
  272. margin-bottom: 20rpx;
  273. }
  274. &.white {
  275. background: #ffffff;
  276. color: #333333;
  277. }
  278. }
  279. }
  280. </style>