index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view class="container">
  3. <uni-navbar title="新增司机"></uni-navbar>
  4. <view class="box">
  5. <u--form :model="form" ref="uForm" :rules="rules" labelWidth="0"
  6. class="formStyle addHeight commonBj commonMt">
  7. <u-form-item prop="truckId" @click="clickCar">
  8. <view class="redCircle"></view>
  9. <text class="itemText">车辆选择</text>
  10. <u-input disabled disabledColor="rgba(0,0,0,0)" class="inputStyle" suffixIcon="arrow-right"
  11. suffixIconStyle="color: #495B93" v-model="form.carValue" placeholder="请选择车辆" />
  12. </u-form-item>
  13. <u-form-item prop="driverName">
  14. <view class="redCircle"></view>
  15. <text class="itemText">司机姓名</text>
  16. <u-input class="inputStyle" v-model="form.driverName" maxlength="10" placeholder="请输入司机姓名" />
  17. </u-form-item>
  18. <u-form-item prop="cardNum">
  19. <view class="redCircle"></view>
  20. <text class="itemText">身份证号</text>
  21. <u-input class="inputStyle" v-model="form.cardNum" placeholder="请输入身份证号" />
  22. </u-form-item>
  23. <u-form-item prop="phone">
  24. <view class="redCircle"></view>
  25. <text class="itemText">联系电话</text>
  26. <u-input class="inputStyle" v-model="form.phone" placeholder="请输入联系电话" />
  27. </u-form-item>
  28. <u-form-item prop="driverType" @click="clickType">
  29. <view class="redCircleNo circleWH"></view>
  30. <text class="itemText">驾照类型</text>
  31. <u-input disabled disabledColor="rgba(0,0,0,0)" class="inputStyle" v-model="form.driverType"
  32. suffixIcon="arrow-right" suffixIconStyle="color: #495B93" placeholder="请选择驾照类型" />
  33. </u-form-item>
  34. <u-form-item>
  35. <view class="uploadBox">
  36. <view class="textBox">
  37. <view class="redCircleNo circleWH"></view>
  38. <text class="itemText">驾驶证件(<text class="redText">确保证件清晰完整 </text>)</text>
  39. </view>
  40. <xfx-image-upload uploadTitle="上传驾驶证主页" uploadType="0" :max="1" :chooseNum="1"
  41. v-model="fileList1" @uploadSuccess="UploadSuccessTruckCertificate"
  42. @imgDelete="delTruckCertificate" mediaType="image">
  43. </xfx-image-upload>
  44. <xfx-image-upload uploadTitle="上传驾驶证副页" uploadType="0" :max="1" :chooseNum="1"
  45. v-model="fileList2" @uploadSuccess="UploadSuccessTruckCertificate2"
  46. @imgDelete="delTruckCertificate2" mediaType="image">
  47. </xfx-image-upload>
  48. <!-- <u-upload class="uploadImg" :fileList="fileList1" @afterRead="afterRead" @delete="deletePic"
  49. name="1" multiple :maxCount="1" width="599rpx" height="270rpx" delIcon="close-circle-fill"
  50. delColor="#FC5536">
  51. <view class="plus-icon">
  52. <view class="imgAdd"></view>
  53. <text class="mt">上传驾驶证主页</text>
  54. </view>
  55. </u-upload>
  56. <u-upload class="uploadImg" :fileList="fileList2" @afterRead="afterRead" @delete="deletePic"
  57. name="2" multiple :maxCount="1" width="599rpx" height="270rpx" delIcon="close-circle-fill"
  58. delColor="#FC5536">
  59. <view class="plus-icon">
  60. <view class="imgAdd"></view>
  61. <text class="mt">上传驾驶证副页</text>
  62. </view>
  63. </u-upload> -->
  64. </view>
  65. </u-form-item>
  66. </u--form>
  67. <!-- <buttonNew @click="submit" class="add-button commonMb" text="确认新增"></buttonNew> -->
  68. <u-button @click="submit" shape="circle" color="linear-gradient(to top, #F59A02, #FFD334 )"
  69. class="custom-style mt27 buttonLang commonMb">确认新增</u-button>
  70. </view>
  71. <selectNew :isShow="isShow" :valueData="form.truckId" :oldList="teuckList" @changSelect="changSelect">
  72. </selectNew>
  73. <selectNew :isCar="false" :isShow="isShowType" title="驾照类型" placeholder="搜索驾照类型" :valueData="form.typeValue"
  74. :oldList="driverTypeData" @changSelect="changSelectType"></selectNew>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. getDriverType,
  80. getTeuckList,
  81. driverAdd
  82. } from '../../api/company/user.js'
  83. export default {
  84. data() {
  85. return {
  86. isShow: false,
  87. isShowType: false,
  88. form: {
  89. id: null,
  90. truckId: null,
  91. carValue: null,
  92. driverName: null,
  93. cardNum: null,
  94. phone: null,
  95. driverType: null,
  96. // companyId: '1023271044427829248',
  97. companyId: null,
  98. typeValue: null,
  99. },
  100. rules: {
  101. truckId: [{
  102. required: true,
  103. message: '请选择车辆',
  104. trigger: ['change']
  105. }, ],
  106. driverName: [{
  107. required: true,
  108. whitespace:true,
  109. message: '请输入司机姓名',
  110. trigger: ['blur', 'change']
  111. }, ],
  112. cardNum: [{
  113. required: true,
  114. message: '请输入身份证号',
  115. trigger: ['blur', 'change']
  116. }, {
  117. // 自定义验证函数
  118. pattern: /^(([1-9][0-9]{5}(19|20)[0-9]{2}((0[1-9])|(1[0-2]))([0-2][1-9]|10|20|30|31)[0-9]{3}([0-9]|X|x))|([1-9][0-9]{5}[0-9]{2}((0[1-9])|(1[0-2]))([0-2][1-9]|10|20|30|31)[0-9]{3}))$/,
  119. // 正则检验前先将值转为字符串
  120. transform(value) {
  121. return String(value);
  122. },
  123. message: '身份证号码不正确',
  124. // 触发器可以同时用blur和change
  125. trigger: ['blur'],
  126. }],
  127. phone: [{
  128. required: true,
  129. message: '请输入联系电话',
  130. trigger: ['blur', 'change']
  131. }, {
  132. // 自定义验证函数
  133. validator: (rule, value, callback) => {
  134. // 上面有说,返回true表示校验通过,返回false表示不通过
  135. // uni.$u.test.mobile()就是返回true或者false的
  136. return uni.$u.test.mobile(value);
  137. },
  138. message: '手机号码不正确',
  139. // 触发器可以同时用blur和change
  140. trigger: ['blur'],
  141. }],
  142. // driverType: [{
  143. // required: true,
  144. // message: '请选择驾照类型',
  145. // trigger: ['change']
  146. // },
  147. // ],
  148. },
  149. fileList1: [],
  150. fileList2: [],
  151. fileListData1: [],
  152. fileListData2: [],
  153. teuckList: [{
  154. name: '吉A.427TH',
  155. value: '0'
  156. },
  157. {
  158. name: '吉b.423TH',
  159. value: '1'
  160. },
  161. {
  162. name: '吉d.257TH',
  163. value: '2'
  164. },
  165. {
  166. name: '吉e.227TH',
  167. value: '3'
  168. },
  169. {
  170. name: '吉e.228TH',
  171. value: '4'
  172. },
  173. {
  174. name: '吉e.229TH',
  175. value: '5'
  176. },
  177. {
  178. name: '吉e.230TH',
  179. value: '6'
  180. },
  181. {
  182. name: '吉e.231TH',
  183. value: '7'
  184. },
  185. {
  186. name: '吉e.232TH',
  187. value: '8'
  188. }
  189. ],
  190. driverTypeData: []
  191. }
  192. },
  193. onLoad() {
  194. this.form.companyId = this.$store.state.user.companyId;
  195. console.log(this.$store.state.user.companyId, 'this.$store.state.userData.companyId');
  196. this.getDriverType()
  197. this.getTeuckList()
  198. },
  199. methods: {
  200. // 删除图片
  201. delTruckCertificate(del, tempFilePaths) {
  202. this.fileList1 = [];
  203. this.fileListData1 = [];
  204. },
  205. delTruckCertificate2(del, tempFilePaths) {
  206. this.fileList2 = [];
  207. this.fileListData2 = [];
  208. },
  209. UploadSuccessTruckCertificate(res) {
  210. /****************
  211. 因为上传接口返回的结构不一致,所以以下代码需要根据实际的接口返回结构开发,在此只是展示如果给数组里添加的过程,仅供参考
  212. ***************/
  213. var _res = JSON.parse(res.data);
  214. console.log(_res);
  215. if (_res.code == 200) {
  216. this.fileListData1.push(_res.data);
  217. this.fileList1.push(_res.data.url)
  218. }
  219. },
  220. UploadSuccessTruckCertificate2(res) {
  221. /****************
  222. 因为上传接口返回的结构不一致,所以以下代码需要根据实际的接口返回结构开发,在此只是展示如果给数组里添加的过程,仅供参考
  223. ***************/
  224. var _res = JSON.parse(res.data);
  225. console.log(_res);
  226. if (_res.code == 200) {
  227. this.fileListData2.push(_res.data);
  228. this.fileList2.push(_res.data.url)
  229. }
  230. },
  231. getDriverType() {
  232. getDriverType().then(res => {
  233. this.driverTypeData = res.data.map(item => {
  234. return {
  235. name: item.dictLabel,
  236. value: item.dictValue
  237. }
  238. })
  239. })
  240. },
  241. getTeuckList() {
  242. getTeuckList({
  243. companyId: this.form.companyId
  244. }).then(res => {
  245. console.log('res', '我是车辆')
  246. this.teuckList = res.data.map(item => {
  247. return {
  248. name: item.carNumber,
  249. value: item.id
  250. }
  251. })
  252. })
  253. },
  254. clickCar() {
  255. this.isShow = true
  256. },
  257. changSelect(data) {
  258. this.isShow = false
  259. if (data && data.value) {
  260. this.form.truckId = data.value;
  261. this.form.carValue = data.name;
  262. }
  263. },
  264. clickType() {
  265. this.isShowType = true
  266. },
  267. changSelectType(data) {
  268. this.isShowType = false
  269. if (data && data.value) {
  270. this.form.driverType = data.name;
  271. this.form.typeValue = data.value;
  272. }
  273. },
  274. // 删除图片
  275. deletePic(event) {
  276. this[`fileList${event.name}`].splice(event.index, 1)
  277. },
  278. // 新增图片
  279. async afterRead(event) {
  280. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  281. let lists = [].concat(event.file)
  282. console.log(event, 'event');
  283. let fileListLen = this[`fileList${event.name}`].length
  284. lists.map((item) => {
  285. this[`fileList${event.name}`].push({
  286. ...item,
  287. status: 'uploading',
  288. message: '上传中'
  289. })
  290. })
  291. for (let i = 0; i < lists.length; i++) {
  292. const result = await this.uploadFilePromise(lists[i].url)
  293. let item = this[`fileList${event.name}`][fileListLen]
  294. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  295. status: 'success',
  296. message: '',
  297. url: result
  298. }))
  299. fileListLen++
  300. }
  301. },
  302. uploadFilePromise(url) {
  303. return new Promise((resolve, reject) => {
  304. let a = uni.uploadFile({
  305. url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  306. filePath: url,
  307. name: 'file',
  308. formData: {
  309. user: 'test'
  310. },
  311. success: (res) => {
  312. setTimeout(() => {
  313. resolve(res.data.data)
  314. }, 1000)
  315. }
  316. });
  317. })
  318. },
  319. driverAdd() {
  320. let imgList = [];
  321. if (this.fileListData1.length > 0) {
  322. imgList.push(this.fileListData1[0])
  323. }
  324. if (this.fileListData2.length > 0) {
  325. imgList.push(this.fileListData2[0])
  326. }
  327. driverAdd({
  328. ...this.form,
  329. imgList: imgList
  330. }).then(res => {
  331. this.$tab.navigateBack()
  332. })
  333. },
  334. // 提交
  335. submit() {
  336. this.$refs.uForm.validate().then(res => {
  337. console.log(res, '111')
  338. this.driverAdd();
  339. }).catch(errors => {
  340. console.log(errors, '222')
  341. })
  342. }
  343. },
  344. }
  345. </script>
  346. <style lang="scss" scoped>
  347. .circleWH {
  348. width: 12rpx;
  349. height: 12rpx;
  350. }
  351. .formStyle {
  352. padding: 41rpx 39rpx;
  353. }
  354. .uploadImg {
  355. width: 599rpx !important;
  356. height: 270rpx !important;
  357. background: rgba(255, 255, 255, 0.1);
  358. border: 2rpx solid #495B93;
  359. border-radius: 15rpx;
  360. margin-top: 30rpx;
  361. /deep/ .u-upload__wrap__preview {
  362. overflow: visible;
  363. }
  364. /deep/ .u-upload__deletable {
  365. width: 30rpx;
  366. height: 30rpx;
  367. // background-color: #FC5536;
  368. background-image: url(../../static/images/user/redClose.png);
  369. background-color: rgba(0, 0, 0, 0);
  370. background-size: 100% 100%;
  371. border-radius: 50%;
  372. position: absolute;
  373. top: -20rpx;
  374. right: -20rpx;
  375. .u-upload__deletable__icon {
  376. position: absolute;
  377. top: 50%;
  378. transform: translateY(-50%);
  379. }
  380. }
  381. /deep/ .u-icon__icon {
  382. font-size: 0 !important;
  383. }
  384. }
  385. // 上传组件样式
  386. .uploadBox {
  387. width: 100%;
  388. .u-upload__wrap__preview__image {
  389. width: 598rpx !important;
  390. height: 250rpx !important;
  391. border-radius: 13rpx;
  392. }
  393. /deep/.xfx-image-upload-list {
  394. display: block;
  395. margin-top: 30rpx;
  396. border: 2rpx solid #495B93;
  397. border-radius: 15rpx;
  398. height: 300rpx;
  399. .xfx-image-upload-Item {
  400. width: 100%;
  401. height: 100%;
  402. margin-right: 0;
  403. margin-bottom: 0;
  404. background-color: rgba(255, 255, 255, 0.1);
  405. }
  406. .xfx-image-upload-Item-add {
  407. padding-top: 100rpx;
  408. }
  409. }
  410. }
  411. .mt27 {
  412. margin-top: 27rpx;
  413. }
  414. .textBox {
  415. display: flex;
  416. align-items: center;
  417. }
  418. .plus-icon {
  419. width: 599rpx;
  420. height: 270rpx;
  421. display: flex;
  422. flex-direction: column;
  423. justify-content: center;
  424. align-items: center;
  425. }
  426. .mt {
  427. margin-top: 31rpx;
  428. font-size: 28rpx;
  429. font-weight: 400;
  430. color: #495B93;
  431. }
  432. .imgAdd {
  433. width: 51rpx;
  434. height: 51rpx;
  435. background-image: url(../../static/images/user/add.png);
  436. background-size: 100% 100%;
  437. }
  438. /deep/ uni-image {
  439. border-radius: 15rpx;
  440. }
  441. </style>