DriverDetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. <template>
  2. <div class="container">
  3. <div class="content">
  4. <el-form
  5. class="form"
  6. ref="form"
  7. :model="form"
  8. :rules="rules"
  9. label-width="150px"
  10. label-position="right"
  11. >
  12. <el-row :gutter="20">
  13. <el-col :xs="24" :md="10" :offset="0">
  14. <el-form-item label="Display Name:" prop="nickName">
  15. <el-input
  16. :disabled="isDispatch"
  17. v-model="form.nickName"
  18. ></el-input>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :xs="24" :md="10" >
  22. <el-form-item label="PDVL:" prop="pdvLicence">
  23. <el-input
  24. :disabled="isDispatch"
  25. v-model="form.pdvLicence"
  26. ></el-input>
  27. </el-form-item>
  28. </el-col>
  29. </el-row>
  30. <el-row :gutter="20">
  31. <el-col :xs="24" :md="10" :offset="0">
  32. <el-form-item label="Email Address:" prop="email">
  33. <el-input
  34. :disabled="isDispatch"
  35. v-model="form.email"
  36. ></el-input>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :xs="24" :md="10">
  40. <el-form-item label="Company:" prop="fleetCompanyId">
  41. <el-select
  42. :disabled="isDispatch"
  43. v-model="form.fleetCompanyId">
  44. <el-option
  45. v-for="(item) in options.fleetCompany"
  46. :key="item.fleetCompanyId"
  47. :label="item.fleetCompanyName"
  48. :value="item.fleetCompanyId"
  49. ></el-option>
  50. </el-select>
  51. </el-form-item>
  52. </el-col>
  53. </el-row>
  54. <el-row :gutter="20">
  55. <el-col :xs="24" :md="10">
  56. <el-form-item label="Country:" prop="phone">
  57. <el-select
  58. :disabled="isDispatch"
  59. v-model="form.countryCode">
  60. <el-option
  61. v-for="item in options.countryList"
  62. :key="item.value"
  63. :label="item.name"
  64. :value="item.value"
  65. />
  66. </el-select>
  67. </el-form-item>
  68. </el-col>
  69. <el-col :xs="24" :md="10" :offset="0">
  70. <el-form-item label="Phone Number:" prop="phone">
  71. <div class="flexc">
  72. <el-select
  73. style="min-width: 75px; max-width: 80px;"
  74. :disabled="isDispatch"
  75. v-model="form.callingCode">
  76. <el-option
  77. v-for="item in options.callingCode"
  78. :key="item.callingCode"
  79. :label="'+' + item.callingCode"
  80. :value="item.callingCode"
  81. />
  82. </el-select>
  83. <el-input
  84. style="margin-left: 10px;"
  85. :disabled="isDispatch"
  86. v-model="form.phone"
  87. />
  88. </div>
  89. <!--el-input
  90. v-else
  91. :disabled="isDispatch"
  92. v-model="form.phone"
  93. ></el-input-->
  94. </el-form-item>
  95. </el-col>
  96. </el-row>
  97. <el-row :gutter="20">
  98. <el-col :span="24">
  99. <el-form-item label="PDVL:" class="pdvl" prop="pdvLicencePictures">
  100. <template v-slot:label>
  101. PDVL Photos: <br> (Front & Back)
  102. </template>
  103. <div class="flexcr">
  104. <el-upload
  105. :disabled="isDispatch"
  106. class="avatar-uploader"
  107. accept=".jpg,.jpeg,.png,.gif,.JPG,.JPEG"
  108. :action="action"
  109. :headers="headers"
  110. :show-file-list="false"
  111. :on-success="handleAvatarSuccessFirst"
  112. :before-upload="beforeAvatarUpload">
  113. <el-image
  114. style="width: 150px; height: 100px"
  115. v-if="form.pdvLicencePictures.front"
  116. :src="form.pdvLicencePictures.front | imageSrc"
  117. :preview-src-list="isDispatch ? previewSrcList : []"/>
  118. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  119. </el-upload>
  120. <el-upload
  121. :disabled="isDispatch"
  122. class="avatar-uploader"
  123. accept=".jpg,.jpeg,.png,.gif,.JPG,.JPEG"
  124. :action="action"
  125. :headers="headers"
  126. :show-file-list="false"
  127. :on-success="handleAvatarSuccessSecond"
  128. :before-upload="beforeAvatarUpload">
  129. <el-image
  130. style="width: 150px; height: 100px"
  131. v-if="form.pdvLicencePictures.back"
  132. :src="form.pdvLicencePictures.back | imageSrc"
  133. :preview-src-list="isDispatch ? previewSrcList : []"/>
  134. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  135. </el-upload>
  136. </div>
  137. </el-form-item>
  138. </el-col>
  139. </el-row>
  140. </el-form>
  141. <el-divider v-if="!isFulfilled"></el-divider>
  142. <div class="buttons" v-if="isDispatch">
  143. <el-button
  144. v-if="!isFulfilled"
  145. @click="onClickRejectButton"
  146. type="primary"
  147. class="cancel-button"
  148. :loading="rejectButtonLoading"
  149. >
  150. Reject
  151. </el-button>
  152. <el-button
  153. v-if="!isFulfilled"
  154. @click="onClickApproveButton"
  155. type="primary"
  156. :loading="approveButtonLoading"
  157. >
  158. Approve
  159. </el-button>
  160. </div>
  161. <div class="buttons" v-else>
  162. <el-button
  163. @click="onClickCancelButton"
  164. type="primary"
  165. class="cancel-button"
  166. >
  167. Cancel
  168. </el-button>
  169. <el-button
  170. @click="onClickConfirmButton"
  171. type="primary"
  172. :loading="confirmButtonLoading"
  173. >
  174. Save
  175. </el-button>
  176. </div>
  177. </div>
  178. </div>
  179. </template>
  180. <script>
  181. import api from '@/http/api/driver'
  182. import { baseURL } from '@/http/http'
  183. import site from '../../http/api/site'
  184. import { getToken } from '@/utils/auth'
  185. import {getCountryList} from '../../utils/index.js'
  186. import settings from '../../settings.js'
  187. export default {
  188. name: "DriverDetail",
  189. data() {
  190. const picturesValidator = (rule, value, callback) => {
  191. if (!value.back || !value.front) {
  192. callback(new Error('must two picture...'))
  193. } else {
  194. callback()
  195. }
  196. }
  197. return {
  198. form: {
  199. userPk: "",
  200. nickName: "",
  201. driverStatus: "",
  202. email: "",
  203. phone: "",
  204. countryCode: settings.defaultCountry,
  205. callingCode: settings.defaultCalling,
  206. fleetCompanyId: "",
  207. pdvLicence: "",
  208. pdvLicencePictures: {
  209. front: "",
  210. back: "",
  211. },
  212. },
  213. options: {
  214. countryList: [],
  215. callingCode: [],
  216. fleetCompany: [],
  217. },
  218. rules: {
  219. nickName: [{
  220. message: "Nickname is required",
  221. trigger: "blur",
  222. required: true,
  223. }],
  224. email: [{
  225. message: "Email is required",
  226. trigger: "blur",
  227. required: true,
  228. }],
  229. phone: [{
  230. message: "Phone number is required",
  231. trigger: "blur",
  232. required: true,
  233. }],
  234. fleetCompanyId: [{
  235. message: "Please select company",
  236. trigger: "blur",
  237. required: true,
  238. }],
  239. pdvLicence: [{
  240. message: "required",
  241. trigger: "blur",
  242. required: false,
  243. }],
  244. pdvLicencePictures: [{
  245. trigger: "blur",
  246. required: false,
  247. //validator: picturesValidator,
  248. }],
  249. },
  250. confirmButtonLoading: false,
  251. approveButtonLoading: false,
  252. rejectButtonLoading: false,
  253. }
  254. },
  255. computed: {
  256. isFulfilled() {
  257. return this.form.driverStatus !== 'Pending Review'
  258. },
  259. action() {
  260. return baseURL + process.env.VUE_APP_API_PREFIX + '/picture/upload'
  261. },
  262. isEdit() {
  263. return !!this.$route.query.id
  264. },
  265. isDispatch() {
  266. return !!this.$route.query.dispatch && !!this.$route.query.id
  267. },
  268. headers() {
  269. return {
  270. accessToken: getToken(),
  271. photoSubDir: "PDVL",
  272. }
  273. },
  274. previewSrcList() {
  275. const imageSrc = []
  276. const { front, back } = this.form.pdvLicencePictures
  277. if (front) {
  278. imageSrc.push(this.getImageSrc(front))
  279. }
  280. if (back) {
  281. imageSrc.push(this.getImageSrc(back))
  282. }
  283. return imageSrc
  284. },
  285. },
  286. filters: {
  287. imageSrc(path) {
  288. return baseURL + path
  289. }
  290. },
  291. methods: {
  292. getImageSrc(path) {
  293. return baseURL + path
  294. },
  295. getDriverId() {
  296. return this.$route.query.id
  297. },
  298. async getDriverDetail() {
  299. if (this.isEdit) {
  300. const { success, data } = await api.fetchDriverDetail({
  301. userPk: this.getDriverId()
  302. })
  303. if (success) {
  304. this.form.driverStatus = data.driverStatus
  305. this.form.email = data.email
  306. this.form.fleetCompanyId = data.fleetCompanyId
  307. this.form.nickName = data.nickName
  308. this.form.pdvLicence = data.pdvLicence
  309. this.form.countryCode = data.countryCode || 'SG'
  310. this.form.callingCode = "" + data.callingCode
  311. this.form.phone = data.phone
  312. this.form.userPk = data.userPk
  313. if (data.pdvLicencePictures) {
  314. const [front = '', back = ''] = data.pdvLicencePictures
  315. this.form.pdvLicencePictures.front = front
  316. this.form.pdvLicencePictures.back = back
  317. }
  318. }
  319. }
  320. },
  321. handleAvatarSuccessFirst(response) {
  322. this.form.pdvLicencePictures.front = response.data.picturePath
  323. },
  324. handleAvatarSuccessSecond(response) {
  325. this.form.pdvLicencePictures.back = response.data.picturePath
  326. },
  327. beforeAvatarUpload(file) {
  328. const IMAGE_TYPE_ARRAY = ['jpg', 'png', 'jpeg', 'gif']
  329. const fileExt = file.name.replace(/.+\./, '').toLowerCase()
  330. if (IMAGE_TYPE_ARRAY.indexOf(fileExt) === -1) {
  331. const msg = `请选择类型为${IMAGE_TYPE_ARRAY.join('、')}的文件`
  332. this.$message.warning(msg)
  333. return false
  334. }
  335. if (file.size / 1024 / 1024 > 2) {
  336. this.$message.warning('上传文件不能超过2m')
  337. return false
  338. }
  339. },
  340. async getFleetCompanyOptions() {
  341. const {
  342. success,
  343. data
  344. } = await api.fetchFleetCompanyOptions()
  345. if (success) {
  346. this.options.fleetCompany = data
  347. }
  348. },
  349. async onClickApproveButton() {
  350. const params = { userPk: this.getDriverId() }
  351. this.approveButtonLoading = true
  352. try {
  353. const { success, msg } = await api.approveDriver(params)
  354. if (success) {
  355. this.$notify.success(msg)
  356. this.$router.back()
  357. }
  358. } catch (error) {
  359. this.$notify.error(msg)
  360. }
  361. this.approveButtonLoading = false
  362. },
  363. async onClickRejectButton() {
  364. const params = { userPk: this.getDriverId() }
  365. this.rejectButtonLoading = true
  366. try {
  367. const { success, msg } = await api.rejectDriver(params)
  368. if (success) {
  369. this.$notify.success(msg)
  370. this.$router.back()
  371. }
  372. } catch (error) {
  373. this.$notify.error(msg)
  374. }
  375. this.rejectButtonLoading = false
  376. },
  377. onClickCancelButton() {
  378. this.$router.back()
  379. },
  380. onClickConfirmButton() {
  381. this.confirmButtonLoading = true
  382. this.$refs.form.validate(async (valid) => {
  383. if (valid) {
  384. try {
  385. const {
  386. pdvLicencePictures: {
  387. front,
  388. back,
  389. },
  390. countryCode,
  391. callingCode,
  392. phone,
  393. ...others
  394. } = this.form
  395. const pdvLicencePictures = []
  396. front && pdvLicencePictures.push(front)
  397. back && pdvLicencePictures.push(back)
  398. let result
  399. if (this.isEdit) {
  400. result = await api.updateDriver({
  401. pdvLicencePictures,
  402. phone,
  403. countryCode,
  404. callingCode,
  405. ...others,
  406. })
  407. } else {
  408. result = await api.addDriver({
  409. pdvLicencePictures,
  410. countryCode,
  411. callingCode,
  412. phone,
  413. ...others,
  414. })
  415. }
  416. if (result.success) {
  417. this.$notify.success(result.msg)
  418. this.$router.back()
  419. }
  420. } catch (error) {
  421. if (error) {
  422. this.$notify.error(error)
  423. }
  424. }
  425. }
  426. })
  427. this.confirmButtonLoading = false
  428. },
  429. getCountryOptions() {
  430. site.getCountryList().then(({ data }) => {
  431. this.options.countryList = data
  432. })
  433. }
  434. },
  435. async created() {
  436. this.getFleetCompanyOptions()
  437. if (this.isEdit) {
  438. this.getDriverDetail()
  439. }
  440. this.getCountryOptions()
  441. getCountryList(list => {
  442. this.options.callingCode = list
  443. })
  444. },
  445. }
  446. </script>
  447. <style lang='scss' scoped>
  448. @import '../../styles/variables.scss';
  449. .container {
  450. width: 100%;
  451. padding: 20px 50px;
  452. background-color: #F0F5FC;
  453. .content {
  454. border-radius: 6px;
  455. min-height: calc(#{$mainAppMinHeight} - (2 * 20px));
  456. background-color: white;
  457. .form {
  458. padding: 45px 100px;
  459. .pdvl {
  460. ::v-deep .el-form-item__label {
  461. padding: 12px;
  462. line-height: 16px;
  463. }
  464. }
  465. .avatar-uploader {
  466. margin-right: 10px;
  467. .avatar-uploader-icon {
  468. border: 1px dashed #d9d9d9;
  469. border-radius: 6px;
  470. cursor: pointer;
  471. font-size: 28px;
  472. color: #8c939d;
  473. width: 100px;
  474. height: 100px;
  475. line-height: 100px;
  476. text-align: center;
  477. }
  478. }
  479. }
  480. .el-select {
  481. width: 100%;
  482. }
  483. .buttons {
  484. padding: 0 45px;
  485. }
  486. }
  487. }
  488. </style>