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

171 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. // todo: transform periodId to type and type desc
  57. type: 0, // 0-成人 1-青少年 2-儿童
  58. isDefault: item.isDefault == '1' ? true : false
  59. }
  60. })
  61. },
  62. async onDefaultChange(id, val) {
  63. try {
  64. const params = {
  65. id,
  66. isDefault: val ? '1' : '0',
  67. }
  68. await this.$fetch('updateTourist', params)
  69. target.isDefault = val
  70. } catch (err) {
  71. }
  72. },
  73. async onDelete(id) {
  74. uni.showToast({
  75. icon: 'loading',
  76. title: '正在删除',
  77. });
  78. try {
  79. // todo: check api & key
  80. // await this.$fetch('deleteTourist', { id })
  81. uni.showToast({
  82. icon: 'success',
  83. title: '删除成功',
  84. });
  85. this.getData()
  86. } catch (err) {
  87. }
  88. },
  89. onEdit(id) {
  90. this.$refs.travelerPopup.open(id)
  91. },
  92. onAdd() {
  93. this.$refs.travelerPopup.open()
  94. },
  95. },
  96. }
  97. </script>
  98. <style scoped lang="scss">
  99. .page__view {
  100. width: 100vw;
  101. min-height: 100vh;
  102. background: $uni-bg-color;
  103. position: relative;
  104. /deep/ .nav-bar__view {
  105. position: fixed;
  106. top: 0;
  107. left: 0;
  108. }
  109. }
  110. .main {
  111. padding: calc(var(--status-bar-height) + 160rpx) 40rpx 254rpx 40rpx;
  112. }
  113. .card {
  114. & + & {
  115. margin-top: 40rpx;
  116. }
  117. }
  118. .bottom {
  119. position: fixed;
  120. left: 0;
  121. bottom: 0;
  122. align-items: flex-start;
  123. width: 100vw;
  124. // height: 214rpx;
  125. padding: 32rpx 40rpx;
  126. padding-bottom: calc(env(safe-area-inset-bottom) + 32rpx);
  127. background: #FFFFFF;
  128. box-sizing: border-box;
  129. .btn {
  130. width: 100%;
  131. padding: 14rpx 0;
  132. box-sizing: border-box;
  133. font-family: PingFang SC;
  134. font-weight: 500;
  135. font-size: 36rpx;
  136. line-height: 1.4;
  137. color: #FFFFFF;
  138. background-image: linear-gradient(to right, #21FEEC, #019AF9);
  139. border: 2rpx solid #00A9FF;
  140. border-radius: 41rpx;
  141. }
  142. }
  143. </style>