鸿宇研学生前端代码
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.

174 lines
3.7 KiB

  1. <template>
  2. <view class="page__view">
  3. <navbar title="选择出行人" leftClick @leftClick="$utils.navigateBack" color="#191919" bgColor="#FFFFFF" />
  4. <view class="main">
  5. <uv-checkbox-group v-model="selectedIdList" placement="column">
  6. <view class="card" v-for="item in list" :key="item.id">
  7. <travelerCard
  8. :data="item"
  9. @defaultChange="onDefaultChange(item.id, $event)"
  10. @edit="onEdit(item.id)"
  11. @delete="onDelete(item.id)"
  12. ></travelerCard>
  13. </view>
  14. </uv-checkbox-group>
  15. </view>
  16. <view class="flex bottom">
  17. <button class="btn" @click="onAdd">添加出行人</button>
  18. </view>
  19. <travelerPopup ref="travelerPopup" @submitted="getData"></travelerPopup>
  20. </view>
  21. </template>
  22. <script>
  23. import mixinsList from '@/mixins/list.js'
  24. import travelerCard from './travelerCard.vue'
  25. import travelerPopup from './travelerPopup.vue'
  26. export default {
  27. mixins: [mixinsList],
  28. components: {
  29. travelerCard,
  30. travelerPopup,
  31. },
  32. data() {
  33. return {
  34. mixinsListApi: 'queryTouristList',
  35. queryParams: {
  36. pageNo: 1,
  37. pageSize: 10,
  38. },
  39. selectedIdList: [],
  40. }
  41. },
  42. onLoad(arg) {
  43. const { selectIds } = arg
  44. this.selectedIdList = selectIds?.split?.(',')?.filter(val => val) || []
  45. this.getData()
  46. },
  47. onUnload() {
  48. const list = this.selectedIdList.map(id => this.list.find(item => item.id === id))
  49. this.$store.commit('setTravelerList', list)
  50. },
  51. methods: {
  52. getDataThen(records) {
  53. this.list = records.map(item => {
  54. return {
  55. ...item,
  56. isDefault: item.isDefault == '1' ? true : false
  57. }
  58. })
  59. },
  60. async onDefaultChange(id, val) {
  61. try {
  62. const params = {
  63. id,
  64. isDefault: val ? '1' : '0',
  65. }
  66. await this.$fetch('updateTourist', params)
  67. target.isDefault = val
  68. } catch (err) {
  69. }
  70. },
  71. async onDelete(id) {
  72. uni.showToast({
  73. icon: 'none',
  74. title: '该功能待对接接口',
  75. });
  76. return
  77. uni.showToast({
  78. icon: 'loading',
  79. title: '正在删除',
  80. });
  81. try {
  82. // todo: check api & key
  83. // await this.$fetch('deleteTourist', { id })
  84. uni.showToast({
  85. icon: 'success',
  86. title: '删除成功',
  87. });
  88. this.getData()
  89. } catch (err) {
  90. }
  91. },
  92. onEdit(id) {
  93. this.$refs.travelerPopup.open(id)
  94. },
  95. onAdd() {
  96. this.$refs.travelerPopup.open()
  97. },
  98. },
  99. }
  100. </script>
  101. <style scoped lang="scss">
  102. .page__view {
  103. width: 100vw;
  104. min-height: 100vh;
  105. background: $uni-bg-color;
  106. position: relative;
  107. /deep/ .nav-bar__view {
  108. position: fixed;
  109. top: 0;
  110. left: 0;
  111. }
  112. }
  113. .main {
  114. padding: calc(var(--status-bar-height) + 160rpx) 40rpx 254rpx 40rpx;
  115. }
  116. .card {
  117. & + & {
  118. margin-top: 40rpx;
  119. }
  120. }
  121. .bottom {
  122. position: fixed;
  123. left: 0;
  124. bottom: 0;
  125. align-items: flex-start;
  126. width: 100vw;
  127. // height: 214rpx;
  128. padding: 32rpx 40rpx;
  129. padding-bottom: calc(env(safe-area-inset-bottom) + 32rpx);
  130. background: #FFFFFF;
  131. box-sizing: border-box;
  132. .btn {
  133. width: 100%;
  134. padding: 14rpx 0;
  135. box-sizing: border-box;
  136. font-family: PingFang SC;
  137. font-weight: 500;
  138. font-size: 36rpx;
  139. line-height: 1.4;
  140. color: #FFFFFF;
  141. background-image: linear-gradient(to right, #21FEEC, #019AF9);
  142. border: 2rpx solid #00A9FF;
  143. border-radius: 41rpx;
  144. }
  145. }
  146. </style>