tradeCarApply.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div class="invoice_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-button style="margin-left: 555px;" @click="DownloadTemplate">查询模板下载</el-button>
  11. </el-upload>
  12. </div>
  13. <div class="demo-input-suffix" style="margin-top: 5px">
  14. <el-input placeholder="公司编码" class="input-demo" v-model="formCondition.companyNum"></el-input>
  15. <el-input placeholder="etc卡号" class="input-demo" v-model="formCondition.cardId"></el-input>
  16. <el-input placeholder="交易id" class="input-demo" v-model="formCondition.tradeId"></el-input>
  17. <el-button type="success" style="margin-left: 1%;" @click="loadData">查询</el-button>
  18. <el-button type="primary" style="margin-left: 1%;" @click="exportExcel">导出报表</el-button>
  19. </div>
  20. </div>
  21. </el-col>
  22. </el-row>
  23. </div>
  24. <!-- 表格部分 -->
  25. <template>
  26. <el-table
  27. class="table"
  28. v-loading="loading"
  29. ref="multipleTable"
  30. :data="invoiceTable"
  31. :height="heightt"
  32. border
  33. tooltip-effect="dark">
  34. <el-table-column
  35. label="ETC卡号"
  36. prop="cardId"
  37. show-overflow-tooltip>
  38. </el-table-column>
  39. <el-table-column
  40. prop="applyId"
  41. label="申请id"
  42. show-overflow-tooltip>
  43. </el-table-column>
  44. <el-table-column
  45. prop="tradeCount"
  46. label="交易数量"
  47. show-overflow-tooltip>
  48. </el-table-column>
  49. <el-table-column
  50. prop="invoiceCount"
  51. label="发票数量"
  52. show-overflow-tooltip>
  53. </el-table-column>
  54. <!-- <el-table-column
  55. prop="invoiceAmount"
  56. label="发票金额"
  57. show-overflow-tooltip>
  58. </el-table-column> -->
  59. <el-table-column
  60. prop="invoiceAmount"
  61. label="发票金额"
  62. width="100"
  63. show-overflow-tooltip>
  64. <template slot-scope="scope">
  65. <span>{{scope.row.invoiceAmount/100| rounding}}</span>
  66. </template>
  67. </el-table-column>
  68. <!-- <el-table-column
  69. prop="taxAmount"
  70. label="发票税额"
  71. show-overflow-tooltip>
  72. </el-table-column> -->
  73. <el-table-column
  74. prop="taxAmount"
  75. label="发票税额"
  76. width="100"
  77. show-overflow-tooltip>
  78. <template slot-scope="scope">
  79. <span>{{scope.row.taxAmount/100| rounding}}</span>
  80. </template>
  81. </el-table-column>
  82. <el-table-column
  83. prop="invoicedCount"
  84. label="已开发票数量"
  85. show-overflow-tooltip>
  86. </el-table-column>
  87. <!-- <el-table-column
  88. prop="invoicedAmount"
  89. label="已开发票金额"
  90. width="100"
  91. show-overflow-tooltip>
  92. </el-table-column> -->
  93. <el-table-column
  94. prop="invoicedAmount"
  95. label="已开发票金额"
  96. width="100"
  97. show-overflow-tooltip>
  98. <template slot-scope="scope">
  99. <span>{{scope.row.invoicedAmount/100| rounding}}</span>
  100. </template>
  101. </el-table-column>
  102. <!-- <el-table-column
  103. prop="applyStatus"
  104. label="申请状态"
  105. width="100"
  106. show-overflow-tooltip>
  107. </el-table-column> -->
  108. <el-table-column
  109. prop="applyStatus"
  110. label="申请状态"
  111. show-overflow-tooltip>
  112. <template slot-scope="scope">
  113. <span v-if="scope.row.applyStatus == 1" style="color: green">申请中</span>
  114. <span v-else-if="scope.row.applyStatus == 2" style="color: red">开票中</span>
  115. <span v-else-if="scope.row.applyStatus == 3" style="color: red">开票完成</span>
  116. </template>
  117. </el-table-column>
  118. </el-table>
  119. </template>
  120. </div>
  121. </template>
  122. <script type="text/javascript">
  123. import FileSaver from 'file-saver'
  124. import CsvExportor from 'csv-exportor'
  125. import XLSX from 'xlsx'
  126. export default {
  127. data() {
  128. return {
  129. formCondition: {
  130. companyNum: ``,
  131. cardId: ``,
  132. tradeId: ``
  133. },
  134. invoiceTable: [],
  135. hightt: `0px`
  136. }
  137. },
  138. created() {
  139. this.heightt = tableHeight - 50 // eslint-disable-line
  140. },
  141. filters: {
  142. rounding(value) {
  143. return value.toFixed(2)
  144. }
  145. },
  146. methods: {
  147. firstLoadData() {
  148. },
  149. // 列表展示
  150. async loadData() {
  151. const formData = new FormData()
  152. for (var i in this.formCondition) {
  153. formData.append(i, this.formCondition[i])
  154. }
  155. const response = await this.$http.post(`selfCarService/getApplyQueryByTradeIds`, formData);
  156. if (response.data.code === 0) {
  157. this.invoiceTable = response.data.data.result;
  158. } else {
  159. this.$message({
  160. type: `error`,
  161. message: `查询结果:` + response.data.msg
  162. });
  163. }
  164. },
  165. importExcel(content) {
  166. const file = content.file;
  167. // let file = file.files[0] // 使用传统的input方法需要加上这一步
  168. const filename = file.name;
  169. if (!filename || typeof filename !== `string`) {
  170. this.$message(`格式错误!请重新选择`);
  171. return;
  172. }
  173. let a = filename.split(``).reverse().join(``);
  174. let types = a.substring(0, a.search(/\./)).split(``).reverse().join(``);
  175. const fileType = [`xlsx`, `xlc`, `xlm`, `xls`, `xlt`, `xlw`, `csv`].some((item) => { return item === types });
  176. if (!fileType) {
  177. this.$message(`格式错误!请重新选择`)
  178. return;
  179. }
  180. this.file2Xce(file).then((tabJson) => {
  181. var companyNums = ``;
  182. var etcIds = ``;
  183. var tradeIds = ``;
  184. if (tabJson && tabJson.length > 0) {
  185. this.xlsxJson = tabJson;
  186. this.fileList = this.xlsxJson[0].sheet;
  187. let n = `匹配的字段`;
  188. var k = 0;
  189. var i = 0;
  190. var j = 0;
  191. this.fileList.forEach((item, index, arr) => {
  192. if (item[`公司编码`] !== null && item[`公司编码`] !== `` && typeof item[`公司编码`] !== `undefined`) {
  193. companyNums += item[`公司编码`].trim() + `,`;
  194. k++;
  195. } else {
  196. companyNums += `#,`;
  197. }
  198. if (item[`etc卡号`] !== null && item[`etc卡号`] !== `` && typeof item[`etc卡号`] !== `undefined`) {
  199. etcIds += item[`etc卡号`].trim() + `,`;
  200. i++;
  201. } else {
  202. etcIds += `#,`;
  203. }
  204. if (item[`交易id`] !== null && item[`交易id`] !== `` && typeof item[`交易id`] !== `undefined`) {
  205. tradeIds += item[`交易id`].trim() + `,`;
  206. j++;
  207. } else {
  208. tradeIds += `#,`;
  209. }
  210. });
  211. }
  212. if (companyNums !== `` && k > 0) {
  213. this.formCondition.companyNum = companyNums.substring(0, companyNums.length - 1);
  214. }
  215. if (etcIds !== `` && i > 0) {
  216. this.formCondition.cardId = etcIds.substring(0, etcIds.length - 1);
  217. }
  218. if (tradeIds !== `` && j > 0) {
  219. this.formCondition.tradeId = tradeIds.substring(0, tradeIds.length - 1);
  220. }
  221. });
  222. },
  223. file2Xce(file) {
  224. return new Promise(function(resolve, reject) {
  225. const reader = new FileReader();
  226. reader.onload = function(e) {
  227. const data = e.target.result;
  228. this.wb = XLSX.read(data, {
  229. type: `binary`
  230. });
  231. const result = [];
  232. var are = (this.wb.Sheets.Sheet1)[`!ref`];
  233. var areRe = are.replace(`A1`, `A2`);
  234. (this.wb.Sheets.Sheet1)[`!ref`] = areRe;
  235. this.wb.SheetNames.forEach((sheetName) => {
  236. result.push({
  237. sheetName: sheetName,
  238. sheet: XLSX.utils.sheet_to_json(this.wb.Sheets[sheetName])
  239. });
  240. });
  241. resolve(result);
  242. };
  243. // reader.readAsBinaryString(file.raw)
  244. reader.readAsBinaryString(file);// 传统input方法
  245. });
  246. },
  247. // 下载模板
  248. DownloadTemplate() {
  249. var url = hostUrl + `noCar/templateDownload?fileName=8`; // eslint-disable-line
  250. window.location.href = url;
  251. },
  252. exportExcel() {
  253. const loading = this.$loading({
  254. lock: true,
  255. text: `系统正在努力接收中,过程大概需要几分钟的时间,请您耐心等待...`,
  256. spinner: `el-icon-loading`,
  257. background: `rgba(0, 0, 0, 0.7)`
  258. });
  259. // 设置当前日期
  260. let time = new Date()
  261. let year = time.getFullYear()
  262. let month = time.getMonth() + 1
  263. let day = time.getDate()
  264. let name = `按交易查询申请列表_` + year + `` + month + `` + day
  265. /* generate workbook object from table */
  266. // .table要导出的是哪一个表格
  267. var wb = XLSX.utils.table_to_book(document.querySelector(`.table`), { raw: true })
  268. /* get binary string as output */
  269. var wbout = XLSX.write(wb, {
  270. bookType: `xlsx`,
  271. bookSST: true,
  272. type: `array`
  273. });
  274. try {
  275. // name+'.xlsx'表示导出的excel表格名字
  276. FileSaver.saveAs(
  277. new Blob([wbout], { type: `application/octet-stream` }),
  278. name + `.xlsx`
  279. );
  280. } catch (e) {
  281. }
  282. loading.close();
  283. return wbout;
  284. },
  285. formatJson(filterVal, jsonData) {
  286. return jsonData.map((v) => {
  287. return filterVal.map((j) => {
  288. if (j === `tradeStatus`) {
  289. if (v[j] === 1) {
  290. return `待开票`
  291. } else if (v[j] === 2) {
  292. return `开票中`
  293. } else if (v[j] === 3) {
  294. return `开票完成`
  295. }
  296. } else if (j === `fee`) {
  297. return v[j] / 100
  298. } else if (j === `totalAmount`) {
  299. return v[j] / 100
  300. } else if (j === `totalTaxAmount`) {
  301. return v[j] / 100
  302. } else if (j === `amount`) {
  303. return v[j] / 100
  304. } else if (j === `sellerTaxpayerCode` || j === `cardId` || j === `invoiceCode` || j === `invoiceNum`) {
  305. return v[j] + `\t`
  306. } else {
  307. return v[j]
  308. }
  309. })
  310. })
  311. }
  312. }
  313. }
  314. </script>
  315. <style>
  316. .invoice_container {
  317. border: 1px solid #d9d9d9;
  318. border-radius: 10px;
  319. }
  320. .invoice_container .title {
  321. font-size: 5px;
  322. margin-bottom: 20px;
  323. }
  324. .invoice_container .top {
  325. padding-top: 20px;
  326. padding-left: 20px;
  327. }
  328. .invoice_container .text {
  329. display: inline-block;
  330. color: #000;
  331. font-size: 16px ;
  332. margin-left: 1%;
  333. }
  334. .invoice_container .input-demo {
  335. display: inline-block;
  336. width: 15%;
  337. margin-left: 1%;
  338. }
  339. .invoice_container .block {
  340. font-size: 5px;
  341. text-align: center;
  342. margin-top: 25px;
  343. margin-bottom: 25px;
  344. }
  345. .invoice_container .el-dialog {
  346. width: 60%;
  347. }
  348. .invoice_container .el-dialog__header, .el-dialog__body {
  349. padding: 0 20px;
  350. }
  351. .invoice_container .tou {
  352. font-size: 20px;
  353. height: 30px;
  354. line-height: 30px;
  355. padding-top: 15px;
  356. }
  357. .invoice_container .line {
  358. margin-top: 15px;
  359. margin-bottom: 15px;
  360. width: 100%;
  361. height: 2px;
  362. background-color: #d9d9d9;
  363. }
  364. .invoice_container .xinxi {
  365. text-align: center;
  366. margin: 15px auto;
  367. font-size: 18px;
  368. }
  369. </style>