addressList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view class="container">
  3. <navbar :config="config" backColor="#666666"></navbar>
  4. <view class="list">
  5. <radio-group>
  6. <view class="item u-bg-fff" v-for="(item,index) in addressList" :key="item.id">
  7. <view class="u-border-one-one userInfo" @click="backSurePay(item.id)">
  8. <view>收货人:<text class="u-999">{{item.name}}</text> <text class="u-ml80">{{item.phone}}</text> </view>
  9. <view class="u-mt5 u-text2">收货地址:<text class="u-999">{{item.province_name}}{{item.city_name}}{{item.area_name}}{{item.street_name}}{{item.community_name}}{{item.address}}</text></view>
  10. </view>
  11. <view class="operation u-flex-center-sb u-font24 u-999">
  12. <view class="u-flex-center" @click="isDefault(item.id)">
  13. <view class="kuang">
  14. <!-- <radio color="#FF0000" style="transform:scale(0.7)" :checked="item.is_default" /> -->
  15. <image v-if="item.is_default" :src="imgUrl+'/checked.png'" mode="widthFix" style="width: 30rpx;height: 30rpx;margin-right: 10rpx;"></image>
  16. <image v-else :src="imgUrl+'/nocheck.png'" mode="widthFix" style="width: 50rpx;height: 50rpx;"></image>
  17. <!-- <checkbox color="#FF0000" style="transform:scale(0.7)" :checked="item.is_default" /> -->
  18. <!-- <radio v-else style="transform:scale(0.7)" :checked="false" /> -->
  19. {{item.is_default?'默认地址':'设为默认'}}
  20. </view>
  21. </view>
  22. <view class="u-flex-center">
  23. <view class="u-mr45" @click="edit(item.id)">编辑</view>
  24. <view @click="del(item.id)">删除</view>
  25. </view>
  26. </view>
  27. </view>
  28. </radio-group>
  29. </view>
  30. <!-- 没有数据 -->
  31. <view class="nogoods u-mt30 u-flex-column-center" v-if="addressList.length==0">
  32. <nodata :config="{top:5,content:'您还没有添加地址~'}"></nodata>
  33. </view>
  34. <view class="add-btn" @click="goAddEditAddress">
  35. <view class="u-plr30">
  36. <button class="u-btn-two u-FFF">添加新地址</button>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. data() {
  44. return {
  45. config: {
  46. back: true, //false是tolbar页面 是则不写
  47. title: '收货地址',
  48. color: '#1A1A1A',
  49. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  50. backgroundColor: [1, "#fff"],
  51. statusBarFontColor: '#1A1A1A'
  52. },
  53. addressList:[],
  54. imgUrl: this.$mConfig.staticUrl
  55. }
  56. },
  57. onLoad() {
  58. },
  59. onShow() {
  60. this.$nextTick(() => {
  61. this.getAddressList()
  62. })
  63. },
  64. methods:{
  65. //获取地址列表
  66. async getAddressList(){
  67. let that = this
  68. this.$http.get('/useraddress/list',{}).then(async res => {
  69. console.log('res',res)
  70. if(res.code ==200){
  71. that.addressList = res.list
  72. }
  73. })
  74. },
  75. listAddress(e){
  76. if(e==1){
  77. this.getAddressList()
  78. }
  79. },
  80. //跳转确认下单页面
  81. backSurePay(id){
  82. // uni.setStorageSync('address',item)
  83. let object={
  84. addressid:id
  85. }
  86. var pages = getCurrentPages();
  87. var prevPage = pages[pages.length - 2];
  88. if(prevPage.$vm.otherFun){
  89. prevPage.$vm.otherFun(object)
  90. }
  91. uni.navigateBack({
  92. delta:1
  93. })
  94. // uni.navigateTo({
  95. // url:'/pages/product/surePay/surePay?addressid='+id
  96. // })
  97. },
  98. //跳转到添加地址
  99. goAddEditAddress(){
  100. uni.navigateTo({
  101. url:"addEditAddress"
  102. })
  103. },
  104. isDefault(id){
  105. let that = this
  106. this.$http.put('/useraddress/set-def/'+id).then(async res => {
  107. if(res&&res.code==200){
  108. uni.showToast({
  109. title:"修改成功",
  110. icon:"none",
  111. duration:3000,
  112. success() {
  113. that.getAddressList()
  114. that.addressList =[]
  115. }
  116. })
  117. }
  118. })
  119. // if(e.is_default == true){
  120. // e.is_default = false
  121. // that.update(e)
  122. // }else{
  123. // e.is_default =true
  124. // that.update(e)
  125. // }
  126. },
  127. update(param){
  128. },
  129. //编辑
  130. edit(id){
  131. uni.navigateTo({
  132. url:"addEditAddress?id="+id
  133. })
  134. },
  135. //删除
  136. async del(id){
  137. let that = this
  138. uni.showModal({
  139. title:'温馨提示',
  140. content:"是否删除这条地址",
  141. success:(res) =>{
  142. if(res.confirm) {
  143. this.$http.delete('/useraddress/delete/'+id,)
  144. .then(async res => {
  145. if(res.code==200){
  146. uni.showToast({
  147. title:"删除成功",
  148. icon:"none",
  149. duration:3000,
  150. success() {
  151. that.getAddressList()
  152. }
  153. })
  154. }
  155. })
  156. }
  157. }
  158. })
  159. },
  160. }
  161. }
  162. </script>
  163. <style lang="scss">
  164. page{
  165. background-color: #F5F5F5;
  166. }
  167. .kuang {
  168. display: flex;
  169. align-items: center;
  170. }
  171. .list{
  172. margin-bottom: 160rpx;
  173. }
  174. .item{
  175. margin-top: 30rpx;
  176. padding:46rpx 30rpx;
  177. .userInfo{
  178. padding-bottom: 36rpx;
  179. }
  180. .operation{
  181. border-top: 2rpx solid #F5F5F5;
  182. padding-top: 42rpx;
  183. }
  184. }
  185. .add-btn{
  186. width: 100%;
  187. position: fixed;
  188. bottom: 45rpx;
  189. button{
  190. width: 100%;
  191. }
  192. }
  193. </style>