addCapacity.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. </div>
  28. <div class="button_box">
  29. <el-button @click="cancel">取消</el-button>
  30. <el-button type="primary" @click="makeSure" :loading="addLoading"
  31. >确定</el-button
  32. >
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import PageTitle from "@/components/Page/Title";
  38. import { getCookie } from "@/utils/util.js";
  39. export default {
  40. components: { PageTitle },
  41. data() {
  42. return {
  43. addLoading: false,
  44. form1: {},
  45. form1Initialization: {
  46. capacityTypeId: 1,
  47. capacityNumber: "",
  48. capacityCorlor: "黄",
  49. capacityOwneris: "否",
  50. capacityVip: "否",
  51. capacityBlacklist: "否",
  52. },
  53. value: undefined,
  54. carrierIds: null,
  55. state: null,
  56. userId: null,
  57. restaurants: [],
  58. accessToken: null,
  59. userCode: null,
  60. carrierUserId: null,
  61. carrierId: null,
  62. };
  63. },
  64. created() {
  65. this.carrierUserId = getCookie("userId");
  66. this.form1 = this.form1Initialization;
  67. // console.log(this.carrierUserId, "carrierUserId");
  68. },
  69. mounted() {
  70. this.axios
  71. .post(
  72. "/api/v1/rms/getCarrierNameBySSOId?carrierSSOId=" + this.carrierUserId
  73. )
  74. .then((res) => {
  75. if (res.data.code == "200") {
  76. // console.log(res.data.data);
  77. if (res.data.data) {
  78. this.state = res.data.data.carrierName;
  79. this.carrierIds = res.data.data.carrierId;
  80. }
  81. }
  82. });
  83. },
  84. methods: {
  85. //承运商弹出层
  86. handleSelect(item) {
  87. this.carrierIds = item.carrierId;
  88. item.carrierName = this.state;
  89. },
  90. //以下是承运商边输边查搜索
  91. querySearch(queryString, cb) {
  92. this.axios
  93. .post("/api/v1/uc/getCarrierMesByLike?index=" + queryString)
  94. .then((res) => {
  95. if (res.data.code == "200") {
  96. // console.log(res.data.data);
  97. var restaurants = res.data.data;
  98. // console.log(restaurants, "restaurants");
  99. var results = queryString
  100. ? restaurants.filter(this.createFilter(queryString))
  101. : restaurants;
  102. // 调用 callback 返回建议列表的数据
  103. cb(results);
  104. }
  105. });
  106. },
  107. createFilter(queryString) {
  108. return (restaurants) => {
  109. return (
  110. restaurants.value.toLowerCase().indexOf(queryString.toLowerCase()) >
  111. -1
  112. );
  113. };
  114. },
  115. //以上是承运商边输边查搜索
  116. deleteUser(userId) {
  117. this.axios.delete("pass/v1/sysusers/" + userId).then((res) => {
  118. this.$message.error("添加失败,车牌可能重复");
  119. });
  120. },
  121. insertRole(userId, userCode) {
  122. this.axios
  123. .post(
  124. "pass/v1/sysuserroles/addUserroles?userId=" +
  125. userId +
  126. "&userCode=" +
  127. userCode +
  128. "&roleId=" +
  129. "923693668269953024"
  130. )
  131. .then((res) => {
  132. if (res.code === "0") {
  133. this.$message.success("操作成功");
  134. this.saveLoading = false;
  135. this.rolesTree.loading = false;
  136. } else {
  137. this.$message.error(res.message);
  138. }
  139. });
  140. },
  141. isVehicleNumber(vehicleNumber) {
  142. // console.log(vehicleNumber);
  143. var result = false;
  144. if (vehicleNumber.length == 7) {
  145. var express =
  146. /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使场领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
  147. result = express.test(vehicleNumber);
  148. }
  149. return result;
  150. },
  151. makeSure() {
  152. this.addLoading = true;
  153. // if (!this.isVehicleNumber(this.form1.capacityNumber.toUpperCase())) {
  154. // this.$message.error("车牌号格式不正确");
  155. // this.addLoading = false;
  156. // return;
  157. // }
  158. if (this.carrierIds == null) {
  159. this.$message.error("请选择承运商");
  160. this.addLoading = false;
  161. return;
  162. }
  163. let RmsCapacity = {
  164. capacityTypeId: this.form1.capacityTypeId,
  165. capacityNumber: this.form1.capacityNumber.toUpperCase(),
  166. capacityCorlor: this.form1.capacityCorlor,
  167. capacityOwneris: this.form1.capacityOwneris,
  168. capacityVip: this.form1.capacityVip,
  169. capacityBlacklist: this.form1.capacityBlacklist,
  170. remark: this.form1.remark,
  171. carrierId: this.carrierIds,
  172. state: this.state,
  173. };
  174. console.log(RmsCapacity)
  175. if (
  176. RmsCapacity.capacityNumber == null ||
  177. RmsCapacity.capacityCorlor == null ||
  178. RmsCapacity.capacityOwneris == null ||
  179. RmsCapacity.capacityVip == null ||
  180. RmsCapacity.capacityBlacklist == null
  181. ) {
  182. this.$message.error("存在空值!");
  183. this.addLoading = false;
  184. } else {
  185. //新增SSO运力账号
  186. var formData = new FormData();
  187. formData.append("userCode", this.form1.capacityNumber.toUpperCase());
  188. formData.append("orgCode", "yunli");
  189. formData.append("orgName", "运力");
  190. formData.append("groupId", "506514577756917769");
  191. formData.append("companyId", "713710108567277568");
  192. formData.append("orgId", "924126716337721344");
  193. // console.log(formData.get("userCode"));
  194. // console.log(typeof formData);
  195. this.$store
  196. .dispatch("system/usersManage/addUser", formData)
  197. .then((res) => {
  198. // console.log(res);
  199. if (res.code === "0") {
  200. // console.log(res.data.userId);
  201. this.userId = res.data.userId;
  202. this.userCode = res.data.userCode;
  203. RmsCapacity.ssoId = res.data.userId;
  204. this.axios
  205. .post("/api/v1/rms/insertCapacity", RmsCapacity)
  206. .then((res) => {
  207. if (res.data.data == 1) {
  208. this.insertRole(this.userId, this.userCode);
  209. this.$message.success("添加成功");
  210. this.$router.push("capacity");
  211. } else if (res.data.code == "201") {
  212. this.deleteUser(this.userId);
  213. } else {
  214. this.deleteUser(this.userId);
  215. }
  216. });
  217. } else {
  218. // console.log(RmsCapacity, "RmsCapacity");
  219. if (res.message == "账号已被注册") {
  220. this.$confirm(
  221. "该账号已经被注册, 是否确定新增承运商绑定关系?",
  222. "提示",
  223. {
  224. confirmButtonText: "确定",
  225. cancelButtonText: "取消",
  226. type: "warning",
  227. }
  228. )
  229. .then(() => {
  230. this.axios
  231. .post("/api/v1/rms/insertCapacity", RmsCapacity)
  232. .then((res) => {
  233. // console.log(res, "res");
  234. if (res.data.data == 0) {
  235. this.$message.success("新增承运商绑定关系成功!");
  236. this.$router.push("capacity");
  237. } else {
  238. this.$message.error("该绑定关系已存在!");
  239. }
  240. });
  241. })
  242. .catch(() => {
  243. this.$message({
  244. type: "info",
  245. message: "已取消删除",
  246. });
  247. });
  248. }
  249. }
  250. });
  251. this.addLoading = false;
  252. }
  253. },
  254. // 取消
  255. cancel() {
  256. this.$router.go(-1);
  257. },
  258. },
  259. };
  260. </script>
  261. <style lang='scss' >
  262. .addCapacity {
  263. .elForm {
  264. margin-left: 40%;
  265. }
  266. .form_box {
  267. width: 100%;
  268. margin-top: 30px;
  269. margin-left: 50px;
  270. display: flex;
  271. justify-content: center;
  272. .el-form-item {
  273. display: flex;
  274. justify-content: center;
  275. .el-form-item__label {
  276. display: flex;
  277. align-items: center;
  278. }
  279. .el-form-item__content {
  280. .el-select {
  281. width: 250px;
  282. }
  283. .el-input {
  284. width: 250px;
  285. }
  286. }
  287. }
  288. }
  289. .inputBox {
  290. display: flex;
  291. justify-content: center;
  292. margin-bottom: 30px;
  293. .text {
  294. text-align: right;
  295. display: flex;
  296. align-items: center;
  297. margin-right: 5px;
  298. }
  299. .input {
  300. width: 250px;
  301. }
  302. }
  303. .button_box {
  304. display: flex;
  305. justify-content: center;
  306. .el-button {
  307. width: 80px;
  308. margin-right: 10px;
  309. }
  310. }
  311. }
  312. </style>