index.vue 10 KB

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