index.vue 10 KB

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