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

214 lines
4.4 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 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. console.log("==========")
  107. let self = this
  108. uni.showModal({
  109. title: '删除地址',
  110. content: '确认删除此地址?删除后数据不可恢复',
  111. success(e) {
  112. if(e.confirm){
  113. self.$api('deleteAddress', {
  114. id
  115. }, res => {
  116. if (res.code == 200) {
  117. uni.showToast({
  118. title: '删除成功',
  119. icon: 'none'
  120. })
  121. self.getAddressList()
  122. }
  123. })
  124. }
  125. }
  126. })
  127. },
  128. //点击新增按钮
  129. addBtn() {
  130. this.title = '新增地址'
  131. this.$refs.addressPopup.open({ //初始化数据
  132. name: '',
  133. phone: '',
  134. address: '',
  135. addressDetail: '',
  136. defaultId: '',
  137. latitude: '',
  138. longitude: ''
  139. })
  140. },
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .address {
  146. width: 750rpx;
  147. margin: 0rpx auto;
  148. background: #F5F5F5;
  149. box-sizing: border-box;
  150. min-height: 100vh;
  151. .address-list {
  152. padding: 40rpx 20rpx 120rpx 20rpx;
  153. }
  154. .add-btn {
  155. position: fixed;
  156. display: flex;
  157. justify-content: center;
  158. align-items: center;
  159. left: 0;
  160. bottom: 0;
  161. width: 750rpx;
  162. height: 100rpx;
  163. background: white;
  164. .btn {
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. width: 85%;
  169. height: 80rpx;
  170. border-radius: 40rpx;
  171. color: white;
  172. text-align: center;
  173. font-size: 28rpx;
  174. background: $uni-color;
  175. }
  176. }
  177. }
  178. @media all and (min-width: 961px) {
  179. .add-btn {
  180. left: 50% !important;
  181. transform: translateX(-50%);
  182. }
  183. }
  184. //选择位置地图样式
  185. :deep(.uni-system-choose-location) {
  186. z-index: 99999 !important;
  187. }
  188. </style>