DriverDetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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="Group:" prop="groupPk">
  41. <el-select
  42. :disabled="isDispatch"
  43. v-model="form.groupPk">
  44. <el-option
  45. v-for="(item, index) in options.fleetCompany"
  46. :key="index"
  47. :label="item.groupName"
  48. :value="item.groupPk"
  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 group from '@/http/api/group'
  183. import { baseURL } from '@/http/http'
  184. import site from '../../http/api/site'
  185. import { getToken } from '@/utils/auth'
  186. import {getCountryList} from '../../utils/index.js'
  187. import settings from '../../settings.js'
  188. export default {
  189. name: "DriverDetail",
  190. data() {
  191. const picturesValidator = (rule, value, callback) => {
  192. if (!value.back || !value.front) {
  193. callback(new Error('must two picture...'))
  194. } else {
  195. callback()
  196. }
  197. }
  198. return {
  199. form: {
  200. userPk: "",
  201. nickName: "",
  202. groupStatus: "",
  203. email: "",
  204. phone: "",
  205. countryCode: settings.defaultCountry,
  206. callingCode: settings.defaultCalling,
  207. groupPk: "",
  208. pdvLicence: "",
  209. pdvLicencePictures: {
  210. front: "",
  211. back: "",
  212. },
  213. },
  214. options: {
  215. countryList: [],
  216. callingCode: [],
  217. fleetCompany: [],
  218. },
  219. rules: {
  220. nickName: [{
  221. message: "Nickname is required",
  222. trigger: "blur",
  223. required: true,
  224. }],
  225. email: [{
  226. message: "Email is required",
  227. trigger: "blur",
  228. required: true,
  229. }],
  230. phone: [{
  231. message: "Phone number is required",
  232. trigger: "blur",
  233. required: true,
  234. }],
  235. groupPk: [{
  236. message: "Please select group",
  237. trigger: "blur",
  238. required: true,
  239. }],
  240. pdvLicence: [{
  241. message: "required",
  242. trigger: "blur",
  243. required: false,
  244. }],
  245. pdvLicencePictures: [{
  246. trigger: "blur",
  247. required: false,
  248. //validator: picturesValidator,
  249. }],
  250. },
  251. confirmButtonLoading: false,
  252. approveButtonLoading: false,
  253. rejectButtonLoading: false,
  254. }
  255. },
  256. computed: {
  257. isFulfilled() {
  258. return this.form.groupStatus !== 'Pending Review'
  259. },
  260. action() {
  261. return baseURL + process.env.VUE_APP_API_PREFIX + '/picture/upload'
  262. },
  263. isEdit() {
  264. return !!this.$route.query.id
  265. },
  266. isDispatch() {
  267. return !!this.$route.query.dispatch && !!this.$route.query.id
  268. },
  269. headers() {
  270. return {
  271. accessToken: getToken(),
  272. photoSubDir: "PDVL",
  273. }
  274. },
  275. previewSrcList() {
  276. const imageSrc = []
  277. const { front, back } = this.form.pdvLicencePictures
  278. if (front) {
  279. imageSrc.push(this.getImageSrc(front))
  280. }
  281. if (back) {
  282. imageSrc.push(this.getImageSrc(back))
  283. }
  284. return imageSrc
  285. },
  286. },
  287. filters: {
  288. imageSrc(path) {
  289. return this.$imageSrc(path)
  290. }
  291. },
  292. methods: {
  293. getImageSrc(path) {
  294. return baseURL + path
  295. },
  296. getDriverId() {
  297. return this.$route.query.id
  298. },
  299. async getDriverDetail() {
  300. if (this.isEdit) {
  301. const { success, data } = await api.fetchDriverDetail({
  302. userPk: this.getDriverId()
  303. })
  304. if (success) {
  305. this.form.groupStatus = data.groupStatus
  306. this.form.email = data.email
  307. this.form.groupPk = data.groupPk
  308. this.form.nickName = data.nickName
  309. this.form.pdvLicence = data.pdvLicence
  310. this.form.countryCode = data.countryCode || 'SG'
  311. this.form.callingCode = "" + data.callingCode
  312. this.form.phone = data.phone
  313. this.form.userPk = data.userPk
  314. if (data.pdvLicencePictures) {
  315. const [front = '', back = ''] = data.pdvLicencePictures
  316. this.form.pdvLicencePictures.front = front
  317. this.form.pdvLicencePictures.back = back
  318. }
  319. }
  320. }
  321. },
  322. handleAvatarSuccessFirst(response) {
  323. this.form.pdvLicencePictures.front = response.data.picturePath
  324. },
  325. handleAvatarSuccessSecond(response) {
  326. this.form.pdvLicencePictures.back = response.data.picturePath
  327. },
  328. beforeAvatarUpload(file) {
  329. const IMAGE_TYPE_ARRAY = ['jpg', 'png', 'jpeg', 'gif']
  330. const fileExt = file.name.replace(/.+\./, '').toLowerCase()
  331. if (IMAGE_TYPE_ARRAY.indexOf(fileExt) === -1) {
  332. const msg = `请选择类型为${IMAGE_TYPE_ARRAY.join('、')}的文件`
  333. this.$message.warning(msg)
  334. return false
  335. }
  336. if (file.size / 1024 / 1024 > 2) {
  337. this.$message.warning('上传文件不能超过2m')
  338. return false
  339. }
  340. },
  341. async getFleetCompanyOptions() {
  342. const {
  343. success,
  344. data
  345. } = await group.getAllUserGroups()
  346. if (success) {
  347. this.options.fleetCompany = data
  348. }
  349. },
  350. async onClickApproveButton() {
  351. const params = { userPk: this.getDriverId() }
  352. this.approveButtonLoading = true
  353. try {
  354. const { success, msg } = await api.approveDriver(params)
  355. if (success) {
  356. this.$notify.success(msg)
  357. this.$router.back()
  358. }
  359. } catch (error) {
  360. this.$notify.error(msg)
  361. }
  362. this.approveButtonLoading = false
  363. },
  364. async onClickRejectButton() {
  365. const params = { userPk: this.getDriverId() }
  366. this.rejectButtonLoading = true
  367. try {
  368. const { success, msg } = await api.rejectDriver(params)
  369. if (success) {
  370. this.$notify.success(msg)
  371. this.$router.back()
  372. }
  373. } catch (error) {
  374. this.$notify.error(msg)
  375. }
  376. this.rejectButtonLoading = false
  377. },
  378. onClickCancelButton() {
  379. this.$nextTick(() => {
  380. this.$router.replace({
  381. path: "/user-management/group"
  382. })
  383. })
  384. },
  385. onClickConfirmButton() {
  386. this.confirmButtonLoading = true
  387. this.$refs.form.validate(async (valid) => {
  388. if (valid) {
  389. try {
  390. const {
  391. pdvLicencePictures: {
  392. front,
  393. back,
  394. },
  395. countryCode,
  396. callingCode,
  397. phone,
  398. ...others
  399. } = this.form
  400. const pdvLicencePictures = []
  401. front && pdvLicencePictures.push(front)
  402. back && pdvLicencePictures.push(back)
  403. let result
  404. if (this.isEdit) {
  405. result = await api.updateDriver({
  406. pdvLicencePictures,
  407. phone,
  408. countryCode,
  409. callingCode,
  410. ...others,
  411. })
  412. } else {
  413. result = await api.addDriver({
  414. pdvLicencePictures,
  415. countryCode,
  416. callingCode,
  417. phone,
  418. ...others,
  419. })
  420. }
  421. if (result.success) {
  422. this.$notify.success(result.msg)
  423. this.onClickCancelButton();
  424. }
  425. } catch (error) {
  426. if (error) {
  427. this.$notify.error(error)
  428. }
  429. }
  430. }
  431. })
  432. this.confirmButtonLoading = false
  433. },
  434. getCountryOptions() {
  435. site.getCountryList().then(({ data }) => {
  436. this.options.countryList = data
  437. })
  438. }
  439. },
  440. async created() {
  441. this.getFleetCompanyOptions()
  442. if (this.isEdit) {
  443. this.getDriverDetail()
  444. }
  445. this.getCountryOptions()
  446. getCountryList(list => {
  447. this.options.callingCode = list
  448. })
  449. },
  450. }
  451. </script>
  452. <style lang='scss' scoped>
  453. @import '../../styles/variables.scss';
  454. .container {
  455. width: 100%;
  456. padding: 20px 50px;
  457. background-color: #F0F5FC;
  458. .content {
  459. border-radius: 6px;
  460. min-height: calc(#{$mainAppMinHeight} - (2 * 20px));
  461. background-color: white;
  462. .form {
  463. padding: 45px 100px;
  464. .pdvl {
  465. ::v-deep .el-form-item__label {
  466. padding: 12px;
  467. line-height: 16px;
  468. }
  469. }
  470. .avatar-uploader {
  471. margin-right: 10px;
  472. .avatar-uploader-icon {
  473. border: 1px dashed #d9d9d9;
  474. border-radius: 6px;
  475. cursor: pointer;
  476. font-size: 28px;
  477. color: #8c939d;
  478. width: 100px;
  479. height: 100px;
  480. line-height: 100px;
  481. text-align: center;
  482. }
  483. }
  484. }
  485. .el-select {
  486. width: 100%;
  487. }
  488. .buttons {
  489. padding: 0 45px;
  490. }
  491. }
  492. }
  493. </style>