phoneOilCard.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <div class="oilCard">
  3. <el-card>
  4. <!-- 表单 -->
  5. <el-form ref="form" :model="formData" label-position="left" >
  6. <el-form-item label="支持油卡的类型:">
  7. <div style="display:inline-block" class="cardType">
  8. <img src="../../assets/petroleum.png" alt="">
  9. <span>中国石油</span>
  10. </div>
  11. <div style="display:inline-block" class="cardType">
  12. <img src="../../assets/petrifaction.png" alt="">
  13. <span>中国石化</span>
  14. </div>
  15. </el-form-item>
  16. <el-form-item label="充值金额:">
  17. <template v-if="oil_amount.length">
  18. <el-button
  19. :type="idx === curBtn ? 'success' : 'info'"
  20. v-for="(item,idx) in oil_amount"
  21. :key="idx"
  22. @click="hRecharge(item,idx)"
  23. size="mini">{{item}}</el-button>
  24. </template>
  25. <span v-else style="font-size: 13px;color: #909399;">请选择充值金额</span>
  26. </el-form-item>
  27. <el-form-item label="卡号:">
  28. <el-input
  29. type="textarea"
  30. placeholder="请填写油卡号,最多一次可以充值30单"
  31. v-model.trim="formData.code"
  32. style="width: 80%"
  33. :rows="8"></el-input>
  34. </el-form-item>
  35. <el-form-item style="padding-left:53px;">
  36. <el-button type="primary" size="small" @click="rechargeBtn" :disabled="disabled">卡号校验</el-button>
  37. <el-button type="success" size="small" @click="confirmRecharge" :disabled="disabledRecharge">充值</el-button>
  38. </el-form-item>
  39. </el-form>
  40. </el-card>
  41. <el-card style="margin-top:20px">
  42. <h3 style="margin-bottom:20px">充值结果:</h3>
  43. <!-- 提示 -->
  44. <el-alert
  45. v-if="tableData.length"
  46. :title="'一共充值 '+all_no+' 条,成功 '+success_no+' 条,失败 '+error_no+' 条'"
  47. type="info"
  48. show-icon
  49. style="margin-top:10px"
  50. :closable="false">
  51. </el-alert>
  52. <!-- 表格 -->
  53. <el-table
  54. :data="tableData"
  55. border
  56. style="width: 100%;margin-top:20px;font-size:13px;"
  57. v-loading="loading"
  58. element-loading-text="充值中">
  59. <el-table-column align="center" prop="card_no" label="卡号" width="170"></el-table-column>
  60. <el-table-column align="center" label="订单号" width="170">
  61. <template slot-scope="scope" v-if="scope.row.state == true">
  62. {{scope.row.err}}
  63. </template>
  64. </el-table-column>
  65. <el-table-column align="center" prop="amount" label="充值金额"></el-table-column>
  66. <el-table-column align="center" label="充值状态" width="85">
  67. <template slot-scope="scope">
  68. <el-tag type="success" size="small" v-if="scope.row.state == true">成功提交</el-tag>
  69. <el-tag type="danger" size="small" v-else>失败</el-tag>
  70. </template>
  71. </el-table-column>
  72. <el-table-column align="center" label="错误原因" width="150">
  73. <template slot-scope="scope" v-if="scope.row.state != true">
  74. {{scope.row.err}}
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. </el-card>
  79. <!-- 查看弹层 -->
  80. <el-dialog
  81. title="请审核充值卡号是否正确(可编辑)"
  82. :visible.sync="dialogVisible"
  83. width="80%"
  84. @close="handleClose">
  85. <el-input v-for="(item, idx) in input" :key="idx" v-model="input[idx]" style="margin-bottom: 10px"></el-input>
  86. <span slot="footer" class="dialog-footer">
  87. <el-button @click="handleClose" size="small">取 消</el-button>
  88. <el-button type="primary" size="small" @click="trueBtn">确认无误</el-button>
  89. </span>
  90. </el-dialog>
  91. <!-- 充值弹层 -->
  92. <el-dialog
  93. title="油卡充值"
  94. :visible.sync="dialogVisibleCard"
  95. width="80%"
  96. @close="handleCloseCard">
  97. <el-input v-for="(item, idx) in input" :key="idx" :value="item" style="margin-bottom: 10px"></el-input>
  98. <span slot="footer" class="dialog-footer">
  99. <el-button @click="handleCloseCard" size="small">取 消</el-button>
  100. <el-button type="primary" size="small" @click="onSubmit">确认充值</el-button>
  101. </span>
  102. </el-dialog>
  103. </div>
  104. </template>
  105. <script>
  106. // getRechargeAmount-充值金额 OilCardRecharge-油卡充值
  107. import { getRechargeAmount, OilCardRecharge } from '@/api'
  108. export default {
  109. name: 'phoneOilCard',
  110. data() {
  111. return {
  112. formData: {
  113. code: ''
  114. },
  115. // 充值金额
  116. oil_amount: [],
  117. // 点击的按钮
  118. curBtn: '',
  119. curMoney: '',
  120. // 表格数据
  121. tableData: [],
  122. // 分页
  123. pageSize: 10,
  124. pageNumber: 1,
  125. total: 0,
  126. // 卡号确认弹层
  127. dialogVisible: false,
  128. dialogVisibleCard: false,
  129. // 卡号
  130. input: [],
  131. // 第一位字符
  132. firstStr: '',
  133. // 文本域字符
  134. codeStr: '',
  135. // 分割后字符
  136. splitStr: '',
  137. loading: false,
  138. // 充值数
  139. all_no: 0,
  140. // 成功数
  141. success_no: 0,
  142. // 失败数
  143. error_no: 0,
  144. disabled: false,
  145. disabledRecharge: false
  146. }
  147. },
  148. created() {
  149. this.getRechargeAmount()
  150. },
  151. watch: {
  152. codeStr(newVal) {
  153. console.log('newVal', newVal);
  154. // 判断是否有,或者;
  155. // console.log('newVal.substr(0,1)',newVal.substr(0,1) == ',');
  156. if (newVal.substr(0,1) == "," || newVal.substr(0,1) == "," || newVal.substr(0,1) == ";" || newVal.substr(0,1) == ";") {
  157. this.codeStr = this.codeStr.replace(/[,,;;]/, "")
  158. console.log('替换', this.codeStr);
  159. }
  160. if (this.codeStr.length > 0) {
  161. this.firstStr = this.codeStr.substr(0,1)
  162. // 1-中石化19位 9-中石油16位
  163. if (this.firstStr == '1') {
  164. if (this.codeStr.length < 19) {
  165. this.dialogVisible = false
  166. this.dialogVisibleCard = false
  167. this.splitStr = ""
  168. this.$message.error('请输入合法卡号')
  169. return
  170. }
  171. this.splitStr = this.splitStr == '' ? this.splitStr.concat(this.codeStr.substring(0,19)) : this.splitStr.concat(',' + this.codeStr.substring(0,19))
  172. this.codeStr = this.codeStr.substr(19)
  173. console.log('codeStr', this.codeStr);
  174. } else if (this.firstStr == '9') {
  175. if (this.codeStr.length < 16) {
  176. this.splitStr = ""
  177. this.dialogVisible = false
  178. this.dialogVisibleCard = false
  179. this.$message.error('请输入合法卡号')
  180. return
  181. }
  182. this.splitStr = this.splitStr == '' ? this.splitStr.concat(this.codeStr.substring(0,16)) : this.splitStr.concat(',' + this.codeStr.substring(0,16))
  183. this.codeStr = this.codeStr.substr(16)
  184. console.log('codeStr', this.codeStr);
  185. } else {
  186. this.splitStr = ""
  187. this.dialogVisible = false
  188. this.dialogVisibleCard = false
  189. this.$message.error('请输入合法卡号')
  190. }
  191. }
  192. if (!newVal) {
  193. this.input = this.splitStr.split(',')
  194. }
  195. },
  196. formData(newVal) {
  197. if (newVal.code == '') {
  198. this.splitStr = ''
  199. this.input = []
  200. }
  201. },
  202. input(newVal) {
  203. if (newVal && newVal.length > 30) {
  204. this.splitStr = ''
  205. this.input = []
  206. this.dialogVisible = false
  207. this.dialogVisibleCard = false
  208. this.$message.error('一次最多可以充值30单')
  209. }
  210. }
  211. },
  212. methods: {
  213. // 获取充值金额
  214. async getRechargeAmount() {
  215. try {
  216. const res = await getRechargeAmount()
  217. console.log('充值金额', res);
  218. if (res && res.code == 200) {
  219. this.oil_amount = res.datas.oil_amount
  220. }
  221. } catch (error) {
  222. console.log(error);
  223. }
  224. },
  225. // 点击充值金额
  226. hRecharge(item,idx) {
  227. this.curMoney = item
  228. this.curBtn = idx
  229. },
  230. // 查看按钮
  231. rechargeBtn() {
  232. this.disabled = true
  233. if (this.dialogVisible) {
  234. this.disabled = false
  235. return
  236. }
  237. if (!this.formData.code) {
  238. this.$message.error('请填写卡号')
  239. this.disabled = false
  240. return
  241. }
  242. if (!this.curMoney) {
  243. this.$message.error('请选择充值金额')
  244. this.disabled = false
  245. return
  246. }
  247. this.dialogVisible = true
  248. this.input = []
  249. // 去掉中间空格和中文
  250. this.codeStr = this.formData.code.replace(/\s/g,"").replace(/[\u4e00-\u9fa5]/g, "")
  251. console.log('1', this.codeStr);
  252. // this.inputBlur()
  253. setTimeout(() => {
  254. this.disabled = false
  255. }, 1000)
  256. },
  257. // 确认无误按钮
  258. trueBtn() {
  259. this.dialogVisible = false
  260. this.splitStr = this.input.toString()
  261. this.formData.code = this.splitStr.replace(/[',]/g, '\n')
  262. this.input = []
  263. // console.log('this.formData.code', this.formData.code);
  264. },
  265. // 充值
  266. confirmRecharge() {
  267. this.disabledRecharge = true
  268. if (this.dialogVisibleCard) {
  269. return
  270. }
  271. if (!this.formData.code) {
  272. this.disabledRecharge = false
  273. this.$message.error('请填写油卡号')
  274. return
  275. }
  276. if (!this.curMoney) {
  277. this.disabledRecharge = false
  278. this.$message.error('请选择充值金额')
  279. return
  280. }
  281. this.codeStr = this.formData.code.replace(/\s/g,"").replace(/[\u4e00-\u9fa5]/g, "")
  282. console.log('1', this.codeStr.substr(0,1));
  283. this.input = []
  284. this.splitStr = ''
  285. this.dialogVisibleCard = true
  286. setTimeout(() => {
  287. this.disabledRecharge = false
  288. }, 1000)
  289. },
  290. // 关闭弹层
  291. handleClose() {
  292. this.dialogVisible = false
  293. this.splitStr = ''
  294. this.input = []
  295. },
  296. handleCloseCard() {
  297. this.dialogVisibleCard = false
  298. this.splitStr = ''
  299. this.input = []
  300. },
  301. // 确认充值按钮
  302. async onSubmit() {
  303. this.dialogVisibleCard = false
  304. this.loading = true
  305. try {
  306. this.splitStr = this.input.toString()
  307. // cardno, amount
  308. let param = new URLSearchParams()
  309. param.append('cardno', this.splitStr)
  310. param.append('amount', this.curMoney)
  311. // const res = await OilCardRecharge({
  312. // cardno: this.splitStr,
  313. // amount: this.curMoney
  314. // })
  315. const res = await OilCardRecharge(param)
  316. console.log('油卡充值', res);
  317. if (res && res.code == 200) {
  318. this.tableData = res.datas.data
  319. this.all_no = res.datas.all_no
  320. this.success_no = res.datas.success_no
  321. this.error_no = res.datas.error_no
  322. this.splitStr = ''
  323. this.curMoney = ''
  324. this.curBtn = ''
  325. this.formData.code = ''
  326. }
  327. this.loading = false
  328. } catch (error) {
  329. console.log(error);
  330. this.loading = false
  331. }
  332. },
  333. // 分页
  334. async onPageChange(page) {
  335. if (page == this.pageNumber) {
  336. return;
  337. } else {
  338. // this.pageNumber = page;
  339. // // setTimeout(() => {
  340. // // // this.getActionLogList();
  341. // // this.getOrderList(this.pageNumber)
  342. // // }, 0);
  343. // const startTime = this.dataRange[0]
  344. // const endTime = this.dataRange[1]
  345. // const res = await queryList(this.pageNumber, startTime, endTime, this.RechargeType)
  346. // console.log('查询订单', res);
  347. // if (res && res.code == 200) {
  348. // this.tableData = res.datas.data
  349. // }
  350. }
  351. }
  352. }
  353. }
  354. </script>
  355. <style scoped lang="less">
  356. .cardType {
  357. margin-right: 10px;
  358. }
  359. .cardType img {
  360. vertical-align: middle;
  361. margin-right: 5px;
  362. }
  363. .cardType span {
  364. vertical-align: middle;
  365. }
  366. /deep/.el-table td,
  367. /deep/.el-table th {
  368. padding: 7px 0;
  369. }
  370. /deep/.el-table .cell,
  371. /deep/.el-table--border td:first-child .cell,
  372. /deep/.el-table--border th:first-child .cell {
  373. padding-left: 7px;
  374. }
  375. /deep/.el-table .cell {
  376. padding-right: 7px;
  377. }
  378. /deep/.el-card__body {
  379. padding: 10px;
  380. }
  381. /deep/.el-button+.el-button {
  382. margin-left: 6px;
  383. }
  384. /deep/.el-button--mini{
  385. padding: 7px 10px;
  386. font-size: 12px;
  387. }
  388. /deep/.el-input__inner {
  389. padding: 0 15px;/*no */
  390. text-align: left;
  391. }
  392. </style>
  393. <style>
  394. .el-main {
  395. padding: 0;
  396. margin-right: calc(100% - 100vw);
  397. }
  398. .el-card {
  399. margin: 20px 30px;
  400. }
  401. .el-table td, .el-table th.is-leaf,.el-table--border, .el-table--group{
  402. border-color: #ccc;
  403. }
  404. .el-table--border::after, .el-table--group::after, .el-table::before{
  405. background-color: #ccc;
  406. }
  407. .el-table td, .el-table th.is-leaf {
  408. border-bottom: 1px solid #ccc;
  409. border-right: 1px solid #ccc;
  410. }
  411. .el-table thead {
  412. color: #606266;
  413. }
  414. .el-message {
  415. min-width: 250px !important;
  416. }
  417. </style>