shangjiaduizhang.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col :span="24" class="first-row">
  5. <div class="tag">商家对账</div>
  6. </el-col>
  7. </el-row>
  8. <el-row>
  9. <el-col :span="24" class="second-row">
  10. <div class="total_balance">当日消费:{{today_xiaofei}}元</div>
  11. <el-link type="primary" class="xiaofei" @click="showxiaofeiDialog">年/月消费</el-link>
  12. <el-form :inline="true" class="demo-form-inline">
  13. <el-form-item label="楼栋号:" class="shuibiaoId">
  14. <el-select v-model="drom_options.value" @change="selectGetBuild(drom_options.value)"
  15. placeholder="请选择楼栋号" class="my-select">
  16. <el-option v-for="item in drom_options.builds" :key="item.value" :label="item.label"
  17. :value="item.value">
  18. </el-option>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="宿舍号:" class="shuibiaoId">
  22. <el-select v-model="room_options.room_value" @change="selectGetroom(room_options.room_value)"
  23. placeholder="请选择宿舍号" class="my-select">
  24. <el-option v-for="item in room_options.rooms" :key="item.value" :label="item.label"
  25. :value="item.value">
  26. </el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="日期:" class="riqi">
  30. <el-date-picker v-model="select_datetime" type="daterange" range-separator="至"
  31. @change="dateChange" start-placeholder="开始日期" end-placeholder="结束日期"
  32. value-format="yyyy-MM-dd">
  33. </el-date-picker>
  34. </el-form-item>
  35. </el-form>
  36. </el-col>
  37. </el-row>
  38. <hr style="background-color: #CCCCCC;height: 1px;border: 0;">
  39. <el-row>
  40. <el-col :span="24" class="third-row">
  41. <el-table ref="multipleTable" :data="tableData" tooltip-effect="dark" style="width: 100%"
  42. @selection-change="handleSelectionChange" highlight-current-row>
  43. <el-table-column type="selection" label="全选" align="center" width="55"></el-table-column>
  44. <el-table-column label="学号" align="center">
  45. <template slot-scope="scope">{{ scope.row.stu_number }}</template>
  46. </el-table-column>
  47. <el-table-column prop="user_name" label="姓名" align="center"></el-table-column>
  48. <el-table-column prop="use_amount" label="消费金额(元)" :formatter="formatDigit" align="center"
  49. show-overflow-tooltip>
  50. </el-table-column>
  51. <el-table-column prop="build" label="楼栋号" align="center" show-overflow-tooltip></el-table-column>
  52. <el-table-column prop="dom" label="宿舍号" align="center" show-overflow-tooltip></el-table-column>
  53. <el-table-column prop="begin_time" label="消费时间" align="center" show-overflow-tooltip>
  54. </el-table-column>
  55. </el-table>
  56. <div style="margin-top: 20px" class="table-footer">
  57. <div class="pages">
  58. <el-pagination :hide-on-single-page="true" layout="prev, pager, next"
  59. :current-page.sync="table.currentPage" :page-size="table.pageRows" :total="rows_total"
  60. @current-change="handleCurrentChange">
  61. </el-pagination>
  62. </div>
  63. <div class="export-table">
  64. <el-button type="primary" size="small" @click="handleDownloadTable">表格导出</el-button>
  65. </div>
  66. </div>
  67. </el-col>
  68. </el-row>
  69. <el-row>
  70. <el-col :span="24" class="forth-row">
  71. <!-- 编辑对话框 -->
  72. <el-dialog title="消费情况" :visible.sync="xiaofeiDialog" :close-on-click-modal="false"
  73. :close-on-press-escape="false" width="640px" top="0vh" class="my-dialog">
  74. <hr
  75. style="width: 100%; position: absolute; top: 60px; left: 0px;background-color: #CCCCCC;height: 1px;border: 0;">
  76. <div class="view-balance">当日消费:{{ xiaofei.day_balance }}元</div>
  77. <div class="view-balance">当月消费:{{ xiaofei.month_balance }}元</div>
  78. <div class="view-balance">当年消费:{{ xiaofei.year_balance }}元</div>
  79. <div class="view-balance"></div>
  80. </el-dialog>
  81. </el-col>
  82. </el-row>
  83. </div>
  84. </template>
  85. <script>
  86. export default {
  87. data() {
  88. return {
  89. // 今日消费
  90. today_xiaofei: 0.0.toFixed(2),
  91. // 年月日的消费
  92. xiaofei: {
  93. day_balance: 0.0.toFixed(2),
  94. month_balance: 0.0.toFixed(2),
  95. year_balance: 0.0.toFixed(2),
  96. },
  97. // 楼栋号下拉列表
  98. drom_options: { // 下拉列表的数据绑定
  99. builds: [{
  100. value: 0,
  101. label: '全部'
  102. }],
  103. value: 0,
  104. label: ''
  105. },
  106. // 宿舍号下拉列表
  107. room_options: {
  108. rooms: [{
  109. value: 0,
  110. label: '全部'
  111. }],
  112. room_value: 0,
  113. room_label: ''
  114. },
  115. select_datetime: [], // 起止日期
  116. startTime: '', // 开始日期
  117. endTime: '', // 结束日期
  118. select_riqi: {
  119. // 选择日期:年-月-日
  120. select_day: '',
  121. // 选择日期:年-月
  122. select_month: '',
  123. // 选择日期:年
  124. select_year: ''
  125. },
  126. // 控制消费对话框显示隐藏
  127. xiaofeiDialog: false,
  128. // 表格数据
  129. tableData: [],
  130. rows_total: 0,
  131. // 表格参数
  132. table: {
  133. currentPage: 1, // 当前所在页码
  134. pageRows: 8, // 每页显示的行数
  135. },
  136. // 多选后,选择的所有行的数据数组
  137. // multipleSelection: []
  138. }
  139. },
  140. created() {
  141. var statue = sessionStorage.getItem('uname')
  142. if (!statue || typeof(statue) == 'undefined' || statue == '' || statue == 'null') {
  143. this.$router.replace('/')
  144. } else {
  145. // 获取当天日期
  146. var myDate = this.getNowFormatDate();
  147. // 获取年月日,并获取消费总金额
  148. this.selectGetDate(myDate)
  149. // 取得楼栋号,填充下拉列表
  150. this.getBuildsFillSelect()
  151. }
  152. // 初始化日期为今天天 至 明天
  153. this.initDate()
  154. },
  155. methods: {
  156. /**
  157. * 初始化日期时间
  158. */
  159. initDate() {
  160. //当前设定的日期时间
  161. let d = new Date;
  162. var year1 = d.getFullYear(); // 获取当前年份
  163. var mon1 = d.getMonth() + 1; // 获取当前月份
  164. var day1 = d.getDate(); // 获取当前日
  165. //后一天设定的日期时间
  166. d.setTime(d.getTime() + 24 * 60 * 60 * 1000);
  167. var year2 = d.getFullYear(); // 获取当前年份
  168. var mon2 = d.getMonth() + 1; // 获取当前月份
  169. var day2 = d.getDate(); // 获取当前日
  170. this.startTime = this.getDate(year1, mon1, day1)
  171. this.endTime = this.getDate(year2, mon2, day2)
  172. this.select_datetime.push(this.startTime)
  173. this.select_datetime.push(this.endTime)
  174. // 显示列表
  175. this.handleCurrentChange(1)
  176. },
  177. /**
  178. * 获取指定格式 年、月、日
  179. * @param {Object} y
  180. * @param {Object} m
  181. * @param {Object} d
  182. */
  183. getDate(y, m, d) {
  184. m = m > 9 ? m : '0' + m;
  185. d = d > 9 ? d : '0' + d;
  186. return y + "-" + m + "-" + d;
  187. },
  188. /**
  189. * 选择起止日期
  190. * @param {Object} val
  191. */
  192. dateChange(val) {
  193. // console.log(val);
  194. this.startTime = val[0]
  195. this.endTime = val[1]
  196. if (this.startTime == this.endTime) {
  197. var d = new Date(this.endTime);
  198. d = d.setDate(d.getDate() + 1);
  199. d = new Date(d);
  200. let dt = this.getDate(d.getFullYear(), d.getMonth() + 1, d.getDate());
  201. this.endTime = dt;
  202. this.select_datetime[1] = dt;
  203. // this.$message.error('起止日期不能为同一天!');
  204. }
  205. // 选择日期后,马上搜索
  206. this.handleCurrentChange(1)
  207. // 获取选择的日期
  208. var selectDate = this.startTime;
  209. // 获取年月日,并获取消费总金额
  210. this.selectGetDate(selectDate)
  211. },
  212. /**
  213. * 导出表格
  214. */
  215. handleDownloadTable() {
  216. var _this = this;
  217. let formData = new FormData();
  218. if (_this.drom_options.label) {
  219. formData.append("build", _this.drom_options.label);
  220. }
  221. if (_this.room_options.room_label) {
  222. formData.append("dom", _this.room_options.room_label);
  223. }
  224. if (_this.select_riqi.select_day) {
  225. formData.append("begin_time", _this.select_riqi.select_day);
  226. }
  227. this.$axios.post('/jxch-smartmp/HotWaters/watertoComExcel.action', formData)
  228. .then(res => {
  229. if (typeof(res.data.downurl) != 'undefined' && res.data.downurl != '' && JSON
  230. .stringify(res
  231. .data) != '{}') {
  232. // console.log(res.data.downurl);
  233. window.open('https://jtishfw.ncjti.edu.cn/jxch-smartmp' + res.data.downurl);
  234. } else {
  235. _this.$message.error('【未获得】表格!');
  236. }
  237. })
  238. .catch(err => {
  239. console.log(err);
  240. _this.$message.error('【导出表格】请求异常: ' + err);
  241. })
  242. },
  243. /**
  244. * 改变页码
  245. * @param {Object} val
  246. */
  247. handleCurrentChange(val) {
  248. // console.log(val);
  249. this.table.currentPage = val
  250. // 组合参数,刷新消费表格
  251. this.selectParams()
  252. },
  253. /**
  254. * 1. 获取日期下拉列表选择的日期
  255. * 2. 拆分到对于的变量中,便于根据
  256. * @param {Object} val
  257. */
  258. selectGetDate(val) {
  259. // console.log(val);
  260. this.select_riqi.select_year = ''
  261. this.select_riqi.select_month = ''
  262. this.select_riqi.select_day = ''
  263. if (val) {
  264. this.select_riqi.select_year = val.split('-')[0]
  265. this.select_riqi.select_month = val.split('-')[0] + '-' + val.split('-')[1]
  266. this.select_riqi.select_day = val
  267. } else {
  268. this.select_riqi.select_year = ""
  269. this.select_riqi.select_month = ""
  270. this.select_riqi.select_day = ""
  271. }
  272. this.table.currentPage = 1
  273. // 获取年月日消费总金额
  274. this.get_year_month_day_amount()
  275. },
  276. /**
  277. * 获取当前时间,格式YYYY-MM-DD
  278. */
  279. getNowFormatDate() {
  280. var date = new Date();
  281. var seperator1 = "-";
  282. var year = date.getFullYear();
  283. var month = date.getMonth() + 1;
  284. var strDate = date.getDate();
  285. if (month >= 1 && month <= 9) {
  286. month = "0" + month;
  287. }
  288. if (strDate >= 0 && strDate <= 9) {
  289. strDate = "0" + strDate;
  290. }
  291. var currentdate = year + seperator1 + month + seperator1 + strDate;
  292. return currentdate;
  293. },
  294. /**
  295. * 获取宿舍号,填充宿舍号下拉列表
  296. */
  297. getRooms() {
  298. var _this = this
  299. let params = {
  300. params: {
  301. build: this.drom_options.label
  302. }
  303. }
  304. this.$axios.get('/jxch-smartmp/HotWaters/watergetdoms.action', params)
  305. .then(res => {
  306. // console.log(res.data);
  307. if (typeof(res.data.doms) != 'undefined' && res.data.doms != '' && JSON.stringify(
  308. res.data) !=
  309. '{}') {
  310. this.room_options.rooms = [{
  311. value: 0,
  312. label: '全部'
  313. }]
  314. for (var i = 0; i < res.data.doms.length; i++) {
  315. let tmp = {
  316. value: i + 1,
  317. label: res.data.doms[i]
  318. }
  319. this.room_options.rooms.push(tmp)
  320. }
  321. } else {
  322. _this.$message.success('【宿舍号】暂无数据!');
  323. }
  324. })
  325. .catch(err => {
  326. // console.log(err);
  327. _this.$message.error('【宿舍号】请求异常: ' + err);
  328. })
  329. },
  330. /**
  331. * 1. 获取楼栋号下拉列表选择的id
  332. * 2. 刷新消费表格
  333. * 3. 获取宿舍号填充下拉列表
  334. * @param {Object} vId
  335. */
  336. selectGetBuild(vId) {
  337. // console.log(vId);
  338. let obj = {};
  339. obj = this.drom_options.builds.find((item) => {
  340. return item.value === vId; //筛选出匹配数据
  341. });
  342. // console.log(obj);
  343. this.drom_options.value = obj.value
  344. this.drom_options.label = obj.label
  345. this.table.currentPage = 1
  346. // 获取宿舍号,填充宿舍号下拉列表
  347. this.getRooms()
  348. // 组合参数,刷新消费表格
  349. this.selectParams()
  350. },
  351. /**
  352. * 1. 获取宿舍号下拉列表选择的id
  353. * 2. 刷新消费表格
  354. * @param {Object} vId
  355. */
  356. selectGetroom(vId) {
  357. // console.log(vId);
  358. let obj = {};
  359. obj = this.room_options.rooms.find((item) => {
  360. return item.value === vId; //筛选出匹配数据
  361. });
  362. // console.log(obj);
  363. this.room_options.room_value = obj.value
  364. this.room_options.room_label = obj.label
  365. this.table.currentPage = 1
  366. // 组合参数,刷新消费表格
  367. this.selectParams()
  368. },
  369. /**
  370. * 1. 组合参数
  371. * 2. 刷新消费表格
  372. */
  373. selectParams() {
  374. var params = {}
  375. params.page = this.table.currentPage
  376. params.rows = this.table.pageRows
  377. if (this.startTime != '' && typeof(this.startTime) != 'undefined') {
  378. params.begin_time = this.startTime
  379. }
  380. if (this.endTime != '' && typeof(this.endTime) != 'undefined') {
  381. params.end_time = this.endTime
  382. }
  383. if (this.drom_options.value != 0) {
  384. params.build = this.drom_options.label
  385. }
  386. if (this.room_options.room_value != 0) {
  387. params.dom = this.room_options.room_label
  388. }
  389. // 刷新消费表格
  390. this.getTodayXiaofei(params)
  391. },
  392. /**
  393. * 获取消费列表
  394. * @param {Object} params
  395. */
  396. getTodayXiaofei(params) {
  397. var _this = this
  398. this.$axios.get('/jxch-smartmp/HotWaters/waterfindConsume.action', {
  399. params: params
  400. })
  401. .then(res => {
  402. // console.log(res.data);
  403. this.tableData = []
  404. _this.rows_total = 0
  405. if (typeof(res.data.rows) != 'undefined' && res.data.rows != '' && JSON.stringify(
  406. res.data) !=
  407. '{}') {
  408. _this.tableData = res.data.rows
  409. _this.rows_total = res.data.total
  410. } else {
  411. _this.$message.success('【当日消费】暂无数据!');
  412. }
  413. })
  414. .catch(err => {
  415. // console.log(err);
  416. _this.$message.error('【当日消费】请求异常: ' + err);
  417. })
  418. },
  419. formatDigit: (row, column, cellValue, index) => {
  420. // row: 行数据
  421. // column: 列属性
  422. // cellValue: 单元格数据值
  423. // index: 行索引,注意:2.3.9版本以后才有。
  424. return cellValue.toFixed(2)
  425. },
  426. /**
  427. * 获取楼栋号,填充下拉列表
  428. */
  429. getBuildsFillSelect() {
  430. // 获取楼栋号,填充下拉列表
  431. var _this = this
  432. this.$axios.get('/jxch-smartmp/HotWaters/watergetBuilds.action')
  433. .then(res => {
  434. // console.log(res.data);
  435. if (typeof(res.data.builds) != 'undefined' && res.data.builds != '' && JSON
  436. .stringify(res
  437. .data) != '{}') {
  438. this.drom_options.builds = [{
  439. value: 0,
  440. label: '全部'
  441. }]
  442. for (var i = 0; i < res.data.builds.length; i++) {
  443. let tmp = {
  444. value: i + 1,
  445. label: res.data.builds[i]
  446. }
  447. this.drom_options.builds.push(tmp)
  448. }
  449. } else {
  450. _this.$message.success('【楼栋号】暂无数据!');
  451. }
  452. })
  453. .catch(err => {
  454. // console.log(err);
  455. _this.$message.error('【楼栋号】请求异常: ' + err);
  456. })
  457. },
  458. /**
  459. * 获取年月日消费总金额
  460. * @param {Object} params
  461. */
  462. get_year_month_day_amount() {
  463. var _this = this
  464. this.xiaofei.year_balance = 0.0.toFixed(2)
  465. this.xiaofei.month_balance = 0.0.toFixed(2)
  466. this.xiaofei.day_balance = 0.0.toFixed(2)
  467. this.today_xiaofei = 0.0.toFixed(2)
  468. // 年消费记录
  469. this.$axios.get('/jxch-smartmp/HotWaters/watertotalFeel.action', {
  470. params: {
  471. year: this.select_riqi.select_year
  472. }
  473. })
  474. .then(res => {
  475. // console.log(res.data);
  476. if (typeof(res.data) != 'undefined' && res.data != '' && JSON.stringify(res
  477. .data) != '{}') {
  478. // _this.$message.success('数据加载成功!');
  479. this.xiaofei.year_balance = parseFloat(res.data.money_year).toFixed(2)
  480. } else {
  481. _this.$message.success('【年消费】暂无数据!');
  482. }
  483. })
  484. .catch(err => {
  485. // console.log(err);
  486. _this.$message.error('【年消费】请求异常: ' + err);
  487. })
  488. // 月消费记录
  489. this.$axios.get('/jxch-smartmp/HotWaters/watertotalFeel.action', {
  490. params: {
  491. month: this.select_riqi.select_month
  492. }
  493. })
  494. .then(res => {
  495. // console.log(res.data);
  496. if (typeof(res.data) != 'undefined' && res.data != '' && JSON.stringify(res
  497. .data) != '{}') {
  498. // _this.$message.success('数据加载成功!');
  499. this.xiaofei.month_balance = parseFloat(res.data.money_month).toFixed(2)
  500. } else {
  501. _this.$message.success('【月消费】暂无数据!');
  502. }
  503. })
  504. .catch(err => {
  505. // console.log(err);
  506. _this.$message.error('【月消费】请求异常: ' + err);
  507. })
  508. // 日消费记录
  509. this.$axios.get('/jxch-smartmp/HotWaters/watertotalFeel.action', {
  510. params: {
  511. day: this.select_riqi.select_day
  512. }
  513. })
  514. .then(res => {
  515. // console.log(res.data);
  516. if (typeof(res.data) != 'undefined' && res.data != '' && JSON.stringify(res
  517. .data) != '{}') {
  518. // _this.$message.success('数据加载成功!');
  519. this.xiaofei.day_balance = parseFloat(res.data.money_day).toFixed(2)
  520. this.today_xiaofei = parseFloat(res.data.money_day).toFixed(2)
  521. } else {
  522. _this.$message.success('【日消费】暂无数据!');
  523. }
  524. })
  525. .catch(err => {
  526. // console.log(err);
  527. _this.$message.error('【日消费】请求异常: ' + err);
  528. })
  529. },
  530. toggleSelection(rows) {
  531. if (rows) {
  532. rows.forEach(row => {
  533. this.$refs.multipleTable.toggleRowSelection(row);
  534. });
  535. } else {
  536. this.$refs.multipleTable.clearSelection();
  537. }
  538. },
  539. // 显示消费对话框
  540. showxiaofeiDialog() {
  541. this.xiaofeiDialog = true
  542. },
  543. // 点击多选按钮获取的行数据数组
  544. handleSelectionChange(val) {
  545. // this.multipleSelection = val
  546. // console.log(val);
  547. }
  548. }
  549. }
  550. </script>
  551. <style scoped>
  552. @import url("shangjiaduizhang.css");
  553. </style>