addCar.vue 8.9 KB

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