addCar.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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" @click="aaa"/> -->
  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">车型</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">
  31. <view class="leftTitle">行驶里程</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">
  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. this.vin=this.vin + v.toString()
  117. },
  118. keyShow(){
  119. },
  120. keyHide(){
  121. },
  122. aaa(){
  123. this.$refs.keyb._keyShow() //显示键盘
  124. },
  125. onConfirm(e) {
  126. console.log(e)
  127. this.carModelInfo = e.obj
  128. },
  129. onCancel() {
  130. this.visible = false
  131. },
  132. getNowFormatDate() {
  133. var date = new Date();
  134. var seperator1 = "-";
  135. var year = date.getFullYear();
  136. var month = date.getMonth() + 1;
  137. var day = date.getDate();
  138. if (month >= 1 && month <= 9) {
  139. month = "0" + month;
  140. }
  141. if (day >= 0 && day <= 9) {
  142. day = "0" + day;
  143. }
  144. var currentdate = year + seperator1 + month + seperator1 + day;
  145. this.currentdate = currentdate;
  146. },
  147. getEditData() {
  148. uni.showLoading({
  149. title: '加载中'
  150. })
  151. var carModelInfo = {
  152. carModelInfo: {
  153. }
  154. }
  155. this.$http('opencarInfoOwner/queryCarInfoDetail', {
  156. id: this.carId
  157. }, 'GET').then(res => {
  158. uni.hideLoading();
  159. carModelInfo.carModelInfo.logo = res.data.brandLogo;
  160. carModelInfo.carModelInfo.brand = res.data.brand;
  161. carModelInfo.carModelInfo.carSeries = res.data.series;
  162. carModelInfo.carModelInfo.displacement = res.data.displacement;
  163. carModelInfo.carModelInfo.transmissionType = res.data.transmissionType;
  164. carModelInfo.carModelInfo.productionYear = res.data.annualmoney;
  165. carModelInfo.carModelInfo.carModel = res.data.carModel;
  166. carModelInfo.carModelInfo.guidePrice = res.data.guidePrice;
  167. carModelInfo.carModelInfo.engineModel = res.data.engineType;
  168. carModelInfo.carModelInfo.nLevelID = res.data.nLevelID;
  169. carModelInfo.carModelInfo.salesName = res.data.saleName;
  170. // 展示时
  171. this.plateNo = res.data.plateNumber;
  172. carModelInfo.value = res.data.carModel;
  173. if (res.data.buyDate) {
  174. this.time = res.data.buyDate.slice(0,10);
  175. }
  176. this.mileage = res.data.milage;
  177. this.carModelInfo = carModelInfo;
  178. this.vin = res.data.vIN
  179. console.log('this carModelInfo', this.carModelInfo);
  180. })
  181. },
  182. goCarModel() {
  183. uni.navigateTo({
  184. url: 'carModel'
  185. })
  186. },
  187. setPlate(plate) {
  188. console.log(plate)
  189. if (plate.length >= 7) this.plateNo = plate;
  190. this.plateShow = false;
  191. if (plate.length == 7) {
  192. this.plate_type = 2
  193. } else {
  194. this.plate_type = 52
  195. }
  196. // this.queryCarmodelByPlateNumber()
  197. },
  198. queryCarmodelByPlateNumber() {
  199. uni.showLoading({
  200. title: '加载中'
  201. })
  202. this.$http('worldKeepCar/worldHome/queryCarmodelByPlateNumber', {
  203. license_plate: this.plateNo,
  204. plate_type: this.plate_type,
  205. }, 'GET').then(res => {
  206. uni.hideLoading();
  207. console.log(res);
  208. if (res.data) {
  209. this.vin = res.data.vin
  210. if (res.data.buyTime) {
  211. this.time = res.data.buyTime.slice(0, res.data.buyTime.length - 8);
  212. }
  213. }
  214. if (res.data.list && res.data.list.length > 0) {
  215. this.sbPlate = res.data.list
  216. //this.sbPlate=this.sbPlate.concat(this.sbPlate)
  217. if (this.sbPlate.length == 1) {
  218. //this.carModelInfo.value=res.data[0].value
  219. this.carModelInfo = res.data.list[0]
  220. } else {
  221. this.visible = true
  222. }
  223. }
  224. })
  225. },
  226. bindChange(e) {
  227. console.log(e);
  228. this.time = e.target.value
  229. },
  230. saveCar() {
  231. uni.showLoading({
  232. title: '保存中'
  233. })
  234. if (this.plateNo == '') {
  235. uni.showToast({
  236. title: '请填写车牌号',
  237. icon: 'none',
  238. duration: 3000
  239. });
  240. return false;
  241. }
  242. if(!this.mileage){
  243. uni.showToast({
  244. title: '请填写里程',
  245. icon: 'none',
  246. duration: 3000
  247. });
  248. return false;
  249. }
  250. if (this.isEditCar == 'true') {
  251. this.updateTMemberCar()
  252. } else {
  253. this.addTMemberCar()
  254. }
  255. },
  256. addTMemberCar() {
  257. var cardata = {
  258. plateNumber: this.plateNo,
  259. milage: this.mileage?this.mileage:0,
  260. brand: "",
  261. displacement: "",
  262. series: "",
  263. annualmoney: "",
  264. carModel: "",
  265. saleName: "",
  266. transmissionType: "",
  267. model: "",
  268. nLevelID: "",
  269. engineType: "",
  270. brandLogo: "",
  271. buyDate: this.time,
  272. guidePrice: "",
  273. vIN: this.vin,
  274. };
  275. if(this.carModelInfo){
  276. cardata = {
  277. plateNumber: this.plateNo,
  278. milage: this.mileage?this.mileage:0,
  279. brand: this.carModelInfo.carModelInfo.brand,
  280. displacement: this.carModelInfo.carModelInfo.displacement,
  281. series: this.carModelInfo.carModelInfo.carSeries,
  282. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  283. carModel: this.carModelInfo.value,
  284. saleName: this.carModelInfo.carModelInfo.salesName,
  285. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  286. model: this.carModelInfo.carModelInfo.carModel,
  287. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  288. engineType: this.carModelInfo.carModelInfo.engineModel,
  289. brandLogo: this.carModelInfo.carModelInfo.logo,
  290. buyDate: this.time,
  291. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  292. vIN: this.vin,
  293. }
  294. }
  295. this.$http('opencarInfoOwner/addCarOwner', cardata, 'POST').then(res => {
  296. uni.hideLoading();
  297. if (res.code == 0) {
  298. uni.showToast({
  299. title: '保存成功',
  300. icon: 'none',
  301. duration: 3000
  302. });
  303. uni.removeStorageSync('carModelInfo');
  304. if(this.type==1){
  305. uni.setStorage({
  306. key: 'indexaddcar',
  307. data: '1',
  308. success: function () {
  309. setTimeout(function() {
  310. uni.navigateBack({
  311. })
  312. }, 1000);
  313. }
  314. });
  315. }else{
  316. setTimeout(function() {
  317. uni.navigateBack({
  318. })
  319. }, 3000);
  320. }
  321. } else {
  322. uni.showToast({
  323. title: res.msg,
  324. icon: 'none',
  325. duration: 3000
  326. });
  327. }
  328. })
  329. },
  330. updateTMemberCar() {
  331. var cardata = {
  332. plateNumber: this.plateNo,
  333. milage: this.mileage,
  334. brand: "",
  335. displacement: "",
  336. series: "",
  337. annualmoney: "",
  338. carModel: "",
  339. saleName: "",
  340. transmissionType: "",
  341. model: "",
  342. nLevelID: "",
  343. engineType: "",
  344. brandLogo: "",
  345. buyDate: this.time,
  346. guidePrice: "",
  347. vIN: this.vin,
  348. id:this.carId,
  349. };
  350. if(this.carModelInfo){
  351. cardata = {
  352. plateNumber: this.plateNo,
  353. milage: this.mileage,
  354. brand: this.carModelInfo.carModelInfo.brand,
  355. displacement: this.carModelInfo.carModelInfo.displacement,
  356. series: this.carModelInfo.carModelInfo.carSeries,
  357. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  358. carModel: this.carModelInfo.value,
  359. saleName: this.carModelInfo.carModelInfo.salesName,
  360. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  361. model: this.carModelInfo.carModelInfo.carModel,
  362. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  363. engineType: this.carModelInfo.carModelInfo.engineModel,
  364. brandLogo: this.carModelInfo.carModelInfo.logo,
  365. buyDate: this.time,
  366. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  367. vIN: this.vin,
  368. id:this.carId,
  369. }
  370. }
  371. this.$http('opencarInfoOwner/addCarOwner', cardata, 'POST').then(res => {
  372. uni.hideLoading();
  373. if (res.code == 0) {
  374. uni.showToast({
  375. title: '保存成功',
  376. icon: 'none',
  377. duration: 3000
  378. });
  379. uni.removeStorageSync('carModelInfo');
  380. setTimeout(function() {
  381. uni.navigateBack({
  382. })
  383. }, 3000);
  384. } else {
  385. uni.showToast({
  386. title: res.msg,
  387. icon: 'none',
  388. duration: 3000
  389. });
  390. }
  391. })
  392. },
  393. }
  394. }
  395. </script>
  396. <style>
  397. .content {
  398. min-height: 100vh;
  399. background-color: #F4F5F7;
  400. padding-top: 20rpx;
  401. }
  402. .carMessage {
  403. margin: 0rpx 24rpx 40rpx;
  404. padding-top: 20rpx;
  405. height: 500rpx;
  406. background-color: #FFFFFF;
  407. border-radius: 10rpx;
  408. }
  409. .mesView {
  410. display: flex;
  411. align-items: center;
  412. width: 100%;
  413. height: 120rpx;
  414. background-color: #FFFFFF;
  415. }
  416. .leftTitle {
  417. margin: 28rpx;
  418. width: 180rpx;
  419. font-size: 28rpx;
  420. color: #666666;
  421. }
  422. .noSelectColor {
  423. color: #999999;
  424. }
  425. .selectColor {
  426. color: #333333;
  427. }
  428. .carMod {
  429. text-overflow: -o-ellipsis-lastline;
  430. overflow: hidden;
  431. text-overflow: ellipsis;
  432. display: -webkit-box;
  433. -webkit-line-clamp: 2;
  434. line-clamp: 2;
  435. -webkit-box-orient: vertical;
  436. }
  437. .big_rightArrow {
  438. margin-right: 28rpx;
  439. width: 14rpx;
  440. height: 23rpx;
  441. }
  442. .cityBtn {
  443. width: 65%;
  444. font-size: 28rpx;
  445. }
  446. .plateNumber {
  447. width: 55%;
  448. font-size: 28rpx;
  449. }
  450. .carModBtn {
  451. width: 65%;
  452. font-size: 28rpx;
  453. }
  454. .timeBtn {
  455. width: 65%;
  456. font-size: 28rpx;
  457. }
  458. .mileageInput {
  459. width: 20%;
  460. font-size: 28rpx;
  461. }
  462. .vinInput{
  463. width: 60%;
  464. font-size: 28rpx;
  465. }
  466. .kmStr {
  467. font-size: 28rpx;
  468. color: #333333;
  469. }
  470. .bottomView {
  471. background-color: #FFFFFF;
  472. width: 100%;
  473. height: 120rpx;
  474. position: fixed;
  475. bottom: 0rpx;
  476. padding-bottom: constant(safe-area-inset-bottom);
  477. padding-bottom: env(safe-area-inset-bottom);
  478. }
  479. .saveCar {
  480. background-color: #D53533;
  481. margin: 23rpx 30rpx;
  482. height: 74rpx;
  483. border-radius: 37rpx;
  484. color: #FFFFFF;
  485. font-size: 30rpx;
  486. font-weight: bold;
  487. text-align: center;
  488. line-height: 74rpx;
  489. }
  490. .line{
  491. margin: 1rpx 28rpx;
  492. background-color: #EEEEEE;
  493. height: 1rpx;
  494. }
  495. </style>