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

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