耀实惠小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
5.9 KiB

  1. <template>
  2. <view class="address h-100">
  3. <view class="address-container" v-if="addressData.length">
  4. <view
  5. class="address-container-item flex align-center justify-between m-b-20"
  6. v-for="(item,index) in addressData"
  7. :key="index"
  8. @click="selectAddress(item)"
  9. >
  10. <view class="nameOne_box">
  11. <text class="nameOne">{{item.name.substr(0,1)}}</text>
  12. </view>
  13. <view class="flex-1 m-r-30">
  14. <view class="flex align-center">
  15. <text class="font-36 m-r-60" style="font-weight: bold;">{{item.name}}</text>
  16. <text class="text-grey font-32">{{item.phone}}</text>
  17. </view>
  18. <view class="m-b-4 address_box">
  19. <view class="icon_box m-r-20" v-if="item.defaultFlag">
  20. <u-tag text="默认" mode="dark" size="mini" v-if="item.defaultFlag"/>
  21. </view>
  22. <text class="font-30 m-r-20">{{item.shippingAddress}}</text>
  23. <text class="text-black font-30">{{item.addressDetail}}</text>
  24. </view>
  25. </view>
  26. <com-view @click="toEdit(item)" v-if="type !== 'select'">
  27. <view class="address-container-item-edit flex align-center justify-end">
  28. <u-icon name="edit-pen" color="#000" size="50"></u-icon>
  29. </view>
  30. </com-view>
  31. </view>
  32. </view>
  33. <view class="vw-100 h-100" v-if="!addressData.length">
  34. <u-empty icon-size="430" text="没有收货地址" :src="IMG_URL + 'address-empty.png'"></u-empty>
  35. </view>
  36. <view class="address-footer position-fixed flex align-center justify-center">
  37. <u-button type="primary" shape="circle" @click="toAdd" class="font-size-34">新增收货地址</u-button>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { IMG_URL } from '@/env.js'
  43. export default{
  44. data(){
  45. return{
  46. IMG_URL,
  47. value:'',
  48. params:{
  49. pageNo:1,
  50. pageSize:10
  51. },
  52. addressData:[],
  53. type: '',
  54. url: '' //从哪里来
  55. }
  56. },
  57. onLoad(options) {
  58. let pages_url = getCurrentPages();
  59. this.url = pages_url[0].route;
  60. if (options.type) this.type = options.type
  61. // 删除地址
  62. uni.$on('delAddress', params => {
  63. let idx = this.addressData.find(item => params.id === item.id)
  64. this.addressData.splice(idx, 1)
  65. })
  66. // 新增地址
  67. uni.$on('addAddress', () => {
  68. this.getAddressList()
  69. })
  70. // 编辑地址
  71. uni.$on('editAddress', params => {
  72. let idx = this.addressData.find(item => params.id === item.id)
  73. this.addressData.splice(idx, 1, {...this.addressData[idx], ...params})
  74. })
  75. },
  76. onShow() {
  77. this.getAddressList()
  78. },
  79. onUnload() {
  80. uni.$off('delAddress')
  81. uni.$off('addAddress')
  82. uni.$off('editAddress')
  83. // 获取倒退的页面
  84. uni.switchTab({
  85. url: this.url
  86. })
  87. },
  88. methods: {
  89. selectAddress (item) {
  90. if (this.type === 'select') {
  91. console.log(item)
  92. // uni.$emit('SELECT_ADDRESS', item)
  93. let params = {
  94. ...item,
  95. type: 'user'
  96. }
  97. this.$store.commit('set_location', params)
  98. uni.navigateBack({
  99. delta: 1
  100. })
  101. }else {
  102. // 从首页进入 选择地址
  103. this.type === 'select_home'
  104. let params = {
  105. ...item,
  106. }
  107. this.$store.commit('set_location', params)
  108. uni.navigateBack({
  109. delta: 3
  110. })
  111. }
  112. },
  113. toEdit(item) {
  114. // 编辑地址
  115. const info = JSON.stringify(item)
  116. console.log(encodeURIComponent(info))
  117. uni.navigateTo({
  118. url: `/pages/my/address/addressEdit?type=edit&title=编辑地址&info=${encodeURIComponent(info)}`
  119. })
  120. },
  121. getAddressList() {
  122. const params = this.params
  123. uni.showLoading();
  124. this.$api('getAddressList', params).then(res => {
  125. let { code, result, message } = res
  126. uni.hideLoading();
  127. if(code == 200) {
  128. this.addressData = result.records;
  129. console.log( code, result, message)
  130. }else{
  131. this.$Toast(message)
  132. }
  133. }).catch(err => {
  134. this.$Toast(err.message)
  135. })
  136. },
  137. toAdd () {
  138. // &info={}
  139. this.$tools.navigateTo({
  140. url: '/pages/my/address/addressEdit?type=add&title=新增地址'
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style scoped lang="scss">
  147. .nameOne_box{
  148. width: 100rpx;
  149. height: 100rpx;
  150. border-radius: 50%;
  151. text-align: center;
  152. line-height: 100rpx;
  153. font-size: 43rpx;
  154. font-weight: bold;
  155. color: #fff;
  156. margin-right: 20rpx;
  157. background-color: rgba(12,133,255,.6);
  158. }
  159. .address_box{
  160. float: left;
  161. .icon_box{
  162. display: inline-block;
  163. }
  164. }
  165. .list-box{
  166. width: 750upx;
  167. }
  168. .u-radio-group{
  169. width: 100%;
  170. }
  171. .item{
  172. margin: 32upx;
  173. border: 1upx solid #707070;
  174. padding: 20upx;
  175. border-radius: 10upx;
  176. position: relative;
  177. width: 100%;
  178. .delete{
  179. position: absolute;
  180. right: 20upx;
  181. top: 20upx;
  182. }
  183. .header-box{
  184. display: flex;
  185. align-items: center;
  186. text{
  187. margin-left: 12upx;
  188. font-size: 26upx;
  189. }
  190. .phone-box{
  191. margin-left: 20upx;
  192. }
  193. .nickname{
  194. font-size: 28upx;
  195. font-weight: bold;
  196. color: #000000;
  197. }
  198. .tel{
  199. color: #707070;
  200. margin-left: 4upx;
  201. }
  202. }
  203. .content-box{
  204. padding: 20upx 10upx;
  205. display: flex;
  206. font-size: 28upx;
  207. color: #707070;
  208. text{
  209. margin-left: 8upx;
  210. }
  211. }
  212. .bottom-box{
  213. padding:10upx 10upx 10upx 10upx;
  214. display: flex;
  215. justify-content: space-between;
  216. align-items: center;
  217. font-size: 26upx;
  218. .text-orange-dark{
  219. color: #FFA206;
  220. font-size: 26upx;
  221. }
  222. }
  223. }
  224. .function-box{
  225. position: fixed;
  226. bottom: 0upx;
  227. left: 0upx;
  228. height: 150upx;
  229. width: 750upx;
  230. display: flex;
  231. align-items: center;
  232. justify-content: center;
  233. .create{
  234. display: flex;
  235. align-items: center;
  236. justify-content: center;
  237. width: 670upx;
  238. height: 95upx;
  239. background-color: #000000;
  240. color: #FFFFFF;
  241. }
  242. }
  243. .address {
  244. padding-bottom: 120rpx;
  245. &-container {
  246. height: 100%;
  247. background: #fff;
  248. padding: 30rpx;
  249. &-item {
  250. border-bottom: 2rpx solid #f1f1f1;
  251. padding-bottom: 20rpx;
  252. &-edit {
  253. width: 50rpx;
  254. height: 50rpx;
  255. }
  256. }
  257. }
  258. &-footer {
  259. height: 120rpx;
  260. bottom: 0;
  261. left: 0;
  262. width: 100%;
  263. background: #fff;
  264. /deep/.u-btn {
  265. width: 600rpx;
  266. height: 80rpx;
  267. }
  268. }
  269. }
  270. </style>