From 17efddc6a667670dca682bf36b51a43e99615e6d Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期三, 16 十月 2024 15:59:38 +0800
Subject: [PATCH] 代码初始化

---
 h5/pages/answer/answer.vue |  255 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 210 insertions(+), 45 deletions(-)

diff --git a/h5/pages/answer/answer.vue b/h5/pages/answer/answer.vue
index c589aa3..92d91bb 100644
--- a/h5/pages/answer/answer.vue
+++ b/h5/pages/answer/answer.vue
@@ -6,24 +6,18 @@
     </view>
     <view class="box_list">
       <view class="box_list_answer" v-if="list && list.length > 0">
-        <!--    鍒ゆ柇   -->
-        <!-- 				<template v-if="list[i].type === 0">
-					<view class="box_list_answer_item" v-for="(item, index) in list[i].options" :key="index" @click="select(index)">
-						<image src="@/static/video_error@2x.png" v-if="success && problemIndex === index" />
-						<image src="@/static/video@2x.png" v-else-if="!String(problemIndex) || problemIndex !== index" />
-						<image src="@/static/video_sel@2x.png" v-else-if="problemIndex === index" />
-						<text style="color: rgba(237, 69, 69, 1)" v-if="success && problemIndex === index">{{item.code}}</text>
-						<text v-else-if="!String(problemIndex) || problemIndex !== index">{{item.code}}</text>
-						<text style="color: rgba(2, 94, 239, 1)" v-else-if="problemIndex === index">{{item.code}}</text>
-					</view>
-				</template> -->
-        <!--    鍗曢��   -->
+        <view v-if="status == 1 || status == 2" class="score_static">
+          <text class="name">鏈寰楀垎锛�</text>
+          <text class="num" :class="{ warry: status == 2 }">{{ score }}鍒�</text>
+        </view>
+        <!--    鍗曢��/鍒ゆ柇   -->
         <view v-for="(item, index) in list" :key="index" class="list_item">
-          <template v-if="item.type == 1">
-            <view class="box_list_answer_name">
-              {{ index + 1 }}銆亄{ item.title
-              }}<text style="color: #ed4545">*</text>
-            </view>
+          <view class="box_list_answer_name">
+            <text>{{ index + 1 }}銆亄{ item.title }}</text>
+            <text v-if="item.score"> ({{ item.score }}鍒�)</text>
+            <text style="color: #ed4545">*</text>
+          </view>
+          <template v-if="item.type == 1 || item.type == 0">
             <view
               class="box_list_answer_item"
               v-for="(line, lIndex) in item.options"
@@ -40,7 +34,9 @@
                   (item.selAnswer &&
                     item.answer === item.selAnswer &&
                     item.selAnswer == line.code) ||
-                  item.selAnswer == line.code
+                  (item.selAnswer == line.code && status != '2') ||
+                  (item.answer === item.selAnswer &&
+                    item.selAnswer == line.code)
                 "
               />
               <image
@@ -61,10 +57,12 @@
                   (item.selAnswer &&
                     item.answer === item.selAnswer &&
                     item.selAnswer == line.code) ||
-                  item.selAnswer == line.code
+                  (item.selAnswer == line.code && status != '2') ||
+                  (item.answer === item.selAnswer &&
+                    item.selAnswer == line.code)
                 "
