mobileCard.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="mobilrCard">
  3. <el-card>
  4. <!-- 表单 -->
  5. <el-form ref="form" :model="formData" label-width="150px">
  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. <el-button
  22. :type="idx === curBtn ? 'success' : 'info'"
  23. v-for="(item,idx) in phone_amount"
  24. :key="idx"
  25. @click="hRecharge(item,idx)"
  26. size="small">{{item}}</el-button>
  27. </el-form-item>
  28. <el-form-item label="手机号:">
  29. <el-input
  30. type="textarea"
  31. placeholder="请填写手机号,最多一次可以充值30单"
  32. v-model.trim="formData.code"
  33. style="width: 70%;"
  34. :rows="15"></el-input>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button type="primary"
  38. @click="rechargeBtn"
  39. :loading="loadingSeeCard"
  40. element-loading-spinner="el-icon-loading"
  41. element-loading-background="rgba(0, 0, 0, 0.5)"
  42. :disabled="loadingSeeCard ? true : false">卡号校验</el-button>
  43. <el-button type="success" @click="confirmRecharge">充值</el-button>
  44. </el-form-item>
  45. </el-form>
  46. </el-card>
  47. <el-card style="margin-top:40px">
  48. <p>充值结果:</p>
  49. <!-- 提示 -->
  50. <el-alert
  51. v-if="tableData.length"
  52. :title="'一共充值 '+all_no+' 单,成功 '+success_no+' 单,失败 '+error_no+' 单'"
  53. type="info"
  54. show-icon
  55. style="margin-top:10px"
  56. :closable="false">
  57. </el-alert>
  58. <!-- 表格 -->
  59. <el-table
  60. :data="tableData"
  61. border
  62. style="width: 100%;margin-top:20px"
  63. v-loading="loading"
  64. element-loading-text="充值中">
  65. <el-table-column align="center" prop="card_no" label="手机号"></el-table-column>
  66. <el-table-column align="center" prop="amount" label="充值金额"></el-table-column>
  67. <el-table-column align="center" label="充值状态">
  68. <template slot-scope="scope">
  69. <el-tag type="success" size="small" v-if="scope.row.state == true">成功</el-tag>
  70. <el-tag type="danger" size="small" v-else>失败</el-tag>
  71. </template>
  72. </el-table-column>
  73. <el-table-column align="center" label="错误原因">
  74. <template slot-scope="scope" v-if="scope.row.state != true">
  75. {{scope.row.err}}
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <!-- 分页 -->
  80. <!-- <el-row style="margin-top:10px;" type="flex" justify="end">
  81. <el-pagination background layout="prev, pager, next" :total="total" :page-size="pageSize" @current-change="onPageChange" :current-page="pageNumber"></el-pagination>
  82. </el-row> -->
  83. </el-card>
  84. <!-- 查看弹层 -->
  85. <el-dialog
  86. title="请审核手机号是否正确(可编辑)"
  87. :visible.sync="dialogVisible"
  88. width="30%"
  89. @close="handleClose">
  90. <el-input v-for="(item, idx) in input" :key="idx" v-model="input[idx]" style="margin-bottom: 10px"></el-input>
  91. <span slot="footer" class="dialog-footer">
  92. <el-button @click="handleClose">取 消</el-button>
  93. <!-- <el-button type="primary" @click="onSubmit">确认无误</el-button> -->
  94. <el-button type="primary" @click="trueBtn">确认无误</el-button>
  95. </span>
  96. </el-dialog>
  97. <!-- 充值弹层 -->
  98. <el-dialog
  99. title="手机卡充值"
  100. :visible.sync="dialogVisibleCard"
  101. width="30%"
  102. @close="handleCloseCard">
  103. <el-input v-for="(item, idx) in input" :key="idx" :value="item" style="margin-bottom: 10px"></el-input>
  104. <span slot="footer" class="dialog-footer">
  105. <el-button @click="handleCloseCard">取 消</el-button>
  106. <el-button type="primary" @click="onSubmit">确认充值</el-button>
  107. </span>
  108. </el-dialog>
  109. </div>
  110. </template>
  111. <script>
  112. // getRechargeAmount-充值金额 OilCardRecharge-油卡充值
  113. import { getRechargeAmount, OilCardRecharge } from '@/api'
  114. export default {
  115. name: 'mobileCard',
  116. data() {
  117. return {
  118. formData: {
  119. code: ''
  120. },
  121. // 充值金额
  122. phone_amount: [],
  123. // 点击的按钮
  124. curBtn: '',
  125. curMoney: '',
  126. // 表格数据
  127. tableData: [],
  128. // 卡号查看弹层
  129. dialogVisible: false,
  130. // 卡号充值弹层
  131. dialogVisibleCard: false,
  132. // 卡号
  133. input: [],
  134. // 第一位字符
  135. firstStr: '',
  136. // 文本域字符
  137. codeStr: '',
  138. // 分割后字符
  139. splitStr: '',
  140. loading: false,
  141. // 充值数
  142. all_no: 0,
  143. // 成功数
  144. success_no: 0,
  145. // 失败数
  146. error_no: 0,
  147. // 查看卡号loading
  148. loadingSeeCard: false
  149. }
  150. },
  151. created() {
  152. this.getRechargeAmount()
  153. },
  154. watch: {
  155. codeStr(newVal) {
  156. console.log('newVal', newVal);
  157. // 判断是否有,或者;
  158. // console.log('newVal.substr(0,1)',newVal.substr(0,1) == ',');
  159. if (newVal.substr(0,1) == "," || newVal.substr(0,1) == "," || newVal.substr(0,1) == ";" || newVal.substr(0,1) == ";") {
  160. this.codeStr = this.codeStr.replace(/[,,;;]/, "")
  161. console.log('替换', this.codeStr);
  162. }
  163. if (this.codeStr.length > 0) {
  164. // 手机卡11位
  165. if (this.codeStr.length < 11) {
  166. this.$message.error('请输入合法手机号')
  167. this.dialogVisible = false
  168. return
  169. }
  170. this.splitStr = this.splitStr == '' ? this.splitStr.concat(this.codeStr.substring(0,11)) : this.splitStr.concat(',' + this.codeStr.substring(0,11))
  171. this.codeStr = this.codeStr.substr(11)
  172. }
  173. if (!newVal) {
  174. this.input = this.splitStr.split(',')
  175. }
  176. },
  177. formData(newVal) {
  178. if (newVal.code == '') {
  179. this.splitStr = ''
  180. this.input = []
  181. }
  182. },
  183. input(newVal) {
  184. if (newVal && newVal.length > 30) {
  185. this.$message.error('一次最多可以充值30单')
  186. this.splitStr = ''
  187. this.input = []
  188. this.dialogVisible = false
  189. this.dialogVisibleCard = false
  190. }
  191. }
  192. },
  193. methods: {
  194. // 获取充值金额
  195. async getRechargeAmount() {
  196. const res = await getRechargeAmount()
  197. console.log('充值金额', res);
  198. if (res && res.code == 200) {
  199. this.phone_amount = res.datas.phone_amount
  200. }
  201. },
  202. // 点击充值金额
  203. hRecharge(item,idx) {
  204. this.curMoney = item
  205. this.curBtn = idx
  206. },
  207. // 查看按钮
  208. rechargeBtn() {
  209. this.loadingSeeCard = true
  210. if (!this.formData.code) {
  211. this.$message.error('请填写手机号')
  212. this.loadingSeeCard = false
  213. return
  214. }
  215. if (!this.curMoney) {
  216. this.$message.error('请选择充值金额')
  217. this.loadingSeeCard = false
  218. return
  219. }
  220. this.dialogVisible = true
  221. this.input = []
  222. this.splitStr = ''
  223. this.codeStr = this.formData.code.replace(/\s/g,"").replace(/[\u4e00-\u9fa5]/g, "")
  224. console.log('1', this.codeStr.substr(0,1));
  225. this.loadingSeeCard = false
  226. },
  227. confirmRecharge() {
  228. if (!this.formData.code) {
  229. this.$message.error('请填写手机号')
  230. return
  231. }
  232. if (!this.curMoney) {
  233. this.$message.error('请选择充值金额')
  234. return
  235. }
  236. this.dialogVisibleCard = true
  237. this.input = []
  238. this.splitStr = ''
  239. this.codeStr = this.formData.code.replace(/\s/g,"").replace(/[\u4e00-\u9fa5]/g, "")
  240. console.log('1', this.codeStr);
  241. },
  242. // 关闭弹层
  243. handleClose() {
  244. this.dialogVisible = false
  245. this.splitStr = ''
  246. this.input = []
  247. },
  248. handleCloseCard() {
  249. this.dialogVisibleCard = false
  250. this.splitStr = ''
  251. this.input = []
  252. },
  253. // 确认无误按钮
  254. trueBtn() {
  255. this.dialogVisible = false
  256. this.splitStr = this.input.toString()
  257. this.formData.code = this.splitStr.replace(/[',]/g, '\n')
  258. // console.log('this.formData.code', this.formData.code);
  259. },
  260. // 确认充值
  261. async onSubmit() {
  262. this.dialogVisibleCard = false
  263. this.loading = true
  264. this.splitStr = this.input.toString()
  265. // cardno, amount this.splitStr, this.curMoney
  266. let param = new URLSearchParams()
  267. param.append('cardno', this.splitStr)
  268. param.append('amount', this.curMoney)
  269. // const res = await OilCardRecharge({
  270. // cardno: this.splitStr,
  271. // amount: this.curMoney
  272. // })
  273. const res = await OilCardRecharge(param)
  274. console.log('手机卡充值', res);
  275. if (res && res.code == 200) {
  276. this.tableData = res.datas.data
  277. this.all_no = res.datas.all_no
  278. this.success_no = res.datas.success_no
  279. this.error_no = res.datas.error_no
  280. this.splitStr = ''
  281. this.curMoney = ''
  282. this.curBtn = ''
  283. this.formData.code = ''
  284. this.loading = false
  285. }
  286. },
  287. }
  288. }
  289. </script>
  290. <style scoped>
  291. .cardType {
  292. margin-right: 20px;
  293. }
  294. .cardType img {
  295. vertical-align: middle;
  296. margin-right: 10px;
  297. }
  298. .cardType span {
  299. vertical-align: middle;
  300. }
  301. </style>