123364 38 73 108 143 178 213 248 283 318 353 363
1 $(function () { 2 var userId = "${userId}", 3 length = $('.swiper-slide').length, 4 $result = $('#result'), 5 $imgs = $('#imgs'), 6 $howMuch = $('#howMuch'), 7 score = null, arrayNo = null; 8 9 // 定义输出文件array10 var array = [11 {12 result: '保守型',13 coverUrl: '/images/app/base/baoshou_anzhuo.png',14 money: '50万'15 },16 {17 result: '稳健型',18 coverUrl: '/images/app/base/wenjian_anzhuo.png',19 money: '300万'20 },21 {22 result: '积极型',23 coverUrl: '/images/app/base/jiji_anzhuo.png',24 money: '您的出借额度不受限制'25 },26 ];27 28 // 输出文件29 var resultData = function ($result, $imgs, $howMuch, num) {30 var data = array[num];31 // console.log(data);32 $result.text(data.result);33 $imgs.attr('src',data.coverUrl);34 $howMuch.text(data.money);35 }36 37 // ajax函数38 var resultAjax = function (score, userId) {39 $.ajax({40 url:"/userCenter/riskTest/saveRiskTest.json",41 async:true,42 data:{"riskPreferenceCore":score,"userId":userId},43 success:function(data){44 var code = data.code;45 if(code == 1){46 console.log("success");47 }else{48 alert("保存失败,请稍后再试");49 }50 }51 });52 }53 54 // dom事件55 $('.swiper-slide').each(function(i, val) {56 var self = $(this);57 self.find('.list').find('li').click(function(){58 if($(this).addClass('current')){59 $(this).find('input:checkbox').prop('checked', true);60 }61 score += parseInt($(this).find('input:checkbox').val());62 console.log(score);63 if(self.index() == 9) {64 if (score >= 20 && score <= 40) {65 arrayNo = 0;66 } else if (score > 40 && score <= 60) {67 arrayNo = 1;68 } else if (score > 60 && score <= 100) {69 arrayNo = 2;70 }71 console.log(arrayNo);72 73 // 输出结果文件74 resultData($result, $imgs, $howMuch, arrayNo);75 76 // ajax接口请求77 resultAjax(score, userId);78 }79 })80 });81 82 $('#comfirm').click(function () {83 $(location).prop('href', '/cheDaiIndex.do');84 });85 86 // 切换造轮子87 var mySwiper = new Swiper ('.swiper-container', {88 navigation: {89 nextEl: '.swiper-button',90 lazyLoading : true,91 lazyLoadingInPrevNext : true,92 autoplay: 3000,93 speed: 300094 },95 });96 97 });