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