address.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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://cos.his.cdwjyyh.com/fs/20240423/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" @click="addAddress()">新建收货地址</view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. import {getAddressList,delAddress} from '@/api/userAddress'
  32. export default {
  33. data() {
  34. return {
  35. address:[],
  36. }
  37. },
  38. onLoad() {
  39. var that=this;
  40. uni.$on('refreshAddress', () => {
  41. that.getAddressList()
  42. })
  43. },
  44. onShow() {
  45. this.getAddressList()
  46. },
  47. methods: {
  48. selectAddress(item){
  49. uni.$emit('updateAddress',item);
  50. uni.navigateBack({
  51. delta: 1
  52. })
  53. },
  54. editAddress(item){
  55. uni.navigateTo({
  56. url: './addEditAddress?type=edit&addressId='+item.addressId
  57. })
  58. },
  59. delAddress(item){
  60. uni.showModal({
  61. title:"提示",
  62. content:"确认删除此地址吗?",
  63. showCancel:true,
  64. cancelText:'取消',
  65. confirmText:'确定',
  66. success:res=>{
  67. if(res.confirm){
  68. // 用户点击确定
  69. var data={addressId:item.addressId}
  70. delAddress(data).then(
  71. res => {
  72. if(res.code==200){
  73. uni.showToast({
  74. icon:'success',
  75. title: "操作成功",
  76. });
  77. this.getAddressList()
  78. }else{
  79. uni.showToast({
  80. icon:'none',
  81. title: "请求失败",
  82. });
  83. }
  84. },
  85. rej => {}
  86. );
  87. }else{
  88. // 否则点击了取消
  89. }
  90. }
  91. })
  92. },
  93. getAddressList(){
  94. getAddressList().then(
  95. res => {
  96. if(res.code==200){
  97. this.address=res.data;
  98. }else{
  99. uni.showToast({
  100. icon:'none',
  101. title: "请求失败",
  102. });
  103. }
  104. },
  105. rej => {}
  106. );
  107. },
  108. // 新建地址
  109. addAddress() {
  110. uni.navigateTo({
  111. url: './addEditAddress?type=add'
  112. })
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss">
  118. page{
  119. height: 100%;
  120. }
  121. .content{
  122. height: 100%;
  123. display: flex;
  124. flex-direction: column;
  125. justify-content: space-between;
  126. .inner{
  127. flex: 1;
  128. padding: 20upx 20upx 160upx;
  129. .top{
  130. padding: 0upx 20upx 20upx;
  131. text-align: right;
  132. .del{
  133. font-size: 28upx;
  134. font-family: PingFang SC;
  135. color: #999999;
  136. }
  137. }
  138. .address-item{
  139. background: #FFFFFF;
  140. border-radius: 16upx;
  141. padding: 46upx 40upx 50upx 24upx;
  142. display: flex;
  143. align-items: center;
  144. justify-content: space-between;
  145. margin-bottom: 20upx;
  146. .info{
  147. width: 75%;
  148. .title{
  149. font-size: 30upx;
  150. font-family: PingFang SC;
  151. font-weight: bold;
  152. color: #111111;
  153. line-height: 42upx;
  154. word-break: break-all;
  155. .tag{
  156. padding: 0 6upx;
  157. height: 32upx;
  158. line-height: 32upx;
  159. font-size: 22upx;
  160. font-family: PingFang SC;
  161. font-weight: 500;
  162. color: #FFFFFF;
  163. background: #C39A58;
  164. border-radius: 4upx;
  165. float: left;
  166. margin-right: 10upx;
  167. margin-top: 5upx;
  168. }
  169. }
  170. .name-phone{
  171. margin-top: 30upx;
  172. display: flex;
  173. align-items: center;
  174. .text{
  175. font-size: 26upx;
  176. font-family: PingFang SC;
  177. font-weight: 500;
  178. color: #999999;
  179. margin-right: 22upx;
  180. &:last-child{
  181. margin-right: 0;
  182. }
  183. }
  184. }
  185. }
  186. .operat-box{
  187. display: flex;
  188. align-items: center;
  189. image{
  190. padding: 15rpx;
  191. width: 30upx;
  192. height: 30upx;
  193. margin-left: 10upx;
  194. &:first-child{
  195. margin-left: 0;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. .btn-box{
  202. z-index: 9999;
  203. width: 100%;
  204. padding: 30upx;
  205. position: fixed;
  206. bottom: 0;
  207. left: 0;
  208. box-sizing: border-box;
  209. background: #FFFFFF;
  210. .sub-btn{
  211. height: 88upx;
  212. line-height: 88upx;
  213. text-align: center;
  214. font-size: 30upx;
  215. font-family: PingFang SC;
  216. font-weight: bold;
  217. color: #FFFFFF;
  218. background: #C39A58;
  219. border-radius: 44upx;
  220. }
  221. }
  222. }
  223. </style>