address.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <view v-for="(item,index) in address" :key="index" @click.stop="selectAddress(item)" class="address-item" >
  5. <view class="info" >
  6. <view class="title">
  7. <view v-if="item.isDefault == 1" class="tag">默认</view>
  8. {{item.province}}{{item.city}}{{item.district}}{{item.detail}}
  9. </view>
  10. <view class="name-phone">
  11. <text class="text">{{item.realName}}</text>
  12. <text class="text">{{$parsePhone(item.phone)}}</text>
  13. </view>
  14. </view>
  15. <view class="operat-box">
  16. <image src="../../static/images/del.png" mode="" @click.stop="delAddress(item)"></image>
  17. <image src="../../static/images/edit.png" mode="" @click.stop="editAddress(item)"></image>
  18. </view>
  19. </view>
  20. <view v-if="address.length == 0" class="no-data-box" @click="getAddressList()">
  21. <image src="https://zkzh-2025.oss-cn-beijing.aliyuncs.com/appimgs/cf4a86b913a04341bb44e34bb4d37aa2.png" mode="aspectFit"></image>
  22. <view class="empty-title">暂无数据</view>
  23. </view>
  24. </view>
  25. <view class="btn-box">
  26. <view class="sub-btn flex-1" @click="addAddress()">新建收货地址</view>
  27. <view class="icon-btn" style="width: 15%;" @click="openShare">
  28. <image src="/static/images/icon_wx.png" mode="aspectFill"></image>
  29. <text>分享</text>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. import {getAddressList,delAddress} from '@/api/userAddress'
  36. export default {
  37. data() {
  38. return {
  39. address:[],
  40. }
  41. },
  42. onLoad() {
  43. var that=this;
  44. uni.$on('refreshAddress', () => {
  45. that.getAddressList()
  46. })
  47. },
  48. onShow() {
  49. this.getAddressList()
  50. },
  51. methods: {
  52. selectAddress(item){
  53. // 获取当前所有页面栈
  54. const pages = getCurrentPages();
  55. if (pages.length >= 2) {
  56. const prevPage = pages[pages.length - 2];
  57. if (prevPage.route === 'pages_mall/index' || prevPage.route === 'pages/user/index') {
  58. uni.navigateTo({
  59. url: './addEditAddress?type=edit&addressId='+item.addressId
  60. })
  61. }else{
  62. uni.$emit('updateAddress',item);
  63. uni.navigateBack({
  64. delta: 1
  65. })
  66. }
  67. }else{
  68. uni.navigateTo({
  69. url: './addEditAddress?type=edit&addressId='+item.addressId
  70. })
  71. }
  72. },
  73. editAddress(item){
  74. uni.navigateTo({
  75. url: './addEditAddress?type=edit&addressId='+item.addressId
  76. })
  77. },
  78. delAddress(item){
  79. uni.showModal({
  80. title:"提示",
  81. content:"确认删除此地址吗?",
  82. showCancel:true,
  83. cancelText:'取消',
  84. confirmText:'确定',
  85. success:res=>{
  86. if(res.confirm){
  87. // 用户点击确定
  88. var data={addressId:item.addressId}
  89. delAddress(data).then(
  90. res => {
  91. if(res.code==200){
  92. uni.showToast({
  93. icon:'success',
  94. title: "操作成功",
  95. });
  96. this.getAddressList()
  97. }else{
  98. uni.showToast({
  99. icon:'none',
  100. title: "请求失败",
  101. });
  102. }
  103. },
  104. rej => {}
  105. );
  106. }else{
  107. // 否则点击了取消
  108. }
  109. }
  110. })
  111. },
  112. getAddressList(){
  113. getAddressList().then(
  114. res => {
  115. if(res.code==200){
  116. this.address=res.data;
  117. }else{
  118. uni.showToast({
  119. icon:'none',
  120. title: "请求失败",
  121. });
  122. }
  123. },
  124. rej => {}
  125. );
  126. },
  127. // 新建地址
  128. addAddress() {
  129. uni.navigateTo({
  130. url: './addEditAddress?type=add'
  131. })
  132. },
  133. openShare() {
  134. //#ifdef H5
  135. uni.showToast({
  136. title: '请使用APP操作',
  137. icon: 'none'
  138. });
  139. //#endif
  140. //#ifdef APP-PLUS
  141. uni.share({
  142. provider: "weixin",
  143. scene: 'WXSceneSession',
  144. type: 5,
  145. imageUrl: 'https://bjzmky-1323137866.cos.ap-chongqing.myqcloud.com/app/app-address.jpg', //分享封面图片
  146. title: '乐享韶华-邀请你填写地址,下单更方便', // 分享标题
  147. miniProgram: {
  148. id: getApp().globalData.miniprogamId,
  149. path: '/pages_user/user/address',
  150. type: 0, //0-正式版; 1-测试版; 2-体验版。 默认值为0。
  151. webUrl: "http://uniapp.dcloud.io"
  152. },
  153. success: function(res) {
  154. uni.showToast({
  155. title: "分享成功",
  156. icon: 'none'
  157. });
  158. },
  159. fail: function(err) {
  160. // 此处是调起微信分享失败的回调
  161. },
  162. complete: (e) => {
  163. console.log("WXSceneSession", e)
  164. }
  165. });
  166. //#endif
  167. }
  168. }
  169. }
  170. </script>
  171. <style lang="scss">
  172. page{
  173. height: 100%;
  174. }
  175. .content{
  176. height: 100%;
  177. display: flex;
  178. flex-direction: column;
  179. justify-content: space-between;
  180. .inner{
  181. flex: 1;
  182. padding: 20upx 20upx 160upx;
  183. .top{
  184. padding: 0upx 20upx 20upx;
  185. text-align: right;
  186. .del{
  187. font-size: 28upx;
  188. font-family: PingFang SC;
  189. color: #999999;
  190. }
  191. }
  192. .address-item{
  193. background: #FFFFFF;
  194. border-radius: 16upx;
  195. padding: 46upx 40upx 50upx 24upx;
  196. display: flex;
  197. align-items: center;
  198. justify-content: space-between;
  199. margin-bottom: 20upx;
  200. .info{
  201. width: 75%;
  202. .title{
  203. font-size: 30upx;
  204. font-family: PingFang SC;
  205. font-weight: bold;
  206. color: #111111;
  207. line-height: 42upx;
  208. word-break: break-all;
  209. .tag{
  210. padding: 0 6upx;
  211. height: 32upx;
  212. line-height: 32upx;
  213. font-size: 22upx;
  214. font-family: PingFang SC;
  215. font-weight: 500;
  216. color: #FFFFFF;
  217. background: #FF233C;
  218. border-radius: 4upx;
  219. float: left;
  220. margin-right: 10upx;
  221. margin-top: 5upx;
  222. }
  223. }
  224. .name-phone{
  225. margin-top: 30upx;
  226. display: flex;
  227. align-items: center;
  228. .text{
  229. font-size: 26upx;
  230. font-family: PingFang SC;
  231. font-weight: 500;
  232. color: #999999;
  233. margin-right: 22upx;
  234. &:last-child{
  235. margin-right: 0;
  236. }
  237. }
  238. }
  239. }
  240. .operat-box{
  241. display: flex;
  242. align-items: center;
  243. image{
  244. padding: 15rpx;
  245. width: 30upx;
  246. height: 30upx;
  247. margin-left: 10upx;
  248. &:first-child{
  249. margin-left: 0;
  250. }
  251. }
  252. }
  253. }
  254. }
  255. .btn-box{
  256. z-index: 9999;
  257. width: 100%;
  258. padding: 30upx;
  259. position: fixed;
  260. bottom: 0;
  261. left: 0;
  262. box-sizing: border-box;
  263. background: #FFFFFF;
  264. display: flex;
  265. align-items: center;
  266. justify-content: space-between;
  267. .sub-btn{
  268. height: 88upx;
  269. line-height: 88upx;
  270. text-align: center;
  271. font-size: 30upx;
  272. font-family: PingFang SC;
  273. font-weight: bold;
  274. color: #FFFFFF;
  275. background: #FF233C;
  276. border-radius: 44upx;
  277. }
  278. }
  279. }
  280. .icon-btn {
  281. display: flex;
  282. flex-direction: column;
  283. align-items: center;
  284. justify-content: center;
  285. image {
  286. width: 55rpx;
  287. height: 55rpx;
  288. }
  289. text {
  290. font-size: 26rpx;
  291. color: #222222;
  292. }
  293. }
  294. </style>