record.vue 14 KB

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