addCar.vue 12 KB

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