index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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. that.$set(that, `money`, arr.data.total);
  224. that.$set(that, `canGet`, arr.data.canGet);
  225. }
  226. }
  227. },
  228. // 查询其他信息
  229. async searchOther() {
  230. const that = this;
  231. let res;
  232. res = await that.$api(`/dictData`, 'GET', {
  233. code: "cashBack_source"
  234. });
  235. if (res.errcode == '0') {
  236. that.$set(that, `sourceList`, res.data)
  237. }
  238. },
  239. // 分页
  240. toPage(e) {
  241. const that = this;
  242. let list = that.list;
  243. let limit = that.limit;
  244. if (that.total > list.length) {
  245. uni.showLoading({
  246. title: '加载中',
  247. mask: true
  248. })
  249. let page = that.page + 1;
  250. that.$set(that, `page`, page)
  251. let skip = page * limit;
  252. that.$set(that, `skip`, skip)
  253. that.search();
  254. uni.hideLoading();
  255. } else that.$set(that, `is_bottom`, true)
  256. },
  257. toScroll(e) {
  258. const that = this;
  259. let up = that.scrollTop;
  260. that.$set(that, `scrollTop`, e.detail.scrollTop);
  261. let num = Math.sign(up - e.detail.scrollTop);
  262. if (num == 1) that.$set(that, `is_bottom`, false);
  263. },
  264. // 选择选项卡
  265. tabsChange(e) {
  266. const that = this;
  267. that.$set(that.tabs, `active`, e.active)
  268. that.clearPage();
  269. that.search()
  270. },
  271. // 清空列表
  272. clearPage() {
  273. const that = this;
  274. that.$set(that, `list`, [])
  275. that.$set(that, `skip`, 0)
  276. that.$set(that, `limit`, 10)
  277. that.$set(that, `page`, 0)
  278. },
  279. // 提现
  280. toCash() {
  281. const that = this;
  282. that.$set(that, `form`, {})
  283. that.$refs.popup.open()
  284. },
  285. // 提现金额
  286. toMoney(value) {
  287. const that = this;
  288. let money = that.canGet;
  289. if (parseFloat(value) > parseFloat(money)) {
  290. uni.showToast({
  291. title: '输入金额不能超过可提现金额',
  292. icon: 'none'
  293. })
  294. }
  295. },
  296. // 全部提现
  297. toAll() {
  298. const that = this;
  299. that.$set(that.form, `money`, that.canGet)
  300. },
  301. // 提交保存
  302. async onSubmit(ref) {
  303. const that = this;
  304. let money = that.canGet;
  305. that.$refs[ref].validate().then(async params => {
  306. if(parseFloat(params.money)>0){
  307. if (parseFloat(params.money) > parseFloat(money)) {
  308. uni.showToast({
  309. title: '输入金额不能超过可提现金额',
  310. icon: 'none'
  311. })
  312. } else {
  313. params.customer = that.user._id;
  314. params.apply_time = moment().format('YYYY-MM-DD HH:mm:ss')
  315. const arr = await that.$api(`/cashOut`, 'POST', params);
  316. if (arr.errcode == '0') {
  317. uni.showToast({
  318. title: `提现申请成功`,
  319. icon: 'success',
  320. });
  321. that.$refs.popup.close();
  322. that.clearPage();
  323. that.search()
  324. } else {
  325. uni.showToast({
  326. title: arr.errmsg,
  327. icon: 'none',
  328. })
  329. }
  330. }
  331. }else{
  332. uni.showToast({
  333. title: '输入金额不能为0',
  334. icon: 'none'
  335. })
  336. }
  337. })
  338. },
  339. // 明细
  340. toDetail(item, type) {
  341. const that = this;
  342. that.clearPage();
  343. uni.navigateTo({
  344. url: `/pagesMy/assets/info?id=${item._id}&type=${type}`
  345. })
  346. },
  347. },
  348. onPullDownRefresh: async function() {
  349. const that = this;
  350. that.$set(that, `list`, [])
  351. that.$set(that, `skip`, 0)
  352. that.$set(that, `limit`, 10)
  353. that.$set(that, `page`, 0)
  354. await that.search();
  355. uni.stopPullDownRefresh();
  356. }
  357. }
  358. </script>
  359. <style lang="scss">
  360. .main {
  361. display: flex;
  362. flex-direction: column;
  363. width: 100vw;
  364. height: 100vh;
  365. .one {
  366. background-color: var(--fFB1Color);
  367. padding: 5vw 2vw;
  368. display: flex;
  369. justify-content: space-between;
  370. .one_1 {
  371. color: #fff;
  372. font-size: 15px;
  373. font-weight: bold;
  374. text:last-child {
  375. padding: 0 0 0 2vw;
  376. font-size: 25px;
  377. }
  378. }
  379. .one_2 {
  380. button {
  381. background: #fff;
  382. color: #ff0000;
  383. border-radius: 25px;
  384. font-size: 14px;
  385. }
  386. }
  387. }
  388. .two {
  389. position: relative;
  390. flex-grow: 1;
  391. padding: 2vw 0 0 0;
  392. .tabsList {
  393. position: relative;
  394. width: 100vw;
  395. height: 78vh;
  396. .list {
  397. width: 92vw;
  398. border-bottom: 0.5vw solid var(--f1Color);
  399. margin: 2vw 2vw 0 2vw;
  400. padding: 2vw;
  401. border-radius: 5px;
  402. .other {
  403. display: flex;
  404. justify-content: space-between;
  405. align-items: center;
  406. .other_1 {
  407. width: 60vw;
  408. font-size: var(--font16Size);
  409. margin: 0 0 1vw 0;
  410. .time {
  411. margin: 1vw 0 0 0;
  412. color: var(--f85Color);
  413. font-size: var(--font12Size);
  414. }
  415. }
  416. .other_2 {
  417. display: flex;
  418. align-items: center;
  419. .money {
  420. font-size: var(--font18Size);
  421. font-weight: bold;
  422. margin: 0 1vw;
  423. }
  424. .iconfont {
  425. font-size: 16px;
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. }
  433. .scroll-view {
  434. position: absolute;
  435. top: 0;
  436. left: 0;
  437. right: 0;
  438. bottom: 0;
  439. .list-scroll-view {
  440. display: flex;
  441. flex-direction: column;
  442. }
  443. }
  444. .is_bottom {
  445. text-align: center;
  446. text {
  447. padding: 2vw 0;
  448. display: inline-block;
  449. color: #858585;
  450. font-size: 14px;
  451. }
  452. }
  453. .popup {
  454. min-height: 80vw;
  455. padding: 2vw;
  456. .money {
  457. margin: 1vw 0 0 0;
  458. font-size: 12px;
  459. text {
  460. color: #6A5ACD;
  461. }
  462. }
  463. .btn {
  464. text-align: center;
  465. button {
  466. background-color: var(--fFB1Color);
  467. }
  468. }
  469. }
  470. </style>