index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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="reason">
  61. <uni-easyinput type="textarea" v-model="form.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 tabs from '@/components/tabs/index.vue';
  73. export default {
  74. components: {
  75. tabs
  76. },
  77. data() {
  78. return {
  79. // 系统设置
  80. config: {},
  81. user: {},
  82. money: 0,
  83. tabs: {
  84. active: '0',
  85. menu: [ //菜单列表
  86. {
  87. title: '收益记录',
  88. active: '0'
  89. },
  90. {
  91. title: '提现记录',
  92. active: '1'
  93. }
  94. ]
  95. },
  96. // 提现金额
  97. moneyInfo: {
  98. payTotal: 1
  99. },
  100. // 提现
  101. form: {},
  102. rules: {
  103. money: {
  104. rules: [{
  105. required: true,
  106. errorMessage: '请输入提现金额',
  107. }]
  108. },
  109. reason: {
  110. rules: [{
  111. required: true,
  112. errorMessage: '请输入提现理由',
  113. }]
  114. },
  115. },
  116. list: [],
  117. total: 0,
  118. skip: 0,
  119. limit: 10,
  120. page: 0,
  121. // 来源
  122. sourceList: [],
  123. // 数据是否触底
  124. is_bottom: false,
  125. scrollTop: 0,
  126. };
  127. },
  128. onShow: async function(e) {
  129. const that = this;
  130. that.searchConfig();
  131. await that.searchOther();
  132. await that.watchLogin();
  133. },
  134. onHide: function() {
  135. const that = this;
  136. that.clearPage();
  137. },
  138. methods: {
  139. // 查询基本设置
  140. searchConfig() {
  141. const that = this;
  142. uni.getStorage({
  143. key: 'config',
  144. success: function(res) {
  145. if (res.data) that.$set(that, `config`, res.data)
  146. },
  147. fail: function(err) {
  148. console.log(err);
  149. }
  150. })
  151. },
  152. watchLogin() {
  153. const that = this;
  154. uni.getStorage({
  155. key: 'token',
  156. success: function(res) {
  157. let user = that.$jwt(res.data);
  158. that.$set(that, `user`, user)
  159. that.search()
  160. }
  161. })
  162. },
  163. // 查询列表
  164. async search() {
  165. const that = this;
  166. let user = that.user;
  167. let active = that.tabs.active;
  168. if (user._id) {
  169. let info = {
  170. skip: that.skip,
  171. limit: that.limit,
  172. inviter: user._id,
  173. }
  174. let res;
  175. if (active == '0') {
  176. // 收益记录
  177. res = await that.$api(`/cashBack`, 'GET', {
  178. ...info,
  179. })
  180. } else {
  181. // 提现记录
  182. res = await that.$api(`/cashBack`, '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. return
  269. }
  270. },
  271. // 全部提现
  272. toAll() {
  273. const that = this;
  274. that.$set(that.form, `money`, that.moneyInfo.payTotal)
  275. },
  276. // 提交保存
  277. async onSubmit(ref) {
  278. const that = this;
  279. that.$refs[ref].validate().then(async params => {
  280. console.log(params);
  281. })
  282. },
  283. // 明细
  284. toDetail(item, type) {
  285. const that = this;
  286. that.clearPage();
  287. uni.navigateTo({
  288. url: `/pagesMy/assets/info?id=${item._id}&type=${type}`
  289. })
  290. },
  291. },
  292. onPullDownRefresh: async function() {
  293. const that = this;
  294. that.$set(that, `list`, [])
  295. that.$set(that, `skip`, 0)
  296. that.$set(that, `limit`, 6)
  297. that.$set(that, `page`, 0)
  298. await that.search();
  299. uni.stopPullDownRefresh();
  300. }
  301. }
  302. </script>
  303. <style lang="scss">
  304. .main {
  305. display: flex;
  306. flex-direction: column;
  307. width: 100vw;
  308. height: 100vh;
  309. .one {
  310. background-color: var(--fFB1Color);
  311. padding: 5vw 2vw;
  312. display: flex;
  313. justify-content: space-between;
  314. .one_1 {
  315. color: #fff;
  316. font-size: 15px;
  317. font-weight: bold;
  318. text:last-child {
  319. padding: 0 0 0 2vw;
  320. font-size: 25px;
  321. }
  322. }
  323. .one_2 {
  324. button {
  325. background: #fff;
  326. color: #ff0000;
  327. border-radius: 25px;
  328. font-size: 14px;
  329. }
  330. }
  331. }
  332. .two {
  333. position: relative;
  334. flex-grow: 1;
  335. padding: 2vw 0 0 0;
  336. .tabsList {
  337. position: relative;
  338. width: 100vw;
  339. height: 82vh;
  340. .list {
  341. width: 92vw;
  342. border-bottom: 0.5vw solid var(--f1Color);
  343. margin: 2vw 2vw 0 2vw;
  344. padding: 2vw;
  345. border-radius: 5px;
  346. .other {
  347. display: flex;
  348. justify-content: space-between;
  349. align-items: center;
  350. .other_1 {
  351. width: 60vw;
  352. font-size: var(--font16Size);
  353. margin: 0 0 1vw 0;
  354. .time {
  355. margin: 1vw 0 0 0;
  356. color: var(--f85Color);
  357. font-size: var(--font12Size);
  358. }
  359. }
  360. .other_2 {
  361. display: flex;
  362. align-items: center;
  363. .money {
  364. font-size: var(--font18Size);
  365. font-weight: bold;
  366. margin: 0 1vw;
  367. }
  368. .iconfont {
  369. font-size: 16px;
  370. }
  371. }
  372. }
  373. }
  374. }
  375. }
  376. }
  377. .scroll-view {
  378. position: absolute;
  379. top: 0;
  380. left: 0;
  381. right: 0;
  382. bottom: 0;
  383. .list-scroll-view {
  384. display: flex;
  385. flex-direction: column;
  386. }
  387. }
  388. .is_bottom {
  389. text-align: center;
  390. text {
  391. padding: 2vw 0;
  392. display: inline-block;
  393. color: #858585;
  394. font-size: 14px;
  395. }
  396. }
  397. .popup {
  398. min-height: 80vw;
  399. padding: 2vw;
  400. .money {
  401. margin: 1vw 0 0 0;
  402. font-size: 12px;
  403. text {
  404. color: #6A5ACD;
  405. }
  406. }
  407. .btn {
  408. text-align: center;
  409. button {
  410. background-color: var(--fFB1Color);
  411. }
  412. }
  413. }
  414. </style>