addCar.vue 12 KB

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