index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. define([
  2. 'api/auth',
  3. 'qrcode',
  4. 'text!components/my/coin/index.html',
  5. 'css!components/my/coin/index.css'
  6. ], function (authApi, QRCode, html) {
  7. return {
  8. props: {
  9. activeName: {
  10. type: String,
  11. default: 'coin'
  12. },
  13. isYue: {
  14. type: Boolean,
  15. default: true
  16. },
  17. isAlipay: {
  18. type: Boolean,
  19. default: true
  20. },
  21. isWechat: {
  22. type: Boolean,
  23. default: true
  24. },
  25. nowMoney: {
  26. type: String,
  27. default: '0'
  28. },
  29. isLogin: {
  30. type: Boolean,
  31. default: false
  32. }
  33. },
  34. data: function () {
  35. return {
  36. active1: 'first',
  37. custom: 1,
  38. user_gold_num: 0,
  39. recharge: 0,
  40. consumption: 0,
  41. recharge_price_list: [],
  42. gold_image: '',
  43. gold_rate: 1,
  44. active2: '',
  45. goldList1: [],
  46. goldList2: [],
  47. goldList3: [],
  48. page1: 1,
  49. page2: 1,
  50. page3: 1,
  51. limit: 20,
  52. total1: 0,
  53. total2: 0,
  54. total3: 0,
  55. filterData: {
  56. picked: 0,
  57. payType: 'yue',
  58. },
  59. isReset: true,
  60. count: 0
  61. };
  62. },
  63. computed: {
  64. customIcon: function () {
  65. return this.custom * this.gold_rate;
  66. }
  67. },
  68. watch: {
  69. isLogin: function (value) {
  70. if (value) {
  71. this.get_gold_coins();
  72. this.user_gold_num_list1();
  73. this.user_gold_num_list2();
  74. this.user_gold_num_list3();
  75. }
  76. },
  77. filterData: {
  78. handler: function () {
  79. this.isReset = true;
  80. },
  81. deep: true
  82. }
  83. },
  84. mounted: function () {
  85. this.$nextTick(function () {
  86. if (!this.isYue) {
  87. if (this.isWechat) {
  88. this.filterData.payType = 'weixin';
  89. } else {
  90. if (this.isAlipay) {
  91. this.filterData.payType = 'zhifubao';
  92. } else {
  93. this.filterData.payType = '';
  94. }
  95. }
  96. }
  97. });
  98. },
  99. methods: {
  100. // 我的金币
  101. get_gold_coins: function () {
  102. var vm = this;
  103. authApi.get_gold_coins().then(function (res) {
  104. var data = res.data;
  105. vm.user_gold_num = data.user_gold_num;
  106. vm.recharge = data.recharge;
  107. vm.consumption = data.consumption;
  108. vm.recharge_price_list = data.recharge_price_list;
  109. vm.gold_image = data.gold_info.gold_image;
  110. vm.gold_rate = data.gold_info.gold_rate;
  111. vm.$parent.$parent.$parent.tabs.forEach(function (item) {
  112. if (item.value == "coin") {
  113. item.name = data.gold_name + '充值';
  114. }
  115. });
  116. });
  117. },
  118. // 支付
  119. create_order: function () {
  120. var vm = this;
  121. authApi.create_order({
  122. special_id: (this.filterData.picked == -1 ? this.custom : (this.recharge_price_list[this.filterData.picked]) / this.gold_rate),
  123. pay_type_num: 30,
  124. payType: this.filterData.payType
  125. }).then(function (res) {
  126. switch (res.data.status) {
  127. case "PAY_ERROR":
  128. case 'ORDER_EXIST':
  129. case 'ORDER_ERROR':
  130. vm.$message.error(res.msg);
  131. break;
  132. case 'WECHAT_PAY':
  133. vm.isReset = false;
  134. if (vm.qrcode) {
  135. vm.qrcode.makeCode(res.data.result.jsConfig);
  136. } else {
  137. vm.$nextTick(function () {
  138. vm.qrcode = new QRCode(vm.$refs.qrcode, res.data.result.jsConfig);
  139. });
  140. }
  141. vm.testing_order_state(res.data.result.orderId);
  142. break;
  143. case 'ZHIFUBAO_PAY':
  144. vm.isReset = false;
  145. if (vm.qrcode) {
  146. vm.qrcode.makeCode(res.data.result.jsConfig);
  147. } else {
  148. vm.$nextTick(function () {
  149. vm.qrcode = new QRCode(vm.$refs.qrcode, res.data.result.jsConfig);
  150. });
  151. }
  152. vm.testing_order_state(res.data.result.orderId);
  153. break;
  154. case 'SUCCESS':
  155. vm.$message.success(res.msg);
  156. vm.payAfterClick();
  157. break;
  158. }
  159. }).catch(function (err) {
  160. vm.$message.error(err.msg);
  161. });
  162. },
  163. // 明细
  164. user_gold_num_list1: function () {
  165. var vm = this;
  166. authApi.user_gold_num_list({
  167. page: this.page1,
  168. limit: this.limit,
  169. index: ''
  170. }).then(function (res) {
  171. vm.goldList1 = res.data.list;
  172. vm.total1 = res.data.count;
  173. }).catch(function (err) {
  174. vm.$message.error(err.msg);
  175. });
  176. },
  177. user_gold_num_list2: function () {
  178. var vm = this;
  179. authApi.user_gold_num_list({
  180. page: this.page2,
  181. limit: this.limit,
  182. index: 1
  183. }).then(function (res) {
  184. vm.goldList2 = res.data.list;
  185. vm.total2 = res.data.count;
  186. }).catch(function (err) {
  187. vm.$message.error(err.msg);
  188. });
  189. },
  190. user_gold_num_list3: function () {
  191. var vm = this;
  192. authApi.user_gold_num_list({
  193. page: this.page3,
  194. limit: this.limit,
  195. index: 2
  196. }).then(function (res) {
  197. vm.goldList3 = res.data.list;
  198. vm.total3 = res.data.count;
  199. }).catch(function (err) {
  200. vm.$message.error(err.msg);
  201. });
  202. },
  203. handleChange: function () {
  204. this.filterData.picked = -1;
  205. },
  206. inputNumberFocus: function () {
  207. this.filterData.picked = -1;
  208. this.isReset = true;
  209. },
  210. payAfterClick: function () {
  211. var vm = this;
  212. vm.custom = 1;
  213. vm.isReset = true;
  214. vm.get_gold_coins();
  215. vm.$emit('update-user');
  216. vm.page1 = 1;
  217. vm.page2 = 1;
  218. vm.page3 = 1;
  219. vm.goldList1 = [];
  220. vm.goldList2 = [];
  221. vm.goldList3 = [];
  222. vm.user_gold_num_list1();
  223. vm.user_gold_num_list2();
  224. vm.user_gold_num_list3();
  225. },
  226. // 扫码回调
  227. testing_order_state: function (orderId) {
  228. var vm = this;
  229. if (vm.timer) {
  230. return;
  231. }
  232. this.timer = setInterval(function () {
  233. vm.count++;
  234. authApi.testing_order_state({
  235. order_id: orderId,
  236. type: 2
  237. }).then(function (res) {
  238. if (res.data == 1) {
  239. clearInterval(vm.timer);
  240. vm.count = 0;
  241. vm.timer = null;
  242. vm.payAfterClick();
  243. }
  244. }).catch(function (err) {
  245. console.error(err.msg);
  246. });
  247. if (vm.count == 12) {
  248. clearInterval(vm.timer);
  249. vm.count = 0;
  250. vm.timer = null;
  251. }
  252. }, 5000);
  253. }
  254. },
  255. template: html
  256. };
  257. });