addCar.vue 9.0 KB

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