yuminge-app/yun-min-program-plugin-master/packageE/questionnaire/surveyResult/surveyResult.js

254 lines
5.8 KiB
JavaScript

// packageE/questionnaire/surveyResult/surveyResult.js
var setInter_Week = '';
var app = getApp();
var int = (app.globalData.statusBarHeight * 2) + 20;
Page({
/**
* 页面的初始数据
*/
data: {
statusBarHeight: int,
plugin_point_name:''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.plugin_point_name){
this.setData({
plugin_point_name:options.plugin_point_name
});
}
if (options.allNum) {
this.setData({
allNum: options.allNum
});
}
if (options.tag) {
this.setData({
tag: options.tag
});
}
if (options.questionnaire_id) {
this.setData({
questionnaire_id: options.questionnaire_id
});
}
if (options.score) {
this.setData({
score: options.score
});
}
if (options.cons) {
this.setData({
cons: options.cons
});
}
if (options.goods_id) {
this.setData({
goods_id: options.goods_id
});
}
if (options.rewardPoint) {
this.setData({
rewardPoint: options.rewardPoint
});
}
this.getData();
},
backone(e){
wx.navigateBack({
delta: 1,
});
},
back(e) {
// 返回时取消弹窗
let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
let prevPage = pages[pages.length - 3];
// if(prevPage.route == 'packageA/detail_v2/detail_v2'){
// wx.navigateTo({
// url: '/packageA/detail_v2/detail_v2?id='+this.data.goods_id+'&open=false',
// })
// }else{
prevPage.setData({ // 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。
questionnaire_is_open:false,
is_open:'close'
});
wx.setStorageSync('closeOpen', 'close');
wx.navigateBack({
delta: 2,
});
// }
console.log(prevPage);
},
continue () {
wx.navigateTo({
url: '/packageE/questionnaire/questionnaireIndex/questionnaireIndex',
});
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
getData() {
let that = this;
let urlStr = app.getNetAddresss("plugin.questionnaire.api.index.indexInfo");
app._getNetWork({
url: urlStr,
data: {
getAnswerScore: 'getAnswerScore',
score: this.data.score,
questionnaire_id: this.data.questionnaire_id
},
success: function (resdata) {
var res = resdata.data;
console.log(res);
if (res.result == 1) {
that.setData({
info: res.data.getAnswerScore.recommendation
});
} else {
wx.showToast({
icon: 'none',
title: res.msg,
duration: 1500
});
}
},
fail: function (res) {
console.log(res);
}
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
const that = this;
var line_w = 10;
if (that.data.systemWidth <= 360) { //根据手机大小改变线条粗细
line_w = 14;
} else if (that.data.systemWidth >= 430) {
line_w = 18;
}
drawGraycir(that, '.cirWeek_gray', 100, line_w); // 画周跑量灰圆
setTimeout(() => {
drawColorcir(that, '.cirWeek_run', parseInt((that.data.score / that.data.allNum) * 100), line_w); // 画周跑量动态圆
}, 500);
},
});
//画布
/**
* 画灰圆方法
*/
function drawGraycir(that, canvasID, progress, line_w) {
wx.createSelectorQuery().select(canvasID).boundingClientRect(function (res) {
if (res != null || res != undefined) {
if (progress > 100)
progress = 100;
var x0 = res.width / 2,
y0 = res.height / 2;
canvasID = canvasID.split('.')[1]; // 截取 '.'号
var ctx = wx.createCanvasContext(canvasID);
ctx.beginPath();
ctx.lineWidth = line_w;
ctx.strokeStyle = '#eee';
ctx.lineCap = 'round';
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
ctx.shadowBlur = 15;
ctx.shadowColor = '#7bbfff';
ctx.arc(x0, y0, (x0 - line_w / 2) - 5, 0.75 * Math.PI, 2.25 * Math.PI, false);
ctx.translate(0, 0);
ctx.stroke();
ctx.draw();
}
}).exec();
}
/**
* 画动态彩圆方法
*/
function drawColorcir(that, canvasID, progress, line_w) {
wx.createSelectorQuery().select(canvasID).boundingClientRect(function (res) {
if (res != null || res != undefined) {
// console.log(res)
var x0 = res.width / 2,
y0 = res.height / 2;
canvasID = canvasID.split('.')[1]; // 截取 '.'号
var ctx = wx.createCanvasContext(canvasID);
if (canvasID == 'cirWeek_run') {
var step3 = 0;
clearInterval(setInter_Week);
setInter_Week = setInterval(function () {
if (step3 >= progress) {
clearInterval(setInter_Week);
step3 = progress;
}
step3++;
ctx.beginPath();
ctx.setLineWidth(line_w);
ctx.setLineCap('round');
ctx.setStrokeStyle('#ffdf70');
ctx.arc(x0, y0, (x0 - line_w / 2) - 5, 0.75 * Math.PI, (0.75 + step3 / 100 * 1.5) * Math.PI);
ctx.translate(0, 0);
ctx.stroke();
ctx.draw();
ctx.closePath();
}, 18);
}
}
}).exec();
}