addCapacity.vue 12 KB

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