addressBook.vue 5.8 KB

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