-                style="color: rgba(2, 94, 239, 1)"
-                ><text class="mr24" style="color: rgba(2, 94, 239, 1)">{{
+                style="color: rgba(77, 153, 168, 1)"
+                ><text class="mr24" style="color: rgba(77, 153, 168, 1)">{{
                   line.code
                 }}</text>
                 {{ line.value }}</text
@@ -72,6 +70,7 @@
               <text
                 v-if="
                   item.selAnswer &&
+                  item.selAnswer == line.code &&
                   item.answer !== item.selAnswer &&
                   status == '2'
                 "
@@ -84,17 +83,110 @@
             </view>
             <view
               class="box_list_answer_tips"
-              v-if="item.selAnswer && item.answer !== item.selAnswer && status != '0'"
+              style="margin-bottom: 0rpx"
+              v-if="
+                item.selAnswer &&
+                item.answer !== item.selAnswer &&
+                status != '0'
+              "
             >
-              <image src="@/static/ic_wrong@2x.png" />
-              <text>鍥炵瓟閿欒</text>
+              <view class="line">
+                <image src="@/static/ic_wrong@2x.png" />
+                <text>鍥炵瓟閿欒</text>
+              </view>
+              <view class="line">姝g‘绛旀锛歿{ item.answer }}</view>
             </view>
             <view
               class="box_list_answer_tips"
-              v-if="item.selAnswer && item.answer === item.selAnswer && status != '0'"
+              v-if="
+                item.selAnswer &&
+                item.answer === item.selAnswer &&
+                status != '0'
+              "
             >
-              <image src="@/static/meeting/icon/ic_choose_sel@2x.png" />
-              <text>鍥炵瓟姝g‘</text>
+              <view class="line">
+                <image src="@/static/ic_success@2.png" />
+                <text class="success">鍥炵瓟姝g‘</text>
+              </view>
+            </view>
+          </template>
+          <template v-if="item.type == 2">
+            <view
+              class="box_list_answer_item"
+              v-for="(line, lIndex) in item.options"
+              :key="lIndex"
+              @click="changeBox(index, lIndex)"
+            >
+              <image src="@/static/checkbox@2x.png" v-if="!line.checked" />
+              <image
+                src="@/static/checkbo1x_sel@2x.png"
+                v-if="
+                  (line.checked && status != '2') ||
+                  (item.selAnswer === item.answer && line.checked)
+                "
+              />
+              <image
+                src="@/static/checkbox_wrong@2x.png"
+                v-if="
+                  line.checked &&
+                  item.selAnswer !== item.answer &&
+                  status == '2'
+                "
+              />
+              <text v-if="!line.checked"
+                ><text class="mr24">{{ line.code }}</text>
+                {{ line.value }}</text
+              >
+              <text
+                v-if="
+                  (line.checked && status != '2') ||
+                  (item.selAnswer === item.answer && line.checked)
+                "
+                style="color: rgba(77, 153, 168, 1)"
+                ><text class="mr24" style="color: rgba(77, 153, 168, 1)">{{
+                  line.code
+                }}</text>
+                {{ line.value }}</text
+              >
+              <text
+                v-if="
+                  line.checked &&
+                  item.selAnswer !== item.answer &&
+                  status == '2'
+                "
+                style="color: rgba(237, 69, 69, 1)"
+                ><text class="mr24" style="color: rgba(237, 69, 69, 1)">{{
+                  line.code
+                }}</text>
+                {{ line.value }}</text
+              >
+            </view>
+            <view
+              class="box_list_answer_tips"
+              v-if="
+                item.selAnswer &&
+                item.answer !== item.selAnswer &&
+                status != '0'
+              "
+            >
+              <view class="line">
+                <image src="@/static/ic_wrong@2x.png" />
+                <text>鍥炵瓟閿欒</text>
+              </view>
+              <view class="line">姝g‘绛旀锛歿{ item.answer }}</view>
+            </view>
+            <view
+              class="box_list_answer_tips"
+              v-if="
+                item.selAnswer &&
+                item.answer === item.selAnswer &&
+                status != '0'
+              "
+            >
+              <view class="line">
+                <image src="@/static/ic_success@2.png" />
+                <text class="success">鍥炵瓟姝g‘</text>
+              </view>
             </view>
           </template>
         </view>
@@ -102,6 +194,7 @@
         <view
           v-if="status == '0'"
           class="box_list_answer_btn"
+          :class="{ disable: !answerIng }"
           @click="onSubmit()"
           >鎻愪氦</view
         >
@@ -112,7 +205,7 @@
           v-if="status == '2'"
           style="background-color: #db534c"
           class="box_list_answer_btn"
-          @click="status = '0'"
+          @click="handleAgain"
           >绛旈澶辫触锛屽啀鏉ヤ竴娆�</view
         >
         <!--    澶氶��    -->
@@ -128,7 +221,7 @@
 						<text style="color: rgba(237, 69, 69, 1)"
 							v-if="success && multiple.toString().indexOf(item.code) !== -1">{{item.code}} {{item.value}}</text>
 						<text v-else-if="!multiple || multiple.toString().indexOf(item.code) === -1">{{item.code}} {{item.value}}</text>
-						<text style="color: rgba(2, 94, 239, 1)"
+						<text style="color: rgba(77, 153, 168, 1)"
 							v-else-if="multiple.toString().indexOf(item.code) !== -1">{{item.code}} {{item.value}}</text>
 					</view>
 				</template> -->
@@ -138,21 +231,32 @@
 </template>
 
 <script>
