ques.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="ques-content" :style="{ fontSize: fontSize(28)}">
  3. <view class="ques-flex" v-if="openCommentStatus!=1" :style="{justifyContent:showTreatment==0 || (showNote==1&&courseNote)?'space-around':'flex-start'}">
  4. <view class="ques-content-tit" :style="{ color: currentId==0&&showNote==1&&courseNote ? '#FF5C03':'#222',fontSize: fontSize(36)}" @click="choose(0)">问答题</view>
  5. <view class="ques-content-tit" v-if="showTreatment==0" :style="{ color: currentId==2? '#FF5C03':'#222',fontSize: fontSize(36)}" @click="choose(2)">活动</view>
  6. <view class="ques-content-tit" v-if="showNote==1&&courseNote" :style="{ color: currentId==1 ? '#FF5C03':'#222',fontSize: fontSize(36)}" @click="choose(1)">笔记</view>
  7. </view>
  8. <view v-if="currentId==1&&showNote==1&&courseNote" class="note" :style="{ fontSize: fontSize(32)}">{{courseNote}}</view>
  9. <template v-if="currentId==2&&showTreatment==0">
  10. <goodsList ref="goodsList" :treatmentPackage="treatmentPackage" :urlOption="urlOption"></goodsList>
  11. </template>
  12. <template v-if="currentId==0">
  13. <view v-for="(item,index) in quesList" :key="index">
  14. <view class="ques-title" :style="{ fontSize: fontSize(32)}">
  15. <text>{{index + 1}}.</text>
  16. <view class="ques-type" :style="{ fontSize: fontSize(24)}" v-show="item.type == 1 || item.type == 2">
  17. {{item.type == 1 ? '单选' : item.type == 2 ? '多选' : ''}}
  18. </view>
  19. <text>{{item.title}}</text>
  20. </view>
  21. <view :class="isAnswer(item,option.name) ?'ques-option ques-option-active':'ques-option'"
  22. v-for="(option,idx) in item.questionOption" :key="idx" @click="handleAnswer(item,option,index)">
  23. <view>
  24. {{numberToLetter(idx)}}.
  25. </view>
  26. <view>{{option.name}}</view>
  27. </view>
  28. </view>
  29. <view class="empty" v-if="quesList&&quesList.length==0">暂未设置题目~</view>
  30. </template>
  31. </view>
  32. </template>
  33. <script>
  34. import goodsList from "./goodsList.vue"
  35. export default {
  36. components: {
  37. goodsList
  38. },
  39. props: ['quesList','openCommentStatus','courseNote','showNote','showTreatment','treatmentPackage','urlOption'],
  40. data() {
  41. return {
  42. currentId: 0
  43. }
  44. },
  45. computed: {
  46. fontSize() {
  47. return size=>{
  48. const value = uni.upx2px(size)
  49. const scale = uni.getStorageSync('fontScale') || 1;
  50. if(scale<1){
  51. return value + 'px';
  52. }else {
  53. return value * scale + 'px';
  54. }
  55. }
  56. },
  57. isAnswer() {
  58. return (item, name) => {
  59. if (item.type == 1) {
  60. return item.answer == name
  61. } else if (item.type == 2) {
  62. const array = item.answer.split(',')
  63. return array.some(i => i == name)
  64. } else {
  65. return false
  66. }
  67. }
  68. }
  69. },
  70. methods: {
  71. numberToLetter(num) {
  72. // 将数字转换为字母的 ASCII 码
  73. let letterCode = num + 65;
  74. // 将 ASCII 码转换为大写字母
  75. let letter = String.fromCharCode(letterCode);
  76. return letter;
  77. },
  78. handleAnswer(item, option,index) {
  79. const param = {
  80. item,
  81. option,
  82. index
  83. }
  84. this.$emit("handleAnswer", param)
  85. },
  86. choose(type) {
  87. this.currentId=type
  88. this.$emit("showBtnType", type)
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. @mixin u-flex($flexD, $alignI, $justifyC) {
  95. display: flex;
  96. flex-direction: $flexD;
  97. align-items: $alignI;
  98. justify-content: $justifyC;
  99. }
  100. .ques-flex {
  101. // justify-content: space-around
  102. @include u-flex(row, center, space-around);
  103. }
  104. .note{
  105. padding: 30rpx 0;
  106. }
  107. .empty {
  108. @include u-flex(row, center, center);
  109. padding: 24rpx 50rpx;
  110. color: #999999;
  111. }
  112. .ques-content {
  113. background-color: #fff;
  114. padding: 24rpx 32rpx 24rpx 32rpx;
  115. box-sizing: border-box;
  116. font-family: PingFang SC, PingFang SC;
  117. font-weight: 400;
  118. font-size: 28rpx;
  119. color: #222222;
  120. }
  121. .ques-content-tit {
  122. font-family: PingFang SC, PingFang SC;
  123. font-weight: 600;
  124. font-size: 36rpx;
  125. color: #222222;
  126. }
  127. .ques-title {
  128. margin: 48rpx 0 34rpx 0;
  129. font-weight: 500;
  130. font-size: 32rpx;
  131. white-space: normal;
  132. }
  133. .ques-type {
  134. flex-shrink: 0;
  135. min-width: 72rpx;
  136. min-height: 40rpx;
  137. padding: 0 12rpx;
  138. margin: 0 12rpx;
  139. box-sizing: border-box;
  140. background: #FF5C03;
  141. border-radius: 8rpx 8rpx 8rpx 8rpx;
  142. line-height: 40rpx;
  143. text-align: center;
  144. font-family: PingFang SC, PingFang SC;
  145. font-weight: 400;
  146. font-size: 24rpx;
  147. color: #FFFFFF;
  148. display: inline-block;
  149. }
  150. .ques-option {
  151. min-height: 88rpx;
  152. padding: 24rpx 32rpx;
  153. box-sizing: border-box;
  154. margin-bottom: 24rpx;
  155. background: #F5F7FA;
  156. border-radius: 16rpx 16rpx 16rpx 16rpx;
  157. display: flex;
  158. align-items: center;
  159. &-active {
  160. color: #FF5C03 !important;
  161. background: #FCF0E7 !important;
  162. }
  163. }
  164. </style>