score.js
4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
var Controller = {
index: function () {
require(['vue', 'ELEMENT'], function (Vue, ELEMENT) {
Vue.use(ELEMENT)
$('#app').show()
var app = new Vue({
el: '#app',
data: function () {
this.scoreItemsLen = 0
return {
tableData: [],
scores: {}
}
},
computed: {
totalScore: function () {
if ('{}' === JSON.stringify(this.scores)) {
return 0
}
return Object.values(this.scores).reduce((a,b) => {
return formatterNum(a) + formatterNum(b)
})
}
},
created: function () {
var _me = this
$.ajax({
url: '/school/project_common/score/index?review_score_id='+Config.review_score_id,
method: 'POST',
success: function (res) {
if (1 === res.code) {
res.data.score_items.forEach(function (v, i) {
_me.scoreItemsLen += v.item_details.length
_me.tableData.push(v)
})
_me.scores = res.data.score_detail || {}
} else {
Toastr.error(res.msg)
}
}
})
},
methods: {
onSave: function() {
var scoreCount = 0,
scoresData = this.scores
for (var p in scoresData) {
if (('string' === typeof scoresData[p]) || ('number' === typeof scoresData[p])) {
scoreCount++
}
}
if (scoreCount !== this.scoreItemsLen) {
Toastr.warning('部分评分项未评分,请先评分')
return
}
$.ajax({
url: '/school/project_common/score/mark',
method: 'POST',
data: {
review_score_id: Config.review_score_id,
total_score: this.totalScore,
scores: JSON.stringify(this.scores)
},
success: function (res) {
if (1 === res.code) {
parent.Toastr.success('打分成功!')
Fast.api.close()
} else {
Toastr.error(res.msg)
}
}
})
}
}
})
/**
* 格式化数字
* @param {String|Number} n 数字或数字字符串
* @return {Number}
*/
function formatterNum(n) {
return Number(n) || 0
}
})
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
},
}
}
return Controller
})