addCapacity.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <!-- 添加运力信息 -->
  3. <div class="addCapacity">
  4. <PageTitle>返回</PageTitle>
  5. <div class="form_box" style=" margin-right: 10rem">
  6. <dil-form :formId="309" v-model="form1" ref="from1"></dil-form>
  7. </div>
  8. <div class="elForm">
  9. <el-form :inline="true" class="demo-form-inline" label-width="80px">
  10. <el-form-item label="选择承运商">
  11. <el-autocomplete
  12. class="inline-input"
  13. v-model="state"
  14. :fetch-suggestions="querySearch"
  15. placeholder="请输入承运商名称"
  16. :trigger-on-focus="false"
  17. @select="handleSelect"
  18. >
  19. <template slot-scope="{ item }">
  20. <div class="name" v-if="item.carrierName">
  21. {{ item.carrierName }}
  22. </div>
  23. </template>
  24. </el-autocomplete>
  25. </el-form-item>
  26. </el-form>
  27. <el-form :inline="true" class="demo-form-inline" label-width="80px">
  28. <el-form-item label="上传行驶证">
  29. <el-upload
  30. class="upload-demo"
  31. ref="upload1"
  32. action="/api/v1/rms/uploadCarrier1"
  33. :before-upload="beforeUpload"
  34. :multiple="false"
  35. list-type="picture"
  36. :show-file-list="false"
  37. :on-success="handleAvatarSuccess"
  38. :on-error="onError(1)"
  39. >
  40. <span class="span"></span>
  41. <el-input
  42. class="shippingCertificate"
  43. placeholder="请选择运输证(必填项)"
  44. v-model="shippingCertificate"
  45. disabled
  46. >
  47. </el-input>
  48. <el-button size="small" type="primary" @click="upCLick(1)"
  49. >点击上传运输证</el-button
  50. >
  51. </el-upload>
  52. </el-form-item>
  53. </el-form>
  54. </div>
  55. <div class="button_box">
  56. <el-button @click="cancel">取消</el-button>
  57. <el-button type="primary" @click="makeSure" :loading="addLoading"
  58. >确定</el-button
  59. >
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import PageTitle from '@/components/Page/Title'
  65. import { getCookie } from '@/utils/util.js'
  66. export default {
  67. components: { PageTitle },
  68. data() {
  69. return {
  70. driverLicence: '',
  71. addLoading: false,
  72. form1: {},
  73. shippingCertificate: '',
  74. form1Initialization: {
  75. capacityTypeId: 1,
  76. capacityNumber: '',
  77. capacityCorlor: '黄',
  78. capacityOwneris: '否',
  79. capacityVip: '否',
  80. capacityBlacklist: '否'
  81. },
  82. value: undefined,
  83. carrierIds: null,
  84. state: null,
  85. userId: null,
  86. restaurants: [],
  87. accessToken: null,
  88. userCode: null,
  89. carrierUserId: null,
  90. carrierId: null,
  91. orgcode: null
  92. }
  93. },
  94. created() {
  95. this.carrierUserId = getCookie('userId')
  96. this.orgcode = getCookie('orgCode')
  97. if (this.orgcode === 'wuliuyunshubu' || this.orgcode === 'dagangadmin') {
  98. }
  99. this.form1 = this.form1Initialization
  100. },
  101. mounted() {
  102. this.axios
  103. .post(
  104. '/api/v1/rms/getCarrierNameBySSOId?carrierSSOId=' + this.carrierUserId
  105. )
  106. .then(res => {
  107. if (res.data.code == '200') {
  108. // console.log(res.data.data);
  109. if (res.data.data) {
  110. this.state = res.data.data.carrierName
  111. this.carrierIds = res.data.data.carrierId
  112. }
  113. }
  114. })
  115. },
  116. methods: {
  117. upCLick(val) {
  118. this.num = val
  119. },
  120. beforeUpload(file) {
  121. this.upBool = true
  122. const isLt2M = file.size < 1024 * 1024 * 0.5
  123. if (!isLt2M) {
  124. this.$message.error('上传文件大小不能超过500kb!')
  125. } else {
  126. let size = file.size / 1024
  127. let _URL = window.URL || window.webkitURL
  128. let img = new Image()
  129. img.src = _URL.createObjectURL(file)
  130. }
  131. return isLt2M
  132. },
  133. onError(err) {
  134. if (this.upBool) {
  135. if (this.num == 1) {
  136. this.shippingCertificate = null
  137. this.imageUrl1 = null
  138. // this.$message.error("上传失败");
  139. } else if (this.num == 2) {
  140. this.businessLicense = null
  141. this.imageUrl2 = null
  142. // this.$message.error("上传失败");
  143. } else if (this.num == 3) {
  144. this.businessLicense1 = null
  145. this.imageUrl3 = null
  146. // this.$message.error("上传失败");
  147. }
  148. }
  149. },
  150. handleAvatarSuccess(res, file) {
  151. console.log(res, file)
  152. if (res.code) {
  153. this.upBool = false
  154. if (this.num == 1) {
  155. this.driverLicence = res.data
  156. this.shippingCertificate = file.name
  157. } else if (this.num == 2) {
  158. this.imageUrl2 = res.data
  159. this.businessLicense = file.name
  160. } else if (this.num == 3) {
  161. this.imageUrl3 = res.data
  162. this.businessLicense1 = file.name
  163. }
  164. this.$message.success('上传成功')
  165. }
  166. },
  167. //承运商弹出层
  168. handleSelect(item) {
  169. this.carrierIds = item.carrierId
  170. item.carrierName = this.state
  171. },
  172. //以下是承运商边输边查搜索
  173. querySearch(queryString, cb) {
  174. this.axios
  175. .post('/api/v1/uc/getCarrierMesByLike?index=' + queryString)
  176. .then(res => {
  177. if (res.data.code == '200') {
  178. // console.log(res.data.data);
  179. var restaurants = res.data.data
  180. // console.log(restaurants, "restaurants");
  181. var results = queryString
  182. ? restaurants.filter(this.createFilter(queryString))
  183. : restaurants
  184. // 调用 callback 返回建议列表的数据
  185. cb(results)
  186. }
  187. })
  188. },
  189. createFilter(queryString) {
  190. return restaurants => {
  191. return (
  192. restaurants.value.toLowerCase().indexOf(queryString.toLowerCase()) >
  193. -1
  194. )
  195. }
  196. },
  197. //以上是承运商边输边查搜索
  198. deleteUser(userId) {
  199. this.axios.delete('pass/v1/sysusers/' + userId).then(res => {
  200. this.$message.error('添加失败,车牌可能重复')
  201. })
  202. },
  203. insertRole(userId, userCode) {
  204. this.axios
  205. .post(
  206. 'pass/v1/sysuserroles/addUserroles?userId=' +
  207. userId +
  208. '&userCode=' +
  209. userCode +
  210. '&roleId=' +
  211. '923693668269953024'
  212. )
  213. .then(res => {
  214. if (res.code === '0') {
  215. this.$message.success('添加成功')
  216. this.$router.push('capacity')
  217. // this.saveLoading = false;
  218. // this.rolesTree.loading = false;
  219. } else {
  220. this.$message.error(res.message)
  221. }
  222. })
  223. },
  224. isVehicleNumber(vehicleNumber) {
  225. // console.log(vehicleNumber);
  226. var result = false
  227. if (vehicleNumber.length == 7) {
  228. var express = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使场领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/
  229. result = express.test(vehicleNumber)
  230. } else if (vehicleNumber.length == 8) {
  231. var express = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}[A-HJ-NP-Z]{1}(([A-HJ-NP-Z0-9]{5})|([0-9]{6}|[A-HJ-NP-Z]{1}[0-9]{5}|[0-9]{5}[A-HJ-NP-Z]{1}|[A-HJ-NP-Z]{2}[0-9]{4}))$/
  232. result = express.test(vehicleNumber)
  233. }
  234. return result
  235. },
  236. makeSure() {
  237. this.addLoading = true
  238. if (!this.isVehicleNumber(this.form1.capacityNumber.toUpperCase())) {
  239. this.$message.error('车牌号格式不正确')
  240. this.addLoading = false
  241. return
  242. }
  243. if (this.carrierIds == null) {
  244. this.$message.error('请选择承运商')
  245. this.addLoading = false
  246. return
  247. }
  248. let RmsCapacity = {
  249. capacityTypeId: this.form1.capacityTypeId,
  250. capacityNumber: this.form1.capacityNumber.toUpperCase(),
  251. capacityCorlor: this.form1.capacityCorlor,
  252. capacityOwneris: this.form1.capacityOwneris,
  253. capacityVip: this.form1.capacityVip,
  254. capacityBlacklist: this.form1.capacityBlacklist,
  255. driverLicence: this.driverLicence,
  256. remark: this.form1.remark,
  257. carrierId: this.carrierIds,
  258. state: this.state,
  259. capacityTel: this.form1.capacityTel
  260. }
  261. console.log(RmsCapacity)
  262. if (
  263. RmsCapacity.capacityNumber == null ||
  264. RmsCapacity.capacityCorlor == null ||
  265. RmsCapacity.capacityOwneris == null ||
  266. RmsCapacity.capacityVip == null ||
  267. RmsCapacity.capacityBlacklist == null
  268. ) {
  269. this.$message.error('存在空值!')
  270. this.addLoading = false
  271. } else {
  272. //新增SSO运力账号
  273. var formData = new FormData()
  274. formData.append('userCode', this.form1.capacityNumber.toUpperCase())
  275. formData.append('orgCode', 'yunli')
  276. formData.append('orgName', '运力')
  277. formData.append('groupId', '506514577756917769')
  278. formData.append('companyId', '713710108567277568')
  279. formData.append('orgId', '924126716337721344')
  280. // console.log(formData.get("userCode"));
  281. // console.log(typeof formData);
  282. this.$store
  283. .dispatch('system/usersManage/addUser', formData)
  284. .then(res => {
  285. // console.log(res);
  286. if (res.code === '0') {
  287. // console.log(res.data.userId);
  288. this.userId = res.data.userId
  289. this.userCode = res.data.userCode
  290. RmsCapacity.ssoId = res.data.userId
  291. this.axios
  292. .post('/api/v1/rms/insertCapacity', RmsCapacity)
  293. .then(res => {
  294. if (res.data.data == 1) {
  295. this.insertRole(this.userId, this.userCode)
  296. } else if (res.data.code == '201') {
  297. this.deleteUser(this.userId)
  298. } else {
  299. this.deleteUser(this.userId)
  300. }
  301. })
  302. } else {
  303. // console.log(RmsCapacity, "RmsCapacity");
  304. if (res.message == '账号已被注册') {
  305. this.$confirm(
  306. '该账号已经被注册, 是否确定新增承运商绑定关系?',
  307. '提示',
  308. {
  309. confirmButtonText: '确定',
  310. cancelButtonText: '取消',
  311. type: 'warning'
  312. }
  313. )
  314. .then(() => {
  315. this.axios
  316. .post('/api/v1/rms/insertCapacity', RmsCapacity)
  317. .then(res => {
  318. // console.log(res, "res");
  319. if (res.data.data == 0) {
  320. this.$message.success('新增承运商绑定关系成功!')
  321. this.$router.push('capacity')
  322. } else {
  323. this.$message.error('该绑定关系已存在!')
  324. }
  325. })
  326. })
  327. .catch(() => {
  328. this.$message({
  329. type: 'info',
  330. message: '已取消删除'
  331. })
  332. })
  333. }
  334. }
  335. })
  336. this.addLoading = false
  337. }
  338. },
  339. // 取消
  340. cancel() {
  341. this.$router.go(-1)
  342. }
  343. }
  344. }
  345. </script>
  346. <style lang="scss">
  347. .shippingCertificate {
  348. width: 200px;
  349. }
  350. .el-form--inline .el-form-item__content {
  351. display: inline-block;
  352. vertical-align: top;
  353. position: relative;
  354. left: 37px;
  355. }
  356. .addCapacity {
  357. .elForm {
  358. margin-left: 40%;
  359. }
  360. .form_box {
  361. width: 100%;
  362. margin-top: 30px;
  363. margin-left: 50px;
  364. display: flex;
  365. justify-content: center;
  366. .el-form-item {
  367. display: flex;
  368. justify-content: center;
  369. .el-form-item__label {
  370. display: flex;
  371. align-items: center;
  372. }
  373. .el-form-item__content {
  374. .el-select {
  375. width: 250px;
  376. }
  377. .el-input {
  378. width: 250px;
  379. }
  380. }
  381. }
  382. }
  383. .inputBox {
  384. display: flex;
  385. justify-content: center;
  386. margin-bottom: 30px;
  387. .text {
  388. text-align: right;
  389. display: flex;
  390. align-items: center;
  391. margin-right: 5px;
  392. }
  393. .input {
  394. width: 250px;
  395. }
  396. }
  397. .button_box {
  398. display: flex;
  399. justify-content: center;
  400. .el-button {
  401. width: 80px;
  402. margin-right: 10px;
  403. }
  404. }
  405. }
  406. </style>