AddSimilarName.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <template>
  2. <div>
  3. <crumbs :title="minTitle" linkTo="/admin/LT-YXSJWH-BMWH"></crumbs>
  4. <div class="contents">
  5. <div class="content" @click="close">
  6. <h3>选择标签</h3>
  7. <p :class="['ename',{'name':flag}]">{{name}}</p>
  8. <div v-if="!flag" class="searchBox">
  9. <input type="text" name="" v-model="searchStr" class="name">
  10. <span class="search" @click.stop="search">搜索</span>
  11. <ul v-if="showFlag">
  12. <li v-for="it in searchDatas" :key="it.id" @click="choose(it)" :title="it.tagName.length>10?it.tagName:''">{{it.tagName}}</li>
  13. </ul>
  14. </div>
  15. <span></span>
  16. <h3>添加别名</h3>
  17. <p class="subtitle">本体添加:</p>
  18. <table class="deptbox">
  19. <tr>
  20. <td>本体</td>
  21. <td>拼音</td>
  22. </tr>
  23. <tr v-if="flag" v-for="item in selfName">
  24. <!-- <td class="desc">{{item.retrievalName}}</td>
  25. <td>{{item.retrievalSpell}}</td> -->
  26. <td><input type="text" name="" v-model="item.retrievalName" maxlength="30" @input="handleInput"></td>
  27. <td><input type="text" name="" v-model="item.retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  28. </tr>
  29. <tr v-if="!flag" v-for="(i,index) in selfEmpty">
  30. <td><input type="text" name="" v-model="selfEmpty[index].retrievalName" maxlength="30" @input="handleInput"></td>
  31. <td><input type="text" name="" v-model="selfEmpty[index].retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  32. </tr>
  33. </table>
  34. <p class="subtitle">别名添加:</p>
  35. <table class="deptbox">
  36. <tr>
  37. <td>别名</td>
  38. <td>拼音</td>
  39. </tr>
  40. <tr v-if="retrievalNames.length>0" v-for="it in retrievalNames">
  41. <td><input type="text" name="" v-model="it.retrievalName" maxlength="30" @input="handleInput"></td>
  42. <td><input type="text" name="" v-model="it.retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  43. </tr>
  44. <tr v-for="(i,index) in retrievalEmpty">
  45. <td><input type="text" name="" v-model="retrievalEmpty[index].retrievalName" maxlength="30" @input="handleInput"></td>
  46. <td><input type="text" name="" v-model="retrievalEmpty[index].retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  47. </tr>
  48. <tr @click="addSpan(2)">
  49. <td colspan="2" class="addSpan">+</td>
  50. </tr>
  51. </table>
  52. <p class="subtitle">子项添加:</p>
  53. <table class="deptbox">
  54. <tr>
  55. <td>子项</td>
  56. <td>拼音</td>
  57. </tr>
  58. <tr v-if="retrievalSonNames.length>0" v-for="v in retrievalSonNames">
  59. <td><input type="text" name="" v-model="v.retrievalName" maxlength="30" @input="handleInput"></td>
  60. <td><input type="text" name="" v-model="v.retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  61. </tr>
  62. <tr v-for="(k,index) in sonEmpty">
  63. <td><input type="text" name="" v-model="sonEmpty[index].retrievalName" maxlength="30" @input="handleInput"></td>
  64. <td><input type="text" name="" v-model="sonEmpty[index].retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  65. </tr>
  66. <tr @click="addSpan(3)">
  67. <td colspan="2" class="addSpan">+</td>
  68. </tr>
  69. </table>
  70. <div class="btn">
  71. <el-button
  72. type="primary"
  73. @click="comfirn"
  74. >确 定</el-button>
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script type="text/javascript">
  81. import api from '@api/icss.js';
  82. export default{
  83. name:'AddSimilarName',
  84. data(){
  85. return{
  86. selfName:[], //本体
  87. retrievalNames:[], //别名
  88. retrievalSonNames:[], //子项
  89. id:null,
  90. name:"",
  91. minTitle:"别名维护-添加别名",
  92. toast:'',
  93. flag:false, //添加修改的标识,true-修改
  94. selfEmpty:[ //本体 新增
  95. {
  96. questionName: '',
  97. questionId:'',
  98. retrievalName:'',
  99. retrievalSpell:'',
  100. retrievalType:1
  101. }
  102. ],
  103. retrievalEmpty:[ //别名新增
  104. {
  105. questionName:'',
  106. questionId:'',
  107. retrievalName:'',
  108. retrievalSpell:'',
  109. retrievalType:2
  110. }
  111. ],
  112. sonEmpty:[ //子项新增
  113. {
  114. questionName:'',
  115. questionId:'',
  116. retrievalName:'',
  117. retrievalSpell:'',
  118. retrievalType:3
  119. }
  120. ],
  121. searchDatas:[],
  122. searchStr:'',
  123. showFlag:false
  124. }
  125. },
  126. created(){
  127. const id = this.$route.params.id;
  128. if(id){
  129. this.id = id;
  130. this.name = this.$route.params.name;
  131. this.selfEmpty[0].questionId = this.retrievalEmpty[0].questionId = this.sonEmpty[0].questionId = this.$route.params.id;
  132. this.selfEmpty[0].questionName = this.retrievalEmpty[0].questionName = this.sonEmpty[0].questionName = this.$route.params.name;
  133. this.flag = true;
  134. this.minTitle = "别名维护-修改别名";
  135. this.getDetail();
  136. }
  137. },
  138. methods:{
  139. getDetail(){
  140. const param = {'questionId':this.id,'questionName':this.name}
  141. api.similarNameDetl(param).then((res)=>{
  142. let result = res.data;
  143. if(result.code==0){
  144. const data = result.data;
  145. for(let i in data){
  146. if(i==1){
  147. this.selfName = data[i];
  148. }else if(i==2){
  149. this.retrievalNames = data[i];
  150. }else if(i==3){
  151. this.retrievalSonNames = data[i];
  152. }
  153. }
  154. }else{
  155. console.log(result.msg);
  156. }
  157. })
  158. },
  159. addSpan(type){
  160. let emptySpan = {
  161. questionName:this.name,
  162. questionId:this.id,
  163. retrievalName:'',
  164. retrievalSpell:'',
  165. retrievalType:type
  166. }
  167. if(type == 2){
  168. this.retrievalEmpty.push(emptySpan);
  169. }else if(type == 3){
  170. this.sonEmpty.push(emptySpan);
  171. }
  172. },
  173. comfirn(){
  174. const {selfName,selfEmpty,retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty} = this;
  175. let dataList = [];
  176. if(this.flag){ //修改
  177. dataList = selfName.concat(retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty);
  178. this.toast = "修改成功";
  179. }else{
  180. dataList = selfEmpty.concat(retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty);
  181. this.toast = "添加成功";
  182. }
  183. // 过滤掉空数据
  184. let filterData = dataList.filter((item)=>{
  185. return item.retrievalName;
  186. })
  187. console.log(111,dataList,filterData);
  188. const params = {
  189. 'itemList':filterData,
  190. 'questionId':this.id,
  191. 'questionName':this.name
  192. }
  193. api.addSimilarName(params).then((res)=>{
  194. const result = res.data;
  195. if(result.code==0){
  196. this.$message({
  197. message: this.toast,
  198. type: 'success',
  199. });
  200. this.$router.push({path:'LT-YXSJWH-BMWH'});
  201. }else{
  202. console.log(result.msg);
  203. this.$message.error(result.msg);
  204. }
  205. })
  206. },
  207. search(){
  208. const param = {
  209. 'tagName':this.searchStr,
  210. 'notTagType':[8,10,11]
  211. }
  212. api.searchLable(param).then((res)=>{
  213. const result = res.data;
  214. console.log(123,result);
  215. if(result.code==0){
  216. this.searchDatas = result.data;
  217. if(result.data.length>0){
  218. this.showFlag = true;
  219. }
  220. }else{
  221. console.log(result.msg);
  222. }
  223. })
  224. },
  225. choose(item){
  226. console.log(item);
  227. this.name = item.tagName;
  228. this.id = item.id;
  229. this.showFlag = false;
  230. this.searchStr = "";
  231. },
  232. close(){
  233. this.showFlag = false;
  234. this.searchStr = "";
  235. },
  236. handleInput(e){//名字只能输入中文、英文和数字
  237. e.target.value = e.target.value.replace(/[^0-9a-zA-Z\u4e00-\u9fa5]/g,'');
  238. },
  239. handlePinyin(e){//只能输入英文
  240. e.target.value = e.target.value.replace(/[^a-zA-Z]/g,'');
  241. }
  242. },
  243. watch:{
  244. name:function(newVal,oldVal){
  245. this.selfEmpty[0].questionName = this.retrievalEmpty[0].questionName = this.sonEmpty[0].questionName = newVal;
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="less" scoped>
  251. @import "../../less/admin.less";
  252. .content{
  253. background: #fff;
  254. padding: 20px 20px 30px;
  255. color: #545455;
  256. }
  257. .name{
  258. width: 221px;
  259. height: 30px;
  260. margin:20px 0 30px 0;
  261. padding-left: 7px;
  262. }
  263. .search{
  264. display: inline-block;
  265. width: 56px;
  266. height: 32px;
  267. border-left: 1px solid #ccc;
  268. position: relative;
  269. left: -57px;
  270. vertical-align: middle;
  271. line-height: 32px;
  272. bottom: 2px;
  273. text-align: center;
  274. cursor: default;
  275. }
  276. h3{
  277. font-size: 16px;
  278. }
  279. .subtitle{
  280. // font-size: 12px;
  281. margin: 21px 0 10px 0;
  282. }
  283. .deptbox{
  284. // width: 100%;
  285. background: #fff;
  286. padding: 20px 10px 30px;
  287. font-size: 14px;
  288. text-align: left;
  289. border-collapse: collapse;
  290. >tr{
  291. height: 30px;
  292. td{
  293. width: 111px;
  294. border: 1px solid #666;
  295. padding-left: 7px;
  296. }
  297. input{
  298. border:none;
  299. width: 100%;
  300. }
  301. }
  302. .addSpan{
  303. text-align: center;
  304. cursor: pointer;
  305. }
  306. }
  307. .btn {
  308. text-align: right;
  309. }
  310. .ename{
  311. height: 20px;
  312. margin-top: 10px;
  313. }
  314. .searchBox{
  315. position: relative;
  316. ul{
  317. width: 175px;
  318. position: absolute;
  319. top: 55px;
  320. border:1px solid #ccc;
  321. background: #fff;
  322. max-height: 291px;
  323. overflow-y: scroll;
  324. li{
  325. border:1px solid #fff;
  326. padding-left: 7px;
  327. height: 27px;
  328. line-height: 27px;
  329. overflow: hidden;
  330. white-space: nowrap;
  331. text-overflow: ellipsis;
  332. }
  333. li:hover{
  334. border-color:#22ccc8;
  335. }
  336. }
  337. }
  338. </style>