index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="content">
  3. <!-- 轮播图 -->
  4. <view class="bBannerList">
  5. <swiper class="swiper" :autoplay="autoplay" :interval="interval" :duration="duration" :circular="true">
  6. <swiper-item v-for="(item,index) in imgData" @click="carBswpClick(item)" v-if="!shopId">
  7. <view class="swiper-item uni-bg-red">
  8. <image :src="item.logo" mode="" class="swpImg"></image>
  9. </view>
  10. </swiper-item>
  11. <swiper-item v-for="(item,index) in imgData" @click="carBswpClickshop(item)" v-if="shopId">
  12. <view class="swiper-item uni-bg-red">
  13. <image :src="item.logo" mode="" class="swpImg"></image>
  14. </view>
  15. </swiper-item>
  16. </swiper>
  17. </view>
  18. <!-- 填写车辆信息 -->
  19. <view class="carMessage">
  20. <view class="mesView">
  21. <view class="leftTitle">城市</view>
  22. <view class="cityBtn noSelectColor" v-if="!cityName" @click="showCity">请选择</view>
  23. <view class="cityBtn selectColor" v-else @click="showCity">{{cityName}}</view>
  24. <image src="../../static/img/rightArrow.png" class="rightArrow"></image>
  25. </view>
  26. <view class="mesView">
  27. <view class="leftTitle">车牌号</view>
  28. <view class="rightView" v-if="!memberCar">
  29. <view class="plateNumber noSelectColor">请添加您的爱车</view>
  30. <view class="changeCarBg" @click="addCar()">
  31. <image src="../../static/img/icon_tianjia.png"
  32. style="width: 32rpx; height: 34rpx; margin-right: 5rpx;"></image>
  33. <view style="color: #FF2400; font-size: 28rpx;">添加</view>
  34. </view>
  35. </view>
  36. <view class="rightView" v-else>
  37. <view class="plateNumber selectColor">{{memberCar.plateNumber}}</view>
  38. <view class="changeCarBg" @click="goCarList()">
  39. <image src="../../static/img/icon_change.png"
  40. style="width: 32rpx; height: 34rpx; margin-right: 5rpx;"></image>
  41. <view style="color: #FF2400; font-size: 28rpx;">换车</view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="mesView">
  46. <view class="leftTitle">车型</view>
  47. <view class="carModBtn selectColor" v-if="memberCar">{{memberCar.carModel}}</view>
  48. <view class="carModBtn noSelectColor" v-else>车型</view>
  49. </view>
  50. <view class="mesView">
  51. <view class="leftTitle">行驶里程</view>
  52. <input class="mileageInput selectColor" type="number" v-model="mileage" placeholder="请输入"
  53. placeholder-style="color:#999999" @input="upMileage" />
  54. <view class="kmStr">km</view>
  55. </view>
  56. </view>
  57. <view class="look4s" @click="gomodule">查看4S店保养价格</view>
  58. </view>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. imgData: [],
  65. uid: '',
  66. cityName: '',
  67. cityCode: '',
  68. memberCar: '',
  69. locationCity: {
  70. cityName: '',
  71. cityCode: '',
  72. lng: '',
  73. lat: '',
  74. },
  75. time: '',
  76. mileage: '',
  77. autoplay: true,
  78. interval: 2000,
  79. duration: 500,
  80. brand:'',
  81. }
  82. },
  83. onLoad() {
  84. },
  85. onShow() {
  86. var that = this;
  87. that.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
  88. that.uid = uni.getStorageSync("logodata").uid;
  89. var selectCity = uni.getStorageSync("selectCity");
  90. if (selectCity) {
  91. //有选择的城市
  92. that.cityName = selectCity.city
  93. that.cityCode = selectCity.code
  94. } else{
  95. //定位到的城市
  96. var nowCity = uni.getStorageSync("locationCity");
  97. if (nowCity) {
  98. that.cityName = nowCity.cityName
  99. that.cityCode = nowCity.cityCode
  100. if (that.uid) {
  101. that.queryHomeDetail();
  102. }
  103. } else {
  104. // 重新去定位城市
  105. that.getLocation()
  106. }
  107. }
  108. if (that.uid) {
  109. that.queryHomeDetail();
  110. }
  111. },
  112. methods: {
  113. upMileage(){
  114. this.$http('worldKeepCar/worldHome/updateTMemberCarByHome', {
  115. id: this.memberCar.id,
  116. milage: this.mileage?this.mileage:0,
  117. }, 'POST').then(res => {
  118. uni.hideLoading();
  119. console.log(res);
  120. if (res.code == 0) {
  121. var cardata = uni.getStorageSync("maintainCarData")
  122. if (cardata) {
  123. cardata.milage = this.mileage
  124. uni.setStorage({
  125. key: 'maintainCarData',
  126. data: cardata,
  127. success: function () {
  128. }
  129. });
  130. }
  131. }
  132. })
  133. },
  134. getLocation() {
  135. const that = this
  136. uni.getLocation({
  137. type: 'gcj02',
  138. success: function(res) {
  139. console.log('定位', res)
  140. that.locationCity.lng = res.longitude
  141. that.locationCity.lat = res.latitude
  142. that.getAdress();
  143. },
  144. fail(err) {
  145. console.log(err)
  146. }
  147. });
  148. },
  149. getAdress() {
  150. // 根据经纬度 逆城市地理编码 获取城市信息
  151. var location = this.locationCity.lng + ',' + this.locationCity.lat
  152. uni.request({
  153. url: 'https://restapi.amap.com/v3/place/around',
  154. data: {
  155. key: '064b6a4a8ade55656edcde2f528876de',
  156. location: location,
  157. types: "190000",
  158. extensions: "all",
  159. radius: 100
  160. },
  161. dataType: "json",
  162. success: (res) => {
  163. console.log('定位城市', res);
  164. let cityname = res.data.pois[0].cityname;
  165. var cityCode = res.data.pois[0].adcode
  166. cityCode = cityCode.slice(0, -2)
  167. cityCode = cityCode + '00'
  168. this.locationCity.cityName = cityname
  169. this.locationCity.cityCode = cityCode
  170. uni.setStorage({
  171. key: 'locationCity',
  172. data: this.locationCity,
  173. success: function() {
  174. console.log('定位城市,保存成功');
  175. }
  176. })
  177. this.cityName = this.locationCity.cityName
  178. this.cityCode = this.locationCity.cityCode
  179. }
  180. });
  181. },
  182. showCity(){
  183. uni.navigateTo({
  184. url:'../chooseCity/chooseCity'
  185. })
  186. },
  187. goLonIn(){
  188. uni.navigateTo({
  189. url:'../login/login'
  190. })
  191. },
  192. queryHomeDetail() {
  193. uni.showLoading({
  194. title: '加载中'
  195. })
  196. this.$http('worldKeepCar/worldHome/queryHomeDetail', {
  197. cityCode: this.cityCode
  198. }, 'GET').then(res => {
  199. uni.hideLoading();
  200. this.imgData = res.data.banners
  201. this.memberCar = res.data.memberCar
  202. if (res.data.memberCar) {
  203. this.mileage = res.data.memberCar.milage
  204. }
  205. else {
  206. this.mileage =''
  207. }
  208. this.brand = res.data.memberCar.brand
  209. var cardata = uni.getStorageSync("maintainCarData")
  210. if (cardata) {
  211. this.memberCar = cardata
  212. if (cardata) {
  213. this.mileage = this.memberCar.milage
  214. }
  215. else {
  216. this.mileage =''
  217. }
  218. this.brand = this.memberCar.brand
  219. }else{
  220. uni.setStorage({
  221. key: 'maintainCarData',
  222. data: this.memberCar,
  223. success: function () {
  224. }
  225. });
  226. }
  227. })
  228. },
  229. gomodule() {
  230. if (!this.uid) {
  231. this.goLonIn();
  232. }
  233. if (!this.cityCode) {
  234. uni.showToast({
  235. title:'请选择城市',
  236. icon:'none',
  237. duration: 3000,
  238. })
  239. return
  240. }
  241. if (!this.memberCar) {
  242. uni.showToast({
  243. title:'请选择车辆',
  244. icon:'none',
  245. duration: 3000,
  246. })
  247. return
  248. }
  249. uni.navigateTo({
  250. url: '../module/maintain?brand='+this.brand
  251. })
  252. },
  253. goCarList() {
  254. if (this.uid) {
  255. uni.navigateTo({
  256. url: 'cailist?type=1'
  257. })
  258. }
  259. },
  260. addCar() {
  261. if (!this.uid) {
  262. this.goLonIn();
  263. }
  264. uni.navigateTo({
  265. url: 'addCar'
  266. })
  267. },
  268. bindChange(e) {
  269. console.log(e);
  270. this.time = e.target.value
  271. },
  272. }
  273. }
  274. </script>
  275. <style>
  276. .content {
  277. min-height: 100vh;
  278. background-color: #F4F5F7;
  279. }
  280. .bBannerList {
  281. width: 100%;
  282. height: 100%;
  283. background-color: #F4F5F7;
  284. }
  285. .swpImg {
  286. width: 100%;
  287. height: 300rpx;
  288. }
  289. .carMessage {
  290. margin: 24rpx 24rpx 40rpx;
  291. padding-top: 10rpx;
  292. height: 500rpx;
  293. background-color: #FFFFFF;
  294. border-radius: 10rpx;
  295. }
  296. .look4s {
  297. margin: 40rpx 24rpx;
  298. height: 88rpx;
  299. line-height: 88rpx;
  300. text-align: center;
  301. background-color: #FD5300;
  302. border-radius: 10rpx;
  303. color: #FFFFFF;
  304. font-weight: bold;
  305. font-size: 30rpx;
  306. }
  307. .mesView {
  308. display: flex;
  309. align-items: center;
  310. width: 100%;
  311. height: 120rpx;
  312. background-color: #FFFFFF;
  313. }
  314. .leftTitle {
  315. margin: 28rpx;
  316. width: 120rpx;
  317. font-size: 28rpx;
  318. color: #666666;
  319. }
  320. .noSelectColor {
  321. color: #999999;
  322. }
  323. .selectColor {
  324. color: #333333;
  325. }
  326. .rightArrow {
  327. margin-right: 28rpx;
  328. width: 14rpx;
  329. height: 23rpx;
  330. }
  331. .cityBtn {
  332. width: 65%;
  333. font-size: 28rpx;
  334. }
  335. .rightView {
  336. display: flex;
  337. justify-content: space-between;
  338. width: 80%;
  339. }
  340. .plateNumber {
  341. font-size: 28rpx;
  342. }
  343. .carModBtn {
  344. width: 65%;
  345. font-size: 28rpx;
  346. }
  347. .timeBtn {
  348. width: 65%;
  349. font-size: 28rpx;
  350. }
  351. .mileageInput {
  352. width: 20%;
  353. font-size: 28rpx;
  354. }
  355. .kmStr {
  356. font-size: 28rpx;
  357. color: #333333;
  358. }
  359. .changeCarBg {
  360. display: flex;
  361. /* justify-content: flex-start; */
  362. align-items: center;
  363. width: 120rpx;
  364. margin-right: 28rpx;
  365. }
  366. </style>