铝交易,微信公众号
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.

213 lines
4.4 KiB

6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
  1. <template>
  2. <view class="address">
  3. <navbar title="地址管理" leftClick @leftClick="leftClick" />
  4. <view class="address-list">
  5. <addressList
  6. controls
  7. ref="addressList"
  8. @deleteAddress="deleteAddress"
  9. @editAddress="editAddress"
  10. @editDefault="editDefault"/>
  11. </view>
  12. <redactAddress
  13. ref="addressPopup"
  14. :addressDetail="addressDetail"
  15. @saveOrUpdate="saveOrUpdate"
  16. :title="title"></redactAddress>
  17. <view class="add-btn">
  18. <view @click="addBtn" class="btn">
  19. 新增地址
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import redactAddress from '../components/address/redactAddress.vue'
  26. import addressList from '../components/address/addressList.vue'
  27. export default {
  28. components: {
  29. redactAddress,
  30. addressList
  31. },
  32. data() {
  33. return {
  34. title: '新增地址',
  35. type : '',
  36. }
  37. },
  38. onLoad(args) {
  39. this.type = args.type
  40. if(this.type == 'back'){
  41. this.addBtn()
  42. }
  43. },
  44. mounted() {
  45. this.getAddressList()
  46. },
  47. methods: {
  48. //获取地址列表
  49. getAddressList() {
  50. this.$refs.addressList.getAddressList()
  51. },
  52. //获取地址详情
  53. editAddress(address) {
  54. this.$refs.addressPopup.open({...address})
  55. },
  56. //返回个人中心
  57. leftClick() {
  58. uni.navigateBack(-1)
  59. },
  60. //添加和修改地址
  61. saveOrUpdate(addressDetail) {
  62. let data = {
  63. name: addressDetail.name,
  64. phone: addressDetail.phone,
  65. address: addressDetail.address,
  66. addressDetail: addressDetail.addressDetail,
  67. // defaultId: addressDetail.defaultId || '0',
  68. latitude: addressDetail.latitude,
  69. longitude: addressDetail.longitude
  70. }
  71. console.log(addressDetail.id,"addressDetail.id")
  72. if (addressDetail.id) {
  73. data.id = addressDetail.id
  74. }
  75. this.$api(data.id ? 'editAddress' : 'addAddress', data, res => {
  76. if (res.code == 200) {
  77. this.$refs.addressPopup.close()
  78. this.getAddressList()
  79. if(this.type == 'back'){
  80. uni.navigateBack(-1)
  81. }
  82. uni.showToast({
  83. title: '操作成功',
  84. icon: 'none'
  85. })
  86. }
  87. })
  88. },
  89. //修改默认地址
  90. editDefault(id) {
  91. this.$api('addressDefault', {
  92. id: id,
  93. }, res => {
  94. if (res.code == 200) {
  95. this.$refs.addressPopup.close()
  96. uni.showToast({
  97. title: '操作成功',
  98. icon: 'none'
  99. })
  100. this.getAddressList()
  101. }
  102. })
  103. },
  104. //删除地址
  105. deleteAddress(id) {
  106. let self = this
  107. uni.showModal({
  108. title: this.$t('components.deleteAddress'),
  109. content: this.$t('components.confirmDeleteAddress'),
  110. success(e) {
  111. if(e.confirm){
  112. self.$api('deleteAddress', {
  113. id
  114. }, res => {
  115. if (res.code == 200) {
  116. uni.showToast({
  117. title: this.$t('components.deleteSuccessful'),
  118. icon: 'none'
  119. })
  120. self.getAddressList()
  121. }
  122. })
  123. }
  124. }
  125. })
  126. },
  127. //点击新增按钮
  128. addBtn() {
  129. this.title = '新增地址'
  130. this.$refs.addressPopup.open({ //初始化数据
  131. name: '',
  132. phone: '',
  133. address: '',
  134. addressDetail: '',
  135. defaultId: '',
  136. latitude: '',
  137. longitude: ''
  138. })
  139. },
  140. }
  141. }
  142. </script>
  143. <style lang="scss" scoped>
  144. .address {
  145. width: 750rpx;
  146. margin: 0rpx auto;
  147. background: #F5F5F5;
  148. box-sizing: border-box;
  149. min-height: 100vh;
  150. .address-list {
  151. padding: 40rpx 20rpx 120rpx 20rpx;
  152. }
  153. .add-btn {
  154. position: fixed;
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. left: 0;
  159. bottom: 0;
  160. width: 750rpx;
  161. height: 100rpx;
  162. background: white;
  163. .btn {
  164. display: flex;
  165. align-items: center;
  166. justify-content: center;
  167. width: 85%;
  168. height: 80rpx;
  169. border-radius: 40rpx;
  170. color: white;
  171. text-align: center;
  172. font-size: 28rpx;
  173. background: $uni-color;
  174. }
  175. }
  176. }
  177. @media all and (min-width: 961px) {
  178. .add-btn {
  179. left: 50% !important;
  180. transform: translateX(-50%);
  181. }
  182. }
  183. //选择位置地图样式
  184. :deep(.uni-system-choose-location) {
  185. z-index: 99999 !important;
  186. }
  187. </style>