AssessList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="content-container">
  3. <el-row class="tool-bar">
  4. <el-col :span="6" class="left">
  5. <div class="content-title">
  6. <span>{{ title }}</span>
  7. </div>
  8. </el-col>
  9. <el-col :span="10">
  10. <span class="tip">说明:红色未达标,黄色表示未评价。</span>
  11. </el-col>
  12. <el-col :span="8" class="right flex-rt">
  13. <p class="current-score"> 当月分值: <span> {{ hosScore }} </span>分</p>
  14. <el-button type="primary" icon="el-icon-document" size="mini" @click="handleExport">导出</el-button>
  15. <el-button style="margin-left: 10px;" type="primary" icon="el-icon-printer" size="mini" @click="handlePrint">打印</el-button>
  16. </el-col>
  17. </el-row>
  18. <el-row id="print_view" class="content-body storyTable">
  19. <el-table v-loading="listLoading" :data="dataList" border height="calc(100vh - 150px)" :span-method="objectSpanMethod">
  20. <el-table-column prop="targetTitle" label="评价指标" width="100">
  21. <template v-slot="{row}">
  22. <span>{{ row.targetTitle }}</span>
  23. </template>
  24. </el-table-column>
  25. <el-table-column prop="itemTitle" label="评价项目" width="100">
  26. <template v-slot="{row}">
  27. <span>{{ row.itemTitle }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="pointContent" label="评价内容">
  31. <template v-slot="{row}">
  32. <span>{{ row.pointContent }}</span>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="pointScore" label="最高分值" width="80" align="center">
  36. <template v-slot="{row}">
  37. <span>{{ row.pointScore }}</span>
  38. </template>
  39. </el-table-column>
  40. <el-table-column prop="scoreCriterion" label="考评方法" width="160">
  41. <template v-slot="{row}">
  42. <span>{{ row.scoreCriterion }}</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="assessTime" label="评价时间" width="160" header-align="center" align="center">
  46. <template v-slot="{row}">
  47. <span v-if="row.assessTime" :class="row.assessTime">{{ row.assessTime }}</span>
  48. <span v-else :class="row.assessTime">-</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column prop="hosScore" label="得分" width="80" header-align="center" align="center">
  52. <template v-slot="{row}">
  53. <span v-if="row.isAssessed > 0" class="hosScore" :class="row|hosScoreClass">{{ row.hosScore }}</span>
  54. <span v-else class="notappraise">未评价</span>
  55. </template>
  56. </el-table-column>
  57. <el-table-column label="操作" width="180" header-align="center" align="center">
  58. <template v-slot="{row,$index}">
  59. <el-button v-if="conditions.year === curYear && conditions.month === curMonth" type="primary" size="mini" @click="handleAssess(row,$index)">评价</el-button>
  60. <el-button size="mini" type="info" @click="handleViewRecord(row)">评价记录</el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. </el-row>
  65. <PointAssess ref="PointAssess" title="自评" @formSuccess="formSuccess" />
  66. <AssessRecord ref="AssessRecord" title="评价记录" />
  67. </div>
  68. </template>
  69. <script>
  70. import PointAssess from '@/views/hos/components/PointAssess'
  71. import AssessRecord from '@/views/hos/components/AssessRecord'
  72. import commonMethodMixin from '@/mixin/commonMethodMixin'
  73. import { getAssessByList, getAssessById } from '@/api/hos/hosAssessApi'
  74. import { getMonthScoreOfStory } from '@/api/hos/hosStatisApi'
  75. export default {
  76. name: 'AssessList',
  77. components: {
  78. PointAssess,
  79. AssessRecord
  80. },
  81. filters: {
  82. isCurrentMonth(time) {
  83. if (!time) return
  84. return new Date(time).getMonth() === new Date().getMonth() ? 'isCurrentMonth' : 'isNotCurrentMonth'
  85. },
  86. hosScoreClass(row) {
  87. const pointScore = row.pointScore
  88. const hosScore = row.hosScore
  89. if (!hosScore) return ''
  90. const isStandards = hosScore >= pointScore * 0.6
  91. if (isStandards) return 'standards'
  92. return 'belowStandards'
  93. }
  94. },
  95. mixins: [commonMethodMixin],
  96. data() {
  97. return {
  98. title: '',
  99. listLoading: false,
  100. total: 0,
  101. dataList: [],
  102. spanArr: [],
  103. position: 0,
  104. spanArr2: [],
  105. position2: 0,
  106. hosScore: 0,
  107. conditions: {
  108. year: 2022,
  109. month: 9,
  110. storyId: 1,
  111. keywords: ''
  112. },
  113. curYear: 0,
  114. curMonth: 0,
  115. handleAssessRows: undefined
  116. }
  117. },
  118. mounted() {
  119. var now = new Date()
  120. this.curYear = now.getFullYear()
  121. this.curMonth = now.getMonth() + 1
  122. },
  123. methods: {
  124. loadData(data) {
  125. if (!data) return
  126. this.conditions.year = data.year
  127. this.conditions.month = data.month
  128. this.conditions.storyId = data.storyId
  129. this.getData()
  130. this.getMonthScore()
  131. },
  132. getMonthScore() {
  133. getMonthScoreOfStory(this.conditions.year, this.conditions.month, this.conditions.storyId).then((res) => {
  134. if (res.data) {
  135. this.hosScore = res.data.hosScore
  136. return
  137. }
  138. this.hosScore = 0
  139. })
  140. },
  141. getData() {
  142. this.listLoading = true
  143. this.position = 0
  144. this.position2 = 0
  145. this.dataList = []
  146. this.$set(this, 'spanArr', [])
  147. this.$set(this, 'spanArr2', [])
  148. getAssessByList(this.conditions).then((resp) => {
  149. this.listLoading = false
  150. const { code, msg, data, total } = resp
  151. if (code === 200) {
  152. this.total = total
  153. if (Array.isArray(data) && data.length > 0) {
  154. this.dataList = this.sortArray(data, 'targetId')
  155. this.rowspan('targetId')
  156. this.rowspan2('itemId') // amount1列合并信息缓存
  157. }
  158. } else {
  159. this.$message.error(msg)
  160. }
  161. }).catch((error) => {
  162. console.log(error)
  163. })
  164. },
  165. objectSpanMethod({ row, column, rowIndex, columnIndex }) {
  166. if (columnIndex === 0) {
  167. const _row = this.spanArr[rowIndex]
  168. const _col = _row > 0 ? 1 : 0
  169. return {
  170. rowspan: _row,
  171. colspan: _col
  172. }
  173. }
  174. if (columnIndex === 1) {
  175. return {
  176. rowspan: this.spanArr2[rowIndex],
  177. colspan: this.spanArr2[rowIndex] > 0 ? 1 : 0
  178. }
  179. }
  180. },
  181. rowspan(name) {
  182. this.dataList.forEach((item, index) => {
  183. if (index === 0) {
  184. this.spanArr.push(1)
  185. this.position = 0
  186. } else {
  187. if (this.dataList[index][name] === this.dataList[index - 1][name]) {
  188. this.spanArr[this.position] += 1
  189. this.spanArr.push(0)
  190. } else {
  191. this.spanArr.push(1)
  192. this.position = index
  193. }
  194. }
  195. })
  196. },
  197. rowspan2(name) {
  198. this.dataList.forEach((item, index) => {
  199. if (index === 0) {
  200. this.spanArr2.push(1)
  201. this.position2 = 0
  202. } else {
  203. if (this.dataList[index][name] === this.dataList[index - 1][name]) {
  204. this.spanArr2[this.position2] += 1
  205. this.spanArr2.push(0)
  206. } else {
  207. this.spanArr2.push(1)
  208. this.position2 = index
  209. }
  210. }
  211. })
  212. },
  213. sortArray(ary, key) {
  214. return ary.reduce((total, next) => {
  215. const index = total.findIndex((item, index, self) => {
  216. return item[key] === next[key]
  217. })
  218. return index === -1 ? total.push(next) && total : total.splice(index, 0, next) && total
  219. }, [])
  220. },
  221. // 结果评估
  222. handleViewRecord(row) {
  223. this.$nextTick(() => {
  224. this.$refs['AssessRecord'].handler(row)
  225. })
  226. },
  227. // 结果评估
  228. handleAssess(row, index) {
  229. this.handleAssessRows = { row, index }
  230. this.$nextTick(() => {
  231. this.$refs['PointAssess'].handler(row)
  232. })
  233. },
  234. formSuccess() {
  235. this.updateRow()
  236. this.$emit('actionUpdate')
  237. },
  238. updateRow() {
  239. var year = this.conditions.year
  240. var month = this.conditions.month
  241. const { storyId, targetId, itemId, pointId } = this.handleAssessRows.row
  242. const index = this.handleAssessRows.index
  243. getAssessById(year, month, storyId, targetId, itemId, pointId).then((res) => {
  244. this.$set(this.dataList, index, res.data)
  245. this.getMonthScore()
  246. })
  247. },
  248. // 导出评价报告
  249. handleExport() {
  250. const loading = this.$loading({
  251. lock: true,
  252. text: '导出中……',
  253. spinner: 'el-icon-loading',
  254. background: 'rgba(0, 0, 0, 0.7)'
  255. })
  256. import('@/vendor/Export2Excel').then(excel => {
  257. const tHeader = ['年度', '月份', '得分']
  258. const filterVal = ['year', 'month', 'hosScore']
  259. const data = this.formatJson(filterVal, this.dataList)
  260. excel.export_json_to_excel({
  261. header: tHeader,
  262. data,
  263. filename: '',
  264. autoWidth: true,
  265. bookType: 'xlsx'
  266. })
  267. loading.close()
  268. })
  269. },
  270. handlePrint() {
  271. let iframe = document.getElementById('print-iframe')
  272. if (!iframe) {
  273. const el = document.querySelector('#print_view')
  274. iframe = document.createElement('IFRAME')
  275. let doc = null
  276. iframe.setAttribute('id', 'print-iframe')
  277. iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;')
  278. document.body.appendChild(iframe)
  279. doc = iframe.contentWindow.document
  280. const styleHtml = 'table{color:#fff;background-color:#0C3444;-webkit-print-color-adjust: exact;}' +
  281. 'td,th{padding:10px;}' +
  282. 'th{background:#306379;-webkit-print-color-adjust: exact;}' +
  283. 'td{background:#0C3444;-webkit-print-color-adjust: exact; }'
  284. doc.write(`<html><head><style media="print">@media print {${styleHtml}}</style></head><body style="zoom: 60%;">${el.innerHTML}</body></html>`)
  285. doc.close()
  286. iframe.contentWindow.focus()
  287. }
  288. iframe.contentWindow.print()
  289. document.body.removeChild(iframe)
  290. },
  291. formatJson(filterVal, jsonData) {
  292. return jsonData.map(v => filterVal.map(j => {
  293. return v[j]
  294. }))
  295. }
  296. }
  297. }
  298. </script>
  299. <style lang="scss" scoped>
  300. .content-container {
  301. margin: 10px 10px 0 10px;
  302. overflow: hidden;
  303. background: #193142;
  304. height: calc(100vh - 95px);
  305. p {
  306. margin: 0;
  307. line-height: 2em;
  308. padding: 0;
  309. }
  310. .tool-bar {
  311. .tip{
  312. color: #9e9595;
  313. font-size: 12px;
  314. padding-left: 10px;
  315. }
  316. .current-score {
  317. text-align: right;
  318. font-size: 12px;
  319. font-weight: 400;
  320. color: #FFFFFF;
  321. padding-right: 20px;
  322. span {
  323. font-size: 20px;
  324. font-weight: 400;
  325. color: #FFFFFF;
  326. }
  327. }
  328. }
  329. .hosScore{
  330. font-size: 18px;
  331. font-weight: 600;
  332. Font-style:oblique
  333. }
  334. .belowStandards{
  335. color: red;
  336. }
  337. .notappraise{
  338. color: yellow;
  339. }
  340. .isNotCurrentMonth{
  341. color: red;
  342. font-weight: 800;
  343. }
  344. }
  345. </style>