handle.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import verification, {VerificationType} from '$utils/verification';
  2. import popup from "$utils/tool/popup";
  3. export default <LibMixins>{
  4. data(){
  5. return{
  6. moneyValue:'',
  7. disabled:false
  8. }
  9. },
  10. computed:{
  11. integral(){
  12. return (this.moneyValue || 0) * (this.$store.state.pay.payRatio || 0);
  13. }
  14. },
  15. methods:{
  16. allExChange(){
  17. if (this.disabled) return;
  18. let intMoney = parseInt(this.$store.getters.money);
  19. if (this.moneyValue !== intMoney) {
  20. this.moneyValue = intMoney;
  21. }
  22. },
  23. submitVerify(callback){
  24. if (!verification.trigger[VerificationType.empty](this.moneyValue)) {
  25. return popup.$toast('请输入兑换金额');
  26. } else if (this.moneyValue > this.$store.getters.money) {
  27. return popup.$toast('兑换金额不能大于余额');
  28. }
  29. return callback();
  30. },
  31. submit(obj){
  32. let value = this.moneyValue;
  33. let integral = this.integral;
  34. return this.$request({
  35. url:'user/exchange',
  36. data:{
  37. money: value
  38. },
  39. next:({status})=>{
  40. this.disabled = status;
  41. },
  42. token:true,
  43. message:true,
  44. failMessage:true
  45. }).then((data)=>{
  46. if (data.isSuccess) {
  47. this.user = {
  48. money: this.$store.getters.money - value,
  49. integral: this.$store.getters.integral + integral
  50. }
  51. // 执行更新 补救措施
  52. this.$store.dispatch('updateUserMoneyPromise');
  53. return this.close();
  54. }
  55. return obj.none();
  56. }).catch(obj.none);
  57. }
  58. }
  59. }