address.vue 7.0 KB

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