addCar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <view class="content">
  3. <!-- 填写车辆信息 -->
  4. <view class="carMessage">
  5. <view class="mesView">
  6. <view class="leftTitle">车牌号</view>
  7. <input class="plateNumber" placeholder-style="color:#999999" placeholder="请输入车牌号" disabled="true"
  8. @tap="plateShow=true" v-model.trim="plateNo" />
  9. <plate-input v-if="plateShow" :plate="plateNo" @export="setPlate" @close="plateShow=false" />
  10. </view>
  11. <view class="mesView" @click="goCarModel()">
  12. <view class="leftTitle">车型</view>
  13. <view class="carModBtn noSelectColor" v-if="!carModelInfo.value">请选择车型</view>
  14. <view class="carModBtn selectColor carMod" v-else>{{carModelInfo.value}}</view>
  15. <image src="../../static/img/rightArrow.png" class="rightArrow"></image>
  16. </view>
  17. <view class="mesView">
  18. <view class="leftTitle">购车时间</view>
  19. <picker class="timeBtn" @change="bindChange" mode="date" :end="currentdate" :value="time">
  20. <view class="uni-input selectColor" v-if="time">{{time}}</view>
  21. <view class="uni-input noSelectColor" v-else>请选择您的购车时间</view>
  22. </picker>
  23. <image src="../../static/img/rightArrow.png" class="rightArrow"></image>
  24. </view>
  25. <view class="mesView">
  26. <view class="leftTitle">行驶里程</view>
  27. <input class="mileageInput selectColor" type="number" v-model="mileage" placeholder="请输入"
  28. placeholder-style="color:#999999" />
  29. <view class="kmStr">km</view>
  30. </view>
  31. </view>
  32. <view class="bottomView">
  33. <view class="saveCar" @click="saveCar()">
  34. <image src="../../static/img/icon_tianjiacheliang.png" mode=""
  35. style="width: 44rpx; height: 36rpx; margin-right: 10rpx;"></image>
  36. <view>保存爱车</view>
  37. </view>
  38. </view>
  39. <view>
  40. <w-picker :visible.sync="visible" mode="selector" value="2" default-type="value"
  41. :default-props="defaultProps" :options="sbPlate" @confirm="onConfirm($event,'selector')"
  42. @cancel="onCancel" ref="selector"></w-picker>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import plateInput from "@/components/uni-plate-input/uni-plate-input.vue"
  48. import wPicker from "@/components/w-picker/w-picker.vue";
  49. export default {
  50. components: {
  51. plateInput,
  52. wPicker
  53. },
  54. data() {
  55. return {
  56. plateNo: '',
  57. plateShow: false,
  58. carModelInfo: '',
  59. time: '',
  60. mileage: '',
  61. carId: '',
  62. isEditCar: false,
  63. currentdate: '',
  64. plate_type: '',
  65. sbPlate: [],
  66. visible: false,
  67. defaultProps: {
  68. "label": "value",
  69. "value": "ids"
  70. },
  71. vin: '',
  72. }
  73. },
  74. onLoad(opt) {
  75. uni.removeStorageSync('carModelInfo');
  76. this.getNowFormatDate();
  77. console.log(opt);
  78. this.isEditCar = opt.isEditCar
  79. this.carId = opt.id
  80. if (this.isEditCar == 'true') {
  81. this.getEditData()
  82. uni.setNavigationBarTitle({
  83. title: '编辑爱车'
  84. })
  85. }
  86. },
  87. onShow() {
  88. var carModelInfo = uni.getStorageSync("carModelInfo");
  89. if (carModelInfo) {
  90. this.carModelInfo = carModelInfo;
  91. }
  92. },
  93. methods: {
  94. onConfirm(e) {
  95. console.log(e)
  96. this.carModelInfo = e.obj
  97. },
  98. onCancel() {
  99. this.visible = false
  100. },
  101. getNowFormatDate() {
  102. var date = new Date();
  103. var seperator1 = "-";
  104. var year = date.getFullYear();
  105. var month = date.getMonth() + 1;
  106. var day = date.getDate();
  107. if (month >= 1 && month <= 9) {
  108. month = "0" + month;
  109. }
  110. if (day >= 0 && day <= 9) {
  111. day = "0" + day;
  112. }
  113. var currentdate = year + seperator1 + month + seperator1 + day;
  114. this.currentdate = currentdate;
  115. },
  116. getEditData() {
  117. uni.showLoading({
  118. title: '加载中'
  119. })
  120. var carModelInfo = {
  121. carModelInfo: {
  122. }
  123. }
  124. this.$http('worldKeepCar/worldHome/queryMyTMemberCarDetail', {
  125. id: this.carId
  126. }, 'GET').then(res => {
  127. uni.hideLoading();
  128. carModelInfo.carModelInfo.logo = res.data.brandLogo;
  129. carModelInfo.carModelInfo.brand = res.data.brand;
  130. carModelInfo.carModelInfo.carSeries = res.data.series;
  131. carModelInfo.carModelInfo.displacement = res.data.displacement;
  132. carModelInfo.carModelInfo.transmissionType = res.data.transmissionType;
  133. carModelInfo.carModelInfo.productionYear = res.data.annualmoney;
  134. carModelInfo.carModelInfo.carModel = res.data.carModel;
  135. carModelInfo.carModelInfo.guidePrice = res.data.guidePrice;
  136. carModelInfo.carModelInfo.engineModel = res.data.engineType;
  137. carModelInfo.carModelInfo.nLevelID = res.data.nLevelID;
  138. carModelInfo.carModelInfo.salesName = res.data.saleName;
  139. // 展示时
  140. this.plateNo = res.data.plateNumber;
  141. carModelInfo.value = res.data.carModel;
  142. if (res.data.acarTime) {
  143. this.time = res.data.acarTime.slice(0, res.data.createTime.length - 8);
  144. }
  145. this.mileage = res.data.milage;
  146. this.carModelInfo = carModelInfo;
  147. this.vin = res.data.vIN
  148. console.log('this carModelInfo', this.carModelInfo);
  149. })
  150. },
  151. goCarModel() {
  152. uni.navigateTo({
  153. url: 'carModel'
  154. })
  155. },
  156. setPlate(plate) {
  157. console.log(plate)
  158. if (plate.length >= 7) this.plateNo = plate;
  159. this.plateShow = false;
  160. if (plate.length == 7) {
  161. this.plate_type = 2
  162. } else {
  163. this.plate_type = 52
  164. }
  165. this.queryCarmodelByPlateNumber()
  166. },
  167. queryCarmodelByPlateNumber() {
  168. uni.showLoading({
  169. title: '加载中'
  170. })
  171. this.$http('worldKeepCar/worldHome/queryCarmodelByPlateNumber', {
  172. license_plate: this.plateNo,
  173. plate_type: this.plate_type,
  174. }, 'GET').then(res => {
  175. uni.hideLoading();
  176. console.log(res);
  177. if (res.data) {
  178. this.vin = res.data.vin
  179. if (res.data.buyTime) {
  180. this.time = res.data.buyTime.slice(0, res.data.buyTime.length - 8);
  181. }
  182. }
  183. if (res.data.list && res.data.list.length > 0) {
  184. this.sbPlate = res.data.list
  185. //this.sbPlate=this.sbPlate.concat(this.sbPlate)
  186. if (this.sbPlate.length == 1) {
  187. //this.carModelInfo.value=res.data[0].value
  188. this.carModelInfo = res.data.list[0]
  189. } else {
  190. this.visible = true
  191. }
  192. }
  193. })
  194. },
  195. bindChange(e) {
  196. console.log(e);
  197. this.time = e.target.value
  198. },
  199. saveCar() {
  200. uni.showLoading({
  201. title: '保存中'
  202. })
  203. if (this.plateNo == '') {
  204. uni.showToast({
  205. title: '请填写车牌号',
  206. icon: 'none',
  207. duration: 3000
  208. });
  209. return false;
  210. }
  211. if (this.carModelInfo == '') {
  212. uni.showToast({
  213. title: '请选择车型',
  214. icon: 'none',
  215. duration: 3000
  216. });
  217. return false;
  218. }
  219. if (this.time == '') {
  220. uni.showToast({
  221. title: '请选择购车时间',
  222. icon: 'none',
  223. duration: 3000
  224. });
  225. return false;
  226. }
  227. if (this.mileage == '') {
  228. uni.showToast({
  229. title: '请输入行驶里程',
  230. icon: 'none',
  231. duration: 3000
  232. });
  233. return false;
  234. }
  235. if (this.isEditCar == 'true') {
  236. this.updateTMemberCar()
  237. } else {
  238. this.addTMemberCar()
  239. }
  240. },
  241. addTMemberCar() {
  242. this.$http('worldKeepCar/worldHome/addTMemberCar', {
  243. plateNumber: this.plateNo,
  244. milage: this.mileage,
  245. brand: this.carModelInfo.carModelInfo.brand,
  246. displacement: this.carModelInfo.carModelInfo.displacement,
  247. series: this.carModelInfo.carModelInfo.carSeries,
  248. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  249. carModel: this.carModelInfo.value,
  250. saleName: this.carModelInfo.carModelInfo.salesName,
  251. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  252. model: this.carModelInfo.carModelInfo.carModel,
  253. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  254. engineType: this.carModelInfo.carModelInfo.engineModel,
  255. brandLogo: this.carModelInfo.carModelInfo.logo,
  256. acarTime: this.time,
  257. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  258. vIN: this.vin,
  259. }, 'POST').then(res => {
  260. uni.hideLoading();
  261. if (res.code == 0) {
  262. uni.showToast({
  263. title: '保存成功',
  264. icon: 'none',
  265. duration: 3000
  266. });
  267. uni.removeStorageSync('carModelInfo');
  268. setTimeout(function() {
  269. uni.navigateBack({
  270. })
  271. }, 3000);
  272. } else {
  273. uni.showToast({
  274. title: res.msg,
  275. icon: 'none',
  276. duration: 3000
  277. });
  278. }
  279. })
  280. },
  281. updateTMemberCar() {
  282. this.$http('worldKeepCar/worldHome/updateTMemberCar', {
  283. plateNumber: this.plateNo,
  284. milage: this.mileage,
  285. brand: this.carModelInfo.carModelInfo.brand,
  286. displacement: this.carModelInfo.carModelInfo.displacement,
  287. series: this.carModelInfo.carModelInfo.carSeries,
  288. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  289. carModel: this.carModelInfo.value,
  290. saleName: this.carModelInfo.carModelInfo.salesName,
  291. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  292. model: this.carModelInfo.carModelInfo.carModel,
  293. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  294. engineType: this.carModelInfo.carModelInfo.engineModel,
  295. brandLogo: this.carModelInfo.carModelInfo.logo,
  296. acarTime: this.time,
  297. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  298. vIN: this.vin,
  299. id: this.carId,
  300. }, 'POST').then(res => {
  301. uni.hideLoading();
  302. if (res.code == 0) {
  303. uni.showToast({
  304. title: '保存成功',
  305. icon: 'none',
  306. duration: 3000
  307. });
  308. uni.removeStorageSync('carModelInfo');
  309. setTimeout(function() {
  310. uni.navigateBack({
  311. })
  312. }, 3000);
  313. } else {
  314. uni.showToast({
  315. title: res.msg,
  316. icon: 'none',
  317. duration: 3000
  318. });
  319. }
  320. })
  321. },
  322. }
  323. }
  324. </script>
  325. <style>
  326. .content {
  327. min-height: 100vh;
  328. background-color: #F4F5F7;
  329. padding-top: 20rpx;
  330. }
  331. .carMessage {
  332. margin: 0rpx 24rpx 40rpx;
  333. padding-top: 20rpx;
  334. height: 500rpx;
  335. background-color: #FFFFFF;
  336. border-radius: 10rpx;
  337. }
  338. .mesView {
  339. display: flex;
  340. align-items: center;
  341. width: 100%;
  342. height: 120rpx;
  343. background-color: #FFFFFF;
  344. }
  345. .leftTitle {
  346. margin: 28rpx;
  347. width: 120rpx;
  348. font-size: 28rpx;
  349. color: #666666;
  350. }
  351. .noSelectColor {
  352. color: #999999;
  353. }
  354. .selectColor {
  355. color: #333333;
  356. }
  357. .carMod {
  358. text-overflow: -o-ellipsis-lastline;
  359. overflow: hidden;
  360. text-overflow: ellipsis;
  361. display: -webkit-box;
  362. -webkit-line-clamp: 2;
  363. line-clamp: 2;
  364. -webkit-box-orient: vertical;
  365. }
  366. .rightArrow {
  367. margin-right: 28rpx;
  368. width: 14rpx;
  369. height: 23rpx;
  370. }
  371. .cityBtn {
  372. width: 65%;
  373. font-size: 28rpx;
  374. }
  375. .plateNumber {
  376. width: 55%;
  377. font-size: 28rpx;
  378. }
  379. .carModBtn {
  380. width: 65%;
  381. font-size: 28rpx;
  382. }
  383. .timeBtn {
  384. width: 65%;
  385. font-size: 28rpx;
  386. }
  387. .mileageInput {
  388. width: 20%;
  389. font-size: 28rpx;
  390. }
  391. .kmStr {
  392. font-size: 28rpx;
  393. color: #333333;
  394. }
  395. .bottomView {
  396. background-color: #FFFFFF;
  397. width: 100%;
  398. height: 120rpx;
  399. position: fixed;
  400. bottom: 0rpx;
  401. padding-bottom: constant(safe-area-inset-bottom);
  402. padding-bottom: env(safe-area-inset-bottom);
  403. }
  404. .saveCar {
  405. background: linear-gradient(135deg, #FD5300 0%, #FF270A 100%);
  406. margin: 23rpx 30rpx;
  407. height: 74rpx;
  408. border-radius: 37rpx;
  409. color: #FFFFFF;
  410. font-size: 30rpx;
  411. font-weight: bold;
  412. align-items: center;
  413. display: flex;
  414. justify-content: center;
  415. }
  416. </style>