| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- import common from '../../utils/util';
- import main from '../../utils/main';
- const app = getApp();
- var intervalBuild = 0;
- var TestReportID = 0;
- Page({
- data: {
- IsSelect: true,
- IsBuild: 0,
- IsIPhoneX: app.globalData.IsIPhoneX,
- },
- onLoad: function (options) {
- var that = this;
- that.setData({
- ReportType:options.type,
- Containnerheight: main.getWindowHeight(),
- });
- that.init();
- },
- init: function () {
- var that = this;
- var TestTask = wx.getStorageSync("TestTask");
- var list = TestTask.List;
- var listRight = [];
- var listSkip = [];
- var listWrong = [];
- if (list) {
- for (var i = 0; i < list.length; i++) {
- if (list[i].Result == 1) {
- listRight.push(list[i]);
- }
- else if (list[i].Result == -1) {
- listWrong.push(list[i]);
- }
- else if (list[i].Result == 0) {
- listSkip.push(list[i]);
- }
- }
- var result = [];
- if (listWrong.length > 0) {
- result.push({ Name: "答错的题目", Expand: 1, List: listWrong });
- if (listSkip.length > 0)
- result.push({ Name: "跳过的题目", Expand: 1, List: listSkip });
- if (listRight.length > 0)
- result.push({ Name: "答对的题目", Expand: 1, List: listRight });
- }
- else {
- if (listSkip.length > 0) {
- result.push({ Name: "跳过的题目", Expand: 1, List: listSkip });
- if (listRight.length > 0)
- result.push({ Name: "答对的题目", Expand: 1, List: listRight });
- }
- else {
- if (listRight.length > 0)
- result.push({ Name: "答对的题目", Expand: 1, List: listRight });
- }
- }
- var name = "";
- if (TestTask.Name && TestTask.Name.indexOf("#")>0){
- name=TestTask.Name;
- name=name.substr(name.indexOf("#")+1);
- if (TestTask.TestType=="read")
- name+=" 会念";
- else
- name+=" 会写";
- }
- that.setData({
- NumberWrong: listWrong.length,
- NumberSkip: listSkip.length,
- NumberRight: listRight.length,
- Name: name,
- List: result,
- NumberTotal: list.length,
- });
- if (that.data.ReportType=="new")
- that.saveInfo();
- wx.setNavigationBarTitle({
- title: "报告"
- });
- }
- },
- expandPanel: function (e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- if (that.data.List[index].Expand == "1")
- that.data.List[index].Expand = "0";
- else
- that.data.List[index].Expand = "1";
- that.setData({
- List: that.data.List,
- });
- },
- onSelectItem: function (e) {
- var that = this;
- var index = e.currentTarget.dataset.index;
- var word = e.currentTarget.dataset.word;
- for (var i = 0; i < that.data.List[index].List.length; i++) {
- if (that.data.List[index].List[i].Word == word) {
- if (that.data.List[index].List[i].Css == "Select") {
- that.data.List[index].List[i].Css = "";
- that.setData({
- List: that.data.List,
- });
- }
- else if (that.data.List[index].List[i].Css == "Select2") {
- wx.showToast({
- title: '已经生成过了',
- image: "../images/universalpic_ribbon_white_96x120.png",
- });
- }
- else {
- that.data.List[index].List[i].Css = "Select";
- that.setData({
- List: that.data.List,
- });
- }
- break;
- }
- }
- },
- buildCard: function () {
- var that = this;
- var arr = [];
- for (var i = 0; i < that.data.List.length; i++) {
- for (var j = 0; j < that.data.List[i].List.length; j++) {
- if (that.data.List[i].List[j].Css === "Select") {
- var item = that.data.List[i].List[j];
- var obj = {};
- obj.Field1 = item.Content[1].Content;
- obj.Field2 = item.Content[2].Content;
- obj.Field3 = "";
- obj.Tags = item.Content[0].Content;
- obj.IsTodayStudy = 0;
- obj.ID = 0;
- obj.LimitTime = common.formatTime(new Date());
- obj.FontSize = item.FontSize;
- arr.push(obj);
- }
- }
- }
- //console.log(arr);
- if (arr.length > 0) {
- that.setData({
- IsBuild: 1,
- });
- var buildCardNumber = 0;
- intervalBuild = setInterval(function () {
- that.addCard(arr[buildCardNumber]);
- buildCardNumber++;
- that.setData({
- BuildCardNumber: Math.round(100 * buildCardNumber / arr.length) + "%",
- });
- if (buildCardNumber >= arr.length) {
- clearInterval(intervalBuild);
- that.setData({
- IsBuild: 2,
- });
- }
- }, 500);
- }
- else {
- wx.showToast({
- title: '先选题目',
- image: "../images/universalpic_wrong_white_120x120.png",
- });
- }
- },
- addCard: function (card) {
- var userid = app.globalData.userInfo.UserID;
- main.postData('AddMiaoguoCard?Type=add&UserID=' + userid, card, function (data) {
- });
- },
- close: function (e) {
- wx.removeStorageSync("TestTask");
- var delta=2;
- if (this.data.ReportType=="edit")
- delta=1;
- wx.navigateBack({
- delta: delta,
- });
- },
- saveInfo: function () {
- var that = this;
- clearInterval(intervalBuild);
- var userid = app.globalData.userInfo.UserID;
- var param1 = wx.getStorageSync("TestTask");
- param1.TestRight = this.data.NumberRight;
- param1.TestWrong = this.data.NumberWrong;
- param1.TestSkip = this.data.NumberSkip;
- param1.TestTotal = param1.List.length;
- param1.List = JSON.stringify(param1.List);
- main.postData('InsertTestReport?UserID=' + userid, param1, function (data) {
- if (data)
- TestReportID = data;
- });
- },
- gotoReport: function (e) {
- if ((this.data.NumberRight + this.data.NumberWrong + this.data.NumberSkip) >= this.data.NumberTotal) {
- wx.showToast({
- title: '已经完成!',
- image: "../images/universalpic_wrong_white_120x120.png",
- });
- }
- else {
- var testTask = wx.getStorageSync("TestTask");
- if (TestReportID)
- testTask.ID = TestReportID;
- wx.setStorageSync("TestTask2", testTask);
- var url = "./item?type=edit";
- wx.redirectTo({
- url: url,
- });
- }
- },
- onUnload: function () {
- wx.removeStorageSync("TestTask");
- },
- onShareAppMessage: function () {
- return {
- title: app.globalData.ShareTitle,
- path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
- imageUrl: app.globalData.ShareImage,
- }
- },
- })
|