addVehicle.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. debugger
  123. _this = this;
  124. console.log(options)
  125. this.dataDetails.driverId = this.userInfo.driverId
  126. },
  127. methods: {
  128. // 车型切换
  129. changeCarModel(e) {
  130. const {
  131. columnIndex,
  132. index,
  133. // 微信小程序无法将picker实例传出来,只能通过ref操作
  134. picker = this.$refs.carTypePicker
  135. } = e
  136. if (columnIndex === 0) {
  137. // 模拟网络请求
  138. picker.setColumnValues(1, this.carModelColumnData[index])
  139. }
  140. },
  141. // 删除图片
  142. deletePic(event) {
  143. this[`fileList${event.name}`].splice(event.index, 1)
  144. },
  145. // 新增图片
  146. async afterRead(event) {
  147. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  148. let lists = [].concat(event.file)
  149. let fileListLen = this[`fileList${event.name}`].length
  150. lists.map((item) => {
  151. this[`fileList${event.name}`].push({
  152. ...item,
  153. status: 'uploading',
  154. message: '上传中'
  155. })
  156. })
  157. for (let i = 0; i < lists.length; i++) {
  158. const result = await this.uploadFilePromise(lists[i].url)
  159. let item = this[`fileList${event.name}`][fileListLen]
  160. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  161. status: 'success',
  162. message: '',
  163. url: result
  164. }))
  165. fileListLen++
  166. }
  167. },
  168. uploadFilePromise(url) {
  169. uploadImage(url, 'appData/',
  170. result => {
  171. // 上传成功回调函数
  172. console.log('图片地址', result)
  173. this.dataDetails.addressUrl += result
  174. }
  175. )
  176. },
  177. //车牌号弹出键盘
  178. handleShowKeyboard(index) {
  179. if (this.dataDetails.carNumber == '') {
  180. this.carNumber = ''
  181. } else {
  182. this.carNumber = this.dataDetails.carNumber
  183. }
  184. if (this.$refs.keyboard.open) {
  185. this.$refs.keyboard.open(false) //true 键盘显示 false 键盘隐藏
  186. } else {
  187. this.$refs.keyboard[0].open(false)
  188. }
  189. this.index = index
  190. if (this.$refs.keyboard.open) {
  191. this.$refs.keyboard.open(true) //true 键盘显示 false 键盘隐藏
  192. } else {
  193. this.$refs.keyboard[0].open(true)
  194. }
  195. },
  196. //车牌号弹出键盘
  197. handleClick(e) {
  198. this.carNumber = e.value
  199. this.dataDetails.carNumber = e.value //键盘输入值
  200. },
  201. confirmColor(val) {
  202. this.dataDetails.carNumberColour = val.value[0]
  203. this.carColor = false
  204. },
  205. colorClose() {
  206. this.carColor = false
  207. },
  208. selectNoColor() {
  209. this.carColor = true
  210. },
  211. confirmCarModel(val) {
  212. this.dataDetails.carType = val.value[0] + ' ' + val.value[1]
  213. this.carModel = false
  214. },
  215. carModelClose() {
  216. this.carModel = false
  217. },
  218. selectCarModel() {
  219. this.carModel = true
  220. },
  221. selectNoColor() {
  222. this.carColor = true
  223. },
  224. unloadGroupPhoto() {
  225. uni.chooseImage({
  226. count: 1,
  227. success: function(res) {
  228. console.log(JSON.stringify(res.tempFilePaths));
  229. uploadImage(res.tempFilePaths[0], 'appData/',
  230. result => {
  231. // 上传成功
  232. console.log('图片地址', result)
  233. }
  234. )
  235. }
  236. });
  237. },
  238. submit() {
  239. this.$request.baseRequest('post', '/driverCarInfo/api/addInfo', this.dataDetails).then(res => {
  240. if (res.code == '200') {
  241. let params = {
  242. type: 'success',
  243. message: "提交成功",
  244. }
  245. this.$refs.uToast.show({
  246. ...params
  247. })
  248. uni.$u.route('/pages/mine/manageVehicles/index');
  249. } else {
  250. uni.$u.toast(res.message);
  251. }
  252. })
  253. .catch(res => {
  254. uni.$u.toast(res.message);
  255. });
  256. },
  257. },
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .container {
  262. margin: 20rpx;
  263. background: white;
  264. padding: 0 20rpx;
  265. border-radius: 20rpx;
  266. .left-text {
  267. // background: red;
  268. width: 290rpx;
  269. color: #333333;
  270. display: flex;
  271. align-items: center;
  272. }
  273. .row {
  274. border-bottom: 1px solid #EEEEEE;
  275. padding-bottom: 28rpx;
  276. margin-top: 26rpx;
  277. .ch-style {}
  278. }
  279. .row-ch {
  280. padding-right: 250rpx;
  281. box-sizing: border-box;
  282. }
  283. }
  284. .input-ckg {
  285. height: 86rpx;
  286. margin-top: 0 !important;
  287. padding-bottom: 0 !important;
  288. .u-input {
  289. height: 100%;
  290. background: #F7F8FA;
  291. padding-left: 10rpx !important;
  292. padding-right: 85rpx !important;
  293. }
  294. .star {
  295. display: flex;
  296. align-items: center;
  297. margin: 0 10rpx;
  298. }
  299. .input-positon {
  300. position: relative;
  301. }
  302. .position-right {
  303. position: absolute;
  304. right: 20rpx;
  305. top: 0;
  306. width: 60rpx;
  307. height: 50rpx;
  308. bottom: 0;
  309. margin: auto;
  310. }
  311. }
  312. .picture {
  313. margin-top: 20rpx;
  314. background: #F5F6FA;
  315. width: 212rpx;
  316. height: 212rpx;
  317. border-radius: 10rpx;
  318. display: flex;
  319. flex-direction: column;
  320. justify-content: center;
  321. align-items: center;
  322. color: #6A7282;
  323. }
  324. .submit-btn {
  325. position: fixed;
  326. bottom: 40rpx;
  327. width: 90%;
  328. background: #2772FB;
  329. color: white;
  330. text-align: center;
  331. margin-left: 5%;
  332. padding: 30rpx 0;
  333. border-radius: 50rpx;
  334. }
  335. </style>