1. //wxss
    2. <view class='quest_container' wx:for="{{quest}}" wx:key="id" wx:for-index="outterIndex">
    3. <!-- {{item.type==1?'(单选)':'(多选)'}} -->
    4. <text class="quest_containerName">{{item.question}}</text>
    5. <view wx:for="{{item.answers}}" wx:key="content" bindtap="answerSelected" data-outidx='{{outterIndex}}' data-idx="{{index}}" class="item {{item.selected?'active':''}}">
    6. <text>{{item.index}}.</text>
    7. <text>{{item.content}}</text>
    8. </view>
    9. <view class="quest_containerImage" wx:if="{{item.image}}">
    10. <image src="{{item.image}}" mode="" />
    11. </view>
    12. </view>
    13. <view class="submit_btn" bindtap="submit">提交</view>
    1. //js
    2. const app = getApp()
    3. const {
    4. $Toast
    5. } = require('../../dist/base/index');
    6. Page({
    7. /**
    8. * 页面的初始数据
    9. */
    10. data: {
    11. Custom: {},
    12. quest: [{
    13. id: 1,
    14. type: 1, //类型,1.单选,2.多选
    15. question: "1.发现有人倒地无反应,你的反应是?",
    16. answers: [{
    17. index: 'A',
    18. content: '不知道,没学过急救知识'
    19. }, {
    20. index: 'B',
    21. content: '拨打120后等待医护人员到场'
    22. },
    23. {
    24. index: 'C',
    25. content: '拨打120后评估病情进行及时急救措施'
    26. }],
    27. correctAnswer: 'C',
    28. scope: 10,
    29. }, {
    30. id: 2,
    31. type: 1,
    32. question: "2.如何判断一个倒地患者是否发生心跳骤停?",
    33. answers: [{
    34. index: 'A',
    35. content: '不知道'
    36. }, {
    37. index: 'B',
    38. content: '拍打肩膀、掐肩膀并大声询问无反应,确定有无意识、判断有无呼吸'
    39. }, {
    40. index: 'C',
    41. content: '掐人中,如果没有反应就是心脏骤停'
    42. }],
    43. correctAnswer: 'B',
    44. scope: 10,
    45. }, {
    46. id: 3,
    47. type: 1,
    48. question: "3.如图所示,您认为胸外按压的部位为?",
    49. image: '/image/dati/xinzhangtu.png',
    50. answers: [{
    51. index: 'A',
    52. content: '不知道'
    53. }, {
    54. index: 'B',
    55. content: '两乳头连线中点(B)'
    56. }, {
    57. index: 'C',
    58. content: '剑突上1/3(A)'
    59. }],
    60. correctAnswer: 'B',
    61. scope: 10,
    62. }, {
    63. id: 4,
    64. type: 1,
    65. question: "4.胸外按压的频率是每分钟多少次?",
    66. answers: [{
    67. index: 'A',
    68. content: '不知道'
    69. }, {
    70. index: 'B',
    71. content: '100-120次'
    72. }, {
    73. index: 'C',
    74. content: '100以下'
    75. }],
    76. correctAnswer: 'B',
    77. scope: 10,
    78. }, {
    79. id: 5,
    80. type: 1,
    81. question: "5.成人心肺复苏时,胸外按压的深度为?",
    82. answers: [{
    83. index: 'A',
    84. content: '不知道'
    85. }, {
    86. index: 'B',
    87. content: '5~6cm'
    88. }, {
    89. index: 'C',
    90. content: '<5cm'
    91. }],
    92. correctAnswer: 'B',
    93. scope: 10,
    94. }, {
    95. id: 6,
    96. type: 1,
    97. question: "6.心脏骤停的病人实施胸外按压与人工呼吸的比例为?",
    98. answers: [{
    99. index: 'A',
    100. content: '不知道'
    101. }, {
    102. index: 'B',
    103. content: '30次按压然后2次吹气'
    104. }, {
    105. index: 'C',
    106. content: '15次按压然后1次吹气'
    107. }],
    108. correctAnswer: 'B',
    109. scope: 10,
    110. }, {
    111. id: 7,
    112. type: 1,
    113. question: "7.你会使用自动除颤仪AED?",
    114. image: '/image/dati/ti2.png',
    115. answers: [{
    116. index: 'A',
    117. content: '没有见过,不知道怎么做'
    118. }, {
    119. index: 'B',
    120. content: '已经学会使用'
    121. }, {
    122. index: 'C',
    123. content: '有见过,不会使用'
    124. }],
    125. correctAnswer: 'B',
    126. scope: 10,
    127. }, {
    128. id: 8,
    129. type: 1,
    130. question: "8.遇到面色苍白、大汗淋漓的胸痛病人,应该?",
    131. answers: [{
    132. index: 'A',
    133. content: '不知道'
    134. }, {
    135. index: 'B',
    136. content: '知道,立即卧床安静 、不随意搬动、迅速拨打“120”、含服硝酸甘油或者速效救心丸'
    137. }, {
    138. index: 'C',
    139. content: '让他自己走路活动一下,看能否缓解'
    140. }],
    141. correctAnswer: 'B',
    142. scope: 10,
    143. },
    144. {
    145. id: 9,
    146. type: 1,
    147. question: "9.对于出现昏迷不醒的伤者,应该?",
    148. answers: [{
    149. index: 'A',
    150. content: '不知道'
    151. }, {
    152. index: 'B',
    153. content: '知道,立即卧床安静 、不随意搬动、迅速拨打“120”、含服硝酸甘油或者速效救心丸'
    154. }, {
    155. index: 'C',
    156. content: '让他自己走路活动一下,看能否缓解'
    157. }],
    158. correctAnswer: 'B',
    159. scope: 10,
    160. },
    161. {
    162. id: 10,
    163. type: 1,
    164. question: "10.是否知道脑血管意外病人的FAST识别原则?",
    165. answers: [{
    166. index: 'A',
    167. content: '不知道'
    168. }, {
    169. index: 'B',
    170. content: '立即心肺复苏'
    171. }, {
    172. index: 'C',
    173. content: '知道,Face/面瘫、Arm/偏瘫、Speech/言语不清、Time/尽快到医院'
    174. }],
    175. correctAnswer: 'C',
    176. scope: 10,
    177. }
    178. ]
    179. },
    180. // 点击问题答案触发事件
    181. answerSelected(e) {
    182. console.log("我的选择", e)
    183. let outidx = e.currentTarget.dataset.outidx;
    184. let idx = e.currentTarget.dataset.idx;
    185. let question = this.data.quest[outidx];
    186. if (question.type == 1) {
    187. //单选
    188. for (let item of question.answers) {
    189. item.selected = false;
    190. }
    191. question.answers[idx].selected = true;
    192. console.log('数据:::', question)
    193. this.setData({
    194. quest: this.data.quest
    195. });
    196. } else if (question.type == 2) {
    197. //多选
    198. question.answers[idx].selected = !question.answers[idx].selected;
    199. this.setData({
    200. quest: this.data.quest
    201. });
    202. }
    203. },
    204. submit() {
    205. let {
    206. quest
    207. } = this.data;
    208. let totalScope = 0; //记录分数
    209. //用来保存选中的答案
    210. let answerSelected = [];
    211. for (let questItem of quest) {
    212. if (questItem.type == 1) { //处理单选题
    213. let isSelected = false;
    214. for (let answerItem of questItem.answers) {
    215. if (answerItem.selected) {
    216. //答案被选中
    217. isSelected = true;
    218. console.log('选中的答案', answerItem)
    219. answerSelected.push(answerItem.index);
    220. }
    221. }
    222. if (!isSelected) {
    223. //如果一个都没选
    224. answerSelected.push('');
    225. console.log('测试', isSelected)
    226. this.handleWarning('请检查题目是否做完')
    227. }
    228. } else { //处理多选题
    229. let multiAnswer = [];
    230. for (let answerItem of questItem.answers) {
    231. if (answerItem.selected) {
    232. //答案被选中
    233. multiAnswer.push(answerItem.index);
    234. }
    235. }
    236. answerSelected.push(multiAnswer.join(''));
    237. }
    238. totalScope += questItem.correctAnswer == answerSelected[answerSelected.length - 1] ? questItem.scope : 0;
    239. }
    240. console.log(answerSelected);
    241. console.log(totalScope);
    242. },
    243. // 弹窗
    244. handleWarning(text) {
    245. $Toast({
    246. content: text,
    247. type: 'warning'
    248. });
    249. },
    250. /**
    251. * 生命周期函数--监听页面加载
    252. */
    253. onLoad: function (options) {
    254. this.setData({
    255. Custom: app.globalData.Custom
    256. })
    257. },
    258. /**
    259. * 生命周期函数--监听页面初次渲染完成
    260. */
    261. onReady: function () {
    262. },
    263. /**
    264. * 生命周期函数--监听页面显示
    265. */
    266. onShow: function () {
    267. },
    268. /**
    269. * 生命周期函数--监听页面隐藏
    270. */
    271. onHide: function () {
    272. },
    273. /**
    274. * 生命周期函数--监听页面卸载
    275. */
    276. onUnload: function () {
    277. },
    278. /**
    279. * 页面相关事件处理函数--监听用户下拉动作
    280. */
    281. onPullDownRefresh: function () {
    282. },
    283. /**
    284. * 页面上拉触底事件的处理函数
    285. */
    286. onReachBottom: function () {
    287. },
    288. /**
    289. * 用户点击右上角分享
    290. */
    291. onShareAppMessage: function () {
    292. }
    293. })
    //less
    
    .headeDemo {
        position: fixed;
        top: 0px;
        background: #fff;
        z-index: 999;
        display: flex;
        align-items: center;
        justify-content: center;
    } 
    
    .questions{
        width: 100%;
    }
    
    .quest_container {
        padding: 20rpx;
      }
    
      .quest_containerName{
        font-size: 32rpx;
        font-weight: bold;
      }
    
      .item {
        margin-top: 32rpx;
      }
    
      .active {
        color: red;
      }
    
      .submit_btn {
        background: #00a050;
        color: white;
        margin: 50rpx;
        padding: 25rpx;
        border-radius: 10rpx;
        text-align: center;
      }
    
      .quest_containerImage{
          width: 100%;
          display: flex;
          justify-content: center;
          margin-top: 20rpx;
    
        image{
            width: 560rpx;
        }
      }