addCar.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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/big_rightArrow.png" class="big_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/big_rightArrow.png" class="big_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.isEditCar == 'true') {
  213. this.updateTMemberCar()
  214. } else {
  215. this.addTMemberCar()
  216. }
  217. },
  218. addTMemberCar() {
  219. var cardata = {
  220. plateNumber: this.plateNo,
  221. milage: this.mileage?this.mileage:0,
  222. brand: "",
  223. displacement: "",
  224. series: "",
  225. annualmoney: "",
  226. carModel: "",
  227. saleName: "",
  228. transmissionType: "",
  229. model: "",
  230. nLevelID: "",
  231. engineType: "",
  232. brandLogo: "",
  233. buyDate: this.time,
  234. guidePrice: "",
  235. vIN: this.vin,
  236. };
  237. if(this.carModelInfo){
  238. cardata = {
  239. plateNumber: this.plateNo,
  240. milage: this.mileage?this.mileage:0,
  241. brand: this.carModelInfo.carModelInfo.brand,
  242. displacement: this.carModelInfo.carModelInfo.displacement,
  243. series: this.carModelInfo.carModelInfo.carSeries,
  244. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  245. carModel: this.carModelInfo.value,
  246. saleName: this.carModelInfo.carModelInfo.salesName,
  247. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  248. model: this.carModelInfo.carModelInfo.carModel,
  249. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  250. engineType: this.carModelInfo.carModelInfo.engineModel,
  251. brandLogo: this.carModelInfo.carModelInfo.logo,
  252. buyDate: this.time,
  253. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  254. vIN: this.vin,
  255. }
  256. }
  257. this.$http('opencarInfoOwner/addCarOwner', cardata, 'POST').then(res => {
  258. uni.hideLoading();
  259. if (res.code == 0) {
  260. uni.showToast({
  261. title: '保存成功',
  262. icon: 'none',
  263. duration: 3000
  264. });
  265. uni.removeStorageSync('carModelInfo');
  266. if(this.type==1){
  267. uni.setStorage({
  268. key: 'indexaddcar',
  269. data: '1',
  270. success: function () {
  271. setTimeout(function() {
  272. uni.navigateBack({
  273. })
  274. }, 1000);
  275. }
  276. });
  277. }else{
  278. setTimeout(function() {
  279. uni.navigateBack({
  280. })
  281. }, 3000);
  282. }
  283. } else {
  284. uni.showToast({
  285. title: res.msg,
  286. icon: 'none',
  287. duration: 3000
  288. });
  289. }
  290. })
  291. },
  292. updateTMemberCar() {
  293. var cardata = {
  294. plateNumber: this.plateNo,
  295. milage: this.mileage,
  296. brand: "",
  297. displacement: "",
  298. series: "",
  299. annualmoney: "",
  300. carModel: "",
  301. saleName: "",
  302. transmissionType: "",
  303. model: "",
  304. nLevelID: "",
  305. engineType: "",
  306. brandLogo: "",
  307. buyDate: this.time,
  308. guidePrice: "",
  309. vIN: this.vin,
  310. id:this.carId,
  311. };
  312. if(this.carModelInfo){
  313. cardata = {
  314. plateNumber: this.plateNo,
  315. milage: this.mileage,
  316. brand: this.carModelInfo.carModelInfo.brand,
  317. displacement: this.carModelInfo.carModelInfo.displacement,
  318. series: this.carModelInfo.carModelInfo.carSeries,
  319. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  320. carModel: this.carModelInfo.value,
  321. saleName: this.carModelInfo.carModelInfo.salesName,
  322. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  323. model: this.carModelInfo.carModelInfo.carModel,
  324. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  325. engineType: this.carModelInfo.carModelInfo.engineModel,
  326. brandLogo: this.carModelInfo.carModelInfo.logo,
  327. buyDate: this.time,
  328. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  329. vIN: this.vin,
  330. id:this.carId,
  331. }
  332. }
  333. this.$http('opencarInfoOwner/addCarOwner', cardata, 'POST').then(res => {
  334. uni.hideLoading();
  335. if (res.code == 0) {
  336. uni.showToast({
  337. title: '保存成功',
  338. icon: 'none',
  339. duration: 3000
  340. });
  341. uni.removeStorageSync('carModelInfo');
  342. setTimeout(function() {
  343. uni.navigateBack({
  344. })
  345. }, 3000);
  346. } else {
  347. uni.showToast({
  348. title: res.msg,
  349. icon: 'none',
  350. duration: 3000
  351. });
  352. }
  353. })
  354. },
  355. }
  356. }
  357. </script>
  358. <style>
  359. .content {
  360. min-height: 100vh;
  361. background-color: #F4F5F7;
  362. padding-top: 20rpx;
  363. }
  364. .carMessage {
  365. margin: 0rpx 24rpx 40rpx;
  366. padding-top: 20rpx;
  367. height: 500rpx;
  368. background-color: #FFFFFF;
  369. border-radius: 10rpx;
  370. }
  371. .mesView {
  372. display: flex;
  373. align-items: center;
  374. width: 100%;
  375. height: 120rpx;
  376. background-color: #FFFFFF;
  377. }
  378. .leftTitle {
  379. margin: 28rpx;
  380. width: 180rpx;
  381. font-size: 28rpx;
  382. color: #666666;
  383. }
  384. .noSelectColor {
  385. color: #999999;
  386. }
  387. .selectColor {
  388. color: #333333;
  389. }
  390. .carMod {
  391. text-overflow: -o-ellipsis-lastline;
  392. overflow: hidden;
  393. text-overflow: ellipsis;
  394. display: -webkit-box;
  395. -webkit-line-clamp: 2;
  396. line-clamp: 2;
  397. -webkit-box-orient: vertical;
  398. }
  399. .big_rightArrow {
  400. margin-right: 28rpx;
  401. width: 14rpx;
  402. height: 23rpx;
  403. }
  404. .cityBtn {
  405. width: 65%;
  406. font-size: 28rpx;
  407. }
  408. .plateNumber {
  409. width: 55%;
  410. font-size: 28rpx;
  411. }
  412. .carModBtn {
  413. width: 65%;
  414. font-size: 28rpx;
  415. }
  416. .timeBtn {
  417. width: 65%;
  418. font-size: 28rpx;
  419. }
  420. .mileageInput {
  421. width: 20%;
  422. font-size: 28rpx;
  423. }
  424. .vinInput{
  425. width: 60%;
  426. font-size: 28rpx;
  427. }
  428. .kmStr {
  429. font-size: 28rpx;
  430. color: #333333;
  431. }
  432. .bottomView {
  433. background-color: #FFFFFF;
  434. width: 100%;
  435. height: 120rpx;
  436. position: fixed;
  437. bottom: 0rpx;
  438. padding-bottom: constant(safe-area-inset-bottom);
  439. padding-bottom: env(safe-area-inset-bottom);
  440. }
  441. .saveCar {
  442. background-color: #D53533;
  443. margin: 23rpx 30rpx;
  444. height: 74rpx;
  445. border-radius: 37rpx;
  446. color: #FFFFFF;
  447. font-size: 30rpx;
  448. font-weight: bold;
  449. text-align: center;
  450. line-height: 74rpx;
  451. }
  452. .line{
  453. margin: 1rpx 28rpx;
  454. background-color: #EEEEEE;
  455. height: 1rpx;
  456. }
  457. </style>