耀实惠小程序
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.

236 lines
5.1 KiB

  1. <template>
  2. <view>
  3. <!-- 视频 -->
  4. <view class="video_box">
  5. <!-- 富文本解析 -->
  6. <rich-text :nodes='top_detalt.article'></rich-text>
  7. <!-- <u-parse :html="items.article" ></u-parse> -->
  8. </view>
  9. <!-- 题目 -->
  10. <view class="topic_box">
  11. <view class="title_box">
  12. <text class="title">{{unm_index+1}}{{list[unm_index].subject}}</text>
  13. <view class="topic_num">
  14. <text>({{unm_index+1}}/{{num_sum}})</text>
  15. </view>
  16. </view>
  17. <!-- 奖励多少 暂未修改 -->
  18. <!-- <text>奖励xx元兑购金</text> -->
  19. <view class="select_answer">
  20. <view :class="index == list[unm_index].select? 'item select_item ': 'item'" class="item"
  21. v-for="(item,index) in list[unm_index].answers" @click="select_option(index)">
  22. <text>{{item}}</text>
  23. </view>
  24. </view>
  25. <button v-if="unm_index+1 != num_sum" class="next" @click="next_">下一题</button>
  26. <button v-else class="submit next" @click="submit_">提交</button>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. unm_index: 0, //当前题目数
  35. num_sum: null, // 总题目数
  36. id: null,
  37. list: [],
  38. top_detalt: {},
  39. }
  40. },
  41. onLoad(options) {
  42. this.id = options.id;
  43. this.getAnswerDetale();
  44. this.getSubjectList();
  45. },
  46. methods: {
  47. getAnswerDetale(){
  48. this.$api('answerDetale',{anWerReqId: this.id}).then( res => {
  49. let { code, result, message} = res;
  50. if(code == 200) {
  51. console.log(result);
  52. this.top_detalt = result;
  53. }else{
  54. this.$Toast(err.message);
  55. }
  56. }).catch(err => {
  57. this.$Toast(err.message);
  58. })
  59. },
  60. getSubjectList(){
  61. this.$api('getSubjectList',{anWerReqId: this.id}).then( res => {
  62. let { code, result, message} = res;
  63. if(code == 200) {
  64. console.log(result);
  65. const list = result;
  66. list.forEach((item,index) =>{
  67. list[index].select = null;
  68. list[index].answers = item.answers.split(",")
  69. })
  70. console.log(list)
  71. this.list = list;
  72. this.num_sum = result.length;
  73. }else{
  74. this.$Toast(err.message);
  75. }
  76. }).catch(err => {
  77. this.$Toast(err.message);
  78. })
  79. },
  80. // 用户选择那个
  81. select_option(index) {
  82. // 将选择的项写入数据
  83. this.list[this.unm_index].select = index;
  84. console.log(this.list);
  85. },
  86. // 下一题
  87. next_() {
  88. // 判断当前题目有没有选择
  89. const isPass = this.isSelect();
  90. if (isPass == 0) return;
  91. // 已经做出选择
  92. this.unm_index += 1
  93. },
  94. // 判断当前题目有没有选择
  95. isSelect() {
  96. if (this.list[this.unm_index].select == null) {
  97. uni.showToast({
  98. title: "请做出您的选择!",
  99. icon: "none"
  100. })
  101. return 0
  102. }
  103. return 1
  104. },
  105. // 提交显示
  106. submit_() {
  107. // 判断当前题目有没有选择
  108. const isPass = this.isSelect();
  109. if (isPass == 0) return;
  110. // 提交
  111. const answer = [];
  112. const answerArray = ['A','B','C','D']
  113. this.list.forEach((item,index) =>{
  114. answer.push({
  115. id: item.id,
  116. name: answerArray[item.select]
  117. });
  118. })
  119. this.$api('getanswerGo',{json:JSON.stringify(answer),id:this.id}).then(res =>{
  120. let { code, result, message} = res;
  121. if(code == 200) {
  122. // num 对的数目 sum 总题目数 integer 兑购
  123. if(result.num ==0) {
  124. // 失败
  125. this.$tools.navigateTo({
  126. url: "../fail/fail"
  127. })
  128. }else {
  129. this.$tools.navigateTo({
  130. url: `../success/success?num=${result.num}&integer=${result.integer}`
  131. })
  132. }
  133. console.log(result)
  134. }else{
  135. this.$Toast(message)
  136. }
  137. }).catch(err => {
  138. this.$Toast(err.message)
  139. })
  140. // const math = Math.random();
  141. // console.log(math)
  142. // if(math>0.5) {
  143. // uni.navigateTo({
  144. // url: "pagesC/success/success"
  145. // })
  146. // }else {
  147. // uni.navigateTo({
  148. // url: "../fail/fail"
  149. // })
  150. // }
  151. },
  152. }
  153. }
  154. </script>
  155. <style lang="scss" scoped>
  156. .video_box {
  157. margin-top: 20rpx;
  158. display: flex;
  159. justify-content: center;
  160. .video_ {
  161. width: 690rpx;
  162. }
  163. }
  164. .topic_box {
  165. width: 710rpx;
  166. margin: 37rpx auto 0;
  167. padding-bottom: 16rpx;
  168. box-shadow: 0 3px 6px 0 rgba(0, 0, 0, 0.16);
  169. .title_box {
  170. padding-top: 33rpx;
  171. margin-left: 37rpx;
  172. display: flex;
  173. justify-content: space-between;
  174. font-size: 30rpx;
  175. .title {
  176. font-weight: bold;
  177. color: #000;
  178. }
  179. .topic_num {
  180. color: #01AEEA;
  181. margin-right: 15rpx;
  182. }
  183. }
  184. .select_answer {
  185. .item {
  186. width: 536rpx;
  187. max-width: 600rpx;
  188. height: 76rpx;
  189. font-size: 30rpx;
  190. border: 3rpx solid #ECECEC;
  191. margin-top: 30rpx;
  192. margin-left: 43rpx;
  193. border-radius: 12rpx;
  194. display: flex;
  195. align-items: center;
  196. color: #707070;
  197. text {
  198. padding-left: 28rpx;
  199. }
  200. }
  201. .select_item {
  202. border-color: #01AEEA;
  203. color: #01AEEA;
  204. }
  205. }
  206. }
  207. .next,
  208. .submit{
  209. width: 463rpx;
  210. height: 94rpx;
  211. border-radius: 45rpx;
  212. margin-top: 30rpx;
  213. background-color: #01AEEA;
  214. font-size: 28rpx;
  215. font-weight: bold;
  216. color: #fff;
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. }
  221. </style>