charge-station.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view
  3. class="charge-station"
  4. :style="{
  5. border: border ? '1rpx solid rgba(0, 0, 0, 0.1)' : 'none',
  6. 'border-radius': fromMap ? '20rpx 20rpx 0 0' : '20rpx',
  7. }"
  8. @touchstart="touchstart"
  9. @touchend="touchend"
  10. >
  11. <view class="flex-between">
  12. <view>
  13. <view class="flex flex-align-center">
  14. <view class="fs-32 fw-bold" @click.stop="detail">{{ title }}</view>
  15. <image v-if="activityList&&activityList.length>0" class="ml-10" src="/static/images/coupon-center.png" mode="widthFix" style="width:32rpx"/>
  16. <view class="coupon-box ml-5" @click.stop="toCouponCenter"
  17. v-if="activityList&&activityList.length>0"
  18. >
  19. <text>活动中</text>
  20. </view>
  21. </view>
  22. <view v-if="tag">
  23. <view class="flex-center tag">{{ tagMap[tag] }}</view>
  24. </view>
  25. <view v-else @click.stop="detail" class="fs-22" style="color: rgba(0, 0, 0, 0.5)"
  26. >{{ address }} | {{ distance }}km
  27. </view
  28. >
  29. </view>
  30. <view
  31. @click.top="nav"
  32. class="nav flex-center flex-shrink"
  33. @touchstart="touchstart"
  34. @touchend.stop="touchend"
  35. >
  36. <image src="/static/images/icon-nav.png" mode="widthFix"/>
  37. <text>导航</text>
  38. </view>
  39. </view>
  40. <view class="mt-20 flex" @click.stop="detail">
  41. <view class="status flex-column flex-grow">
  42. <view class="flex-align-center" v-if="price">
  43. <text class="fs-32 fw-600" style="color: var(--color-warning)">{{
  44. price
  45. }}
  46. </text>
  47. <text class="fs-22 ml-6 color-666">元/度</text>
  48. </view>
  49. <view class="flex-align-center lh-0 mt-auto" v-if="!fromMap">
  50. <charge-icon type="fast"></charge-icon>
  51. <view class="fs-22 ml-8 color-666" v-if="fast"
  52. >空闲:{{ freeLength(fast) }}|共:{{ fast.length }}
  53. </view
  54. >
  55. <view class="ml-60">
  56. <charge-icon type="slow"></charge-icon>
  57. </view>
  58. <view class="fs-22 ml-8 color-666" v-if="slow"
  59. >空闲:{{ freeLength(slow) }}|共:{{ slow.length }}
  60. </view
  61. >
  62. </view>
  63. <block v-else>
  64. <view class="lh-0 mt-18 fs-20" style="color: #999"
  65. >停车费用:以场地方公告为准!
  66. </view
  67. >
  68. <view
  69. class="top-right-bound flex-align-center lh-32"
  70. v-if="slow && slow.length"
  71. >
  72. <charge-icon type="slow"></charge-icon>
  73. <view class="ml-6 fs-22 color-666"
  74. >{{ freeLength(slow) }} / {{ slow.length }}
  75. </view
  76. >
  77. </view>
  78. <view
  79. class="top-right-bound flex-align-center lh-32"
  80. v-if="fast && fast.length"
  81. >
  82. <charge-icon type="fast"></charge-icon>
  83. <view class="ml-6 fs-22 color-666"
  84. >{{ freeLength(fast) }} / {{ fast.length }}
  85. </view
  86. >
  87. </view>
  88. </block>
  89. </view>
  90. <view
  91. class="btn flex-shrink flex-column flex-center"
  92. @tap.stop="collect" >
  93. <uni-icons
  94. :type="collected ? 'star-filled' : 'star'"
  95. size="20"
  96. :color="collected ? 'var(--color-warning)' : '#999999'"
  97. ></uni-icons>
  98. <view
  99. class="fs-22 mt-6"
  100. :style="{
  101. color: collected ? 'var(--color-warning)' : '#999999',
  102. }"
  103. >收藏
  104. </view
  105. >
  106. </view>
  107. </view>
  108. <station-coupon ref="station_coupon_ref"></station-coupon>
  109. </view>
  110. </template>
  111. <script lang="ts">
  112. import {addCollectList, fetchCollectList} from "../../api/user";
  113. import StationCoupon from "@/components/station-coupon/station-coupon.vue";
  114. export default {
  115. components: {StationCoupon},
  116. props: {
  117. sId: {
  118. type: String,
  119. },
  120. title: String,
  121. address: String,
  122. tag: Number,
  123. price: String,
  124. fast: Array,
  125. slow: Array,
  126. latitude: Number,
  127. longitude: Number,
  128. distance: String,
  129. border: Boolean,
  130. fromMap: Boolean,
  131. activityList: Array
  132. },
  133. watch: {
  134. sId: {
  135. handler: function (newV) {
  136. if (newV) {
  137. fetchCollectList().then((res) => {
  138. this.collected = res ? res.includes(Number(newV)) : false;
  139. });
  140. }
  141. },
  142. immediate: true,
  143. },
  144. },
  145. data() {
  146. return {
  147. touchtime: 0,
  148. collected: false,
  149. tagMap: [
  150. "",
  151. "居民区",
  152. "公共机构",
  153. "企事业单位",
  154. "写字楼",
  155. "工业园区",
  156. "交通枢纽",
  157. "大型文体设施",
  158. "城市绿地",
  159. "大型建筑配建停车场",
  160. "路边停车位",
  161. "城际高速服务区",
  162. ],
  163. };
  164. },
  165. methods: {
  166. toCouponCenter() {
  167. const {address, latitude, longitude, activityList} = this;
  168. getApp<any>().globalData.lastData.station = {
  169. address,
  170. latitude,
  171. longitude,
  172. activityList
  173. };
  174. // uni.navigateTo({
  175. // url: `/pages-charge/coupon-center/coupon-center?title=${this.title}&id=${this.sId}`,
  176. // });
  177. this.$refs.station_coupon_ref?.open(this.sId);
  178. },
  179. detail() {
  180. const {address, latitude, longitude, activityList} = this;
  181. getApp<any>().globalData.lastData.station = {
  182. address,
  183. latitude,
  184. longitude,
  185. activityList
  186. };
  187. uni.navigateTo({
  188. url: `/pages-charge/machines/machines?title=${this.title}&id=${this.sId}`,
  189. });
  190. },
  191. collect() {
  192. addCollectList(Number(this.sId)).then((collected) => {
  193. collected &&
  194. uni.vibrateShort &&
  195. uni.vibrateShort({
  196. type: "light",
  197. });
  198. this.collected = collected;
  199. });
  200. },
  201. nav() {
  202. const {latitude, longitude, title, address} = this;
  203. uni.openLocation({
  204. latitude,
  205. longitude,
  206. scale: 18,
  207. name: title,
  208. address,
  209. });
  210. },
  211. freeLength(infos: any[]) {
  212. var length = 0;
  213. infos.forEach(function (item) {
  214. item.connectorInfos.forEach(function (conItem: any) {
  215. if (
  216. conItem.connectorStatusInfo &&
  217. conItem.connectorStatusInfo.status === 1
  218. ) {
  219. length += 1;
  220. }
  221. });
  222. });
  223. return length;
  224. },
  225. touchstart() {
  226. this.touchtime = new Date().getTime();
  227. },
  228. touchend(e: any) {
  229. const current = new Date().getTime();
  230. // if (current - this.touchtime < 100) {
  231. // this[e.currentTarget.dataset.method]();
  232. // }
  233. },
  234. },
  235. };
  236. </script>
  237. <style lang="scss">
  238. .charge-station {
  239. background: #ffffff;
  240. width: 100%;
  241. padding: 30rpx;
  242. .tag {
  243. display: inline-block;
  244. box-sizing: content-box;
  245. padding: 0px 6rpx;
  246. height: 34rpx;
  247. background: var(--color-sec);
  248. border-radius: 4rpx;
  249. color: #999999;
  250. font-size: 22rpx;
  251. }
  252. .nav {
  253. width: 120rpx;
  254. height: 60rpx;
  255. border-radius: 30rpx;
  256. background-color: var(--color-primary);
  257. color: #fff;
  258. font-size: 26rpx;
  259. image {
  260. width: 24rpx;
  261. margin-right: 8rpx;
  262. }
  263. }
  264. .status {
  265. background: var(--color-sec);
  266. border-radius: 10rpx;
  267. padding: 16rpx 20rpx;
  268. position: relative;
  269. }
  270. .top-right-bound {
  271. position: absolute;
  272. top: 18rpx;
  273. right: 26rpx;
  274. padding: 4rpx 10rpx 4rpx 4rpx;
  275. background: #ffffff;
  276. border: 1rpx solid #44deba;
  277. border-radius: 20rpx;
  278. }
  279. .btn {
  280. height: 118rpx;
  281. width: 64rpx;
  282. margin-left: 10rpx;
  283. background: var(--color-sec);
  284. border-radius: 10rpx;
  285. transition: all 0.3s;
  286. }
  287. }
  288. .coupon-box {
  289. display: inline-flex;
  290. justify-content: space-between;
  291. align-items: center;
  292. color: #fff;
  293. background-color: #2d9e95;
  294. font-size: 14rpx;
  295. border-radius: 8rpx;
  296. padding: 0rpx 6rpx;
  297. text {
  298. font-size: 24rpx;
  299. }
  300. }
  301. </style>