|
@@ -0,0 +1,224 @@
|
|
|
+let app = getApp()
|
|
|
+Page({
|
|
|
+ data: {
|
|
|
+ tabs: [{
|
|
|
+ name: '未完成'
|
|
|
+ }, {
|
|
|
+ name: '合格'
|
|
|
+ }, {
|
|
|
+ name: '不合格'
|
|
|
+ }, {
|
|
|
+ name: '缺考'
|
|
|
+ }],
|
|
|
+ currentTab: 0,
|
|
|
+ phone: '',
|
|
|
+ answerList: [],
|
|
|
+ qualifiedList: [],
|
|
|
+ unqualifiedList: [],
|
|
|
+ missedList: [],
|
|
|
+ record: [],//答题结果
|
|
|
+ recordindex: 0
|
|
|
+ },
|
|
|
+ onShareAppMessage(){},
|
|
|
+ onLoad() {
|
|
|
+ let that = this;
|
|
|
+ dd.getStorage({
|
|
|
+ key: 'userInf',
|
|
|
+ success: function (res) {
|
|
|
+ that.setData({
|
|
|
+ phone: res.data.phone
|
|
|
+ })
|
|
|
+ let params = {
|
|
|
+ phone: res.data.phone
|
|
|
+ // phone: '17611172370'
|
|
|
+ }
|
|
|
+ that.getUndoneExam(params)
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ dd.alert({ content: res.errorMessage });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+ onShow() {
|
|
|
+ let that = this
|
|
|
+ dd.getStorage({
|
|
|
+ key: 'record',
|
|
|
+ success: function (res) {
|
|
|
+ that.setData({
|
|
|
+ record: res
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ dd.alert({ content: res.errorMessage });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ // tab切换逻辑
|
|
|
+ swichNav(e) {
|
|
|
+ if (this.data.currentTab === e.target.dataset.current) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ currentTab: e.target.dataset.current
|
|
|
+ })
|
|
|
+ this.getCurrentTab()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ goAnswer(e) {
|
|
|
+ let exam_id = e.target.dataset.examid
|
|
|
+ let result_id = e.target.dataset.resultid
|
|
|
+ let duration = e.target.dataset.duration
|
|
|
+ let result_status = e.target.dataset.resultstatus
|
|
|
+ if (e.target.dataset.resultstatus == 1) {
|
|
|
+ dd.confirm({
|
|
|
+ title: '温馨提示',
|
|
|
+ content: '是否继续考试',
|
|
|
+ confirmButtonText: '是',
|
|
|
+ cancelButtonText: '否',
|
|
|
+ success: (result) => {
|
|
|
+ if (result.confirm) {
|
|
|
+ dd.navigateTo({
|
|
|
+ url: '../answer/answer?exam_id=' + exam_id + '&result_id=' + result_id + '&duration=' + duration + '&result_status=' + result_status
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ dd.confirm({
|
|
|
+ title: '温馨提示',
|
|
|
+ content: '是否开始考试',
|
|
|
+ confirmButtonText: '是',
|
|
|
+ cancelButtonText: '否',
|
|
|
+ success: (result) => {
|
|
|
+ if (result.confirm) {
|
|
|
+ this.goStartExam(exam_id, result_id, duration, result_status)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ goStartExam(exam_id, result_id, duration, result_status) {
|
|
|
+ let params = {
|
|
|
+ result_id: result_id
|
|
|
+ }
|
|
|
+ app.https('POST', app.globaldata.apiUrl.startExam, JSON.stringify(params), {
|
|
|
+ type: false
|
|
|
+ }).then(res => {
|
|
|
+
|
|
|
+ dd.reLaunch({
|
|
|
+ url: '../answer/answer?exam_id=' + exam_id + '&result_id=' + result_id + '&duration=' + duration + '&result_status=' + result_status
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ goretakeExam(e) {
|
|
|
+ console.log(e)
|
|
|
+ dd.setStorage({
|
|
|
+ key: 'answerid',
|
|
|
+ data: {
|
|
|
+ exam_id:e.target.dataset.examid,
|
|
|
+ result_id: e.target.dataset.resultid
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dd.reLaunch({
|
|
|
+ url: "../result/result?scores=" + e.target.dataset.scores + "&qualified=" + 0
|
|
|
+ })
|
|
|
+ },
|
|
|
+ swiperChange(e) {
|
|
|
+ this.setData({ currentTab: e.detail.current });
|
|
|
+ this.getCurrentTab()
|
|
|
+ },
|
|
|
+ getCurrentTab() {
|
|
|
+ let currentTab = this.data.currentTab
|
|
|
+ console.log(currentTab)
|
|
|
+ let params = {
|
|
|
+ phone: this.data.phone
|
|
|
+ }
|
|
|
+ if (currentTab == 0) {
|
|
|
+ this.getUndoneExam(params);
|
|
|
+ } else if (currentTab == 1) {
|
|
|
+ this.getQualifiedExam(params);
|
|
|
+ } else if (currentTab == 2) {
|
|
|
+ this.getUnqualifiedExam(params);
|
|
|
+ } else {
|
|
|
+ this.getMissedExam(params);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ // 未完成
|
|
|
+ getUndoneExam(params) {
|
|
|
+ let that = this
|
|
|
+ app.https('POST', app.globaldata.apiUrl.getUndoneExam, JSON.stringify(params), {
|
|
|
+ type: false
|
|
|
+ }).then(res => {
|
|
|
+ that.setData({
|
|
|
+ answerList: res.data.data
|
|
|
+ })
|
|
|
+ let record = this.data.record.data
|
|
|
+ if (record && record != []) {
|
|
|
+ that.getnum(record)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getnum(record) {
|
|
|
+ let that = this
|
|
|
+ let counter = 0;
|
|
|
+ for (let i = 0; i < record.length; i++) {
|
|
|
+ if (record[i]) counter++;
|
|
|
+ }
|
|
|
+ let percent = (counter / (record.length)) * 100
|
|
|
+ dd.getStorage({
|
|
|
+ key: 'answerid',
|
|
|
+ success: function (res) {
|
|
|
+ let answerLists = that.data.answerList.map((item) => {
|
|
|
+ if (item.exam_id == res.data.exam_id) {
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ percent: percent ? percent : 0
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ ...item
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ that.setData({
|
|
|
+ answerList: answerLists
|
|
|
+ })
|
|
|
+ console.log(that.data.answerList)
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+ getQualifiedExam(params) {
|
|
|
+ app.https('POST', app.globaldata.apiUrl.getQualifiedExam, JSON.stringify(params), {
|
|
|
+ type: false
|
|
|
+ }).then(res => {
|
|
|
+ this.setData({
|
|
|
+ qualifiedList: res.data.data
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getUnqualifiedExam(params) {
|
|
|
+ app.https('POST', app.globaldata.apiUrl.getUnqualifiedExam, JSON.stringify(params), {
|
|
|
+ type: false
|
|
|
+ }).then(res => {
|
|
|
+ this.setData({
|
|
|
+ unqualifiedList: res.data.data
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getMissedExam(params) {
|
|
|
+ app.https('POST', app.globaldata.apiUrl.getMissedExam, JSON.stringify(params), {
|
|
|
+ type: false
|
|
|
+ }).then(res => {
|
|
|
+ this.setData({
|
|
|
+ missedList: res.data.data
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+});
|