CheckJobReportWeek.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <template>
  2. <div class="page-header-index-wide">
  3. <a-card title="保养任务周工作负荷统计报表" :loading="loading" v-show="visible" :bordered="false" :body-style="{padding: '0'}">
  4. <div class="salesCard">
  5. <a-tabs default-active-key="1" size="large" :tab-bar-style="{marginBottom: '24px', paddingLeft: '16px'}">
  6. <div class="extra-wrapper" slot="tabBarExtraContent">
  7. <a-button type="primary" icon="printer" @click="getData()">刷新</a-button>
  8. <a-button style="margin-left: 8px" type="primary" icon="printer" @click="handlePrint()">打印</a-button>
  9. <a-button style="margin-left: 8px" type="primary" @click="doExport()">导出</a-button>
  10. <a-select style="margin-left: 8px" @change="changeYear" v-model="queryParam.year" placeholder="请选择">
  11. <a-select-option
  12. v-for="item in years"
  13. :key="item.value"
  14. :label="item.label"
  15. :value="item.value">{{ item.label }}
  16. </a-select-option>
  17. </a-select>
  18. <a-select style="margin-left: 8px" @change="changeLevel" v-model="queryParam.standardLevel" placeholder="请选择">
  19. <a-select-option
  20. v-for="(label,value) in levelMap"
  21. :key="value"
  22. :label="label"
  23. :value="parseInt(value)">{{ label }}
  24. </a-select-option>
  25. </a-select>
  26. </div>
  27. <a-tab-pane loading="true" tab="图形统计" key="1">
  28. <a-row>
  29. <a-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
  30. <div style="padding: 10px">
  31. <div id="container"></div>
  32. </div>
  33. </a-col>
  34. </a-row>
  35. </a-tab-pane>
  36. <a-tab-pane loading="true" tab="表格统计" key="2">
  37. <a-row>
  38. <a-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
  39. <div style="padding: 10px">
  40. <a-table
  41. bordered
  42. :data-source="chartsData"
  43. :columns="columns"
  44. tableLayout="auto"
  45. :scroll="{x: 1, y: BaseTool.Constant.scrollY }"
  46. rowKey="week">
  47. <template slot="useHours" slot-scope="text, record">
  48. <div class="editable-cell-input-wrapper">
  49. <a-input :value="text" :id="record.week + ',useHours'" @change="$event => onUseHoursChange($event, record.week, 'useHours')" />
  50. </div>
  51. </template>
  52. <template slot="usePeople" slot-scope="text, record">
  53. <div class="editable-cell-input-wrapper">
  54. <a-input :value="text" :id="record.year + record.week + ',useHours'" @change="$event => onUsePeopleChange($event, record.week, 'usePeople')" />
  55. </div>
  56. </template>
  57. <span slot="action" slot-scope="record">
  58. <template>
  59. <a @click="handleAdd(record)">提交数据</a>
  60. <a-divider type="vertical" />
  61. <a @click="handleView(record)">查看明细</a>
  62. <a-divider type="vertical" />
  63. <a @click="doExportDetail(record)">导出</a>
  64. </template>
  65. </span>
  66. </a-table>
  67. </div>
  68. </a-col>
  69. </a-row>
  70. </a-tab-pane>
  71. </a-tabs>
  72. </div>
  73. </a-card>
  74. <print-in-check-job-report-week ref="basePrintModal" @ok="handleOk"/>
  75. <detail-check-job-report ref="detailModal" @ok="handleOk"/>
  76. </div>
  77. </template>
  78. <script>
  79. import { getWeekReport, exportWeekReport, saveWorkHour, exportWeekReportWeek } from '@/api/report/check-job'
  80. import { Chart } from '@antv/g2'
  81. import PrintInCheckJobReportWeek from '@/views/dashboard/modules/PrintInCheckJobReportWeek'
  82. import DetailCheckJobReport from '@/views/dashboard/modules/DetailCheckJobReport'
  83. export default {
  84. name: 'Analysis',
  85. components: {
  86. PrintInCheckJobReportWeek,
  87. Chart,
  88. DetailCheckJobReport
  89. },
  90. data () {
  91. return {
  92. confirmLoading: false,
  93. loading: false,
  94. serverData: [],
  95. queryParam: {
  96. year: 2021,
  97. standardLevel: 2
  98. },
  99. years: [],
  100. levelMap: {},
  101. visible: true,
  102. chart: null, // 创建一个chart变量
  103. chartsData: [],
  104. // 表头
  105. columns: [
  106. {
  107. title: '年',
  108. width: 180,
  109. dataIndex: 'year'
  110. },
  111. {
  112. title: '周',
  113. width: 180,
  114. dataIndex: 'week'
  115. },
  116. {
  117. title: '标准工时',
  118. width: 120,
  119. dataIndex: 'totalHours'
  120. },
  121. {
  122. title: '可用工时',
  123. width: 120,
  124. dataIndex: 'useHours',
  125. scopedSlots: { customRender: 'useHours' }
  126. },
  127. {
  128. title: '可用人数',
  129. width: 120,
  130. dataIndex: 'usePeople',
  131. scopedSlots: { customRender: 'usePeople' }
  132. },
  133. {
  134. title: '操作',
  135. key: 'action',
  136. width: '200px',
  137. align: 'center',
  138. scopedSlots: { customRender: 'action' }
  139. }
  140. ]
  141. }
  142. },
  143. created () {
  144. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_LEVEL)
  145. this.initSelectYear()
  146. },
  147. mounted () {
  148. this.changeYear(this.queryParam.year)
  149. },
  150. methods: {
  151. initSelectYear () {
  152. var myDate = new Date()
  153. this.queryParam.year = myDate.getFullYear()// 获取当前年
  154. this.years = []
  155. for (let i = 0; i < 5; i++) {
  156. this.years.push({ value: (this.queryParam.year - i), label: (this.queryParam.year - i) + '年' })
  157. }
  158. },
  159. changeYear (value) {
  160. this.queryParam.year = value
  161. this.getData()
  162. },
  163. changeLevel (value) {
  164. this.queryParam.standardLevel = value
  165. this.getData()
  166. },
  167. getData () {
  168. getWeekReport(this.queryParam)
  169. .then(res => {
  170. this.chartsData = res.data
  171. // 需要将数据分组:总数,完成数
  172. const groupData = []
  173. this.chartsData.forEach(function (data) {
  174. groupData.push({ name: '标准工时', week: data.week + '', totalHours: data.totalHours, totalUseHours: data.useHours * data.usePeople })
  175. })
  176. this.getCharts('container', groupData)// 调用统计图
  177. })
  178. },
  179. getCharts (id, data) {
  180. this.chart && this.chart.destroy()// 防止点击搜索按钮新增一个
  181. this.chart = new Chart({
  182. container: 'container',
  183. autoFit: true,
  184. height: 400
  185. })
  186. this.chart.data(data)
  187. this.chart.scale('totalHours', {
  188. nice: true
  189. })
  190. this.chart.tooltip({
  191. showMarkers: false,
  192. shared: true,
  193. showCrosshairs: true // 展示 Tooltip 辅助线
  194. })
  195. this.chart.interval().position('week*totalHours').color('name').adjust([
  196. {
  197. type: 'dodge',
  198. marginRatio: 0
  199. }
  200. ])
  201. this.chart.interaction('active-region')
  202. this.chart.legend({
  203. position: 'bottom'
  204. })
  205. this.chart.line().position('week*totalUseHours')
  206. this.chart.point().position('week*totalUseHours').size(4).shape('circle').style({
  207. stroke: '#fff',
  208. lineWidth: 1
  209. })
  210. this.chart.render()
  211. },
  212. doExport () {
  213. const parameter = {
  214. ...this.queryParam
  215. }
  216. exportWeekReport(parameter).then(file => {
  217. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  218. })
  219. },
  220. doExportDetail (record) {
  221. const parameter = {
  222. ...this.queryParam,
  223. week: record.week,
  224. year: record.year
  225. }
  226. exportWeekReportWeek(parameter).then(file => {
  227. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  228. })
  229. },
  230. handlePrint (record) {
  231. const modal = this.$refs.basePrintModal
  232. this.visible = false
  233. modal.base({ year: this.queryParam.year, data: this.chartsData })
  234. },
  235. handleView (record) {
  236. const modal = this.$refs.detailModal
  237. modal.base(record)
  238. },
  239. handleAdd (record) {
  240. this.confirmLoading = true
  241. record.detailList = null
  242. saveWorkHour(record)
  243. .then((res) => {
  244. this.$message.info(res.data)
  245. }).catch(() => {
  246. this.confirmLoading = false
  247. })
  248. },
  249. handleOk () {
  250. this.visible = true
  251. },
  252. onUseHoursChange (e, week, attr) {
  253. const value = e.target.value
  254. console.log(value)
  255. if (value !== 0 && !value) {
  256. return
  257. }
  258. const data = [...this.chartsData]
  259. const target = data.find(item => item.week === week)
  260. if (target) {
  261. target[attr] = value
  262. this.chartsData = data
  263. }
  264. },
  265. onUsePeopleChange (e, week, attr) {
  266. const value = e.target.value
  267. console.log(value)
  268. if (value !== 0 && !value) {
  269. return
  270. }
  271. const data = [...this.chartsData]
  272. const target = data.find(item => item.week === week)
  273. if (target) {
  274. target[attr] = value
  275. this.chartsData = data
  276. }
  277. }
  278. }
  279. }
  280. </script>
  281. <style lang="less" scoped>
  282. .extra-wrapper {
  283. line-height: 55px;
  284. padding-right: 24px;
  285. .extra-item {
  286. display: inline-block;
  287. margin-right: 24px;
  288. a {
  289. margin-left: 24px;
  290. }
  291. }
  292. }
  293. .antd-pro-pages-dashboard-analysis-twoColLayout {
  294. position: relative;
  295. display: flex;
  296. display: block;
  297. flex-flow: row wrap;
  298. }
  299. .antd-pro-pages-dashboard-analysis-salesCard {
  300. height: calc(100% - 24px);
  301. /deep/ .ant-card-head {
  302. position: relative;
  303. }
  304. }
  305. .dashboard-analysis-iconGroup {
  306. i {
  307. margin-left: 16px;
  308. color: rgba(0,0,0,.45);
  309. cursor: pointer;
  310. transition: color .32s;
  311. color: black;
  312. }
  313. }
  314. .analysis-salesTypeRadio {
  315. position: absolute;
  316. right: 54px;
  317. bottom: 12px;
  318. }
  319. </style>