addVehicle.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. if(!this.dataDetails.addressUrl){
  177. this.dataDetails.addressUrl = result
  178. }else{
  179. this.dataDetails.addressUrl = this.dataDetails.addressUrl+','+ result
  180. }
  181. }
  182. )
  183. },
  184. //车牌号弹出键盘
  185. handleShowKeyboard(index) {
  186. if (this.dataDetails.carNumber == '') {
  187. this.carNumber = ''
  188. } else {
  189. this.carNumber = this.dataDetails.carNumber
  190. }
  191. if (this.$refs.keyboard.open) {
  192. this.$refs.keyboard.open(false) //true 键盘显示 false 键盘隐藏
  193. } else {
  194. this.$refs.keyboard[0].open(false)
  195. }
  196. this.index = index
  197. if (this.$refs.keyboard.open) {
  198. this.$refs.keyboard.open(true) //true 键盘显示 false 键盘隐藏
  199. } else {
  200. this.$refs.keyboard[0].open(true)
  201. }
  202. },
  203. //车牌号弹出键盘
  204. handleClick(e) {
  205. this.carNumber = e.value
  206. this.dataDetails.carNumber = e.value //键盘输入值
  207. },
  208. confirmColor(val) {
  209. this.dataDetails.carNumberColour = val.value[0]
  210. this.carColor = false
  211. },
  212. colorClose() {
  213. this.carColor = false
  214. },
  215. selectNoColor() {
  216. this.carColor = true
  217. },
  218. confirmCarModel(val) {
  219. this.dataDetails.carType = val.value[0] + ' ' + val.value[1]
  220. this.carModel = false
  221. },
  222. carModelClose() {
  223. this.carModel = false
  224. },
  225. selectCarModel() {
  226. this.carModel = true
  227. },
  228. selectNoColor() {
  229. this.carColor = true
  230. },
  231. unloadGroupPhoto() {
  232. uni.chooseImage({
  233. count: 1,
  234. success: function(res) {
  235. console.log(JSON.stringify(res.tempFilePaths));
  236. uploadImage('image',res.tempFilePaths[0], 'appData/',
  237. result => {
  238. // 上传成功
  239. console.log('图片地址', result)
  240. }
  241. )
  242. }
  243. });
  244. },
  245. validate() {
  246. // true 为校验不通过
  247. if (uni.$u.test.isEmpty(this.dataDetails.carNumber)) {
  248. this.$refs.uToast.show({
  249. type: 'error',
  250. message: "车牌号不能为空!",
  251. })
  252. return true
  253. }
  254. if (uni.$u.test.isEmpty(this.dataDetails.carTotalWeight)) {
  255. this.$refs.uToast.show({
  256. type: 'error',
  257. message: "总质量不能为空!",
  258. })
  259. return true
  260. }
  261. if (uni.$u.test.isEmpty(this.dataDetails.carApprovedWeight)) {
  262. this.$refs.uToast.show({
  263. type: 'error',
  264. message: "核定载质量不能为空!",
  265. })
  266. return true
  267. }
  268. if (uni.$u.test.isEmpty(this.dataDetails.carLong)&&uni.$u.test.isEmpty(this.dataDetails.caWidth)&&uni.$u.test.isEmpty(this.dataDetails.carHeight)) {
  269. this.$refs.uToast.show({
  270. type: 'error',
  271. message: "外廓尺寸不能为空!",
  272. })
  273. return true
  274. }
  275. // if (uni.$u.test.isEmpty(this.dataDetails.drivingLicenseBackPage)) {
  276. // this.$refs.uToast.show({
  277. // type: 'error',
  278. // message: "行驶证副页不能为空!",
  279. // })
  280. // return true
  281. // }
  282. return false
  283. },
  284. submit() {
  285. // 校验
  286. if (this.validate()) return
  287. this.$request.baseRequest('post', '/driverCarInfo/api/addInfo', this.dataDetails).then(res => {
  288. if (res.code == '200') {
  289. let params = {
  290. type: 'success',
  291. message: "提交成功",
  292. }
  293. this.$refs.uToast.show({
  294. ...params
  295. })
  296. uni.$u.route('/pages/mine/manageVehicles/index');
  297. } else {
  298. uni.$u.toast(res.message);
  299. }
  300. })
  301. .catch(res => {
  302. uni.$u.toast(res.message);
  303. });
  304. },
  305. },
  306. }
  307. </script>
  308. <style lang="scss" scoped>
  309. .container {
  310. margin: 20rpx;
  311. background: white;
  312. padding: 0 20rpx;
  313. border-radius: 20rpx;
  314. .left-text {
  315. // background: red;
  316. width: 290rpx;
  317. color: #333333;
  318. display: flex;
  319. align-items: center;
  320. }
  321. .row {
  322. border-bottom: 1px solid #EEEEEE;
  323. padding-bottom: 28rpx;
  324. margin-top: 26rpx;
  325. .ch-style {}
  326. }
  327. .row-ch {
  328. padding-right: 250rpx;
  329. box-sizing: border-box;
  330. }
  331. }
  332. .input-ckg {
  333. height: 86rpx;
  334. margin-top: 0 !important;
  335. padding-bottom: 0 !important;
  336. .u-input {
  337. height: 100%;
  338. background: #F7F8FA;
  339. padding-left: 10rpx !important;
  340. padding-right: 85rpx !important;
  341. }
  342. .star {
  343. display: flex;
  344. align-items: center;
  345. margin: 0 10rpx;
  346. }
  347. .input-positon {
  348. position: relative;
  349. }
  350. .position-right {
  351. position: absolute;
  352. right: 20rpx;
  353. top: 0;
  354. width: 60rpx;
  355. height: 50rpx;
  356. bottom: 0;
  357. margin: auto;
  358. }
  359. }
  360. .picture {
  361. margin-top: 20rpx;
  362. background: #F5F6FA;
  363. width: 212rpx;
  364. height: 212rpx;
  365. border-radius: 10rpx;
  366. display: flex;
  367. flex-direction: column;
  368. justify-content: center;
  369. align-items: center;
  370. color: #6A7282;
  371. }
  372. .submit-btn {
  373. position: fixed;
  374. bottom: 40rpx;
  375. width: 90%;
  376. background: #2772FB;
  377. color: white;
  378. text-align: center;
  379. margin-left: 5%;
  380. padding: 30rpx 0;
  381. border-radius: 50rpx;
  382. }
  383. </style>