address.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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">{{utils.parsePhone(item.phone)}}</text>
  16. </view>
  17. </view>
  18. <view class="operat-box">
  19. <image src="../../static/images/del.png" mode="" @click="delAddress(item)"></image>
  20. <image src="../../static/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/no_data.png" mode="aspectFit"></image>
  25. <view class="empty-title">暂无数据</view>
  26. </view>
  27. </view>
  28. <view class="btn-box">
  29. <view class="sub-btn" @click="addAdress">新建收货地址</view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import {getAddressList,delAddress,delAllAddress} from '@/api/address'
  35. export default {
  36. data() {
  37. return {
  38. address:[],
  39. }
  40. },
  41. onLoad() {
  42. this.getAddressList()
  43. uni.$on('refreshAddress', () => {
  44. this.getAddressList()
  45. })
  46. },
  47. methods: {
  48. selectAddress(item){
  49. console.log("数据",item)
  50. uni.$emit('updateAddress',item);
  51. uni.navigateBack({
  52. delta: 1
  53. })
  54. },
  55. editAddress(item){
  56. uni.navigateTo({
  57. url: './addAddress?type=edit&id='+item.id
  58. })
  59. },
  60. delAllAddress(item){
  61. uni.showModal({
  62. title:"提示",
  63. content:"确认删除所有地址吗?",
  64. showCancel:true,
  65. cancelText:'取消',
  66. confirmText:'确定',
  67. success:res=>{
  68. if(res.confirm){
  69. var data={ }
  70. delAllAddress(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. delAddress(item){
  94. uni.showModal({
  95. title:"提示",
  96. content:"确认删除此地址吗?",
  97. showCancel:true,
  98. cancelText:'取消',
  99. confirmText:'确定',
  100. success:res=>{
  101. if(res.confirm){
  102. // 用户点击确定
  103. var data={id:item.id}
  104. delAddress(data).then(
  105. res => {
  106. if(res.code==200){
  107. uni.showToast({
  108. icon:'success',
  109. title: "操作成功",
  110. });
  111. this.getAddressList()
  112. }else{
  113. uni.showToast({
  114. icon:'none',
  115. title: "请求失败",
  116. });
  117. }
  118. },
  119. rej => {}
  120. );
  121. }else{
  122. // 否则点击了取消
  123. }
  124. }
  125. })
  126. },
  127. getAddressList(){
  128. uni.showLoading({
  129. title:"正在加载中"
  130. })
  131. getAddressList().then(
  132. res => {
  133. uni.hideLoading()
  134. if(res.code==200){
  135. this.address=res.data;
  136. }else{
  137. uni.showToast({
  138. icon:'none',
  139. title: "请求失败",
  140. });
  141. }
  142. },
  143. rej => {}
  144. );
  145. },
  146. // 新建收货地址
  147. addAdress() {
  148. uni.navigateTo({
  149. url: './addAddress?type=add'
  150. })
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="scss">
  156. page{
  157. height: 100%;
  158. }
  159. .content{
  160. height: 100%;
  161. display: flex;
  162. flex-direction: column;
  163. justify-content: space-between;
  164. .inner{
  165. flex: 1;
  166. padding: 20upx 20upx 160upx;
  167. .top{
  168. padding: 0upx 20upx 20upx;
  169. text-align: right;
  170. .del{
  171. font-size: 28upx;
  172. font-family: PingFang SC;
  173. color: #999999;
  174. }
  175. }
  176. .address-item{
  177. background: #FFFFFF;
  178. border-radius: 16upx;
  179. padding: 46upx 40upx 50upx 24upx;
  180. display: flex;
  181. align-items: center;
  182. justify-content: space-between;
  183. margin-bottom: 20upx;
  184. .info{
  185. width: 75%;
  186. .title{
  187. font-size: 30upx;
  188. font-family: PingFang SC;
  189. font-weight: bold;
  190. color: #111111;
  191. line-height: 42upx;
  192. word-break: break-all;
  193. .tag{
  194. padding: 0 6upx;
  195. height: 32upx;
  196. line-height: 32upx;
  197. font-size: 22upx;
  198. font-family: PingFang SC;
  199. font-weight: 500;
  200. color: #FFFFFF;
  201. background: #2BC7B9;
  202. border-radius: 4upx;
  203. float: left;
  204. margin-right: 10upx;
  205. margin-top: 5upx;
  206. }
  207. }
  208. .name-phone{
  209. margin-top: 30upx;
  210. display: flex;
  211. align-items: center;
  212. .text{
  213. font-size: 26upx;
  214. font-family: PingFang SC;
  215. font-weight: 500;
  216. color: #999999;
  217. margin-right: 22upx;
  218. &:last-child{
  219. margin-right: 0;
  220. }
  221. }
  222. }
  223. }
  224. .operat-box{
  225. display: flex;
  226. align-items: center;
  227. image{
  228. width: 30upx;
  229. height: 30upx;
  230. margin-left: 38upx;
  231. &:first-child{
  232. margin-left: 0;
  233. }
  234. }
  235. }
  236. }
  237. }
  238. .btn-box{
  239. z-index: 9999;
  240. width: 100%;
  241. padding: 30upx;
  242. position: fixed;
  243. bottom: 0;
  244. left: 0;
  245. box-sizing: border-box;
  246. background: #FFFFFF;
  247. .sub-btn{
  248. height: 88upx;
  249. line-height: 88upx;
  250. text-align: center;
  251. font-size: 30upx;
  252. font-family: PingFang SC;
  253. font-weight: bold;
  254. color: #FFFFFF;
  255. background: #2BC7B9;
  256. border-radius: 44upx;
  257. }
  258. }
  259. }
  260. </style>