selfCarTrade.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <div class="billWay_container">
  3. <div class="title">
  4. <el-row>
  5. <el-col :span="24">
  6. <div class="top">
  7. <div class="demo-input-suffix" style="margin-left: 10px;">
  8. <el-upload :action="url" :http-request="importExcel" list-type="text" :show-file-list="false" >
  9. <el-button type="primary">导入参数</el-button>
  10. <el-select style="margin-left: 110px;" v-model="formCondition.status" placeholder="交易状态">
  11. <el-option
  12. v-for="item in tradeStatus"
  13. :key="item.value"
  14. :label="item.label"
  15. :value="item.value">
  16. </el-option>
  17. </el-select>
  18. <el-button style="margin-left: 10px;" @click="DownloadTemplate">查询模板下载</el-button>
  19. </el-upload>
  20. </div>
  21. <div class="demo-input-suffix" style="margin-top: 5px;">
  22. <el-input placeholder="公司名称" class="input-demo" v-model="formCondition.companyName"></el-input>
  23. <el-input placeholder="etc卡号" class="input-demo" v-model="formCondition.cardId"></el-input>
  24. <el-input placeholder="税号" class="input-demo" v-model="formCondition.companyReferencenum"></el-input>
  25. <el-input placeholder="交易id" class="input-demo" v-model="formCondition.tradeId"></el-input>
  26. </div>
  27. <div class="demo-input-suffix" style="margin-top: 5px;margin-left: 10px;">
  28. <el-date-picker v-model="formCondition.exTimeBegin" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="交易时间始" end-placeholder="交易时间止"></el-date-picker>
  29. <el-date-picker v-model="formCondition.aclTimeBegin" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="申请开票时间始" end-placeholder="申请开票时间止"></el-date-picker>
  30. <el-button type="success" style="margin-left: 1%;" @click="firstLoadData">查询</el-button>
  31. <el-button type="success" style="margin-left: 1%;" @click="update">更新</el-button>
  32. <el-button type="primary" @click="exportExcel">导出报表</el-button>
  33. </div>
  34. </div>
  35. </el-col>
  36. </el-row>
  37. </div>
  38. <!-- 表格部分 -->
  39. <template>
  40. <el-table
  41. class="table"
  42. v-loading="loading"
  43. ref="multipleTable"
  44. :data="selfcarTrade"
  45. :height="heightt"
  46. border
  47. tooltip-effect="dark" @selection-change="handleSelectionChange">
  48. <el-table-column
  49. type="selection"
  50. width="55">
  51. </el-table-column>
  52. <el-table-column
  53. label="企业编号"
  54. prop="companyNum"
  55. show-overflow-tooltip>
  56. </el-table-column>
  57. <el-table-column
  58. prop="companyName"
  59. label="公司名称"
  60. show-overflow-tooltip>
  61. </el-table-column>
  62. <el-table-column
  63. prop="companyReferencenum"
  64. label="公司税号"
  65. show-overflow-tooltip>
  66. </el-table-column>
  67. <el-table-column
  68. prop="tradeId"
  69. label="交易Id"
  70. show-overflow-tooltip>
  71. </el-table-column>
  72. <el-table-column
  73. prop="cardId"
  74. label="ETC卡号"
  75. show-overflow-tooltip>
  76. </el-table-column>
  77. <el-table-column
  78. prop="fee"
  79. label="交易费用"
  80. show-overflow-tooltip>
  81. <template slot-scope="scope">
  82. <span>{{scope.row.fee/100| rounding}}</span>
  83. </template>
  84. </el-table-column>
  85. <el-table-column
  86. prop="exTime"
  87. label="交易时间"
  88. show-overflow-tooltip>
  89. </el-table-column>
  90. <el-table-column
  91. prop="aclTime"
  92. label="申请开票时间"
  93. show-overflow-tooltip>
  94. </el-table-column>
  95. <el-table-column
  96. prop="applId"
  97. label="申请Id"
  98. show-overflow-tooltip>
  99. </el-table-column>
  100. <el-table-column
  101. prop="status"
  102. label="状态"
  103. show-overflow-tooltip>
  104. <template slot-scope="scope">
  105. <span v-if="scope.row.status == 1" style="color: green">待开票</span>
  106. <span v-else-if="scope.row.status == 2" style="color: red">开票中</span>
  107. <span v-else-if="scope.row.status == 3" style="color: red">已开票</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column
  111. prop="interType"
  112. label="对接方式"
  113. show-overflow-tooltip>
  114. <template slot-scope="scope">
  115. <span v-if="scope.row.interType == 0">接口</span>
  116. <span v-if="scope.row.interType == 1">平台</span>
  117. <span v-if="scope.row.interType == 3">迁移数据</span>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. </template>
  122. <!-- 分页 -->
  123. <div class="block">
  124. <el-pagination
  125. @size-change="handleSizeChange"
  126. @current-change="handleCurrentChange"
  127. :current-page="current"
  128. :page-sizes="[6, 8, 10, 20, 50, 100]"
  129. :page-size="pagesize"
  130. layout="total, sizes, prev, pager, next, jumper"
  131. :total="total">
  132. </el-pagination>
  133. </div>
  134. </div>
  135. </template>
  136. <script type="text/javascript">
  137. import CsvExportor from 'csv-exportor'
  138. import FileSaver from 'file-saver'
  139. import XLSX from 'xlsx'
  140. export default {
  141. data() {
  142. return {
  143. multipleSelection: [],
  144. formCondition: {
  145. status: ``,
  146. cardId: ``,
  147. tradeId: ``
  148. },
  149. formUserList: {
  150. 'file': ``
  151. },
  152. tradeStatus: [{'label': `待开票`, 'value': `1`}, {'label': `开票中`, 'value': `2`}, {'label': `已开票`, 'value': `3`}],
  153. selfcarTrade: [],
  154. hightt: `0px`,
  155. current: 1,
  156. pagesize: 8,
  157. total: ``
  158. }
  159. },
  160. created() {
  161. this.heightt = tableHeight - 90 // eslint-disable-line
  162. this.loadData()
  163. },
  164. filters: {
  165. rounding(value) {
  166. return value.toFixed(2)
  167. }
  168. },
  169. methods: {
  170. firstLoadData() {
  171. this.current = 1
  172. this.pagesize = 8
  173. this.loadData()
  174. },
  175. async update() {
  176. var loading = null
  177. if (this.multipleSelection.length == 0) {
  178. loading = this.$loading({
  179. lock: true,
  180. text: `全量更新中,速度较慢,请您耐心等待...`,
  181. spinner: `el-icon-loading`,
  182. background: `rgba(0, 0, 0, 0.7)`
  183. })
  184. };
  185. const formData = new FormData()
  186. formData.append(`selfCarTradesStr`, JSON.stringify(this.multipleSelection))
  187. const response = await this.$http.post(`selfCar/updateTrades`, formData)
  188. if (this.multipleSelection.length == 0) {
  189. loading.close()
  190. };
  191. this.loadData()
  192. this.$message({
  193. type: `success`,
  194. message: `更新成功`
  195. })
  196. },
  197. // 列表展示
  198. async loadData() {
  199. const formData = new FormData()
  200. formData.append(`current`, this.current)
  201. formData.append(`size`, this.pagesize)
  202. for (var i in this.formCondition) {
  203. formData.append(i, this.formCondition[i])
  204. }
  205. const response = await this.$http.post(`selfCar/findTrades`, formData)
  206. if (response.data.code == 0) {
  207. this.selfcarTrade = response.data.data.records
  208. this.total = response.data.data.total
  209. }
  210. },
  211. importExcel(content) {
  212. const file = content.file
  213. // let file = file.files[0] // 使用传统的input方法需要加上这一步
  214. const filename = file.name
  215. if (!filename || typeof filename != `string`) {
  216. this.$message(`格式错误!请重新选择`)
  217. return
  218. }
  219. let a = filename.split(``).reverse().join(``)
  220. let types = a.substring(0, a.search(/\./)).split(``).reverse().join(``)
  221. const fileType = [`xlsx`, `xlc`, `xlm`, `xls`, `xlt`, `xlw`, `csv`].some((item) => { return item === types })
  222. if (!fileType) {
  223. this.$message(fileType + `格式错误!请重新选择xlsx格式`)
  224. return
  225. }
  226. this.file2Xce(file).then((tabJson) => {
  227. var tradeIds = ``
  228. var etcIds = ``
  229. if (tabJson && tabJson.length > 0) {
  230. this.xlsxJson = tabJson
  231. this.fileList = this.xlsxJson[0].sheet
  232. let n = `匹配的字段`
  233. var i = 0
  234. var j = 0
  235. this.fileList.forEach((item, index, arr) => {
  236. if (item[`etc卡号`] != null && item[`etc卡号`] != `` && typeof item[`etc卡号`] != `undefined`) {
  237. etcIds += item[`etc卡号`].trim() + `,`
  238. i++
  239. } else {
  240. etcIds += `#,`
  241. }
  242. if (item[`交易id`] != null && item[`交易id`] != `` && typeof item[`交易id`] != `undefined`) {
  243. tradeIds += item[`交易id`].trim() + `,`
  244. j++
  245. } else {
  246. tradeIds += `#,`
  247. }
  248. })
  249. }
  250. if (etcIds != `` && i > 0) {
  251. this.formCondition.cardId = etcIds.substring(0, etcIds.length - 1)
  252. }
  253. if (tradeIds != `` && j > 0) {
  254. this.formCondition.tradeId = tradeIds.substring(0, tradeIds.length - 1)
  255. }
  256. })
  257. },
  258. file2Xce(file) {
  259. return new Promise(function(resolve, reject) {
  260. const reader = new FileReader()
  261. reader.onload = function(e) {
  262. const data = e.target.result
  263. this.wb = XLSX.read(data, {
  264. type: `binary`
  265. })
  266. const result = []
  267. var are = (this.wb.Sheets.Sheet1)[`!ref`]
  268. var areRe = are.replace(`A1`, `A2`);
  269. (this.wb.Sheets.Sheet1)[`!ref`] = areRe
  270. this.wb.SheetNames.forEach((sheetName) => {
  271. result.push({
  272. sheetName: sheetName,
  273. sheet: XLSX.utils.sheet_to_json(this.wb.Sheets[sheetName])
  274. })
  275. })
  276. resolve(result)
  277. }
  278. // reader.readAsBinaryString(file.raw)
  279. reader.readAsBinaryString(file) // 传统input方法
  280. })
  281. },
  282. handleSelectionChange(value) {
  283. this.multipleSelection = value
  284. },
  285. // 下载模板
  286. DownloadTemplate() {
  287. var url = hostUrl + `noCar/templateDownload?fileName=6` // eslint-disable-line
  288. window.location.href = url
  289. },
  290. handleRemove(file, fileList) {
  291. },
  292. handlePreview(file) {
  293. },
  294. handleSuccess(a) {
  295. this.formUserList.file = a.raw
  296. },
  297. // 批量上传模板信息
  298. async batchUpload() {
  299. this.fullscreenLoading = true
  300. const formData = new FormData()
  301. formData.append(`file`, this.formUserList.file)
  302. const response = await this.$http.post(`selfCar/batchImportSelfcarTrades`, formData)
  303. var {data: { code, msg, data }} = response
  304. if (code == 0 && msg == `1`) {
  305. this.fullscreenLoading = false
  306. this.invoiceTable = response.data.data
  307. this.total = response.data.data.length
  308. } else {
  309. this.fullscreenLoading = false
  310. this.$message.error(`数据存在错误,请检查文件中数据`)
  311. }
  312. },
  313. // 分页方法
  314. handleSizeChange(val) {
  315. this.pagesize = val
  316. this.loadData()
  317. },
  318. handleCurrentChange(val) {
  319. this.current = val
  320. this.loadData()
  321. },
  322. async exportExcel1() {
  323. const loading = this.$loading({
  324. lock: true,
  325. text: `系统正在努力接收中,过程大概需要几分钟的时间,请您耐心等待...`,
  326. spinner: `el-icon-loading`,
  327. background: `rgba(0, 0, 0, 0.7)`
  328. })
  329. let curr = this.current
  330. let pagesize1 = this.pagesize
  331. this.current = 1
  332. this.pagesize = this.total
  333. await this.loadData()
  334. // 设置当前日期
  335. let time = new Date()
  336. let year = time.getFullYear()
  337. let month = time.getMonth() + 1
  338. let day = time.getDate()
  339. let name = `自有车交易查询列表_` + year + `` + month + `` + day
  340. /* generate workbook object from table */
  341. // .table要导出的是哪一个表格
  342. var wb = XLSX.utils.table_to_book(document.querySelector(`.table`), { raw: true })
  343. /* get binary string as output */
  344. var wbout = XLSX.write(wb, {
  345. bookType: `xlsx`,
  346. bookSST: true,
  347. type: `array`
  348. })
  349. try {
  350. // name+'.xlsx'表示导出的excel表格名字
  351. FileSaver.saveAs(
  352. new Blob([wbout], { type: `application/octet-stream` }),
  353. name + `.xlsx`
  354. )
  355. } catch (e) {
  356. }
  357. this.current = curr
  358. this.pagesize = pagesize1
  359. this.loadData()
  360. loading.close()
  361. return wbout
  362. },
  363. async exportExcel() {
  364. const loading = this.$loading({
  365. lock: true,
  366. text: `系统正在努力接收中,过程大概需要几分钟的时间,请您耐心等待...`,
  367. spinner: `el-icon-loading`,
  368. background: `rgba(0, 0, 0, 0.7)`
  369. })
  370. var recodes = []
  371. for (var j = 1; j <= this.total / 10000 + 1; j++) {
  372. const formData = new FormData()
  373. formData.append(`current`, j)
  374. formData.append(`size`, 10000)
  375. for (var i in this.formCondition) {
  376. formData.append(i, this.formCondition[i])
  377. }
  378. const response = await this.$http.post(`selfCar/findTrades`, formData)
  379. if (response.data.code == 0) {
  380. recodes = recodes.concat(response.data.data.records)
  381. }
  382. }
  383. // 设置当前日期
  384. let time = new Date()
  385. let year = time.getFullYear()
  386. let month = time.getMonth() + 1
  387. let day = time.getDate()
  388. let name = `自有车交易查询列表_` + year + `` + month + `` + day
  389. let cloums = [
  390. {'title': `企业编号`, 'key': `companyNum`},
  391. {'title': `公司名称`, 'key': `companyName`},
  392. {'title': `公司税号`, 'key': `companyReferencenum`},
  393. {'title': `交易Id`, 'key': `tradeId`},
  394. {'title': `etc卡号`, 'key': `cardId`},
  395. {'title': `交易费用`, 'key': `fee`},
  396. {'title': `交易时间`, 'key': `exTime`},
  397. {'title': `申请开票时间`, 'key': `aclTime`},
  398. {'title': `申请Id`, 'key': `applId`},
  399. {'title': `状态`, 'key': `status`}
  400. ]
  401. this.exportExcelComm(cloums, recodes, name, loading)
  402. },
  403. // 导出Excel
  404. exportExcelComm(columns, list, excelName, loading) {
  405. let tHeader = []
  406. let filterVal = []
  407. columns.forEach((item) => {
  408. tHeader.push(item.title)
  409. filterVal.push(item.key)
  410. })
  411. const data = this.formatJson(filterVal, list)
  412. data.unshift(tHeader)
  413. CsvExportor.downloadCsv(data, { tHeader }, excelName + `.csv`)
  414. loading.close()
  415. },
  416. formatJson(filterVal, jsonData) {
  417. return jsonData.map((v) => {
  418. return filterVal.map((j) => {
  419. if (j == `status`) {
  420. if (v[j] == 1) {
  421. return `待开票`
  422. } else if (v[j] == 2) {
  423. return `开票中`
  424. } else if (v[j] == 3) {
  425. return `开票完成`
  426. }
  427. } else if (j == `fee`) {
  428. return v[j] / 100
  429. } else if (j == `companyReferencenum` || j == `cardId`) {
  430. return v[j] + `\t`
  431. } else {
  432. return v[j]
  433. }
  434. })
  435. })
  436. }
  437. }
  438. }
  439. </script>
  440. <style>
  441. .billWay_container {
  442. border: 1px solid #d9d9d9;
  443. border-radius: 10px;
  444. }
  445. .billWay_container .title {
  446. font-size: 5px;
  447. margin-bottom: 20px;
  448. }
  449. .billWay_container .top {
  450. padding-top: 20px;
  451. padding-left: 20px;
  452. }
  453. .billWay_container .text {
  454. display: inline-block;
  455. color: #000;
  456. font-size: 16px ;
  457. margin-left: 1%;
  458. }
  459. .billWay_container .input-demo {
  460. display: inline-block;
  461. width: 20%;
  462. margin-left: 1%;
  463. }
  464. .billWay_container .block {
  465. font-size: 5px;
  466. text-align: center;
  467. margin-top: 25px;
  468. margin-bottom: 25px;
  469. }
  470. .billWay_container .el-dialog {
  471. width: 60%;
  472. }
  473. .billWay_container .el-dialog__header, .el-dialog__body {
  474. padding: 0 20px;
  475. }
  476. .billWay_container .tou {
  477. font-size: 20px;
  478. height: 30px;
  479. line-height: 30px;
  480. padding-top: 15px;
  481. }
  482. .billWay_container .line {
  483. margin-top: 15px;
  484. margin-bottom: 15px;
  485. width: 100%;
  486. height: 2px;
  487. background-color: #d9d9d9;
  488. }
  489. .billWay_container .xinxi {
  490. text-align: center;
  491. margin: 15px auto;
  492. font-size: 18px;
  493. }
  494. </style>