addVehicle.vue 8.8 KB

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