index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. <template>
  2. <div class="mianBox">
  3. <van-row class="headerBox">
  4. <van-icon name="arrow-left" @click="$router.go(-1)" />
  5. 交易记录
  6. </van-row>
  7. <van-tabs
  8. v-model="active"
  9. class="type"
  10. color="red"
  11. line-width="60px"
  12. @click="tab"
  13. >
  14. <div class="timeSelectWrap">
  15. <p class="start" @click="start(1)">{{startTime2}}</p> ~
  16. <p class="end" @click="end(2)">{{endTime2}}</p>
  17. <van-icon name="search" @click="search" class="searchIcon"/>
  18. </div>
  19. <van-tab title="充值记录">
  20. <div class="listHeight">
  21. <van-list
  22. v-model="loading"
  23. :finished="finished"
  24. finished-text="没有更多了"
  25. @load="onLoad"
  26. :style="height"
  27. class="listData"
  28. line-width="60px"
  29. :immediate-check="false"
  30. >
  31. <van-row
  32. class="listBoxCell"
  33. v-for="(item, index) in recharge"
  34. :key="index"
  35. >
  36. <van-col span="14">
  37. <van-row class="jlName">{{ item.shopName }}</van-row>
  38. <van-row class="jlTime">时间:{{ item.createTime }}</van-row>
  39. </van-col>
  40. <van-col span="10">
  41. <div class="jlMoney just">{{ item.amt }}元</div>
  42. <div class="jlBalance">余额:{{ item.balance }} 元</div>
  43. </van-col>
  44. </van-row>
  45. </van-list>
  46. </div>
  47. </van-tab>
  48. <van-tab title="消费记录">
  49. <div class="listHeight">
  50. <van-list
  51. v-model="loading"
  52. :finished="finished"
  53. finished-text="没有更多了"
  54. @load="onLoad"
  55. class="listData"
  56. :immediate-check="false"
  57. >
  58. <van-row class="listBoxCell" v-for="(item, index) in consumption" :key="index">
  59. <van-col span="14">
  60. <div class="jlName">{{ item.shopName }}</div>
  61. <div class="jlTime">时间:{{ item.createTime }}</div>
  62. </van-col>
  63. <van-col span="10">
  64. <div class="jlMoney negative"> {{ item.amt>0 ? '-' + item.amt : '+' + Math.abs(item.amt)}}元</div>
  65. <div class="jlBalance">余额:{{ item.balance }} 元</div>
  66. </van-col>
  67. </van-row>
  68. </van-list>
  69. </div>
  70. </van-tab>
  71. </van-tabs>
  72. <van-overlay :show="loading3" style="z-index: 1; position: fixed" />
  73. <van-datetime-picker
  74. v-if="timeStatus"
  75. v-model="currentDate"
  76. type="date"
  77. title="选择年月日"
  78. :min-date="minDate"
  79. :max-date="maxDate"
  80. class="timeSelect2"
  81. @cancel="cancel"
  82. @confirm="confirm"
  83. />
  84. <!-- <van-cell
  85. title="选择日期区间"
  86. :value="date"
  87. @click="show = true"
  88. class="timeSelect"
  89. />
  90. <van-calendar
  91. v-model="show"
  92. type="range"
  93. @confirm="onConfirm"
  94. :min-date="minDate"
  95. /> -->
  96. </div>
  97. </template>
  98. <script>
  99. import { Toast, } from "vant";
  100. // import { DatetimePicker } from 'vant';
  101. import { getMonthStartDate, getMonthEndDate, getDateStrNowDay} from '@/assets/js/dataFormate.js'
  102. import { returnFloat } from '@/assets/js/common.js'
  103. import Cookies from "js-cookie";
  104. export default {
  105. data() {
  106. return {
  107. minDate: new Date(2022, 1, 1),
  108. maxDate: new Date(2099, 12, 31),
  109. currentDate: new Date(),
  110. timeStatus:false,
  111. startTime2:undefined,
  112. endTime2:undefined,
  113. select:undefined,
  114. loading3:false,
  115. recharge: [],//支付记录
  116. consumption: [], //消费记录
  117. loading: false,
  118. finished: false,
  119. refreshing: true,
  120. height: {
  121. height: false,
  122. },
  123. active: 0,
  124. date: "",
  125. show: false,
  126. minDate: new Date(2020, 1, 1),
  127. page1:1,
  128. page2:1,
  129. current:20,
  130. isref:true,
  131. starTime:undefined,
  132. endTime:undefined,
  133. userId:undefined
  134. };
  135. },
  136. components: {
  137. [Toast.name]: Toast,
  138. },
  139. created() {
  140. this.startTime2 = getMonthStartDate(),
  141. this.endTime2 = getDateStrNowDay(),
  142. this.height.height = document.documentElement.clientHeight - 120 + "px";
  143. if(localStorage.getItem("user_wt")){//ERP途径
  144. this.userId = localStorage.getItem("user_wt")
  145. }
  146. if(Cookies.get("userId57")){//公众号途径
  147. this.userId = Cookies.get("userId57")
  148. }
  149. if(this.userId){
  150. if(this.$route.query){
  151. if(this.$route.query.id == "1"){
  152. this.active = 0
  153. this.charge()
  154. this.charge2()
  155. }else if(this.$route.query.id == "2"){
  156. this.active = 1
  157. this.dish()
  158. this.dish2()
  159. }else{
  160. this.active = 0
  161. this.charge()
  162. this.charge2()
  163. }
  164. }
  165. }else{
  166. this.finished = true
  167. }
  168. },
  169. mouted(){
  170. if(Cookies.get("userId57")){//公众号途径
  171. document.title = '中国东信智慧园区'
  172. }
  173. },
  174. methods: {
  175. // 标准日转化为年月日
  176. transformTime(date){
  177. let data = new Date(date);
  178. let d = data.getDate()
  179. let m = (data.getMonth() + 1)
  180. if(d<10){
  181. d = "0" + d
  182. }
  183. if(m<10){
  184. m = "0" + m
  185. }
  186. let datetime = data.getFullYear() + "-" + m + "-" + d;
  187. return datetime;
  188. },
  189. //时间选择开始
  190. start(){
  191. this.timeStatus = true
  192. this.select = 1
  193. this.loading3 = true
  194. },
  195. //时间选择结束
  196. end(){
  197. this.timeStatus = true
  198. this.select = 2
  199. this.loading3 = true
  200. },
  201. //时间选择搜索
  202. search(){
  203. this.page1 = 1
  204. this.page2 = 1
  205. let start = Date.parse(new Date(this.startTime2)) / 1000
  206. let end = Date.parse(new Date(this.endTime2)) / 1000
  207. if(start>end){
  208. Toast("开始时间不能大于结束时间")
  209. }else{
  210. if(this.active == 0){
  211. this.recharge = []
  212. this.charge()
  213. }else{
  214. this.consumption = []
  215. this.dish()
  216. }
  217. }
  218. },
  219. //时间选择取消
  220. cancel(){
  221. this.timeStatus = false
  222. this.loading3 = false
  223. },
  224. //时间选择确定
  225. confirm(val){
  226. if(this.select == 1){
  227. this.startTime2 = this.transformTime(val)
  228. }else{
  229. this.endTime2 = this.transformTime(val)
  230. }
  231. this.timeStatus = false
  232. this.loading3 = false
  233. },
  234. // change(picker, value, colum) {
  235. // let startTime = picker.getValues();
  236. // console.log(startTime,value, colum)
  237. // // this.startTime = startTime[0] + ":" + startTime[1];
  238. // // console.log(this.startTime);
  239. // },
  240. tab(name, title) {
  241. this.date = "";
  242. this.active = name
  243. if (name == 0) {
  244. if (this.recharge.length == 0) {
  245. this.charge()
  246. this.charge2()
  247. }
  248. this.starTime = undefined,
  249. this.endTime = undefined
  250. } else {
  251. if (this.consumption.length == 0) {
  252. this.dish()
  253. this.dish2()
  254. }
  255. }
  256. },
  257. formatDate(date) {
  258. return `${date.getMonth() + 1}/${date.getDate()}`;
  259. },
  260. onConfirm(date) {
  261. this.show = false;
  262. var start_ = new Date(date[0]);
  263. this.starTime =start_.getFullYear() +"-" +(start_.getMonth() + 1) +"-" +start_.getDate() + ' ' + '00:00:00'
  264. var end_ = new Date(date[1]);
  265. this.endTime = end_.getFullYear() + "-" + (end_.getMonth() + 1) + "-" + end_.getDate() + ' ' + '23:59:59'
  266. this.date = this.starTime.slice(0,10) + " 至 " + this.endTime.slice(0,10);
  267. this.isref = true
  268. if(this.active == 0){
  269. this.page1 = 1
  270. this.charge()
  271. this.recharge = []
  272. }else{
  273. this.page2 = 1
  274. this.consumption = []
  275. this.dish()
  276. }
  277. },
  278. charge(){//充值
  279. this.finished = false
  280. axios.post(`/dxtop/charge/page`,{
  281. "startTime":this.startTime2 + " 00:00:00",
  282. "endTime":this.endTime2 + " 23:59:59",
  283. "size":this.current,
  284. "current":this.page1,
  285. //"userId":"0001T110000000002HBL" //测试
  286. "userId":this.userId
  287. }).then(res => {
  288. if (res?.data?.data?.records.length > 0) {
  289. let data = res.data.data.records
  290. for(let i =0;i<data.length;i++){
  291. if(data[i].type == "31") {//减帐
  292. data[i].amt = "- " + data[i].amt
  293. }else{
  294. data[i].amt = "+ " + data[i].amt
  295. }
  296. this.recharge.push(data[i])
  297. this.recharge[i].balance = returnFloat(data[i].balance)
  298. }
  299. this.page1 ++
  300. this.isref = true
  301. } else {
  302. this.page1--
  303. this.isref = false
  304. }
  305. this.finished = true
  306. }).catch(err =>{
  307. })
  308. },
  309. charge2(){//充值未读改已读
  310. axios.put(`/dxtop/charge?userId=${this.userId}`
  311. ).then(res => {
  312. })
  313. },
  314. dish2(){//消费未读改已读
  315. axios.put(`/dxtop/dish?userId=${this.userId}`,{
  316. "userId":this.userId
  317. }).then(res => {
  318. })
  319. },
  320. dish(){//消费
  321. this.finished = false
  322. axios.post(`/dxtop/dish/page`,{
  323. "startTime":this.startTime2 + " 00:00:00",
  324. "endTime":this.endTime2 + " 23:59:59",
  325. "size":this.current,
  326. "current":this.page2,
  327. //"userId":"0001T110000000002HBL" //测试
  328. "userId":this.userId
  329. }).then(res => {
  330. if (res?.data?.data?.records.length > 0) {
  331. let data = res.data.data.records
  332. for(let i =0;i<data.length;i++){
  333. this.consumption.push(data[i])
  334. this.consumption[i].balance = returnFloat(data[i].balance)
  335. }
  336. this.page2 ++
  337. this.isref = true
  338. } else {
  339. this.page2--
  340. this.isref = false
  341. }
  342. this.finished = true
  343. })
  344. },
  345. onLoad() {
  346. if(timeout){
  347. clearTimeout(timeout);
  348. }
  349. let timeout = setTimeout(() => {//节流
  350. if (this.isref) {
  351. this.loading = true;
  352. //防止多次上滑动导致page等于2没加载出来就加载page等于3的内容
  353. this.isref = false;
  354. if(this.active == 0){
  355. this.charge()
  356. }else{
  357. this.dish()
  358. }
  359. this.loading = false;
  360. }
  361. }, 1000);
  362. },
  363. onRefresh() {
  364. },
  365. }
  366. }
  367. </script>
  368. <style lang="scss" scoped>
  369. .mianBox {
  370. width: 100vw;
  371. padding-top: 44px;
  372. height: 100vh;
  373. color: #000;
  374. box-sizing: border-box;
  375. overflow-y: hidden;
  376. font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif;
  377. letter-spacing: 1px;
  378. }
  379. .listBoxCell {
  380. height: 75px;
  381. width: 100%;
  382. padding: 10px 10px 10px;
  383. box-sizing: border-box;
  384. display: flex;
  385. align-items: center;
  386. border-bottom: 1px solid rgba(237, 237, 237, 1);
  387. .jlName {
  388. font-size: 16px;
  389. color: #000;
  390. }
  391. .jlTime {
  392. margin-top: 5px;
  393. font-size: 13px;
  394. color: #ccc;
  395. }
  396. .jlBalance {
  397. margin-top: 5px;
  398. font-size: 13px;
  399. color: #000;
  400. display: block;
  401. text-align: right;
  402. }
  403. .jlMoney {
  404. text-align: right;
  405. font-size: 16px;
  406. }
  407. .jlMoney.just {
  408. color: rgba(56, 129, 253, 1);
  409. text-align: right;
  410. }
  411. .jlMoney.negative {
  412. color: rgba(242, 46, 60, 1);
  413. text-align: right;
  414. }
  415. }
  416. .van-list {
  417. overflow-y: auto;
  418. }
  419. .timeSelectWrap{
  420. width:calc(100% - 20px);
  421. margin:10px;
  422. overflow: hidden;
  423. background-color: #fff;
  424. border:1px solid #ccc;
  425. border-radius: 20px;
  426. height:35px;
  427. line-height: 35px;
  428. position: relative;
  429. .start{
  430. display: inline-block;
  431. font-size: 16px;
  432. line-height: 30px;
  433. margin-left:15px;
  434. width:30%;
  435. }
  436. .end{
  437. display: inline-block;
  438. font-size: 16px;
  439. width:30%;
  440. margin-left:10px;
  441. }
  442. .search{
  443. background-color: rgba(242, 46, 60, 1);
  444. border-radius: 6px;
  445. margin-top:-2px;
  446. color:#fff;
  447. width:10%;
  448. }
  449. .searchIcon{
  450. color:rgba(242, 46, 60, 1);
  451. font-size: 24px;
  452. position: absolute;
  453. top:6px;
  454. right:10px;
  455. }
  456. }
  457. .timeSelect2{
  458. width:100%;
  459. height:30%;
  460. position: fixed;
  461. bottom:0;
  462. // position: absolute;
  463. // top: 92px;
  464. left: 0;
  465. z-index: 10
  466. }
  467. .timeSelect{
  468. // width:100%;
  469. // height:30%;
  470. // position: fixed;
  471. // bottom:0;
  472. position: absolute;
  473. top: 92px;
  474. left: 0;
  475. z-index: 10
  476. }
  477. .listHeight{
  478. margin-top:10px;
  479. height:78vh;
  480. width:100%;
  481. overflow: hidden;
  482. padding-bottom:50px;
  483. .listData{
  484. height:100%;
  485. overflow-y: scroll;
  486. padding:0 4px;
  487. }
  488. }
  489. </style>
  490. <style>
  491. .van-tab__text--ellipsis{
  492. font-size: 16px !important;
  493. }
  494. .van-tabs__line{
  495. width:187px !important
  496. }
  497. </style>