changeAddress.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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('userChangeAddress')"></u-navbar>
  6. </view>
  7. <view class="content">
  8. <text class="title">{{$i18n.locale=='zh'?'常用地址':'Common Address'}}</text>
  9. <u-empty v-if="isShow" style="margin: 30rpx 0;" :text="$i18n.locale == 'zh' ? '暂无地址:' : 'No Address:'"
  10. mode="search">
  11. </u-empty>
  12. <view v-else class="list" v-for="(item,index) in addressList" :key="item.id">
  13. <view style="margin-right: 30rpx;">
  14. <image class="addressImg" v-if="item.status=='1'?true:false" src="/static/address/address.png"
  15. mode="">
  16. </image>
  17. <image class="addressImg" v-else src="/static/address/user-adrs.png" mode=""></image>
  18. </view>
  19. <view class="mainContent">
  20. <view>
  21. <text class="name">{{item.consignee }}</text>
  22. <text class="phone">{{item.mobile}}</text>
  23. <text v-if="item.status=='1'?true:false">
  24. <image v-if="$i18n.locale=='zh'" class="defaultImg" src="/static/address/user.png" mode="">
  25. </image>
  26. <image v-else class="defaultImg" src="/static/address/user123321.png" mode="">
  27. </image>
  28. </text>
  29. </view>
  30. <view class="mainAddress">
  31. <text
  32. class="detailAddress">{{item.province}}&nbsp;{{item.city}}&nbsp;{{item.area}}&nbsp;{{item.address}}</text>
  33. </view>
  34. <view class="radio" v-if="item.status=='1'?false:true">
  35. <u-checkbox-group>
  36. <u-checkbox @change="checkboxChange(item)" v-model="item.stauts" shape="circle">
  37. <text
  38. style="color: rgba(51, 51, 51, 1);font-size: 20rpx;">{{$i18n.locale=='zh'?'设为默认地址':'Set As Default Address'}}</text>
  39. </u-checkbox>
  40. </u-checkbox-group>
  41. </view>
  42. </view>
  43. <view class="right" @click="toEdit(item)">
  44. <image class="editImg" style="display: inline-block;width: 24rpx;height: 24rpx;"
  45. src="/static/address/user-12.png"></image>
  46. </view>
  47. </view>
  48. <view class="botton">
  49. <u-button @tap="toAdd" shape="circle" type="primary" style="background-color: #1579fb;">
  50. <u-icon name="plus"></u-icon>
  51. <text style="margin-left:20rpx;">{{$i18n.locale=='zh'?'添加收货地址':'Add Received Address'}}</text>
  52. </u-button>
  53. </view>
  54. <view class="user-btn">
  55. <button @tap="dialogToggle()" style="background-color: #1579fb;">
  56. <text class="btn-text">{{$i18n.locale=='zh'?'确定':'OK'}}</text>
  57. </button>
  58. </view>
  59. <view>
  60. <!-- 提示信息弹窗 -->
  61. <uni-popup ref="messageaa">
  62. <uni-popup-message :type="msgType" :message="messageText" :duration="2000">
  63. </uni-popup-message>
  64. </uni-popup>
  65. </view>
  66. <view>
  67. <!-- 提示窗示例 -->
  68. <uni-popup ref="alertDialog" type="dialog" v-if="$i18n.locale=='zh'">
  69. <uni-popup-dialog :type="msgType" cancelText="取消" confirmText="确认" content="是否添加到我的订单?"
  70. @confirm="dialogConfirm(shopDetails)" @close="dialogClose" mode='base'></uni-popup-dialog>
  71. </uni-popup>
  72. <uni-popup ref="alertDialog" type="dialog" v-if="$i18n.locale!='zh'">
  73. <uni-popup-dialog :type="msgType" cancelText="Cancel" confirmText="Notarize
  74. " content="Do you want to add it to my order?" @confirm="dialogConfirm(shopDetails)" @close="dialogClose" mode='base'>
  75. </uni-popup-dialog>
  76. </uni-popup>
  77. </view>
  78. </view>
  79. </view>
  80. </template>
  81. <script>
  82. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
  83. import uniPopupMessage from '@/components/uni-popup/uni-popup-message.vue'
  84. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  85. import {
  86. addUmsUserCommodityAddresss,
  87. exchangeUserPoints
  88. } from "@/api/address"
  89. export default {
  90. components: {
  91. uniPopupDialog,
  92. uniPopupMessage,
  93. uniPopup
  94. },
  95. data() {
  96. return {
  97. background: {
  98. backgroundImage: 'linear-gradient(270deg, #4BC0E2 0%, #538BE7 100%)',
  99. },
  100. backStyle: {
  101. color: '#FFFFFF',
  102. },
  103. addressList: [],
  104. userId: null,
  105. isShow: null,
  106. addressId: null,
  107. shopId: null,
  108. shopNum: null,
  109. shopDetails: {},
  110. msgType: 'success',
  111. messageText: '请稍后...',
  112. }
  113. },
  114. onLoad(option) {
  115. console.log(option.id, '--------------------'); //礼品id
  116. console.log(option.num, '========================'); //礼品数量
  117. this.shopId = option.id;
  118. this.shopNum = option.num;
  119. this.initData()
  120. },
  121. methods: {
  122. initData() {
  123. this.getAddressList()
  124. },
  125. // 获取地址列表
  126. async getAddressList() {
  127. this.userId = JSON.parse(uni.getStorageSync("user"))
  128. let params = {
  129. userId: this.userId.id,
  130. }
  131. const res = await this.$myRequest({
  132. url: '/uc/umsUserCommodityAddresss',
  133. method: 'get',
  134. data: params
  135. });
  136. let data = res.data
  137. if (JSON.stringify(data) !== "{}") {
  138. this.addressList = res.data.umsUserCommodityAddresss
  139. this.isShow = false
  140. } else {
  141. this.isShow = true
  142. }
  143. },
  144. navTo(route) {
  145. this.$mRouter.push({
  146. route
  147. });
  148. },
  149. i18n(data) {
  150. return this.$t('common.' + data);
  151. },
  152. // 新建地址
  153. toAdd() {
  154. this.navTo('/pages/profile/personIntegrate/addAddress')
  155. },
  156. // 编辑地址
  157. toEdit(item) {
  158. uni.setStorageSync('addressId', item.id);
  159. this.navTo('/pages/profile/personIntegrate/editAddress')
  160. },
  161. checkboxChange(data) {
  162. this.addressId = data.id
  163. let params = {
  164. // userId: this.userId.id,
  165. consignee: data.consignee,
  166. mobile: data.mobile,
  167. province: data.province,
  168. city: data.city,
  169. area: data.area,
  170. address: data.address,
  171. postalCode: data.postalCode,
  172. status: "1",
  173. id: data.id,
  174. };
  175. },
  176. change(e) {
  177. console.log('当前模式:' + e.type + ',状态:' + e.show);
  178. },
  179. dialogToggle() {
  180. let test = this.addressId ? this.addressId : this.addressList[0].id
  181. let ShopId = this.shopId
  182. let ShopNum = this.shopNum
  183. let params = {
  184. id: ShopId,
  185. exchangeQuantity: ShopNum,
  186. addressId: test
  187. }
  188. this.shopDetails = params
  189. // console.log(this.shopDetails);
  190. this.$refs.alertDialog.open()
  191. },
  192. async dialogConfirm(params) {
  193. const tokendata = await this.$myRequest({
  194. url: '/sys/token',
  195. method: 'get'
  196. });
  197. let demo = params
  198. exchangeUserPoints(demo, tokendata.data)
  199. .then((res) => {
  200. if (res.status == 200) {
  201. if (this.$i18n.locale == 'zh') {
  202. this.messageText = '兑换成功!'
  203. } else {
  204. this.messageText = 'For successful!'
  205. }
  206. } else {
  207. this.msgType = 'error'
  208. this.messageText = res.msg
  209. }
  210. })
  211. .catch((error) => {
  212. console.log(error.msg, '---msg---');
  213. this.messageText = error.msg
  214. });
  215. this.$refs.alertDialog.close()
  216. this.$refs.messageaa.open()
  217. setTimeout(() => {
  218. uni.navigateTo({
  219. url: './integrateConversion',
  220. });
  221. }, 3000)
  222. },
  223. dialogClose() {},
  224. },
  225. computed: {
  226. defaultAddress() {
  227. this.addressList.forEach((item, index) => {
  228. if (item.status == "1") {
  229. return true
  230. } else {
  231. return false
  232. }
  233. })
  234. }
  235. }
  236. }
  237. </script>
  238. <style lang="scss" scoped>
  239. .content {
  240. padding: 20rpx 10rpx 20rpx 30rpx;
  241. .title {
  242. font-size: 32rpx;
  243. font-family: PingFangSC-Semibold, PingFang SC;
  244. font-weight: 600;
  245. color: #333333;
  246. line-height: 34rpx;
  247. }
  248. .list {
  249. position: relative;
  250. margin-top: 10rpx;
  251. background: #FFF;
  252. border-radius: 5%;
  253. padding: 30rpx;
  254. display: flex;
  255. flex-direction: row;
  256. .addressImg {
  257. display: inline-block;
  258. width: 52rpx;
  259. height: 52rpx;
  260. margin-top: 20rpx;
  261. }
  262. .mainContent {
  263. .name {
  264. display: inline-block;
  265. width: 150rpx;
  266. overflow: hidden;
  267. white-space: nowrap;
  268. text-overflow: ellipsis;
  269. color: rgba(51, 51, 51, 1);
  270. font-size: 30rpx;
  271. font-family: PingFangSC-Semibold;
  272. white-space: nowrap;
  273. font-weight: 600;
  274. line-height: 38rpx;
  275. }
  276. .phone {
  277. display: inline-block;
  278. width: 200rpx;
  279. overflow: hidden;
  280. white-space: nowrap;
  281. text-overflow: ellipsis;
  282. overflow-wrap: break-word;
  283. color: rgba(162, 162, 162, 1);
  284. font-size: 26rpx;
  285. white-space: nowrap;
  286. line-height: 38rpx;
  287. margin: 0 30rpx 0 30rpx;
  288. }
  289. .defaultImg {
  290. display: inline-block;
  291. width: 70rpx;
  292. height: 28rpx;
  293. }
  294. .mainAddress {
  295. .detailAddress {
  296. display: inline-block;
  297. width: 491rpx;
  298. margin-right: 30rpx;
  299. overflow-wrap: break-word;
  300. color: rgba(51, 51, 51, 1);
  301. font-size: 26rpx;
  302. line-height: 37rpx;
  303. }
  304. }
  305. }
  306. .right {
  307. .editImg {
  308. margin-top: 200%;
  309. }
  310. }
  311. }
  312. .botton {
  313. margin-bottom: 10rpx;
  314. }
  315. .user-btn {
  316. background-color: #2979ff;
  317. border-radius: 50rpx;
  318. overflow: hidden;
  319. .btn-text {
  320. // margin-left: 20rpx;
  321. color: #fff;
  322. }
  323. }
  324. }
  325. </style>