| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- 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;
- TestReportID = 0;
- var TestTask = wx.getStorageSync("TestTask");
- var list = TestTask.List;
- var listRight = [];
- var listSkip = [];
- var listWrong = [];
- TestTask.TestRightStr = [];
- TestTask.TestWrongStr = [];
- TestTask.TestSkipStr = [];
- if (list) {
- for (var i = 0; i < list.length; i++) {
- // if (TestTask.BookID > 12) {
- // list[i].Field1 = list[i].ContentNew.Field[1][0].Content;
- // list[i].Word = list[i].ID;
- // }
- if (list[i].Result == 1) {
- listRight.push(list[i]);
- TestTask.TestRightStr.push(list[i].Word);
- } else if (list[i].Result == -1) {
- listWrong.push(list[i]);
- TestTask.TestWrongStr.push(list[i].Word);
- } else if (list[i].Result == 0) {
- listSkip.push(list[i]);
- TestTask.TestSkipStr.push(list[i].Word);
- }
- }
- 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 (name.indexOf("#")>0)
- name = name.substr(0,name.indexOf("#"));
- if (TestTask.TestType == "read")
- name += " 会念";
- else if (TestTask.TestType == "recite")
- name += " 会背";
- else
- name += " 会写";
- }
- that.setData({
- NumberWrong: listWrong.length,
- NumberSkip: listSkip.length,
- NumberRight: listRight.length,
- BookID: Number(TestTask.BookID),
- Name: name,
- List: result,
- NumberTotal: list.length,
- });
- if (that.data.ReportType == "new")
- that.saveInfo(TestTask);
- 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 = [],
- TestExistStr = [];
- 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;
- if (item.Content[3] && item.Content[3].Content)
- obj.Field3 = item.Content[3].Content;
- else
- obj.Field3="";
- obj.Tags = item.Content[0].Content;
- if (!common.checkIsArray(obj.Tags))
- obj.Tags = obj.Tags.split(",");
-
- obj.ID = 0;
- obj.LimitTime = common.formatTime(new Date());
- obj.FontSize = item.FontSize;
- arr.push(obj);
- TestExistStr.push(item.Word);
-
- } else if (that.data.List[i].List[j].Css === "Select2") {
- var item = that.data.List[i].List[j];
- TestExistStr.push(item.Word);
- }
- }
- }
- //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);
- var TestTask = {};
- TestTask.TestExistStr = TestExistStr;
-
- that.saveInfo(TestTask);
- 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;
-
- if (this.data.BookID==100 || (this.data.BookID>=25 && this.data.BookID<=36))
- delta = 1;
- wx.navigateBack({
- delta: delta,
- });
- },
- saveInfo: function (TestTask) {
- var that = this;
- clearInterval(intervalBuild);
- var userid = app.globalData.userInfo.UserID;
- var param1 = wx.getStorageSync("TestTask");
- if (param1.List)
- param1.TestTotal = param1.List.length;
- var symbol="";
- if (that.data.BookID > 12) {
- symbol=","
- }
- if (TestTask.TestRightStr)
- param1.TestRightStr = TestTask.TestRightStr.join(symbol);
- if (common.checkIsArray(param1.TestWrongStr))
- param1.TestRightStr=param1.TestRightStr.join(symbol);
- if (TestTask.TestWrongStr)
- param1.TestWrongStr = TestTask.TestWrongStr.join(symbol);
- if (common.checkIsArray(param1.TestWrongStr))
- param1.TestWrongStr=param1.TestWrongStr.join(symbol);
-
- if (TestTask.TestSkipStr)
- param1.TestSkipStr = TestTask.TestSkipStr.join(symbol);
- if (common.checkIsArray(param1.TestSkipStr))
- param1.TestSkipStr=param1.TestSkipStr.join(symbol);
-
-
- if (TestTask.TestExistStr)
- param1.TestExistStr = TestTask.TestExistStr.join(symbol);
- if (common.checkIsArray(param1.TestExistStr))
- param1.TestExistStr=param1.TestExistStr.join(symbol);
-
- if (TestReportID)
- param1.ID = TestReportID;
- param1.BookID=that.data.BookID;
- wx.setStorageSync('TestTask', param1);
-
- delete 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,
- }
- },
- })
|