index.vue 12 KB

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