建材商城系统20241014
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.

217 lines
4.1 KiB

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