list.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="container">
  3. <view class="main">
  4. <fs-card gutter v-for="item in list" :key="item.id">
  5. <view class="layout-box">
  6. <view class="title">{{item.name}} {{item.phone}}</view>
  7. <view class="content">{{item.address}}</view>
  8. </view>
  9. <template #footer>
  10. <view class="flex justify-between align-center">
  11. <fs-radio-group v-model="item.default" v-if="item.default == 1">
  12. <fs-radio label="默认地址" value="1" checked></fs-radio>
  13. </fs-radio-group>
  14. <fs-radio-group v-else @change="setDefaultAddress(item)">
  15. <fs-radio label="设为默认地址" value="1"></fs-radio>
  16. </fs-radio-group>
  17. <view class="flex align-center">
  18. <view class="flex align-center" @click="handleEdit(item)">
  19. <fs-icon type="icon-edit"></fs-icon>
  20. <view>编辑</view>
  21. </view>
  22. <view class="flex align-center" style="margin-left: 30rpx;" @click="handleDel(item)">
  23. <fs-icon type="icon-del"></fs-icon>
  24. <view>删除</view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. </fs-card>
  30. <fs-empty v-if="!list.length && loaded"></fs-empty>
  31. </view>
  32. <fs-modal
  33. v-model="visible"
  34. content="您确定要删除该地址吗"
  35. :beforeClose="beforeClose">
  36. </fs-modal>
  37. <view class="layout-box">
  38. <fs-button block round link="./add">添加地址</fs-button>
  39. </view>
  40. </view>
  41. </template>
  42. <script setup>
  43. import { ref } from 'vue'
  44. const list = ref([])
  45. const loaded = ref(false)
  46. let visible = ref(false)
  47. setTimeout(() => {
  48. list.value = [
  49. {
  50. name: '陈女士',
  51. phone: '18734354541',
  52. address: '山西省太原市小店区晋阳街和泰花园南区5-2-1006',
  53. default: '1',
  54. id: 1
  55. },
  56. {
  57. name: '王先生',
  58. phone: '18734354542',
  59. address: '山西省太原市小店区晋阳街和泰花园南区5-2-1006',
  60. default: '0',
  61. id: 2
  62. }
  63. ]
  64. loaded.value = true
  65. }, 0)
  66. const setDefaultAddress = (item) => {
  67. list.value.forEach(address => {
  68. if(address.id === item.id) {
  69. address.default = '1'
  70. } else {
  71. address.default = '0'
  72. }
  73. })
  74. }
  75. const handleEdit = item => {
  76. getApp().globalData.addressDetail = item
  77. uni.navigateTo({
  78. url: './add'
  79. })
  80. }
  81. // 删除相关逻辑
  82. let addressItem = ref({})
  83. const handleDel = item => {
  84. visible.value = true
  85. addressItem.value = item
  86. }
  87. const beforeClose = (action, done) => {
  88. setTimeout(() => {
  89. done()
  90. }, 2000)
  91. }
  92. </script>
  93. <style lang="scss">
  94. page{
  95. height: 100%;
  96. }
  97. </style>