index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <view class="one_1">
  6. <text>¥</text><text>{{money}}</text>
  7. </view>
  8. <view class="one_2" @tap="toCash">
  9. <button type="default" size="mini">提现</button>
  10. </view>
  11. </view>
  12. <view class="two">
  13. <tabs :tabs="tabs" @tabsChange="tabsChange">
  14. <view class="tabsList">
  15. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  16. <view class="list-scroll-view">
  17. <view class="list" v-for="(item, index) in list" :key="index">
  18. <view v-if="tabs.active=='0'" class="other" @tap="toDetail(item,'0')">
  19. <view class="other_1">
  20. <view class="source textOver">{{item.zhSource}}</view>
  21. <view class="time">{{item.time}}</view>
  22. </view>
  23. <view class="other_2">
  24. <view class="money"><text>{{item.source=='-2'||item.source=='-1'?'-':'+'}}</text> {{item.money}}</view>
  25. <text class="iconfont icon-jiantouyou"></text>
  26. </view>
  27. </view>
  28. <view v-if="tabs.active=='1'" class="other" @tap="toDetail(item,'1')">
  29. <view class="other_1">
  30. <view class="source textOver">{{item.apply_reason}}</view>
  31. <view class="time">{{item.apply_time}}</view>
  32. </view>
  33. <view class="other_2">
  34. <view class="money">-{{item.money}}</view>
  35. <text class="iconfont icon-jiantouyou"></text>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="is_bottom" v-if="is_bottom">
  40. <text>{{config.bottom_title}}</text>
  41. </view>
  42. </view>
  43. </scroll-view>
  44. </view>
  45. </tabs>
  46. </view>
  47. </view>
  48. <uni-popup ref="popup" background-color="#fff" type="bottom">
  49. <view class="popup">
  50. <uni-forms ref="form" :rules="rules" :model="form" label-width="auto">
  51. <uni-forms-item label="真实姓名" name="card_name">
  52. <uni-easyinput v-model="form.card_name" placeholder="请输入真实姓名" />
  53. </uni-forms-item>
  54. <uni-forms-item label="所属银行" name="card_bank">
  55. <uni-easyinput v-model="form.card_bank" placeholder="请输入所属银行" />
  56. </uni-forms-item>
  57. <uni-forms-item label="银行卡号" name="card">
  58. <uni-easyinput v-model="form.card" placeholder="请输入银行卡号" />
  59. </uni-forms-item>
  60. <uni-forms-item label="提现金额" name="money">
  61. <uni-easyinput type="digit" v-model="form.money" @input="toMoney" placeholder="请输入提现金额" />
  62. <view class="money">
  63. 可提现金额为{{canGet||0}}(收货{{config.reward_day}}天以后才可提现),<text @tap="toAll">全部提现</text>
  64. </view>
  65. </uni-forms-item>
  66. <uni-forms-item label="提现理由" name="apply_reason">
  67. <uni-easyinput type="textarea" v-model="form.apply_reason" placeholder="请输入提现理由" />
  68. </uni-forms-item>
  69. <view class="btn">
  70. <button type="primary" @tap="onSubmit('form')">提现</button>
  71. </view>
  72. </uni-forms>
  73. </view>
  74. </uni-popup>
  75. </mobile-frame>
  76. </template>
  77. <script>
  78. import moment from 'moment';
  79. import tabs from '../components/tabs/index.vue';
  80. export default {
  81. components: {
  82. tabs
  83. },
  84. data() {
  85. return {
  86. // 系统设置
  87. config: {},
  88. user: {},
  89. money: 0,
  90. tabs: {
  91. active: '0',
  92. menu: [ //菜单列表
  93. {
  94. title: '收益记录',
  95. active: '0'
  96. },
  97. {
  98. title: '提现记录',
  99. active: '1'
  100. }
  101. ]
  102. },
  103. // 提现金额
  104. canGet: 0,
  105. // 提现
  106. form: {},
  107. rules: {
  108. card_name: {
  109. rules: [{
  110. required: true,
  111. errorMessage: '请输入真实姓名',
  112. }]
  113. },
  114. card_bank: {
  115. rules: [{
  116. required: true,
  117. errorMessage: '请输入所属银行',
  118. }]
  119. },
  120. card: {
  121. rules: [{
  122. required: true,
  123. errorMessage: '请输入银行卡号',
  124. }]
  125. },
  126. money: {
  127. rules: [{
  128. required: true,
  129. errorMessage: '请输入提现金额',
  130. }]
  131. },
  132. apply_reason: {
  133. rules: [{
  134. required: true,
  135. errorMessage: '请输入提现理由',
  136. }]
  137. },
  138. },
  139. list: [],
  140. total: 0,
  141. skip: 0,
  142. limit: 10,
  143. page: 0,
  144. // 来源
  145. sourceList: [],
  146. // 数据是否触底
  147. is_bottom: false,
  148. scrollTop: 0,
  149. };
  150. },
  151. onShow: async function(e) {
  152. const that = this;
  153. that.searchConfig();
  154. await that.searchOther();
  155. await that.watchLogin();
  156. },
  157. onHide: function() {
  158. const that = this;
  159. that.clearPage();
  160. },
  161. methods: {
  162. // 查询基本设置
  163. searchConfig() {
  164. const that = this;
  165. uni.getStorage({
  166. key: 'config',
  167. success: function(res) {
  168. if (res.data) that.$set(that, `config`, res.data)
  169. },
  170. fail: function(err) {
  171. console.log(err);
  172. }
  173. })
  174. },
  175. watchLogin() {
  176. const that = this;
  177. uni.getStorage({
  178. key: 'token',
  179. success: function(res) {
  180. let user = that.$jwt(res.data);
  181. that.$set(that, `user`, user)
  182. that.search()
  183. }
  184. })
  185. },
  186. // 查询列表
  187. async search() {
  188. const that = this;
  189. let user = that.user;
  190. let active = that.tabs.active;
  191. if (user._id) {
  192. let info = {
  193. skip: that.skip,
  194. limit: that.limit,
  195. }
  196. let res;
  197. if (active == '0') {
  198. info.inviter = user._id;
  199. // 收益记录
  200. res = await that.$api(`/cashBack`, 'GET', {
  201. ...info,
  202. })
  203. } else {
  204. info.customer = user._id;
  205. // 提现记录
  206. res = await that.$api(`/cashOut`, 'GET', {
  207. ...info,
  208. })
  209. }
  210. if (res.errcode == '0') {
  211. let list = [...that.list, ...res.data];
  212. for (let val of list) {
  213. let source = that.sourceList.find(i => i.value == val.source)
  214. if (source) val.zhSource = source.label;
  215. }
  216. that.$set(that, `list`, list);
  217. that.$set(that, `total`, res.total)
  218. }
  219. let arr = await that.$api(`/cashBack/computedTotal`, 'GET', {
  220. customer: user._id
  221. })
  222. if (arr.errcode == '0'){
  223. if(arr.data.money<0) that.$set(that, `money`, 0);
  224. else that.$set(that, `money`, 0);
  225. that.$set(that, `money`, arr.data.total);
  226. if(arr.data.canGet<0) that.$set(that, `canGet`, 0);
  227. else that.$set(that, `canGet`, arr.data.canGet);
  228. }
  229. }
  230. },
  231. // 查询其他信息
  232. async searchOther() {
  233. const that = this;
  234. let res;
  235. res = await that.$api(`/dictData`, 'GET', {
  236. code: "cashBack_source"
  237. });
  238. if (res.errcode == '0') {
  239. that.$set(that, `sourceList`, res.data)
  240. }
  241. },
  242. // 分页
  243. toPage(e) {
  244. const that = this;
  245. let list = that.list;
  246. let limit = that.limit;
  247. if (that.total > list.length) {
  248. uni.showLoading({
  249. title: '加载中',
  250. mask: true
  251. })
  252. let page = that.page + 1;
  253. that.$set(that, `page`, page)
  254. let skip = page * limit;
  255. that.$set(that, `skip`, skip)
  256. that.search();
  257. uni.hideLoading();
  258. } else that.$set(that, `is_bottom`, true)
  259. },
  260. toScroll(e) {
  261. const that = this;
  262. let up = that.scrollTop;
  263. that.$set(that, `scrollTop`, e.detail.scrollTop);
  264. let num = Math.sign(up - e.detail.scrollTop);
  265. if (num == 1) that.$set(that, `is_bottom`, false);
  266. },
  267. // 选择选项卡
  268. tabsChange(e) {
  269. const that = this;
  270. that.$set(that.tabs, `active`, e.active)
  271. that.clearPage();
  272. that.search()
  273. },
  274. // 清空列表
  275. clearPage() {
  276. const that = this;
  277. that.$set(that, `list`, [])
  278. that.$set(that, `skip`, 0)
  279. that.$set(that, `limit`, 10)
  280. that.$set(that, `page`, 0)
  281. },
  282. // 提现
  283. toCash() {
  284. const that = this;
  285. that.$set(that, `form`, {})
  286. that.$refs.popup.open()
  287. },
  288. // 提现金额
  289. toMoney(value) {
  290. const that = this;
  291. let money = that.canGet;
  292. if (parseFloat(value) > parseFloat(money)) {
  293. uni.showToast({
  294. title: '输入金额不能超过可提现金额',
  295. icon: 'none'
  296. })
  297. }
  298. },
  299. // 全部提现
  300. toAll() {
  301. const that = this;
  302. that.$set(that.form, `money`, that.canGet)
  303. },
  304. // 提交保存
  305. async onSubmit(ref) {
  306. const that = this;
  307. let money = that.canGet;
  308. that.$refs[ref].validate().then(async params => {
  309. if(parseFloat(params.money)>0){
  310. if (parseFloat(params.money) > parseFloat(money)) {
  311. uni.showToast({
  312. title: '输入金额不能超过可提现金额',
  313. icon: 'none'
  314. })
  315. } else {
  316. params.customer = that.user._id;
  317. params.apply_time = moment().format('YYYY-MM-DD HH:mm:ss')
  318. const arr = await that.$api(`/cashOut`, 'POST', params);
  319. if (arr.errcode == '0') {
  320. uni.showToast({
  321. title: `提现申请成功`,
  322. icon: 'success',
  323. });
  324. that.$refs.popup.close();
  325. that.clearPage();
  326. that.search()
  327. } else {
  328. uni.showToast({
  329. title: arr.errmsg,
  330. icon: 'none',
  331. })
  332. }
  333. }
  334. }else{
  335. uni.showToast({
  336. title: '输入金额不能为0',
  337. icon: 'none'
  338. })
  339. }
  340. })
  341. },
  342. // 明细
  343. toDetail(item, type) {
  344. const that = this;
  345. that.clearPage();
  346. uni.navigateTo({
  347. url: `/pagesMy/assets/info?id=${item._id}&type=${type}`
  348. })
  349. },
  350. },
  351. onPullDownRefresh: async function() {
  352. const that = this;
  353. that.$set(that, `list`, [])
  354. that.$set(that, `skip`, 0)
  355. that.$set(that, `limit`, 10)
  356. that.$set(that, `page`, 0)
  357. await that.search();
  358. uni.stopPullDownRefresh();
  359. }
  360. }
  361. </script>
  362. <style lang="scss">
  363. .main {
  364. display: flex;
  365. flex-direction: column;
  366. width: 100vw;
  367. height: 100vh;
  368. .one {
  369. background-color: var(--fFB1Color);
  370. padding: 5vw 2vw;
  371. display: flex;
  372. justify-content: space-between;
  373. .one_1 {
  374. color: #fff;
  375. font-size: 15px;
  376. font-weight: bold;
  377. text:last-child {
  378. padding: 0 0 0 2vw;
  379. font-size: 25px;
  380. }
  381. }
  382. .one_2 {
  383. button {
  384. background: #fff;
  385. color: var(--fFB1Color);
  386. border-radius: 25px;
  387. font-size: 14px;
  388. }
  389. }
  390. }
  391. .two {
  392. position: relative;
  393. flex-grow: 1;
  394. padding: 2vw 0 0 0;
  395. .tabsList {
  396. position: relative;
  397. width: 100vw;
  398. height: 78vh;
  399. .list {
  400. width: 92vw;
  401. border-bottom: 0.5vw solid var(--f1Color);
  402. margin: 2vw 2vw 0 2vw;
  403. padding: 2vw;
  404. border-radius: 5px;
  405. .other {
  406. display: flex;
  407. justify-content: space-between;
  408. align-items: center;
  409. .other_1 {
  410. width: 60vw;
  411. font-size: var(--font16Size);
  412. margin: 0 0 1vw 0;
  413. .time {
  414. margin: 1vw 0 0 0;
  415. color: var(--f85Color);
  416. font-size: var(--font12Size);
  417. }
  418. }
  419. .other_2 {
  420. display: flex;
  421. align-items: center;
  422. .money {
  423. font-size: var(--font18Size);
  424. font-weight: bold;
  425. margin: 0 1vw;
  426. }
  427. .iconfont {
  428. font-size: 16px;
  429. }
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. .scroll-view {
  437. position: absolute;
  438. top: 0;
  439. left: 0;
  440. right: 0;
  441. bottom: 0;
  442. .list-scroll-view {
  443. display: flex;
  444. flex-direction: column;
  445. }
  446. }
  447. .is_bottom {
  448. text-align: center;
  449. text {
  450. padding: 2vw 0;
  451. display: inline-block;
  452. color: #858585;
  453. font-size: 14px;
  454. }
  455. }
  456. .popup {
  457. min-height: 80vw;
  458. padding: 2vw;
  459. .money {
  460. margin: 1vw 0 0 0;
  461. font-size: 12px;
  462. text {
  463. color: #6A5ACD;
  464. }
  465. }
  466. .btn {
  467. text-align: center;
  468. button {
  469. background-color: var(--fFB1Color);
  470. }
  471. }
  472. }
  473. </style>