addCar.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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="mesView" @click="goCarModel()">
  12. <view class="leftTitle">车型</view>
  13. <view class="carModBtn noSelectColor" v-if="!carModelInfo.value">请选择车型</view>
  14. <view class="carModBtn selectColor" v-else>{{carModelInfo.value}}</view>
  15. <image src="../../static/img/rightArrow.png" class="rightArrow"></image>
  16. </view>
  17. <view class="mesView">
  18. <view class="leftTitle">购车时间</view>
  19. <picker class="timeBtn" @change="bindChange" mode="date" :end="currentdate" :value="time">
  20. <view class="uni-input selectColor" v-if="time">{{time}}</view>
  21. <view class="uni-input noSelectColor" v-else>请选择您的购车时间</view>
  22. </picker>
  23. <image src="../../static/img/rightArrow.png" class="rightArrow"></image>
  24. </view>
  25. <view class="mesView">
  26. <view class="leftTitle">行驶里程</view>
  27. <input class="mileageInput selectColor" type="number" v-model="mileage" placeholder="请输入"
  28. placeholder-style="color:#999999" />
  29. <view class="kmStr">km</view>
  30. </view>
  31. </view>
  32. <view class="bottomView">
  33. <view class="saveCar" @click="saveCar()">
  34. <image src="../../static/img/icon_tianjiacheliang.png" mode="" style="width: 44rpx; height: 36rpx; margin-right: 10rpx;"></image>
  35. <view>保存爱车</view>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import plateInput from "@/components/uni-plate-input/uni-plate-input.vue"
  42. export default {
  43. components: {
  44. plateInput
  45. },
  46. data() {
  47. return {
  48. plateNo: '',
  49. plateShow: false,
  50. carModelInfo: '',
  51. time: '',
  52. mileage: '',
  53. carId: '',
  54. isEditCar: false,
  55. currentdate:'',
  56. }
  57. },
  58. onLoad(opt) {
  59. uni.removeStorageSync('carModelInfo');
  60. this.getNowFormatDate();
  61. console.log(opt);
  62. this.isEditCar = opt.isEditCar
  63. this.carId = opt.id
  64. if (this.isEditCar == 'true') {
  65. this.getEditData()
  66. uni.setNavigationBarTitle({
  67. title:'编辑爱车'
  68. })
  69. }
  70. },
  71. onShow() {
  72. var carModelInfo = uni.getStorageSync("carModelInfo");
  73. if (carModelInfo) {
  74. this.carModelInfo = carModelInfo;
  75. }
  76. },
  77. methods: {
  78. getNowFormatDate(){
  79. var date = new Date();
  80. var seperator1 = "-";
  81. var year = date.getFullYear();
  82. var month = date.getMonth() + 1;
  83. var day = date.getDate();
  84. if (month >= 1 && month <= 9) {
  85. month = "0" + month;
  86. }
  87. if (day >= 0 && day <= 9) {
  88. day = "0" + day;
  89. }
  90. var currentdate = year + seperator1 + month + seperator1 + day;
  91. this.currentdate = currentdate;
  92. },
  93. getEditData() {
  94. uni.showLoading({
  95. title: '加载中'
  96. })
  97. var carModelInfo = {
  98. carModelInfo: {
  99. }
  100. }
  101. this.$http('worldKeepCar/worldHome/queryMyTMemberCarDetail', {
  102. id: this.carId
  103. }, 'GET').then(res => {
  104. uni.hideLoading();
  105. carModelInfo.carModelInfo.logo = res.data.brandLogo;
  106. carModelInfo.carModelInfo.brand = res.data.brand;
  107. carModelInfo.carModelInfo.carSeries = res.data.series;
  108. carModelInfo.carModelInfo.displacement = res.data.displacement;
  109. carModelInfo.carModelInfo.transmissionType = res.data.transmissionType;
  110. carModelInfo.carModelInfo.modelYear = res.data.annualmoney;
  111. carModelInfo.carModelInfo.carModel = res.data.carModel;
  112. carModelInfo.carModelInfo.guidePrice = res.data.guidePrice;
  113. // 展示时
  114. this.plateNo = res.data.plateNumber;
  115. carModelInfo.value = res.data.carModel;
  116. if (res.data.acarTime) {
  117. this.time = res.data.acarTime.slice(0,res.data.createTime.length-8);
  118. }
  119. this.mileage = res.data.milage;
  120. this.carModelInfo = carModelInfo;
  121. console.log('this carModelInfo',this.carModelInfo);
  122. })
  123. },
  124. goCarModel() {
  125. uni.navigateTo({
  126. url: 'carModel'
  127. })
  128. },
  129. setPlate(plate) {
  130. if (plate.length >= 7) this.plateNo = plate;
  131. this.plateShow = false;
  132. },
  133. bindChange(e) {
  134. console.log(e);
  135. this.time = e.target.value
  136. },
  137. saveCar() {
  138. uni.showLoading({
  139. title: '保存中'
  140. })
  141. if (this.plateNo == '') {
  142. uni.showToast({
  143. title: '请填写车牌号',
  144. icon: 'none',
  145. duration: 3000
  146. });
  147. return false;
  148. }
  149. if (this.carModelInfo == '') {
  150. uni.showToast({
  151. title: '请选择车型',
  152. icon: 'none',
  153. duration: 3000
  154. });
  155. return false;
  156. }
  157. if (this.time == '') {
  158. uni.showToast({
  159. title: '请选择购车时间',
  160. icon: 'none',
  161. duration: 3000
  162. });
  163. return false;
  164. }
  165. if (this.mileage == '') {
  166. uni.showToast({
  167. title: '请输入行驶里程',
  168. icon: 'none',
  169. duration: 3000
  170. });
  171. return false;
  172. }
  173. if (this.isEditCar == 'true') {
  174. this.updateTMemberCar()
  175. }
  176. else {
  177. this.addTMemberCar()
  178. }
  179. },
  180. addTMemberCar(){
  181. this.$http('worldKeepCar/worldHome/addTMemberCar', {
  182. plateNumber: this.plateNo,
  183. milage: this.mileage,
  184. brand: this.carModelInfo.carModelInfo.brand,
  185. displacement: this.carModelInfo.carModelInfo.displacement,
  186. series: this.carModelInfo.carModelInfo.carSeries,
  187. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  188. carModel: this.carModelInfo.value,
  189. salesName: this.carModelInfo.carModelInfo.salesName,
  190. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  191. model: this.carModelInfo.carModelInfo.carModel,
  192. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  193. engineType: this.carModelInfo.carModelInfo.engineModel,
  194. brandLogo: this.carModelInfo.carModelInfo.logo,
  195. acarTime: this.time,
  196. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  197. }, 'POST').then(res => {
  198. uni.hideLoading();
  199. if (res.code == 0) {
  200. uni.showToast({
  201. title: '保存成功',
  202. icon: 'none',
  203. duration: 3000
  204. });
  205. uni.removeStorageSync('carModelInfo');
  206. setTimeout(function() {
  207. uni.navigateBack({
  208. })
  209. }, 3000);
  210. } else {
  211. uni.showToast({
  212. title: res.msg,
  213. icon: 'none',
  214. duration: 3000
  215. });
  216. }
  217. })
  218. },
  219. updateTMemberCar(){
  220. this.$http('worldKeepCar/worldHome/updateTMemberCar', {
  221. plateNumber: this.plateNo,
  222. milage: this.mileage,
  223. brand: this.carModelInfo.carModelInfo.brand,
  224. displacement: this.carModelInfo.carModelInfo.displacement,
  225. series: this.carModelInfo.carModelInfo.carSeries,
  226. annualmoney: this.carModelInfo.carModelInfo.productionYear,
  227. carModel: this.carModelInfo.value,
  228. salesName: this.carModelInfo.carModelInfo.salesName,
  229. transmissionType: this.carModelInfo.carModelInfo.transmissionType,
  230. model: this.carModelInfo.carModelInfo.carModel,
  231. nLevelID: this.carModelInfo.carModelInfo.nLevelID,
  232. engineType: this.carModelInfo.carModelInfo.engineModel,
  233. brandLogo: this.carModelInfo.carModelInfo.logo,
  234. acarTime: this.time,
  235. guidePrice: this.carModelInfo.carModelInfo.guidePrice,
  236. id: this.carId,
  237. }, 'POST').then(res => {
  238. uni.hideLoading();
  239. if (res.code == 0) {
  240. uni.showToast({
  241. title: '保存成功',
  242. icon: 'none',
  243. duration: 3000
  244. });
  245. uni.removeStorageSync('carModelInfo');
  246. setTimeout(function() {
  247. uni.navigateBack({
  248. })
  249. }, 3000);
  250. } else {
  251. uni.showToast({
  252. title: res.msg,
  253. icon: 'none',
  254. duration: 3000
  255. });
  256. }
  257. })
  258. },
  259. }
  260. }
  261. </script>
  262. <style>
  263. .content {
  264. min-height: 100vh;
  265. background-color: #F4F5F7;
  266. padding-top: 20rpx;
  267. }
  268. .carMessage {
  269. margin: 0rpx 24rpx 40rpx;
  270. padding-top: 20rpx;
  271. height: 500rpx;
  272. background-color: #FFFFFF;
  273. border-radius: 10rpx;
  274. }
  275. .mesView {
  276. display: flex;
  277. align-items: center;
  278. width: 100%;
  279. height: 120rpx;
  280. background-color: #FFFFFF;
  281. }
  282. .leftTitle {
  283. margin: 28rpx;
  284. width: 120rpx;
  285. font-size: 28rpx;
  286. color: #666666;
  287. }
  288. .noSelectColor {
  289. color: #999999;
  290. }
  291. .selectColor {
  292. color: #333333;
  293. }
  294. .rightArrow {
  295. margin-right: 28rpx;
  296. width: 14rpx;
  297. height: 23rpx;
  298. }
  299. .cityBtn {
  300. width: 65%;
  301. font-size: 28rpx;
  302. }
  303. .plateNumber {
  304. width: 55%;
  305. font-size: 28rpx;
  306. }
  307. .carModBtn {
  308. width: 65%;
  309. font-size: 28rpx;
  310. }
  311. .timeBtn {
  312. width: 65%;
  313. font-size: 28rpx;
  314. }
  315. .mileageInput {
  316. width: 20%;
  317. font-size: 28rpx;
  318. }
  319. .kmStr {
  320. font-size: 28rpx;
  321. color: #333333;
  322. }
  323. .bottomView {
  324. background-color: #FFFFFF;
  325. width: 100%;
  326. height: 120rpx;
  327. position: fixed;
  328. bottom: 0rpx;
  329. }
  330. .saveCar {
  331. background: linear-gradient(135deg, #FD5300 0%, #FF270A 100%);
  332. margin: 23rpx 30rpx;
  333. height: 74rpx;
  334. border-radius: 37rpx;
  335. color: #FFFFFF;
  336. font-size: 30rpx;
  337. font-weight: bold;
  338. align-items: center;
  339. display: flex;
  340. justify-content: center;
  341. }
  342. </style>