phoneMobileCard.vue 13 KB

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