猫妈狗爸伴宠师小程序前端代码
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.

144 lines
2.9 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
  1. <template>
  2. <popupSelect
  3. ref="popupRef"
  4. title="请选择增值服务"
  5. @confirm="onConfirm"
  6. >
  7. <view class="content">
  8. <view class="flex-between option"
  9. v-for="(option, index) in increaseServiceOptions"
  10. :key="index"
  11. @click="onSelectServe(option.id)"
  12. >
  13. <view class="option-info"
  14. v-if="option && isNeedCertificate(option.needCertificate)">
  15. <view class="option-title">{{ option.title }}</view>
  16. <view class="option-desc">{{ option.detail }}</view>
  17. </view>
  18. <up-icon
  19. v-if="option && isNeedCertificate(option.needCertificate)"
  20. name="checkmark-circle-fill"
  21. :color="serves.includes(option.id) ? '#FFBF60' : '#BDBDBD'"
  22. size="46rpx"
  23. ></up-icon>
  24. </view>
  25. </view>
  26. </popupSelect>
  27. </template>
  28. <script setup>
  29. import { ref, computed } from 'vue'
  30. import { useStore } from 'vuex'
  31. import popupSelect from '../components/popupSelect.vue';
  32. const store = useStore()
  33. const props = defineProps({
  34. modelValue: {
  35. type: Array,
  36. default() {
  37. return []
  38. }
  39. },
  40. certificate: {
  41. type: String,
  42. default: ''
  43. }
  44. })
  45. const emit = defineEmits(['update:modelValue', 'confirm'])
  46. const serves = ref([])
  47. const increaseServiceOptions = computed(() => {
  48. return store.getters.increaseServiceOptions || []
  49. })
  50. const onSelectServe = (serve) => {
  51. const oldServes = serves.value
  52. let newServes = []
  53. if (oldServes.includes(serve)) {
  54. newServes = oldServes.filter(item => item !== serve)
  55. } else {
  56. newServes = oldServes.concat(serve)
  57. }
  58. serves.value = newServes
  59. }
  60. function isNeedCertificate(needCertificate) {
  61. if (!needCertificate || typeof needCertificate !== 'string') {
  62. return true
  63. }
  64. let a = false
  65. const needCertificateArr = needCertificate.split(';')
  66. const certificateArr = props.certificate ? props.certificate.split(';') : []
  67. needCertificateArr.forEach(item => {
  68. if (certificateArr.includes(item)) {
  69. a = true
  70. }
  71. })
  72. return a
  73. }
  74. const popupRef = ref()
  75. const open = () => {
  76. store.dispatch('fetchIncreaseServiceOptions')
  77. serves.value = props.modelValue
  78. popupRef.value.open()
  79. }
  80. const close = () => {
  81. popupRef.value.close()
  82. }
  83. const onConfirm = () => {
  84. emit('update:modelValue', serves.value)
  85. emit('confirm')
  86. }
  87. defineExpose({ open, close })
  88. </script>
  89. <style lang="scss" scoped>
  90. .content {
  91. padding-bottom: 25rpx;
  92. }
  93. .option {
  94. padding: 0 49rpx 0 25rpx;
  95. background-color: #FFF5E5;
  96. border-radius: 8rpx;
  97. & + & {
  98. margin-top: 12rpx;
  99. }
  100. &-info {
  101. padding: 7rpx 0 13rpx 0;
  102. }
  103. &-title {
  104. color: #000000;
  105. font-size: 28rpx;
  106. line-height: 37rpx;
  107. }
  108. &-desc {
  109. margin-top: 12rpx;
  110. color: #707070;
  111. font-size: 20rpx;
  112. line-height: 26rpx;
  113. }
  114. }
  115. </style>