userAddress.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <view>
  3. <view>
  4. <u-navbar :back-text="i18n('Back')" :back-text-style="backStyle" back-icon-color="#fff" title-color="#fff"
  5. :background="background" title-width="300" :title="i18n('UserAddress')"></u-navbar>
  6. </view>
  7. <view class="content">
  8. <text class="title">{{$i18n.locale=='zh'?'常用地址':'Common Address'}}</text>
  9. <text
  10. class="address-num">{{$i18n.locale=='zh'?'您已经创建':'You have created'}}{{addressList.length}}{{$i18n.locale=='zh'?'个收货地址':'address'}},{{$i18n.locale=='zh'?'最多可创建25个':'A maximum of 25 can be created'}}</text>
  11. <u-empty v-if="isShow" style="margin: 30rpx 0;" :text="$i18n.locale == 'zh' ? '暂无地址:' : 'No Address:'"
  12. mode="search">
  13. </u-empty>
  14. <view v-else class="list" v-for="(item,index) in addressList" :key="item.id">
  15. <view style="margin-right: 30rpx;">
  16. <image class="addressImg" v-if="item.status=='1'?true:false" src="/static/address/address.png"
  17. mode="">
  18. </image>
  19. <image class="addressImg" v-else src="/static/address/user-adrs.png" mode=""></image>
  20. </view>
  21. <view class="mainContent">
  22. <view>
  23. <text class="name">{{item.consignee }}</text>
  24. <text class="phone">{{item.mobile}}</text>
  25. <text v-if="item.status=='1'?true:false">
  26. <image v-if="$i18n.locale=='zh'" class="defaultImg" src="/static/address/user.png" mode="">
  27. </image>
  28. <image v-else class="defaultImg" src="/static/address/user123321.png" mode="">
  29. </image>
  30. </text>
  31. </view>
  32. <view class="mainAddress" v-if="$i18n.locale=='zh'">
  33. <text
  34. class="detailAddress">{{item.province}}&nbsp;{{item.city}}&nbsp;{{item.area}}&nbsp;{{item.address}}</text>
  35. </view>
  36. <view class="mainAddress" v-if="$i18n.locale!='zh'">
  37. <text class="detailAddress">{{item.address}}</text>
  38. </view>
  39. <view class="radio" v-if="item.status=='1'?false:true">
  40. <u-checkbox-group>
  41. <u-checkbox @change="checkboxChange(item)" v-model="item.stauts" shape="circle">
  42. <text
  43. style="color: rgba(51, 51, 51, 1);font-size: 20rpx;">{{$i18n.locale=='zh'?'设为默认地址':'Set As Default Address'}}</text>
  44. </u-checkbox>
  45. </u-checkbox-group>
  46. </view>
  47. </view>
  48. <view class="right" @click="toEdit(item)">
  49. <image class="editImg" style="display: inline-block;width: 24rpx;height: 24rpx;"
  50. src="/static/address/user-12.png"></image>
  51. </view>
  52. </view>
  53. <view class="botton">
  54. <u-button @click="toAdd" shape="circle" type="primary">
  55. <u-icon name="plus"></u-icon>
  56. <text
  57. style="margin-left:20rpx;background-color: #1579fb;">{{$i18n.locale=='zh'?'添加收货地址':'Add Received Address'}}</text>
  58. </u-button>
  59. </view>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import {
  65. addUmsUserCommodityAddresss
  66. } from "@/api/address"
  67. export default {
  68. data() {
  69. return {
  70. background: {
  71. backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
  72. },
  73. backStyle: {
  74. color: '#FFFFFF',
  75. },
  76. addressList: [],
  77. userId: null,
  78. isShow: null,
  79. }
  80. },
  81. onShow() {
  82. this.initData()
  83. },
  84. methods: {
  85. initData() {
  86. this.getAddressList()
  87. },
  88. // 获取地址列表
  89. async getAddressList() {
  90. this.userId = JSON.parse(uni.getStorageSync("user"))
  91. let params = {
  92. userId: this.userId.id,
  93. }
  94. const res = await this.$myRequest({
  95. url: '/uc/umsUserCommodityAddresss',
  96. method: 'get',
  97. data: params
  98. });
  99. let data = res.data
  100. if (JSON.stringify(data) !== "{}") {
  101. this.addressList = res.data.umsUserCommodityAddresss
  102. this.isShow = false
  103. } else {
  104. this.isShow = true
  105. }
  106. },
  107. navTo(route) {
  108. this.$mRouter.push({
  109. route
  110. });
  111. },
  112. i18n(data) {
  113. return this.$t('common.' + data);
  114. },
  115. // 新建地址
  116. toAdd() {
  117. this.navTo('/pages/profile/personIntegrate/addAddress')
  118. },
  119. // 编辑地址
  120. toEdit(item) {
  121. uni.setStorageSync('addressId', item.id);
  122. this.navTo('/pages/profile/personIntegrate/editAddress')
  123. },
  124. async checkboxChange(data) {
  125. let params = {
  126. // userId: this.userId.id,
  127. consignee: data.consignee,
  128. mobile: data.mobile,
  129. province: data.province,
  130. city: data.city,
  131. area: data.area,
  132. address: data.address,
  133. postalCode: data.postalCode,
  134. status: "1",
  135. id: data.id,
  136. };
  137. const tokendata = await this.$myRequest({
  138. url: '/sys/token',
  139. method: 'get'
  140. });
  141. // console.log(res.data)
  142. addUmsUserCommodityAddresss(params, tokendata.data).then((res) => {
  143. this.initData();
  144. });
  145. },
  146. },
  147. computed: {
  148. defaultAddress() {
  149. this.addressList.forEach((item, index) => {
  150. if (item.status == "1") {
  151. return true
  152. } else {
  153. return false
  154. }
  155. })
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang="scss" scoped>
  161. .content {
  162. padding: 20rpx 10rpx 20rpx 30rpx;
  163. .title {
  164. font-size: 32rpx;
  165. font-family: PingFangSC-Semibold, PingFang SC;
  166. font-weight: 600;
  167. color: #333333;
  168. line-height: 34rpx;
  169. }
  170. .address-num {
  171. font-size: 22rpx;
  172. margin-left: 20%;
  173. }
  174. .list {
  175. position: relative;
  176. margin-top: 10rpx;
  177. background: #FFF;
  178. border-radius: 5%;
  179. padding: 30rpx;
  180. display: flex;
  181. flex-direction: row;
  182. .addressImg {
  183. display: inline-block;
  184. width: 52rpx;
  185. height: 52rpx;
  186. margin-top: 20rpx;
  187. }
  188. .mainContent {
  189. .name {
  190. display: inline-block;
  191. width: 150rpx;
  192. overflow: hidden;
  193. white-space: nowrap;
  194. text-overflow: ellipsis;
  195. color: rgba(51, 51, 51, 1);
  196. font-size: 30rpx;
  197. font-family: PingFangSC-Semibold;
  198. white-space: nowrap;
  199. font-weight: 600;
  200. line-height: 38rpx;
  201. }
  202. .phone {
  203. display: inline-block;
  204. width: 200rpx;
  205. overflow: hidden;
  206. white-space: nowrap;
  207. text-overflow: ellipsis;
  208. overflow-wrap: break-word;
  209. color: rgba(162, 162, 162, 1);
  210. font-size: 26rpx;
  211. white-space: nowrap;
  212. line-height: 38rpx;
  213. margin: 0 30rpx 0 30rpx;
  214. }
  215. .defaultImg {
  216. display: inline-block;
  217. width: 70rpx;
  218. height: 28rpx;
  219. }
  220. .mainAddress {
  221. .detailAddress {
  222. display: inline-block;
  223. width: 491rpx;
  224. margin-right: 30rpx;
  225. overflow-wrap: break-word;
  226. color: rgba(51, 51, 51, 1);
  227. font-size: 26rpx;
  228. line-height: 37rpx;
  229. }
  230. }
  231. }
  232. .right {
  233. .editImg {
  234. margin-top: 200%;
  235. }
  236. }
  237. }
  238. }
  239. </style>