addressBook.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <!-- 地址簿 -->
  3. <view>
  4. <u-navbar title="地址簿" autoBack placeholder></u-navbar>
  5. <!-- <view class="card_ship">
  6. <view class="addres_title" :class="pickUpFlag ? 'pitch' : ''" @click="pickUp('sender')">寄件地址</view>
  7. <view class="line_title">|</view>
  8. <view class="addres_title" :class="!pickUpFlag ? 'pitch' : ''" @click="pickUp('consignee')">收件地址</view>
  9. </view> -->
  10. <u-sticky :customNavHeight="navbarHeight()">
  11. <view class="search_card">
  12. <u-search :showAction="false" v-model="keyword" @change="searchChange"
  13. placeholder="输入关键字快速查找"></u-search>
  14. </view>
  15. </u-sticky>
  16. <view class="address_book" v-if="list.length > 0">
  17. <view class="card_item_address" v-for="(item,index) in list" :key="index" @click="selectAddress(item)">
  18. <view class="address_border">
  19. <view class="head_title">
  20. <view class="title_name">{{item.name}}</view>
  21. <view class="title_name">{{item.phone}}</view>
  22. </view>
  23. <view class="title_address">{{item.address}}</view>
  24. </view>
  25. <view class="keepRight">
  26. <view class="flex_row" @click.stop="redact(item)">
  27. <u-icon name="edit-pen" color="#82848a" size="22" style="margin-right: 10rpx;"></u-icon>
  28. 编辑
  29. </view>
  30. <view class="flex_row" @click.stop="delAddress(item)">
  31. <u-icon name="trash" color="#82848a" size="22" style="margin-right: 10rpx;"></u-icon>
  32. 删除
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view style="margin-top: 20%;" v-else>
  38. <u-empty mode="address" text="暂无地址"></u-empty>
  39. </view>
  40. <view style="width: 100%;height: 150rpx;"></view>
  41. <view class="btn_print" @click="addAddress(pickUpFlag)">
  42. <u-button type="primary" text="新增地址" shape="circle"></u-button>
  43. </view>
  44. <u-modal :show="modalShow" showCancelButton :content='reminder' @confirm="confirm"
  45. @cancel="modalShow = false"></u-modal>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. pickUpFlag: false,
  53. keyword: '',
  54. list: [],
  55. operationType: 'consignee',
  56. stateType: true,
  57. PageIndex: 1,
  58. PageSize: 10,
  59. modalShow: false,
  60. reminder: '您确定要删除该地址信息吗?',
  61. loadingMore: true,
  62. addressId: null,
  63. }
  64. },
  65. onReachBottom() {
  66. if (!this.loadingMore) {
  67. this.getList()
  68. }
  69. },
  70. onShow() {
  71. if (this.operationType) {
  72. this.PageIndex = 1
  73. this.list = []
  74. this.loadingMore = true
  75. this.getList()
  76. }
  77. },
  78. onLoad(value) {
  79. // if (value.type) {
  80. // if (value.type == 'sender') {
  81. // this.pickUpFlag = true
  82. // } else {
  83. // this.pickUpFlag = false
  84. // }
  85. // this.operationType = value.type
  86. // this.stateType = true
  87. // } else {
  88. // this.operationType = 'sender'
  89. // this.stateType = false
  90. // }
  91. },
  92. methods: {
  93. // 搜索
  94. searchChange(value) {
  95. this.PageIndex = 1
  96. this.list = []
  97. this.loadingMore = true
  98. this.getList()
  99. },
  100. getList() {
  101. this.loadingMore = true;
  102. this.$api.get('/api/address', {
  103. page: this.PageIndex,
  104. pageSize: this.PageSize,
  105. name: this.keyword,
  106. addressType: this.operationType,
  107. }).then(res => {
  108. if (res.code == 200) {
  109. const data = res.data.list
  110. if (this.loadingMore == true && data) {
  111. this.list = this.list.concat(data);
  112. }
  113. if (data.length < this.PageSize) {
  114. this.loadingMore = true
  115. } else {
  116. this.loadingMore = false
  117. this.PageIndex++
  118. }
  119. }
  120. })
  121. },
  122. pickUp(type) {
  123. this.PageIndex = 1
  124. this.list = []
  125. this.loadingMore = true
  126. this.operationType = type
  127. if (type == 'sender') {
  128. this.pickUpFlag = true
  129. } else if (type == 'consignee') {
  130. this.pickUpFlag = false
  131. }
  132. this.getList()
  133. },
  134. // 新增地址
  135. addAddress() {
  136. uni.navigateTo({
  137. url: '/pages/order/addAddress?type=' + this.operationType + '&newly=true'
  138. });
  139. },
  140. // 编辑
  141. redact(row) {
  142. uni.setStorageSync('currentAddress', row)
  143. uni.navigateTo({
  144. url: '/pages/order/addAddress?type=' + this.operationType + '&newly=false'
  145. });
  146. },
  147. // 删除
  148. delAddress(row) {
  149. this.modalShow = true
  150. this.addressId = row.id
  151. },
  152. // 确定删除
  153. confirm() {
  154. this.$api.delete('/api/address', {
  155. id: this.addressId,
  156. }).then(res => {
  157. if (res.code == 200) {
  158. this.modalShow = false
  159. uni.showLoading({
  160. icon: 'success',
  161. title: '删除成功'
  162. });
  163. this.PageIndex = 1
  164. this.list = []
  165. this.loadingMore = true
  166. this.getList()
  167. setTimeout(function() {
  168. uni.hideLoading();
  169. }, 1000);
  170. }
  171. })
  172. },
  173. // 选择地址
  174. selectAddress(row) {
  175. if (this.stateType) {
  176. uni.setStorageSync('selectAddress', row)
  177. uni.navigateBack({
  178. delta: 1
  179. });
  180. }
  181. },
  182. navbarHeight() {
  183. let systemInfo = uni.getSystemInfoSync();
  184. /* (750 / systemInfo.windowWidth) */
  185. /* 在uview navBar组件中有一个默认高度,当这个默认高度加上状态栏高度后就是吸顶的位置,由于这两者相加是px,所以最后还需要转为rpx */
  186. let topHeight = 0
  187. // #ifdef APP-PLUS
  188. topHeight = 44 + systemInfo.statusBarHeight;
  189. // #endif
  190. // #ifdef MP
  191. let height = systemInfo.platform == 'ios' ? 44 : 48;
  192. topHeight = height + systemInfo.statusBarHeight
  193. // #endif
  194. /* 最后一步将px转为rpx */
  195. return topHeight * (750 / systemInfo.windowWidth) / 2
  196. },
  197. },
  198. }
  199. </script>
  200. <style lang="scss">
  201. .card_ship {
  202. display: flex;
  203. justify-content: space-evenly;
  204. align-items: center;
  205. background-color: #fff;
  206. padding: 20rpx 0rpx;
  207. }
  208. .line_title {
  209. color: #c8c9cc;
  210. }
  211. .addres_title {
  212. font-size: 30rpx;
  213. padding-bottom: 10rpx;
  214. border-bottom: 4rpx solid #fff;
  215. }
  216. .search_card {
  217. background-color: #fff;
  218. padding: 20rpx;
  219. }
  220. .pitch {
  221. font-weight: 500;
  222. color: #2979ff;
  223. border-bottom: 4rpx solid #2979ff;
  224. }
  225. .address_book {
  226. margin-top: 20rpx;
  227. display: flex;
  228. flex-direction: column;
  229. }
  230. .card_item_address {
  231. margin: 0rpx 20rpx 20rpx 20rpx;
  232. background-color: #fff;
  233. border-radius: 10rpx;
  234. padding: 20rpx 0rpx;
  235. }
  236. .address_border {
  237. padding: 0rpx 20rpx;
  238. padding-bottom: 30rpx;
  239. border-bottom: 2rpx solid #f4f4f5;
  240. }
  241. .head_title {
  242. display: flex;
  243. margin-bottom: 10rpx;
  244. }
  245. .title_address {
  246. font-size: 28rpx;
  247. color: #82848a;
  248. }
  249. .title_name {
  250. font-weight: 600;
  251. font-size: 32rpx;
  252. margin-left: 10rpx;
  253. }
  254. .keepRight {
  255. padding-top: 20rpx;
  256. padding-right: 20rpx;
  257. display: flex;
  258. justify-content: flex-end;
  259. }
  260. .flex_row {
  261. display: flex;
  262. align-items: center;
  263. margin-left: 20rpx;
  264. color: #82848a;
  265. font-size: 30rpx;
  266. }
  267. </style>