addOtherCapacity.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. "956144357092757504"
  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. makeSure() {
  142. this.addLoading = true;
  143. // if (!this.isVehicleNumber(this.form1.capacityNumber.toUpperCase())) {
  144. // this.$message.error("车牌号格式不正确");
  145. // this.addLoading = false;
  146. // return;
  147. // }
  148. if (this.form1.capacityNumber.length <= 2) {
  149. this.$message.error("车牌号必须大于三位");
  150. this.addLoading = false;
  151. return;
  152. }
  153. if (this.carrierIds == null) {
  154. this.$message.error("请选择承运商");
  155. this.addLoading = false;
  156. return;
  157. }
  158. let RmsCapacity = {
  159. capacityTypeId: this.form1.capacityTypeId,
  160. capacityNumber: this.form1.capacityNumber.toUpperCase(),
  161. capacityCorlor: this.form1.capacityCorlor,
  162. capacityOwneris: this.form1.capacityOwneris,
  163. capacityVip: this.form1.capacityVip,
  164. capacityBlacklist: this.form1.capacityBlacklist,
  165. remark: this.form1.remark,
  166. carrierId: this.carrierIds,
  167. state: this.state
  168. };
  169. if (
  170. RmsCapacity.capacityNumber == null ||
  171. RmsCapacity.capacityCorlor == null ||
  172. RmsCapacity.capacityOwneris == null ||
  173. RmsCapacity.capacityVip == null ||
  174. RmsCapacity.capacityBlacklist == null
  175. ) {
  176. this.$message.error("存在空值!");
  177. this.addLoading = false;
  178. } else {
  179. //新增SSO运力账号
  180. var formData = new FormData();
  181. formData.append("userCode", this.form1.capacityNumber.toUpperCase());
  182. formData.append("orgCode", "yunli");
  183. formData.append("orgName", "运力");
  184. formData.append("groupId", "506514577756917769");
  185. formData.append("companyId", "713710108567277568");
  186. formData.append("orgId", "924126716337721344");
  187. // console.log(formData.get("userCode"));
  188. // console.log(typeof formData);
  189. this.$store
  190. .dispatch("system/usersManage/addUser", formData)
  191. .then(res => {
  192. // console.log(res);
  193. if (res.code === "0") {
  194. // console.log(res.data.userId);
  195. this.userId = res.data.userId;
  196. this.userCode = res.data.userCode;
  197. RmsCapacity.ssoId = res.data.userId;
  198. this.axios
  199. .post("/api/v1/rms/insertCapacity", RmsCapacity)
  200. .then(res => {
  201. if (res.data.data == 1) {
  202. this.insertRole(this.userId, this.userCode);
  203. this.$message.success("添加成功");
  204. this.$router.push("capacity");
  205. } else if (res.data.code == "201") {
  206. this.deleteUser(this.userId);
  207. } else {
  208. this.deleteUser(this.userId);
  209. }
  210. });
  211. } else {
  212. // console.log(RmsCapacity, "RmsCapacity");
  213. if (res.message == "账号已被注册") {
  214. this.$confirm(
  215. "该账号已经被注册, 是否确定新增承运商绑定关系?",
  216. "提示",
  217. {
  218. confirmButtonText: "确定",
  219. cancelButtonText: "取消",
  220. type: "warning"
  221. }
  222. )
  223. .then(() => {
  224. this.axios
  225. .post("/api/v1/rms/insertCapacity", RmsCapacity)
  226. .then(res => {
  227. // console.log(res, "res");
  228. if (res.data.data == 0) {
  229. this.$message.success("新增承运商绑定关系成功!");
  230. this.$router.push("capacity");
  231. } else {
  232. this.$message.error("该绑定关系已存在!");
  233. }
  234. });
  235. })
  236. .catch(() => {
  237. this.$message({
  238. type: "info",
  239. message: "已取消删除"
  240. });
  241. });
  242. }
  243. }
  244. });
  245. this.addLoading = false;
  246. }
  247. },
  248. // 取消
  249. cancel() {
  250. this.$router.go(-1);
  251. }
  252. }
  253. };
  254. </script>
  255. <style lang="scss">
  256. .addCapacity {
  257. .elForm {
  258. margin-left: 40%;
  259. }
  260. .form_box {
  261. width: 100%;
  262. margin-top: 30px;
  263. margin-left: 50px;
  264. display: flex;
  265. justify-content: center;
  266. .el-form-item {
  267. display: flex;
  268. justify-content: center;
  269. .el-form-item__label {
  270. display: flex;
  271. align-items: center;
  272. }
  273. .el-form-item__content {
  274. .el-select {
  275. width: 250px;
  276. }
  277. .el-input {
  278. width: 250px;
  279. }
  280. }
  281. }
  282. }
  283. .inputBox {
  284. display: flex;
  285. justify-content: center;
  286. margin-bottom: 30px;
  287. .text {
  288. text-align: right;
  289. display: flex;
  290. align-items: center;
  291. margin-right: 5px;
  292. }
  293. .input {
  294. width: 250px;
  295. }
  296. }
  297. .button_box {
  298. display: flex;
  299. justify-content: center;
  300. .el-button {
  301. width: 80px;
  302. margin-right: 10px;
  303. }
  304. }
  305. }
  306. </style>