dealerAddVehicle.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <template>
  2. <view class="main">
  3. <u-navbar :title="vehicleForm.id ? $t('base.button.update') : $t('base.button.add')" :autoBack="true"
  4. :placeholder="true">
  5. </u-navbar>
  6. <view v-if="vehicleForm.vehicleType == 0" class="order-card">
  7. <u-form labelPosition="left" :model="vehicleForm" ref="form1" labelWidth='90'>
  8. <u-form-item :label="$t('driver.name')" borderBottom prop="driver">
  9. <u--input v-model="vehicleForm.driver" border="none"
  10. :placeholder="$t('base.common.placeholderI') + $t('driver.name')"></u--input>
  11. </u-form-item>
  12. <!-- <u-form-item :label="$t('driver.agricultural')" borderBottom prop="driver">
  13. <u-radio-group v-model="vehicleForm.agricultural">
  14. <u-radio shape="circle" name="1" :label="$t('driver.yes')"></u-radio>
  15. <u-radio shape="circle" name="0" :label="$t('driver.no')"></u-radio>
  16. </u-radio-group>
  17. </u-form-item> -->
  18. <u-form-item :label="$t('order.phone')" borderBottom prop="phone">
  19. <u--input @input="phoneInput" maxlength="11" v-model="vehicleForm.phone" border="none" type="number"
  20. :placeholder="$t('base.common.placeholderI') + $t('order.phone')">
  21. </u--input>
  22. </u-form-item>
  23. <!-- #ifndef APP-PLUS -->
  24. <!-- <u-form-item label="车轴" borderBottom prop="axle" @click="showPopup('popupAxle')">
  25. <span>{{ vehicleForm.axleName }}</span>
  26. </u-form-item>
  27. <PopupSelect ref="popupAxle" :hasSearch='false' :option="axleOption" @onConfirm="onAxleConfirm" /> -->
  28. <!-- #endif -->
  29. <!-- <u-form-item v-if="vehicleForm.agricultural == 0" :label="$t('driver.vehicle')" borderBottom prop="vehicle"
  30. @click="carKeyboardShow = true">
  31. <u-input readonly v-model="vehicleForm.vehicle" border="none"
  32. :placeholder="$t('base.common.placeholderI') + $t('driver.vehicle')"></u-input>
  33. </u-form-item> -->
  34. <u-form-item :label="$t('driver.vehicle')" borderBottom prop="vehicle">
  35. <u-input @input="vehicleForm.vehicle=vehicleForm.vehicle.toUpperCase()" v-model="vehicleForm.vehicle" border="none"
  36. :placeholder="$t('base.common.placeholderI') + $t('driver.vehicle')"></u-input>
  37. </u-form-item>
  38. <u-form-item :label="$t('order.idcard')" borderBottom prop="idCard">
  39. <u-input v-model="vehicleForm.idCard" border="none"
  40. :placeholder="$t('base.common.placeholderI') + $t('order.idcard')"></u-input>
  41. </u-form-item>
  42. <!--
  43. <view class="img_box">
  44. <text class="label_text">{{$t('order.idcardImg')}}:</text>
  45. <view class="img_small_box">
  46. <uni-file-picker v-model="imageValue" ref="files" :auto-upload="false" :limit='1'
  47. @select="onFileSelect" @progress="progress" @success="success"
  48. @delete="deleteImg" />
  49. </view>
  50. </view> -->
  51. </u-form>
  52. </view>
  53. <view v-if="vehicleForm.vehicleType == 1">
  54. <u-form labelPosition="left" :model="vehicleForm" ref="form1" labelWidth='90' class="order-card">
  55. <u-form-item :label="$t('driver.fleet')" borderBottom prop="fleet">
  56. <u--input v-model="vehicleForm.fleet" border="none"
  57. :placeholder="$t('base.common.placeholderI') + $t('driver.fleet')">
  58. <template slot="suffix">
  59. <u-button type="success" :text="$t('base.common.motorcade')" @click="onFleetClick"></u-button>
  60. </template>
  61. </u--input>
  62. </u-form-item>
  63. </u-form>
  64. </view>
  65. <CarKeyboard :show.sync="carKeyboardShow" :isProvince="isProvince" :vehicleNo="vehicleForm.vehicle"
  66. @confirm="keyboardconfirm" vehicleType="car">
  67. </CarKeyboard>
  68. <div class="btn-wrap">
  69. <u-button type="primary" color='#4680F9' native-type="submit" @click="submit()">
  70. {{ $t('base.common.submit') }}</u-button>
  71. </div>
  72. </view>
  73. </template>
  74. <script>
  75. import PopupSelect from '../../components/popup-select/index'
  76. import CarKeyboard from '../../components/carKeyboard/carKeyboard'
  77. import {
  78. publicUrl
  79. } from '../../utils/config'
  80. import {
  81. bindDriver,
  82. getAxleOption
  83. } from '../../api/dealer'
  84. import {
  85. getVehicleListByFleet,
  86. } from '../../api/driver'
  87. import prototype from '../../utils/prototype.js'
  88. export default {
  89. components: {
  90. CarKeyboard,
  91. PopupSelect
  92. },
  93. data() {
  94. return {
  95. isProvince: true,
  96. fleetVehicleList: [],
  97. axleOption: [],
  98. isShowVehicleList: false,
  99. imageValue:[],
  100. vehicleForm: {
  101. axle: '',
  102. axleOption: [],
  103. driver: '',
  104. vehicle: '',
  105. phone: '',
  106. vehicleType: '0',
  107. fleet: "",
  108. id: '',
  109. // agricultural: '0'
  110. },
  111. vehicleRules: {
  112. vehicle: [{
  113. required: true,
  114. message: this.$t('base.common.placeholderI') + this.$t('driver.name')
  115. }],
  116. },
  117. carKeyboardShow: false,
  118. }
  119. },
  120. onLoad(options) {
  121. // this.getAxleOption()
  122. console.log("获取到参数信息、", options)
  123. Object.assign(this.vehicleForm, options);
  124. if(options.idCardImage){
  125. this.imageValue = [
  126. {
  127. "imageName":'',
  128. "url":options.idCardImage,
  129. "imageType": "ACCEPT",
  130. "name": ""
  131. }
  132. ]
  133. }
  134. //#ifdef APP-PLUS
  135. this.isProvince = false
  136. //#endif
  137. },
  138. methods: {
  139. //手机号输入
  140. phoneInput(){
  141. if(this.vehicleForm.phone.length >= 9){
  142. uni.showToast({
  143. title: this.$t('base.smsCode.phoneTooLong'),
  144. icon: 'none'
  145. })
  146. }
  147. },
  148. //获取本地的车轴信息
  149. async getAxleOption() {
  150. var that = this;
  151. //获取租户
  152. this.vehicleForm.tenantId = uni.getStorageSync('currentTenantId').value;
  153. //通过云端调用本地车轴信息接口
  154. console.log("开始获取本地车轴信息", that.vehicleForm);
  155. await this.$request({
  156. url: '/admin/appStand/getAxleOption',
  157. method: 'post',
  158. data: that.vehicleForm
  159. }).then(res => {
  160. // 请求成功的处理逻辑
  161. console.log("getAxleOption:success")
  162. console.log("res::::", res);
  163. if (res.data) {
  164. that.axleOption = res.data.data.appAxle;
  165. //车轴转名称
  166. that.axleOption.forEach(item => {
  167. if (item.value == this.vehicleForm.axle) {
  168. this.vehicleForm.axleName = item.text
  169. }
  170. })
  171. } else {
  172. that.axleOption = [{ text: "空", value: "0" }]
  173. }
  174. console.log("获取到的车轴列表", that.axleOption);
  175. })
  176. },
  177. //勾选车轴
  178. onAxleConfirm(value) {
  179. this.vehicleForm.axle = ''
  180. this.vehicleForm.axleName = ''
  181. if (value.value) {
  182. this.vehicleForm.axle = value.value,
  183. this.vehicleForm.axleName = value.text
  184. }
  185. },
  186. //显示选择
  187. showPopup(refs) {
  188. console.log("ddd", this.axleOption);
  189. if (!this.axleOption) {
  190. this.axleOption = [{
  191. text: this.$t('order.notSelected'),
  192. value: null
  193. }] //物料选项
  194. }
  195. this.$refs[refs].showPicker = true
  196. },
  197. //判断平台
  198. onFleetClick() {
  199. if (!this.vehicleForm.fleet) {
  200. uni.showToast({
  201. title: this.$t('base.common.placeholderI') + this.$t('driver.fleet'),
  202. icon: "none",
  203. duration: 2500,
  204. })
  205. return;
  206. }
  207. uni.navigateTo({
  208. url: '/subpages/driver/fleetVehicle?fleet=' + this.vehicleForm.fleet
  209. })
  210. },
  211. //车号键盘输出
  212. keyboardconfirm(id) {
  213. this.vehicleForm.vehicle = id
  214. },
  215. //提交表单
  216. submit() {
  217. let _this = this
  218. let phone = /^\d{9}$/
  219. if (_this.vehicleForm.vehicleType == 0) {
  220. if (!_this.vehicleForm.vehicle) {
  221. uni.showToast({
  222. title: this.$t('base.common.placeholderI') + this.$t('driver.vehicle'),
  223. icon: "none",
  224. duration: 2500,
  225. })
  226. return;
  227. }
  228. } else {
  229. if (!_this.vehicleForm.fleet) {
  230. uni.showToast({
  231. title: this.$t('base.common.placeholderI') + this.$t('driver.fleet'),
  232. icon: "none",
  233. duration: 2500,
  234. })
  235. return;
  236. }
  237. _this.vehicleForm.vehicle = _this.vehicleForm.fleet
  238. }
  239. if (!_this.vehicleForm.idCard) {
  240. uni.showToast({
  241. title: this.$t('base.common.placeholderI') + this.$t('order.idcard'),
  242. icon: "none",
  243. duration: 2500,
  244. })
  245. return;
  246. }
  247. // if (!_this.imageValue.length) {
  248. // uni.showToast({
  249. // title: this.$t('order.idcardImg'),
  250. // icon: "none",
  251. // duration: 2500,
  252. // })
  253. // return;
  254. // }
  255. console.log(_this.vehicleForm);
  256. let data = JSON.parse(JSON.stringify(_this.vehicleForm))
  257. this.imageValue.length?data.idCardImage = this.imageValue[0].url:''
  258. bindDriver(data).then(res => {
  259. if (res.statusCode == 200) {
  260. var that = this;
  261. //获取租户
  262. that.vehicleForm.tenantId = uni.getStorageSync('currentTenantId').value;
  263. // this.$request({
  264. // url: '/ymt/appStand/updateVehicleAxle',
  265. // method: 'post',
  266. // data: that.vehicleForm
  267. // }).then(res => {
  268. // // 请求成功的处理逻辑
  269. // console.log("res::::", res);
  270. // })
  271. uni.showModal({
  272. // title: '提示',
  273. content: _this.$t('order.checkAddVehicle'),
  274. showCancel: true,
  275. cancelText: _this.$t('driver.no'),
  276. confirmText: _this.$t('driver.yes'),
  277. success: function (r) {
  278. if (r.confirm) {
  279. _this.$refs[ref]
  280. .resetFields()
  281. console.log('用户点击确定');
  282. } else if (r.cancel) {
  283. console.log('用户点击取消');
  284. uni.navigateBack({
  285. url: '/subpages/driver/dealerList'
  286. })
  287. }
  288. }
  289. })
  290. }
  291. })
  292. },
  293. onFileSelect(e) {
  294. console.log('选择文件:', e)
  295. uni.showLoading({
  296. title: this.$t('userinfo.uploading')
  297. })
  298. // if (this.uploadImgSrcType == '102') {
  299. console.log('图片信息',uni.getStorageSync('tenantId'),e.tempFilePaths);
  300. uni.uploadFile({
  301. // #ifdef APP-PLUS || MP-WEIXIN
  302. url: publicUrl + '/admin/sys-file/upload',
  303. // #endif
  304. // #ifndef APP-PLUS || MP-WEIXIN
  305. url: '/admin/sys-file/upload',
  306. // #endif
  307. filePath: e.tempFilePaths[0],
  308. name: 'file',
  309. header: {
  310. 'Authorization': 'Bearer ' + uni.getStorageSync('token'),
  311. 'TENANT-ID': uni.getStorageSync('tenantId'),
  312. },
  313. data: {
  314. file: e.tempFilePaths[0]
  315. },
  316. success: (res) => {
  317. console.log(res.data);
  318. let data = JSON.parse(res.data)
  319. if (data.code == 0) {
  320. this.imageValue.push({
  321. // #ifdef APP-PLUS || MP-WEIXIN
  322. "imageName":publicUrl + data.data.url,
  323. "url": publicUrl + data.data.url,
  324. // #endif
  325. // #ifndef APP-PLUS || MP-WEIXIN
  326. "imageName":data.data.url,
  327. "url":data.data.url,
  328. // #endif
  329. "imageType": "ACCEPT",
  330. "name": ""
  331. })
  332. uni.showToast({
  333. title: this.$t('settings.successText'),
  334. icon: 'none'
  335. })
  336. } else {
  337. uni.showToast({
  338. title: this.$t('settings.fail'),
  339. icon: 'none'
  340. })
  341. }
  342. },
  343. fail: function(res) {
  344. console.log('图片上传接口失败',res,uni.getStorageSync('tenantId'),e.tempFilePaths[0]);
  345. uni.showToast({
  346. title: this.$t('tips.error'),
  347. icon: 'none'
  348. })
  349. },
  350. complete: function(res) {
  351. console.log('图片上传接口完成',res);
  352. // console.log(res);
  353. uni.hideLoading()
  354. }
  355. })
  356. },
  357. progress(e) {
  358. console.log('上传进度:', e)
  359. },
  360. success(e) {
  361. console.log('上传成功', e)
  362. },
  363. deleteImg(e) {
  364. console.log('删除成功', e)
  365. console.log(this.imageValue);
  366. },
  367. },
  368. }
  369. </script>
  370. <style>
  371. /* #ifndef H5 */
  372. page {
  373. /* height: 100%; */
  374. background-color: #f2f2f2;
  375. }
  376. /* #endif */
  377. </style>
  378. <style lang="scss" scoped>
  379. @import '../../common/css/public.scss';
  380. /deep/ .uni-date-x {
  381. padding: 0;
  382. }
  383. /deep/ .u-button {
  384. margin: 0px 0px 0px 0px !important;
  385. }
  386. .btn-wrap {
  387. position: absolute;
  388. bottom: 10px;
  389. width: 100%;
  390. box-sizing: border-box;
  391. padding: 32rpx;
  392. }
  393. .img_box {
  394. display: flex;
  395. align-items: center;
  396. // height: 200rpx;
  397. // line-height: 200rpx;
  398. padding-bottom: 50rpx;
  399. background-color: #fff;
  400. padding: 40rpx 0;
  401. text {
  402. // flex: .8;
  403. width: 200rpx;
  404. display: inline-block;
  405. text-align: right;
  406. margin-right: 20rpx;
  407. }
  408. .img_small_box {
  409. flex: 3;
  410. }
  411. /deep/ .uni-file-picker__container {
  412. margin-top: 10rpx !important;
  413. }
  414. }
  415. </style>