record.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <template>
  2. <view>
  3. <view class="records">
  4. <view class="changebox">
  5. <view class="date" @click="getdate">
  6. <view>{{suredate}}</view>
  7. <view :class="[dateup?'up':'arrow']"></view>
  8. </view>
  9. <picker @change="bindPickerChange" :range="plateList" :disabled="plateList.length==1">
  10. <view class="allcar">
  11. <view>{{carName}}</view>
  12. <view :class="[carup?'up':'arrow']" v-show="plateList.length>1"></view>
  13. </view>
  14. </picker>
  15. </view>
  16. <view class="month" v-for="(item,index) in datalist" :key="index">
  17. <view class="title">
  18. <view v-if="type === 4">共{{item.total}}次换电记录</view>
  19. <view v-else><text>{{item.month}}</text>月/{{item.year}}</view>
  20. <view class="money">
  21. <view>换电量 {{(item.exchangePower*1).toFixed(1) || '0.0'}}(kW/h)</view>
  22. <view>换电费用 {{(item.powerFee*1).toFixed(1) || '0.0'}}元</view>
  23. </view>
  24. </view>
  25. <view class="list">
  26. <view class="info" v-for="(data,index) in item.list" :key="data.id"
  27. @click="$utils.navigateTo('ucenter/record_show',{id: data.id})">
  28. <view class="first">
  29. <view>{{data.plate}}</view>
  30. <view>¥{{data.powerFee}}</view>
  31. </view>
  32. <view class="second">
  33. <view>{{data.createTime}}</view>
  34. <view>换电量{{data.exchangePower}}(kW/h)</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="month" v-if="datalist.length === 0 || datalist[0].list.length === 0">
  40. <view class="title">
  41. <view>共0次换电记录</view>
  42. <view class="money">
  43. <view>换电量 0.00(kW/h)</view>
  44. <view>换电费用 0.00元</view>
  45. </view>
  46. </view>
  47. <view class="list">
  48. <view class="norecord">暂无记录</view>
  49. </view>
  50. </view>
  51. </view>
  52. <uni-popup ref="popup" background-color="#fff" type="bottom">
  53. <view class="datebox">
  54. <view class="header">
  55. <view @click="chooseMonth" :class="{'isactive':visible}">月份选择</view>
  56. <view @click="chooseDefine" :class="{'isactive':!visible}">自定义</view>
  57. <view @click="chooseAll" class="alltime">全部</view>
  58. <view @click="closed">×</view>
  59. </view>
  60. <view class="content">
  61. <picker-view v-if="visible" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
  62. class="picker-view">
  63. <picker-view-column>
  64. <view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
  65. </picker-view-column>
  66. <picker-view-column>
  67. <view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
  68. </picker-view-column>
  69. <!-- <picker-view-column>
  70. <view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
  71. </picker-view-column> -->
  72. </picker-view>
  73. <view class="change_date" v-if="!visible">
  74. <view>换电时间</view>
  75. <view class="datelist">
  76. <view @click="getMonthDay(0)" :class="{'active':isnum===0}">上月</view>
  77. <view @click="getMonthDay(1)" :class="{'active':isnum===1}">近三月</view>
  78. <view @click="getMonthDay(2)" :class="{'active':isnum===2}">近半年</view>
  79. </view>
  80. </view>
  81. <view class="change_date" v-if="!visible">
  82. <view>自定义</view>
  83. <view class="iptlist">
  84. <view><input class="define-input" :class="{'active':isinput===0}" v-model="beginDate"
  85. @click="getCurrentDate(0)" disabled="disabled" /></view>
  86. <view> — </view>
  87. <view><input class="define-input" :class="{'active':isinput===1}" v-model="endDate"
  88. @click="getCurrentDate(1)" disabled="disabled" /></view>
  89. </view>
  90. </view>
  91. <picker-view v-if="ishow" :indicator-style="indicatorStyle" :value="value" @change="bindChange"
  92. class="picker-view">
  93. <picker-view-column>
  94. <view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
  95. </picker-view-column>
  96. <picker-view-column>
  97. <view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
  98. </picker-view-column>
  99. <picker-view-column>
  100. <view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
  101. </picker-view-column>
  102. </picker-view>
  103. <view class="submit" @click="submitdate">确定</view>
  104. </view>
  105. </view>
  106. </uni-popup>
  107. <tab-bar></tab-bar>
  108. </view>
  109. </template>
  110. <script>
  111. export default {
  112. data() {
  113. const date = new Date()
  114. const years = []
  115. const year = date.getFullYear()
  116. const months = []
  117. const month = date.getMonth() + 1
  118. const days = []
  119. const day = date.getDate()
  120. for (let i = 1990; i <= date.getFullYear(); i++) {
  121. years.push(i)
  122. }
  123. for (let i = 1; i <= 12; i++) {
  124. months.push(i)
  125. }
  126. for (let i = 1; i <= 31; i++) {
  127. days.push(i)
  128. }
  129. return {
  130. datalist: [], //数据列表
  131. dateup: 0,
  132. carup: 0,
  133. plateList: ['全部车辆'], //车辆弹窗数据
  134. carName: '全部车辆', //右上角车辆选择
  135. //自定义日期控件开始
  136. years,
  137. year,
  138. months,
  139. month,
  140. days,
  141. day,
  142. value: [9999, month - 1, day - 1],
  143. visible: true,
  144. indicatorStyle: `height: 50px;`,
  145. //自定义日期控件结束
  146. suredate: '所有记录', //左上角最后确定得日期
  147. middledate: '', //日期选择中间变量
  148. beginDate: null, //文本框开始日期
  149. endDate: null, //文本框结束日期
  150. ishow: false, //是否显示日历控件
  151. isnum: null, //上月、近三月、近半年中间变量
  152. isinput: null, //自定义日期中间变量
  153. type: 0 //查询类型
  154. }
  155. },
  156. mounted() {
  157. this.getExchangeRecord()
  158. this.getUserCarList()
  159. },
  160. onLoad(option) {
  161. if (option.plate) {
  162. this.carName = option.plate
  163. }
  164. },
  165. methods: {
  166. //获取个人所有车辆列表
  167. getUserCarList(){
  168. this.$http.userCarList().then(res=>{
  169. if(res.code ==0){
  170. if(res.data.length > 0){
  171. this.plateList=this.plateList.concat(res.data)
  172. }
  173. }else{
  174. this.$utils.msg(rs.msg)
  175. }
  176. })
  177. },
  178. //获取换电记录列表
  179. getExchangeRecord() {
  180. let monthDay = ''
  181. let plateName = ''
  182. if (this.suredate === '所有记录') {
  183. this.monthDay = ''
  184. this.type = 0
  185. } else {
  186. monthDay = this.suredate
  187. }
  188. if (this.carName === '全部车辆') {
  189. plateName = ''
  190. } else {
  191. plateName = this.carName
  192. }
  193. let params = {
  194. monthDate: monthDay, //单月参数
  195. type: this.type, //查询类型
  196. plate: plateName, //车牌号
  197. page: 1,
  198. pageSize: 2,
  199. startTime: this.beginDate,
  200. endTime: this.endDate,
  201. }
  202. this.$http.exchangeRecord(params).then(rs => {
  203. if (rs.code === 0) {
  204. this.datalist = rs.data.list
  205. } else {
  206. this.$utils.msg(rs.msg)
  207. }
  208. })
  209. },
  210. getdate() {
  211. this.dateup = !this.dateup
  212. this.$refs.popup.open('bottom')
  213. },
  214. bindPickerChange(e) {
  215. this.carup = !this.carup
  216. this.carName = this.plateList[e.detail.value]
  217. this.getExchangeRecord()
  218. },
  219. bindChange(e) {
  220. const val = e.detail.value
  221. if (this.visible) {
  222. this.middledate = null
  223. this.middledate = this.years[val[0]] + '.' + this.months[val[1]]
  224. } else {
  225. this.middledate = null
  226. if (this.isinput === 0) {
  227. this.beginDate = this.years[val[0]] + '.' + this.months[val[1]] + '.' + this.days[val[2]]
  228. } else if (this.isinput === 1) {
  229. this.endDate = this.years[val[0]] + '.' + this.months[val[1]] + '.' + this.days[val[2]]
  230. }
  231. }
  232. },
  233. closed() {
  234. this.$refs.popup.close()
  235. },
  236. submitdate() {
  237. if (this.visible) {
  238. this.type = 0
  239. this.beginDate = null
  240. this.endDate = null
  241. if (this.middledate) {
  242. this.suredate = this.$moment(this.middledate,'YYYY.MM').format('YYYY.MM')
  243. } else {
  244. this.suredate = this.$moment().format('YYYY.MM');
  245. }
  246. this.$refs.popup.close()
  247. } else {
  248. if (this.isnum === 0) {
  249. this.suredate = '上月'
  250. this.$refs.popup.close()
  251. this.type = 1
  252. } else if (this.isnum === 1) {
  253. this.suredate = '近三月'
  254. this.$refs.popup.close()
  255. this.type = 2
  256. } else if (this.isnum === 2) {
  257. this.suredate = '近半年'
  258. this.$refs.popup.close()
  259. this.type = 3
  260. }
  261. if (this.isinput !== null) {
  262. if (this.isinput !== 2) {
  263. if (this.beginDate && this.endDate) {
  264. const diffday = this.$moment(this.endDate).diff(this.$moment(this.beginDate), 'days')
  265. const diffmonth = this.$moment(this.endDate).diff(this.$moment(this.beginDate), 'months')
  266. if (diffday < 0) {
  267. this.$utils.msg('结束日期不能小于开始日期')
  268. } else if (diffmonth > 6) {
  269. this.$utils.msg('日期范围不能超过半年')
  270. } else {
  271. this.suredate = this.$moment(this.beginDate,'YYYY.MM.DD').format('YYYY.MM.DD') + ' - ' + this.$moment(this.endDate,'YYYY.MM.DD').format('YYYY.MM.DD')
  272. this.type = 4
  273. this.$refs.popup.close()
  274. }
  275. } else {
  276. this.$utils.msg('请填写完整')
  277. }
  278. }
  279. }
  280. }
  281. this.getExchangeRecord()
  282. },
  283. //选择月份
  284. chooseMonth() {
  285. this.visible = true
  286. this.ishow = false
  287. },
  288. //选择自定义
  289. chooseDefine() {
  290. this.visible = false
  291. },
  292. //选择全部时间
  293. chooseAll() {
  294. this.suredate = '所有记录'
  295. this.type = 0
  296. this.$refs.popup.close()
  297. this.getExchangeRecord()
  298. },
  299. //获取input框得值
  300. getCurrentDate(d) {
  301. if (this.isinput === 2) {
  302. this.beginDate = null
  303. this.endDate = null
  304. }
  305. if (d === 0) {
  306. this.beginDate = this.$moment().format('YYYY.MM.DD')
  307. } else {
  308. this.endDate = this.$moment().format('YYYY.MM.DD')
  309. }
  310. this.isinput = d
  311. this.isnum = null
  312. this.ishow = true
  313. },
  314. //获取月份数据
  315. getMonthDay(num) {
  316. this.isnum = num
  317. this.isinput = 2
  318. if (num === 0) {
  319. this.beginDate = this.$moment().month(this.$moment().month() - 1).startOf('month').format(
  320. 'YYYY.MM.DD');
  321. this.endDate = this.$moment().month(this.$moment().month() - 1).endOf('month').format('YYYY.MM.DD');
  322. } else if (num === 1) {
  323. this.beginDate = this.$moment().month(this.$moment().month() - 3).format('YYYY.MM.DD');
  324. this.endDate = this.$moment().format('YYYY.MM.DD');
  325. } else {
  326. this.beginDate = this.$moment().month(this.$moment().month() - 6).format('YYYY.MM.DD');
  327. this.endDate = this.$moment().format('YYYY.MM.DD');
  328. }
  329. }
  330. }
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. .datebox {
  335. display: flex;
  336. flex-direction: column;
  337. min-height: 500rpx;
  338. background-color: #fff;
  339. .header {
  340. height: 100rpx;
  341. display: flex;
  342. justify-content: space-between;
  343. padding: 0 45rpx;
  344. line-height: 100rpx;
  345. box-sizing: border-box;
  346. border-bottom: #e7e7e7 solid 1px;
  347. color: #959ea8;
  348. font-weight: bold;
  349. view:nth-child(2) {
  350. margin-right: 60rpx;
  351. }
  352. view:last-child {
  353. font-weight: bold;
  354. font-size: 36rpx;
  355. }
  356. .isactive {
  357. color: #1a1a1a;
  358. }
  359. .alltime {
  360. color: #58be6b;
  361. }
  362. }
  363. .content {
  364. display: flex;
  365. flex-direction: column;
  366. .picker-view {
  367. width: 750rpx;
  368. height: 280rpx;
  369. margin-top: 20rpx;
  370. }
  371. .item {
  372. align-items: center;
  373. justify-content: center;
  374. line-height: 50px;
  375. text-align: center;
  376. }
  377. .submit {
  378. background-color: #58be6b;
  379. height: 85rpx;
  380. border-radius: 40rpx;
  381. width: 600rpx;
  382. margin: 30rpx auto;
  383. font-size: 36rpx;
  384. font-weight: bold;
  385. color: #fff;
  386. text-align: center;
  387. line-height: 84rpx;
  388. }
  389. .change_date {
  390. display: flex;
  391. flex-direction: column;
  392. padding: 0 45rpx;
  393. color: #949da7;
  394. font-weight: bold;
  395. margin-top: 30rpx;
  396. .datelist {
  397. display: flex;
  398. .active {
  399. background-color: #eef8f0;
  400. color: #58be6b;
  401. font-weight: bold;
  402. }
  403. view {
  404. width: 128rpx;
  405. height: 60rpx;
  406. background-color: #f5f5f5;
  407. border-radius: 10rpx;
  408. text-align: center;
  409. line-height: 60rpx;
  410. margin-top: 28rpx;
  411. margin-right: 22rpx;
  412. font-weight: normal;
  413. }
  414. }
  415. .iptlist {
  416. display: flex;
  417. margin-top: 20rpx;
  418. .active {
  419. border: #1d2129 solid 1px;
  420. }
  421. .define-input {
  422. background-color: #f5f5f5;
  423. width: 248rpx;
  424. height: 60rpx;
  425. line-height: 60rpx;
  426. border-radius: 15rpx;
  427. font-size: 28rpx;
  428. font-weight: 500;
  429. text-align: center;
  430. color: #949da7;
  431. }
  432. view:nth-child(2) {
  433. line-height: 60rpx;
  434. padding: 0 10rpx;
  435. }
  436. }
  437. }
  438. }
  439. }
  440. .records {
  441. width: 690rpx;
  442. padding: 25rpx 30rpx;
  443. display: flex;
  444. flex-direction: column;
  445. padding-bottom: 128rpx;
  446. .changebox {
  447. display: flex;
  448. justify-content: space-between;
  449. font-weight: bold;
  450. padding: 0 10rpx;
  451. font-size: 26rpx;
  452. .date {
  453. display: flex;
  454. }
  455. .arrow {
  456. width: 0;
  457. height: 0;
  458. border-top: 12rpx solid #1d2129;
  459. border-right: 12rpx solid transparent;
  460. border-left: 12rpx solid transparent;
  461. margin-left: 10rpx;
  462. margin-top: 13rpx;
  463. transition: all 0.5s ease 0s;
  464. }
  465. .up {
  466. width: 0;
  467. height: 0;
  468. border-top: 12rpx solid #1d2129;
  469. border-right: 12rpx solid transparent;
  470. border-left: 12rpx solid transparent;
  471. margin-left: 10rpx;
  472. margin-top: 13rpx;
  473. transform: rotate(180deg);
  474. transition: all 0.5s ease 0s;
  475. }
  476. .allcar {
  477. display: flex;
  478. }
  479. }
  480. .norecord {
  481. text-align: center;
  482. color: #939da7;
  483. line-height: 180rpx;
  484. }
  485. .month {
  486. width: 690rpx;
  487. display: flex;
  488. flex-direction: column;
  489. margin-top: 30rpx;
  490. .title {
  491. width: 690rpx;
  492. height: 184rpx;
  493. background-image: url('https://rl-zk-image.oss-cn-hangzhou.aliyuncs.com/image/bgr.png');
  494. background-size: 100% 100%;
  495. display: flex;
  496. padding: 20rpx 30rpx;
  497. box-sizing: border-box;
  498. font-size: 30rpx;
  499. font-weight: bold;
  500. flex-direction: column;
  501. justify-content: space-around;
  502. .money {
  503. display: flex;
  504. justify-content: space-between;
  505. }
  506. text {
  507. font-size: 45rpx;
  508. }
  509. }
  510. .list {
  511. display: flex;
  512. background-color: #fff;
  513. width: 690rpx;
  514. border-bottom-left-radius: 35rpx;
  515. border-bottom-right-radius: 35rpx;
  516. padding: 0 35rpx;
  517. box-sizing: border-box;
  518. flex-direction: column;
  519. padding-bottom: 15rpx;
  520. .info {
  521. width: 100%;
  522. margin-top: 20rpx;
  523. margin-bottom: 10rpx;
  524. }
  525. .first {
  526. display: flex;
  527. justify-content: space-between;
  528. font-size: 30rpx;
  529. view:last-child {
  530. font-size: 32rpx;
  531. font-weight: bold;
  532. }
  533. }
  534. .second {
  535. color: #86909c;
  536. font-size: 28rpx;
  537. display: flex;
  538. justify-content: space-between;
  539. margin-top: 2rpx;
  540. }
  541. }
  542. }
  543. }
  544. </style>