addCar.vue 14 KB

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