address.vue 5.6 KB

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