index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <div class="login-container">
  3. <el-form ref="dataForm" :model="dataForm" :rules="ruleForm">
  4. <el-row :gutter="30" class="el-bg-border">
  5. <el-col :span="5">
  6. <el-form-item label="游戏平台" prop="pid">
  7. <el-select v-model="dataForm.pid" placeholder="Select" class="filter-item">
  8. <el-option
  9. v-for="item in rechargePlatform"
  10. :key="item.pid"
  11. :label="item.platform"
  12. :value="item.pid"
  13. />
  14. </el-select>
  15. </el-form-item>
  16. <!-- <el-form-item label="渠道余额" style="width: 300px;">
  17. <el-input v-model="balanceMoney" type="number" class="inline-input filter-item" disabled style="width: 160px;" />&nbsp;元
  18. </el-form-item> -->
  19. <el-form-item label="渠道账号" prop="cid">
  20. <el-select v-model="dataForm.cid" placeholder="Select" class="filter-item">
  21. <el-option
  22. v-for="item in rechargeChannelPlatform"
  23. :key="item.cid"
  24. :label="item.account"
  25. :value="item.cid"
  26. />
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="选择游戏" prop="gfid">
  30. <el-select v-model="dataForm.gfid" placeholder="Select" class="filter-item">
  31. <el-option
  32. v-for="item in rechargeGame"
  33. :key="item.id"
  34. :label="item.name"
  35. :value="item.id"
  36. />
  37. </el-select>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="4">
  41. <el-form-item label="充值账户" prop="username" class="filter-item">
  42. <span style="font-size: 5px; color: #67C23A;">:{{ accountNum }}</span>
  43. <el-input
  44. v-model="dataForm.username"
  45. type="textarea"
  46. placeholder="待检测账号."
  47. :autosize="{ minRows: 15, maxRows: 100 }"
  48. @change="setAccountNum"
  49. />
  50. </el-form-item>
  51. <span v-show="repeatNumList">重复账号:{{ repeatNumList }}</span>
  52. </el-col>
  53. <el-col :span="5">
  54. <el-form-item label="账户余额">
  55. <span>{{ user_money }}元</span>
  56. </el-form-item>
  57. <el-form-item label="充值金额" prop="money">
  58. <el-input v-model="dataForm.money" type="number" min="0" class="filter-item" />
  59. </el-form-item>
  60. <!-- <el-form-item label="平台折扣">
  61. <span>9.8折</span>
  62. </el-form-item>
  63. <el-form-item label="游戏折扣">
  64. <span>9.8折</span>
  65. </el-form-item> -->
  66. <el-form-item label="支付方式">
  67. <el-radio-group v-model="dataForm.payway" prop="payway" class="filter-item">
  68. <el-radio :label="1">久币支付</el-radio>
  69. <!-- <el-radio :label="2">商务币支付</el-radio> -->
  70. </el-radio-group>
  71. </el-form-item>
  72. <el-form-item label="支付金额">
  73. <span>{{ dataForm.money }} 元</span>
  74. </el-form-item>
  75. <el-form-item>
  76. <el-button type="primary" @click="onSubmit">立即支付</el-button>
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="6">
  80. <el-row :gutter="30">
  81. <el-col :span="12">
  82. <span style="font-size: 5px; color: #67C23A;">成功账户:{{ thenAccountNum }}</span>
  83. <el-input
  84. v-model="thenAccount"
  85. type="textarea"
  86. :autosize="{ minRows: 15, maxRows: 100 }"
  87. />
  88. </el-col>
  89. <el-col :span="12">
  90. <span style="font-size: 5px; color: #F56C6C;">失败账户:{{ catchAccountNum }}</span>
  91. <el-input
  92. v-model="catchAccount"
  93. type="textarea"
  94. :autosize="{ minRows: 15, maxRows: 100 }"
  95. />
  96. </el-col>
  97. </el-row>
  98. </el-col>
  99. </el-row>
  100. </el-form>
  101. </div>
  102. </template>
  103. <script>
  104. var LodashArray = require('lodash/array')
  105. import { Message, MessageBox, Loading } from 'element-ui'
  106. import { rechargeChannelPlatformAccount } from '@/api/common'
  107. // import { validMobile } from '@/utils/validate'
  108. export default {
  109. name: 'Recharge',
  110. data() {
  111. return {
  112. // accountHandleSuccess: '', // 处理成功账号
  113. repeatNumList: [], // 重复账号
  114. dataForm: {
  115. pid: 'd65aa6d7614589bffe62456b88e98811', // 游戏平台ID;默认魅族平台
  116. cid: '', // 渠道账号ID
  117. gfid: '', // 游戏ID
  118. paypwd: '', // 支付密码
  119. // username: '13121776520\n13121776521\n13121776522\n\n13121776523\n13121776524\n13121776525', // 充值账户
  120. username: '', // 充值账户
  121. money: 1, // 充值金额(单位:元)
  122. recharge: 2, //
  123. payway: 1, // 充值方式
  124. type: 3 //
  125. },
  126. ruleForm: {
  127. pid: [{ required: true, message: '请选择平台.', trigger: 'change' }],
  128. cid: [{ required: true, message: '请选择渠道账号.', trigger: 'change' }],
  129. gfid: [{ required: true, message: '请选择游戏.', trigger: 'change' }],
  130. username: [{ required: true, message: '缺少充值账户.', trigger: 'blur' }],
  131. money: [{ required: true, message: '请输入充值金额,最低一元.', trigger: 'blur' }]
  132. },
  133. // 游戏平台列表
  134. rechargePlatform: [
  135. {
  136. 'pid': 'd65aa6d7614589bffe62456b88e98811',
  137. 'platform': 'MM',
  138. 'disRate': 9.8,
  139. 'rate': 9.7,
  140. 'type': 0,
  141. 'length': 2
  142. }
  143. ],
  144. // balanceMoney: 0, // 渠道余额
  145. user_money: 0, // 账户余额
  146. rechargeChannelPlatform: [], // 渠道账号
  147. rechargeGame: [], // 游戏列表
  148. accountNum: 0, // 总账户个数
  149. thenAccount: '', // 成功账户
  150. thenAccountNum: 0, // 成功个数
  151. catchAccount: '', // 失败账户
  152. catchAccountNum: 0 // 失败个数
  153. // loadingText: '处理中,请稍等。。。',
  154. // loadingTextNum: 0 // 操作百分比
  155. }
  156. },
  157. created() {
  158. // this.getBalanceMoney(this.dataForm.pid)
  159. this.getRechargePlatform(this.dataForm.pid)
  160. this.getRechargeGame(this.dataForm.pid)
  161. this.updateUserMoney()
  162. },
  163. methods: {
  164. // 更新用户余额
  165. updateUserMoney() {
  166. this.$store.dispatch('user/getInfo').then((res) => {
  167. const { data } = res
  168. this.user_money = data.user_money
  169. })
  170. },
  171. // 统计充值账户数量并处理行数不是账号的
  172. setAccountNum() {
  173. if (!this.dataForm.username) {
  174. return false
  175. }
  176. this.accountNum = 0
  177. this.repeatNumList = []
  178. var newQuestion = this.dataForm.username.replace(/\n\n/, '\n')
  179. const list = newQuestion.split('\n')
  180. var newList = [] // 处理重复数据
  181. for (var i = 0; i < list.length; i++) {
  182. // 账户去重,并提示
  183. if (newList.indexOf(list[i]) === -1) {
  184. this.accountNum++
  185. newList.push(list[i])
  186. } else {
  187. if (this.repeatNumList.indexOf(list[i]) === -1) {
  188. this.repeatNumList.push(list[i])
  189. }
  190. }
  191. }
  192. this.dataForm.username = newList.join().replace(new RegExp(',', 'g'), '\n')
  193. },
  194. async onSubmit() {
  195. // this.setAccountNum()
  196. this.thenAccount = ''
  197. this.catchAccount = ''
  198. // TODO: 正式服务器未上线,暂时不需要
  199. // if ((this.balanceMoney - this.dataForm.money) < 0) {
  200. // return Message({
  201. // type: 'info',
  202. // message: '余额不足以充值.'
  203. // })
  204. // }
  205. this.$refs['dataForm'].validate((valid) => {
  206. if (valid) {
  207. // 截取数据
  208. var userLists = this.dataForm.username.split('\n')
  209. MessageBox.prompt('输入支付密码', 'Tip', {
  210. confirmButtonText: '确认',
  211. cancelButtonText: '取消'
  212. }).then(({ value }) => {
  213. // 提取第一条账号数据,针对接口提交判断数据是否有误
  214. var oneData = { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: value, username: userLists[0], money: this.dataForm.money, recharge: this.dataForm.recharge, payway: this.dataForm.payway, type: this.dataForm.type }
  215. this.$store.dispatch('common/rechargePlayer', oneData).then((res) => {
  216. const { code, status } = res
  217. if (code === 200 && status === true) {
  218. this.thenAccount = this.thenAccount + oneData.username + '\n'
  219. this.thenAccountNum++
  220. // 遮屏
  221. const loading = Loading.service({
  222. lock: true,
  223. text: '处理中, 请稍等...',
  224. background: 'rgba(0, 0, 0, 0.7)'
  225. })
  226. // 成功后处理剩下账号数据
  227. // const loadingNum = userLists.length - 1
  228. console.log('# AAA:', userLists)
  229. userLists = LodashArray.drop(userLists)
  230. console.log('# BBBB:', userLists)
  231. loading.close()
  232. // userLists.forEach(async(item, index) => {
  233. // var _data = { pid: this.dataForm.pid, cid: this.dataForm.cid, gfid: this.dataForm.gfid, paypwd: value, username: item, money: this.dataForm.money, recharge: this.dataForm.recharge, payway: this.dataForm.payway, type: this.dataForm.type }
  234. // await this.rechargePlayer(_data, index)
  235. // if (loadingNum === index) {
  236. // loading.close()
  237. // this.updateUserMoney()
  238. // }
  239. // })
  240. } else {
  241. this.catchAccount = this.catchAccount + oneData.username + '\n'
  242. this.catchAccountNum++
  243. }
  244. }).catch((res) => {
  245. this.catchAccount = this.catchAccount + oneData.username + '\n'
  246. this.catchAccountNum++
  247. })
  248. }).catch(() => {
  249. return Message({
  250. type: 'info',
  251. message: '取消充值.'
  252. })
  253. })
  254. } else {
  255. return Message({
  256. type: 'error',
  257. message: '请完善提交内容.'
  258. })
  259. }
  260. })
  261. },
  262. // 异步进行账户充值
  263. rechargePlayer(data, index) {
  264. return new Promise((resolve, reject) => {
  265. setTimeout((_data) => {
  266. this.$store.dispatch('common/rechargePlayer', _data).then((res) => {
  267. const { code, status } = res
  268. if (code === 200 && status === true) {
  269. this.thenAccount = this.thenAccount + _data.username + '\n'
  270. this.thenAccountNum++
  271. resolve()
  272. } else {
  273. this.catchAccount = this.catchAccount + _data.username + '\n'
  274. this.catchAccountNum++
  275. resolve()
  276. }
  277. }).catch((res) => {
  278. this.catchAccount = this.catchAccount + _data.username + '\n'
  279. this.catchAccountNum++
  280. resolve()
  281. })
  282. }, 2000 * index, data)
  283. })
  284. },
  285. // 账户余额 -- 弃用
  286. getBalanceMoney(val) {
  287. this.$store.dispatch('common/getMainChannelMoney', val).then((res) => {
  288. this.balanceMoney = res
  289. }).catch((res) => {
  290. return Message({
  291. message: res,
  292. type: 'error',
  293. duration: 5 * 1000
  294. })
  295. })
  296. },
  297. // 渠道账号列表
  298. getRechargePlatform(val) {
  299. rechargeChannelPlatformAccount(val).then(response => {
  300. // console.log('# getRechargePlatform:', response)
  301. this.rechargeChannelPlatform = response.data.data
  302. this.dataForm.cid = response.data.data[0]['cid']
  303. }).catch(res => {
  304. return Message({
  305. message: res,
  306. type: 'error',
  307. duration: 5 * 1000
  308. })
  309. })
  310. },
  311. // 游戏列表
  312. getRechargeGame(pid) {
  313. this.$store.dispatch('common/rechargeGame', pid).then((res) => {
  314. this.rechargeGame = res
  315. // TODO: 判断当前账户是否有默认选项,没有则选中第一条。
  316. this.dataForm.gfid = 42670
  317. }).catch((res) => {
  318. return Message({
  319. message: res,
  320. type: 'error',
  321. duration: 5 * 1000
  322. })
  323. })
  324. }
  325. }
  326. }
  327. </script>
  328. <style lang="scss">
  329. .login-container{
  330. margin: 20px;
  331. background-color: #FFFFFF;
  332. .el-bg-border{
  333. border: 2px dashed #909399;
  334. padding: 10px;
  335. }
  336. }
  337. </style>