ques.vue 4.7 KB

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