-import { getProblemsVO, getSystemDictData } from '@/api'
+import { getProblemsVO, getSystemDictData, saveProblemsVO } from '@/api'
 export default {
   name: 'answer',
 
   data() {
     return {
       list: [],
-      bg: require("@/static/banner_dati.jpg"),
+      bg: require("@/static/banner_dati.png"),
       title: '',
       content: '',
 
-      status: '0'
+      status: '0',
+      score: 0
     }
   },
-
+  computed: {
+    answerIng() {
+      let count = 0
+      this.list.forEach(item => {
+        if (item.selAnswer || item.selAnswer == 0) {
+          count++
+        }
+      })
+      return count === this.list.length
+    }
+  },
   onLoad() {
     this.getProblems()
     this.getInfo()
@@ -186,16 +290,20 @@
             res.data.forEach(item => {
               // 鍒ゆ柇
               if (item.type === 0) {
-                item.options = [{ code: '姝g‘', value: '姝g‘' }, { code: '閿欒', value: '閿欒' }]
+                item.options = [{ code: '姝g‘' }, { code: '閿欒' }]
               }
               // 鍗曢��/澶氶��
               if (item.type === 1 || item.type === 2) {
                 item.options = JSON.parse(item.options)
               }
+              if (item.type === 2) {
+                item.options.forEach(i => {
+                  i.checked = false
+                })
+              }
               item.status = '0'
               item.selAnswer = null
             })
-            console.log('options', res.data)
             this.list = res.data
           }
           // res.param.problemsDOList.forEach(item => {
@@ -207,12 +315,26 @@
     },
     // 鍗曢�夐�夋嫨涓鐩�
     select(line, i) {
+      if (this.status != '0') return
       this.list.forEach((item, index) => {
         if (index === i) {
           item.selAnswer = line.code
         }
       })
       // this.problemIndex = index
+    },
+    changeBox(index, jeck) {
+      if (this.status != '0') return
+      this.list.forEach((item, i) => {
+        if (index === i) {
+          item.options.forEach((item2, j) => {
+            if (j === jeck) {
+              item2.checked = !item2.checked
+            }
+          })
+          item.selAnswer = item.options.filter(a => a.checked).map(b => b.code).sort().join(',')
+        }
+      })
     },
     sort(arr) {
       arr.sort(function (a, b) {
@@ -242,6 +364,7 @@
     },
     // 涓嬩竴棰�
     onSubmit() {
+      if (!this.answerIng) return
       const { list } = this
       // 楠岃瘉鎵�鏈夐鐩兘鏈夐�夐」
       let count = 0
@@ -261,6 +384,8 @@
       list.forEach(item => {
         if (item.selAnswer !== item.answer) {
           flag++
+        } else {
+          this.score += item.score
         }
       })
       if (flag > 0) {
@@ -273,10 +398,23 @@
         this.status = '1'
       }
     },
+    handleAgain() {
+      this.status = '0'
+      this.score = 0
+      this.getProblems()
+    },
     next() {
-      uni.navigateTo({
-        url: `/pages/userinfo/userinfo`
+      saveProblemsVO({
+        openId: this.$store.state.openId,
+        useType: '1',
+        content: ''
+      }).then(res => {
+        this.score = 0
+        uni.navigateTo({
+          url: `/pages/userinfo/userinfo?answerId=${res.data}`
+        })
       })
+
     }
   }
 }
@@ -286,7 +424,7 @@
 .box {
   width: 100%;
   height: 100vh;
-  background: #025eef;
+  background: $uni-color-primary;
   .box_bgimage {
     width: 100%;
     padding: 0 40rpx;
@@ -338,9 +476,17 @@
         box-sizing: border-box;
         background: #f7f7f7;
         border-radius: 8rpx;
-        display: flex;
-        align-items: center;
         margin-bottom: 24rpx;
+        .line {
+          display: flex;
+          align-items: center;
+          font-size: 28rpx;
+          color: #333333;
+          margin-bottom: 20rpx;
+          &:nth-last-child(1){
+            margin-bottom: 0;
+          }
+        }
         image {
           width: 28rpx;
           height: 28rpx;
@@ -351,10 +497,27 @@
           color: #e42d2d;
           margin-left: 16rpx;
         }
+        .success {
+          color: $uni-color-primary;
+        }
+      }
+    }
+    .score_static {
+      display: flex;
+      font-size: 32rpx;
+      margin-bottom: 40rpx;
+      .name {
+        font-weight: 600;
+      }
+      .num {
+        color: $uni-color-primary;
+      }
+      .warry {
+        color: #ed4545;
       }
     }
     .list_item {
-      margin-bottom: 24rpx;
+      margin-bottom: 46rpx;
     }
     .box_list_answer_item {
       width: 100%;
@@ -382,19 +545,21 @@
     }
     .box_list_answer_btn {
       position: fixed;
-      bottom: 140rpx;
+      bottom: 120rpx;
       left: 60rpx;
       width: 630rpx;
       height: 88rpx;
       line-height: 88rpx;
       text-align: center;
-      background: #025eef;
-      box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(2, 94, 239, 0.3);
+      background: $uni-color-primary;
+      box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(77, 153, 168, 0.3);
       border-radius: 44rpx;
       font-size: 30rpx;
-      font-weight: 500;
       color: #ffffff;
     }
+    .disable {
+      background-color: #cccccc;
+    }
   }
 }
 </style>
\ No newline at end of file

--
Gitblit v1.9.3