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

216 lines
4.0 KiB

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