addVehicle.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. <!-- 管理车辆 -->
  2. <template>
  3. <view class="content">
  4. <view class="flex s-row container">
  5. <view class="flex row">
  6. <view class="left left-text">车牌号</view>
  7. <view class="right flex">
  8. <input class="car-uumber" v-model='dataDetails.carNumber' @click.stop="handleShowKeyboard(index)"
  9. :disabled="true" placeholder="输入车牌号" name="input"></input>
  10. </view>
  11. </view>
  12. <view class="flex row">
  13. <view class="left-text">车牌颜色</view>
  14. <view class="color" @click="selectNoColor">{{dataDetails.carNumberColour}}</view>
  15. <view>></view>
  16. <u-picker :show="carColor" :columns="colorColumns" :closeOnClickOverlay='true' @close='colorClose'
  17. @cancel='colorClose' @confirm='confirmColor' @change="changeCarModel"></u-picker>
  18. </view>
  19. <view class="flex row">
  20. <view class="left-text">车型</view>
  21. <view class="color" @click="selectCarModel">{{dataDetails.carType}}</view>
  22. <view>></view>
  23. <u-picker :show="carModel" :columns="carModelColumns" :closeOnClickOverlay='true' @close='carModelClose'
  24. @cancel='carModelClose' @confirm='confirmCarModel' @change="changeCarModel"></u-picker>
  25. </view>
  26. <view class="flex row">
  27. <view class="left-text">车辆所属车主</view>
  28. <u--input placeholder="输入车主姓名" inputAlign='left' border="none" v-model="dataDetails.owner">
  29. </u--input>
  30. </view>
  31. <view class="flex row">
  32. <view class="left-text">总质量(千克)</view>
  33. <u--input placeholder="输入总质量" inputAlign='left' border="none" v-model="dataDetails.carTotalWeight">
  34. </u--input>
  35. </view>
  36. <view class="flex row">
  37. <view class="left-text">核定载质量(千克)</view>
  38. <u--input placeholder="输入核定载质量" inputAlign='left' border="none" v-model="dataDetails.carApprovedWeight">
  39. </u--input>
  40. </view>
  41. <view class="flex row noborder">
  42. <view class="left-text">外廓尺寸</view>
  43. </view>
  44. <view class="flex row noborder input-ckg">
  45. <view class="input-positon">
  46. <u--input class="input" placeholder="长" inputAlign='left' border="none"
  47. v-model="dataDetails.carLong">
  48. </u--input>
  49. <view class="position-right">
  50. mm
  51. </view>
  52. </view>
  53. <view class="star">*</view>
  54. <view class="input-positon">
  55. <u--input placeholder="宽" inputAlign='left' border="none" v-model="dataDetails.carWidth">
  56. </u--input>
  57. <view class="position-right">
  58. mm
  59. </view>
  60. </view>
  61. <view class="star">*</view>
  62. <view class="input-positon">
  63. <u--input placeholder="高" inputAlign='left' border="none" v-model="dataDetails.carHeight">
  64. </u--input>
  65. <view class="position-right">
  66. mm
  67. </view>
  68. </view>
  69. </view>
  70. <view class="flex row noborder s-row">
  71. <view class="left-text" style="width: 100%;">人车合影(车头车牌号可见)</view>
  72. <u-upload class="uview-upload" :fileList="fileList1" @afterRead="afterRead($event)" @delete="deletePic"
  73. name="1" multiple :maxCount="1"></u-upload>
  74. </view>
  75. </view>
  76. <view class="submit-btn" @click="submit">提交</view>
  77. <master-keyboard ref="keyboard" keyboardtype="car" :show="keyShow" :randomNumber="true" :newCar="false"
  78. :defaultValue="carNumber" @keyboardClick="handleClick"></master-keyboard>
  79. <u-toast ref="uToast"></u-toast>
  80. </view>
  81. </template>
  82. <script>
  83. import uploadImage from '@/components/ossutil/uploadFile.js';
  84. import keyboard from "@/components/master-keyboard/master-keyboard.vue";
  85. var _this;
  86. import {
  87. mapState
  88. } from 'vuex';
  89. export default {
  90. data() {
  91. return {
  92. index: '',
  93. keyShow: false,
  94. carNumber: '',
  95. dataDetails: {
  96. driverId:'',
  97. carNumber: '',
  98. carNumberColour: '黄色',
  99. carType: '挂车 高栏',
  100. carTotalWeight: '',
  101. carApprovedWeight: '',
  102. carLong: '',
  103. carWidth: '',
  104. carHeight: '',
  105. addressUrl:''
  106. },
  107. carModelColumns: [
  108. ['挂车', '非挂车'],
  109. ['高栏', '集装箱', '自卸车']
  110. ],
  111. carModelColumnData: [
  112. ['高栏', '集装箱', '自卸车'],
  113. ['重型仓栏']
  114. ],
  115. colorColumns: [
  116. ['黄色', '蓝色']
  117. ],
  118. carColor: false,
  119. carModel: false,
  120. fileList1: []
  121. };
  122. },
  123. computed: {
  124. ...mapState(['hasLogin', 'userInfo','firstAuthentication']),
  125. },
  126. onLoad(options) {
  127. _this = this;
  128. this.dataDetails.driverId = this.userInfo.driverId
  129. },
  130. methods: {
  131. // 车型切换
  132. changeCarModel(e) {
  133. const {
  134. columnIndex,
  135. index,
  136. // 微信小程序无法将picker实例传出来,只能通过ref操作
  137. picker = this.$refs.carTypePicker
  138. } = e
  139. if (columnIndex === 0) {
  140. // 模拟网络请求
  141. picker.setColumnValues(1, this.carModelColumnData[index])
  142. }
  143. },
  144. // 删除图片
  145. deletePic(event) {
  146. this[`fileList${event.name}`].splice(event.index, 1)
  147. },
  148. // 新增图片
  149. async afterRead(event) {
  150. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  151. let lists = [].concat(event.file)
  152. let fileListLen = this[`fileList${event.name}`].length
  153. lists.map((item) => {
  154. this[`fileList${event.name}`].push({
  155. ...item,
  156. status: 'uploading',
  157. message: '上传中'
  158. })
  159. })
  160. for (let i = 0; i < lists.length; i++) {
  161. const result = await this.uploadFilePromise(lists[i].url)
  162. let item = this[`fileList${event.name}`][fileListLen]
  163. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  164. status: 'success',
  165. message: '',
  166. url: result
  167. }))
  168. fileListLen++
  169. }
  170. },
  171. uploadFilePromise(url) {
  172. uploadImage('image',url, 'appData/',
  173. result => {
  174. // 上传成功回调函数
  175. console.log('图片地址', result)
  176. this.dataDetails.addressUrl =this.dataDetails.addressUrl+','+ result
  177. }
  178. )
  179. },
  180. //车牌号弹出键盘
  181. handleShowKeyboard(index) {
  182. if (this.dataDetails.carNumber == '') {
  183. this.carNumber = ''
  184. } else {
  185. this.carNumber = this.dataDetails.carNumber
  186. }
  187. if (this.$refs.keyboard.open) {
  188. this.$refs.keyboard.open(false) //true 键盘显示 false 键盘隐藏
  189. } else {
  190. this.$refs.keyboard[0].open(false)
  191. }
  192. this.index = index
  193. if (this.$refs.keyboard.open) {
  194. this.$refs.keyboard.open(true) //true 键盘显示 false 键盘隐藏
  195. } else {
  196. this.$refs.keyboard[0].open(true)
  197. }
  198. },
  199. //车牌号弹出键盘
  200. handleClick(e) {
  201. this.carNumber = e.value
  202. this.dataDetails.carNumber = e.value //键盘输入值
  203. },
  204. confirmColor(val) {
  205. this.dataDetails.carNumberColour = val.value[0]
  206. this.carColor = false
  207. },
  208. colorClose() {
  209. this.carColor = false
  210. },
  211. selectNoColor() {
  212. this.carColor = true
  213. },
  214. confirmCarModel(val) {
  215. this.dataDetails.carType = val.value[0] + ' ' + val.value[1]
  216. this.carModel = false
  217. },
  218. carModelClose() {
  219. this.carModel = false
  220. },
  221. selectCarModel() {
  222. this.carModel = true
  223. },
  224. selectNoColor() {
  225. this.carColor = true
  226. },
  227. unloadGroupPhoto() {
  228. uni.chooseImage({
  229. count: 1,
  230. success: function(res) {
  231. console.log(JSON.stringify(res.tempFilePaths));
  232. uploadImage('image',res.tempFilePaths[0], 'appData/',
  233. result => {
  234. // 上传成功
  235. console.log('图片地址', result)
  236. }
  237. )
  238. }
  239. });
  240. },
  241. validate() {
  242. // true 为校验不通过
  243. if (uni.$u.test.isEmpty(this.dataDetails.carNumber)) {
  244. this.$refs.uToast.show({
  245. type: 'error',
  246. message: "车牌号不能为空!",
  247. })
  248. return true
  249. }
  250. if (uni.$u.test.isEmpty(this.dataDetails.carTotalWeight)) {
  251. this.$refs.uToast.show({
  252. type: 'error',
  253. message: "总质量不能为空!",
  254. })
  255. return true
  256. }
  257. if (uni.$u.test.isEmpty(this.dataDetails.carApprovedWeight)) {
  258. this.$refs.uToast.show({
  259. type: 'error',
  260. message: "核定载质量不能为空!",
  261. })
  262. return true
  263. }
  264. if (uni.$u.test.isEmpty(this.dataDetails.carLong)&&uni.$u.test.isEmpty(this.dataDetails.caWidth)&&uni.$u.test.isEmpty(this.dataDetails.carHeight)) {
  265. this.$refs.uToast.show({
  266. type: 'error',
  267. message: "外廓尺寸不能为空!",
  268. })
  269. return true
  270. }
  271. // if (uni.$u.test.isEmpty(this.dataDetails.drivingLicenseBackPage)) {
  272. // this.$refs.uToast.show({
  273. // type: 'error',
  274. // message: "行驶证副页不能为空!",
  275. // })
  276. // return true
  277. // }
  278. return false
  279. },
  280. submit() {
  281. // 校验
  282. if (this.validate()) return
  283. this.$request.baseRequest('post', '/driverCarInfo/api/addInfo', this.dataDetails).then(res => {
  284. if (res.code == '200') {
  285. let params = {
  286. type: 'success',
  287. message: "提交成功",
  288. }
  289. this.$refs.uToast.show({
  290. ...params
  291. })
  292. uni.$u.route('/pages/mine/manageVehicles/index');
  293. } else {
  294. uni.$u.toast(res.message);
  295. }
  296. })
  297. .catch(res => {
  298. uni.$u.toast(res.message);
  299. });
  300. },
  301. },
  302. }
  303. </script>
  304. <style lang="scss" scoped>
  305. .container {
  306. margin: 20rpx;
  307. background: white;
  308. padding: 0 20rpx;
  309. border-radius: 20rpx;
  310. .left-text {
  311. // background: red;
  312. width: 290rpx;
  313. color: #333333;
  314. display: flex;
  315. align-items: center;
  316. }
  317. .row {
  318. border-bottom: 1px solid #EEEEEE;
  319. padding-bottom: 28rpx;
  320. margin-top: 26rpx;
  321. .ch-style {}
  322. }
  323. .row-ch {
  324. padding-right: 250rpx;
  325. box-sizing: border-box;
  326. }
  327. }
  328. .input-ckg {
  329. height: 86rpx;
  330. margin-top: 0 !important;
  331. padding-bottom: 0 !important;
  332. .u-input {
  333. height: 100%;
  334. background: #F7F8FA;
  335. padding-left: 10rpx !important;
  336. padding-right: 85rpx !important;
  337. }
  338. .star {
  339. display: flex;
  340. align-items: center;
  341. margin: 0 10rpx;
  342. }
  343. .input-positon {
  344. position: relative;
  345. }
  346. .position-right {
  347. position: absolute;
  348. right: 20rpx;
  349. top: 0;
  350. width: 60rpx;
  351. height: 50rpx;
  352. bottom: 0;
  353. margin: auto;
  354. }
  355. }
  356. .picture {
  357. margin-top: 20rpx;
  358. background: #F5F6FA;
  359. width: 212rpx;
  360. height: 212rpx;
  361. border-radius: 10rpx;
  362. display: flex;
  363. flex-direction: column;
  364. justify-content: center;
  365. align-items: center;
  366. color: #6A7282;
  367. }
  368. .submit-btn {
  369. position: fixed;
  370. bottom: 40rpx;
  371. width: 90%;
  372. background: #2772FB;
  373. color: white;
  374. text-align: center;
  375. margin-left: 5%;
  376. padding: 30rpx 0;
  377. border-radius: 50rpx;
  378. }
  379. </style>