transitRouteAdd.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. // 新增运输路线
  2. <template>
  3. <div class="transitRouteAdd">
  4. <page-title>新增</page-title>
  5. <div class="form_top">
  6. <div class="link_name" v-if="state > 0">
  7. <span>线路编号:</span>
  8. <el-input placeholder="请输入内容" v-model="lineNo" disabled>
  9. </el-input>
  10. </div>
  11. <div class="link_name">
  12. <span>线路名称:</span>
  13. <el-input placeholder="请输入内容" v-model="line_name" clearable>
  14. </el-input>
  15. </div>
  16. <div class="link_type">
  17. <span>线路类型:</span>
  18. <el-select v-model="value" placeholder="请选择">
  19. <el-option
  20. v-for="item in options"
  21. :key="item.value"
  22. :label="item.label"
  23. :value="item.value"
  24. >
  25. </el-option>
  26. </el-select>
  27. </div>
  28. <div class="spellNumber">
  29. <span class="text">拼数:</span>
  30. <el-input placeholder="请输入内容" v-model="spellNumber" clearable>
  31. </el-input>
  32. </div>
  33. <div class="link_zi_list">
  34. <span>环节:</span>
  35. <el-tag
  36. :key="index"
  37. v-for="(item,index) in btnList"
  38. :disable-transitions="false"
  39. @click="addClick(item)"
  40. class="link_zi_list_btn"
  41. >
  42. {{item.linkName}}
  43. </el-tag>
  44. <el-input
  45. class="input-new-tag"
  46. v-if="inputVisible"
  47. v-model="inputValue"
  48. ref="saveTagInput"
  49. size="small"
  50. @blur="onBlur"
  51. >
  52. </el-input>
  53. <el-button v-else class="button-new-tag" size="small" @click="showInput"> + 新增</el-button>
  54. </div>
  55. </div>
  56. <div class="linkList">
  57. <div class="link_list" id="tag">
  58. <el-tag
  59. class="tag"
  60. size="small"
  61. v-for="(item, i) in linkList"
  62. :key="i"
  63. @close="deleteClick(i)"
  64. closable
  65. >
  66. {{ item.linkName }}
  67. </el-tag>
  68. </div>
  69. </div>
  70. <div class="btn">
  71. <el-button class="cancel" @click="cancelClick">取消</el-button>
  72. <el-button class="confirm" type="primary" @click="confirmClick"
  73. >确认</el-button
  74. >
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import PageTitle from "@/components/Page/Title";
  80. import Sortable from "sortablejs";
  81. export default {
  82. components: { PageTitle },
  83. data() {
  84. return {
  85. inputVisible:false,
  86. inputValue: '',
  87. lineNo: "",
  88. line_name: "",
  89. spellNumber: 1,
  90. options: [
  91. {
  92. value: "1",
  93. label: "内转",
  94. },
  95. {
  96. value: "2",
  97. label: "销售",
  98. },
  99. {
  100. value: "3",
  101. label: "采购",
  102. },
  103. {
  104. value: "4",
  105. label: "退货",
  106. },
  107. ],
  108. value: "",
  109. btnList: [],
  110. linkList: [],
  111. state: 0,
  112. };
  113. },
  114. created() {
  115. this.initialization();
  116. },
  117. mounted() {
  118. this.drag();
  119. },
  120. methods: {
  121. A(){
  122. // 获取所有的作业环节
  123. this.axios.post("/api/v1/rms/getLink").then((res) => {
  124. if (res.data.code == "200") {
  125. this.btnList = res.data.data;
  126. }
  127. });
  128. },
  129. //将新增变为输入框
  130. showInput() {
  131. this.inputVisible = true;
  132. },
  133. //当输入框失去焦点之后触发,新增作业环节
  134. onBlur() {
  135. console.log(this.inputValue);
  136. if (this.inputValue) {
  137. this.axios.post('/api/v1/rms/LinkInsertSelective',
  138. {
  139. linkName:this.inputValue,
  140. userName:""
  141. }).then((res)=>{
  142. if(res.data.code == "200"){
  143. this.A();
  144. }
  145. })
  146. }
  147. this.inputVisible = false;
  148. this.inputValue = '';
  149. },
  150. // 初始化页面的数据
  151. initialization() {
  152. this.state = this.$route.params.addup;
  153. // 获取所有的作业环节
  154. this.A();
  155. if (this.state == 0) {
  156. console.log("新增");
  157. } else {
  158. this.axios
  159. .post("/api/v1/rms/getLinkToUpdate?lineId=" + this.state)
  160. .then((res) => {
  161. if (res.data.code == "200") {
  162. this.lineNo = res.data.data.lineNo;
  163. this.line_name = res.data.data.lineName;
  164. this.options.forEach((e) => {
  165. if (e.value == res.data.data.lineType) {
  166. this.value = e.value;
  167. }
  168. });
  169. this.linkList = res.data.data.mapList;
  170. }
  171. });
  172. console.log("修改");
  173. }
  174. },
  175. // 将点击的对象添加到linkList的数组中
  176. addClick(item) {
  177. this.linkList.push(item);
  178. },
  179. // 删除被点击的对象
  180. deleteClick(index) {
  181. this.linkList.splice(index, 1);
  182. },
  183. // 点击取消按钮
  184. cancelClick() {
  185. // 若linkList数组有数据,则提示用户数据将会清空,若没有,则直接退出
  186. if (this.linkList.length > 0) {
  187. this.$confirm("离开此页面,修改的数据不会保存, 是否继续?", "提示", {
  188. confirmButtonText: "确定",
  189. cancelButtonText: "取消",
  190. type: "warning",
  191. })
  192. .then(() => {
  193. this.$router.go(-1);
  194. })
  195. .catch(() => {});
  196. } else {
  197. this.$router.go(-1);
  198. }
  199. },
  200. // 点击确定按钮
  201. confirmClick() {
  202. // 判断是否存在空值
  203. if (this.line_name && this.value && this.linkList.length > 0) {
  204. var map = {
  205. spellNumber: parseInt(this.spellNumber),
  206. lineId: parseInt(this.state),
  207. line_name: this.line_name,
  208. line_type: parseInt(this.value),
  209. linkList: this.linkList,
  210. };
  211. var URL = "";
  212. var messageText = "";
  213. // 若上一个页面传递的值为0则新增
  214. if (this.state == 0) {
  215. URL = "/api/v1/rms/insertSelective";
  216. messageText = "新增成功!";
  217. } else if (this.state > 0) {
  218. // 若上一个页面传递的值大于0,则更新
  219. URL = "/api/v1/rms/updateByPrimaryKeySelective";
  220. messageText = "修改成功!";
  221. }
  222. this.axios.post(URL, map).then((res) => {
  223. if ((res.data.code = "200")) {
  224. this.$message({
  225. showClose: true,
  226. message: messageText,
  227. type: "success",
  228. });
  229. this.$router.go(-1);
  230. }
  231. });
  232. } else {
  233. this.$message({
  234. showClose: true,
  235. message: "不能存在空值",
  236. type: "warning",
  237. });
  238. }
  239. },
  240. //拖动事件
  241. drag() {
  242. var _this = this;
  243. var $ul = document.getElementById("tag");
  244. new Sortable($ul, {
  245. onUpdate: function (event) {
  246. //修改items数据顺序
  247. var newIndex = event.newIndex,
  248. oldIndex = event.oldIndex,
  249. $li = $ul.children[newIndex],
  250. $oldLi = $ul.children[oldIndex];
  251. // 先删除移动的节点
  252. $ul.removeChild($li);
  253. // 再插入移动的节点到原有节点,还原了移动的操作
  254. if (newIndex > oldIndex) {
  255. $ul.insertBefore($li, $oldLi);
  256. } else {
  257. $ul.insertBefore($li, $oldLi.nextSibling);
  258. }
  259. // 更新items数组
  260. var item = _this.linkList.splice(oldIndex, 1);
  261. _this.linkList.splice(newIndex, 0, item[0]);
  262. },
  263. animation: 150,
  264. });
  265. },
  266. },
  267. };
  268. </script>
  269. <style lang="scss" scoped>
  270. .transitRouteAdd {
  271. .form_top {
  272. width: 100%;
  273. height: 10.625rem;
  274. .link_name {
  275. display: flex;
  276. align-items: center;
  277. justify-content: center;
  278. margin-top: 1.25rem;
  279. }
  280. .link_type {
  281. display: flex;
  282. align-items: center;
  283. justify-content: center;
  284. margin-top: 1.25rem;
  285. }
  286. .spellNumber {
  287. display: flex;
  288. align-items: center;
  289. justify-content: center;
  290. margin-top: 1.25rem;
  291. .text {
  292. width: 80px;
  293. text-align: right;
  294. }
  295. }
  296. .link_zi_list {
  297. display: flex;
  298. align-items: center;
  299. justify-content: center;
  300. margin-top: 1.25rem;
  301. .link_zi_list_btn{
  302. width: 3.125rem; height: 2rem;
  303. display: flex;
  304. align-items: center;
  305. justify-content: center;
  306. margin-right: 0.625rem;
  307. }
  308. .input-new-tag {
  309. width: 4.375rem;
  310. margin-left: 0.625rem;
  311. vertical-align: bottom;
  312. }
  313. }
  314. }
  315. .linkList {
  316. margin-top: 5.625rem;
  317. display: flex;
  318. justify-content: center;
  319. .link_list {
  320. border: #8d8c8c 0.0625rem solid;
  321. width: 80%;
  322. height: 12.5rem;
  323. display: flex;
  324. flex-wrap: wrap;
  325. justify-content: flex-start;
  326. overflow: hidden;
  327. padding: 0.625rem;
  328. .tag {
  329. margin: 0.3125rem;
  330. }
  331. }
  332. }
  333. .btn {
  334. display: flex;
  335. width: 100%;
  336. justify-content: center;
  337. margin-top: 20px;
  338. }
  339. }
  340. </style>