addCar.vue 13 KB

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