addVehicle.vue 8.8 KB

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