瑶都万能墙
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.

212 lines
3.9 KiB

3 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. onShow() {
  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. defaultFlag: addressDetail.defaultFlag || '0',
  68. latitude: addressDetail.latitude,
  69. longitude: addressDetail.longitude
  70. }
  71. if (addressDetail.id) {
  72. data.id = addressDetail.id
  73. }
  74. this.$api('addOrEditAddress', data, res => {
  75. if (res.code == 200) {
  76. this.$refs.addressPopup.close()
  77. this.getAddressList()
  78. if(this.type == 'back'){
  79. uni.navigateBack(-1)
  80. }
  81. uni.showToast({
  82. title: '操作成功',
  83. icon: 'none'
  84. })
  85. }
  86. })
  87. },
  88. //修改默认地址
  89. editDefault(id) {
  90. this.$api('addressDefault', {
  91. id: id,
  92. }, res => {
  93. if (res.code == 200) {
  94. this.$refs.addressPopup.close()
  95. uni.showToast({
  96. title: '操作成功',
  97. icon: 'none'
  98. })
  99. this.getAddressList()
  100. }
  101. })
  102. },
  103. //删除地址
  104. deleteAddress(addressId) {
  105. let self = this
  106. uni.showModal({
  107. title: '删除地址',
  108. content: '确认删除此地址?删除后数据不可恢复',
  109. success(e) {
  110. if(e.confirm){
  111. self.$api('deleteAddress', {
  112. addressId
  113. }, res => {
  114. if (res.code == 200) {
  115. uni.showToast({
  116. title: '删除成功',
  117. icon: 'none'
  118. })
  119. self.getAddressList()
  120. }
  121. })
  122. }
  123. }
  124. })
  125. },
  126. //点击新增按钮
  127. addBtn() {
  128. this.title = '新增地址'
  129. this.$refs.addressPopup.open({ //初始化数据
  130. name: '',
  131. phone: '',
  132. address: '',
  133. addressDetail: '',
  134. defaultFlag: '',
  135. latitude: '',
  136. longitude: ''
  137. })
  138. },
  139. }
  140. }
  141. </script>
  142. <style lang="scss" scoped>
  143. .address {
  144. width: 750rpx;
  145. margin: 0rpx auto;
  146. background: #F5F5F5;
  147. box-sizing: border-box;
  148. min-height: 100vh;
  149. .address-list {
  150. padding: 40rpx 20rpx 120rpx 20rpx;
  151. }
  152. .add-btn {
  153. position: fixed;
  154. display: flex;
  155. justify-content: center;
  156. align-items: center;
  157. left: 0;
  158. bottom: 0;
  159. width: 750rpx;
  160. height: 100rpx;
  161. background: white;
  162. .btn {
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. width: 85%;
  167. height: 80rpx;
  168. border-radius: 40rpx;
  169. color: white;
  170. text-align: center;
  171. font-size: 28rpx;
  172. background: $uni-color;
  173. }
  174. }
  175. }
  176. @media all and (min-width: 961px) {
  177. .add-btn {
  178. left: 50% !important;
  179. transform: translateX(-50%);
  180. }
  181. }
  182. //选择位置地图样式
  183. :deep(.uni-system-choose-location) {
  184. z-index: 99999 !important;
  185. }
  186. </style>