mobileCard.vue 10 KB

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