AddSimilarName.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <div>
  3. <crumbs :title="minTitle" linkTo="SimilarName"></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.typeName+')':''">{{it.tagName+'('+it.typeName+')'}}</li> -->
  13. <li v-for="it in searchDatas" :key="it.id" @click="choose(it)" :title="(it.tagName+'('+typeList[it.type]+')').length>10?it.tagName+'('+typeList[it.type]+')':''">{{it.tagName+'('+typeList[it.type]+')'}}</li>
  14. </ul>
  15. </div>
  16. <span></span>
  17. <h3>添加别名</h3>
  18. <p class="subtitle">本体添加:</p>
  19. <table class="deptbox">
  20. <tr>
  21. <td>本体</td>
  22. <td>拼音</td>
  23. </tr>
  24. <tr v-if="flag" v-for="item in selfName">
  25. <!-- 本体名字不能修改 3-15 与标签名联动可修改 3-28-->
  26. <td>
  27. <input type="text" name="" v-model="item.retrievalName" maxlength="30" @input="handleInput">
  28. <!-- <p>{{item.retrievalName}}</p> -->
  29. </td>
  30. <td>
  31. <input type="text" name="" v-model="item.retrievalSpell" maxlength="30" @input="handlePinyin">
  32. </td>
  33. </tr>
  34. <tr v-if="!flag" v-for="(i,index) in selfEmpty">
  35. <td>
  36. <!-- <input type="text" name="" v-model="selfEmpty[index].retrievalName" maxlength="30" @input="handleInput"> -->
  37. <p>{{i.retrievalName}}</p>
  38. </td>
  39. <td><input type="text" name="" v-model="i.retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  40. </tr>
  41. </table>
  42. <p class="subtitle">别名添加:</p>
  43. <table class="deptbox">
  44. <tr>
  45. <td>别名</td>
  46. <td>拼音</td>
  47. </tr>
  48. <tr v-if="retrievalNames.length>0" v-for="it in retrievalNames">
  49. <td><input type="text" name="" v-model="it.retrievalName" maxlength="30" @input="handleInput"></td>
  50. <td><input type="text" name="" v-model="it.retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  51. </tr>
  52. <tr v-for="(i,index) in retrievalEmpty">
  53. <td><input type="text" name="" v-model="retrievalEmpty[index].retrievalName" maxlength="30" @input="handleInput" @blur="handleBlur(index,2)"></td>
  54. <td><input type="text" name="" v-model="retrievalEmpty[index].retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  55. </tr>
  56. <tr @click="addSpan(2)">
  57. <td colspan="2" class="addSpan">+</td>
  58. </tr>
  59. </table>
  60. <p class="subtitle">子项添加:</p>
  61. <table class="deptbox">
  62. <tr>
  63. <td>子项</td>
  64. <td>拼音</td>
  65. </tr>
  66. <tr v-if="retrievalSonNames.length>0" v-for="v in retrievalSonNames">
  67. <td><input type="text" name="" v-model="v.retrievalName" maxlength="30" @input="handleInput"></td>
  68. <td><input type="text" name="" v-model="v.retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  69. </tr>
  70. <tr v-for="(k,index) in sonEmpty">
  71. <td><input type="text" name="" v-model="sonEmpty[index].retrievalName" maxlength="30" @input="handleInput" @blur="handleBlur(index,3)"></td>
  72. <td><input type="text" name="" v-model="sonEmpty[index].retrievalSpell" maxlength="30" @input="handlePinyin"></td>
  73. </tr>
  74. <tr @click="addSpan(3)">
  75. <td colspan="2" class="addSpan">+</td>
  76. </tr>
  77. </table>
  78. <div class="btn">
  79. <el-button
  80. type="primary"
  81. @click="comfirn"
  82. >确 定</el-button>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. </template>
  88. <script type="text/javascript">
  89. import api from '@api/icss.js';
  90. import pinyin from '../../js/Convert_Pinyin.js'
  91. export default{
  92. name:'AddSimilarName',
  93. data(){
  94. return{
  95. selfName:[], //本体
  96. retrievalNames:[], //别名
  97. retrievalSonNames:[], //子项
  98. id:null,
  99. name:"",
  100. minTitle:"别名维护-添加别名",
  101. toast:'',
  102. flag:false, //添加修改的标识,true-修改
  103. selfEmpty:[ //本体 新增
  104. {
  105. questionName: '',
  106. questionId:'',
  107. retrievalName:'',
  108. retrievalSpell:'',
  109. retrievalType:1
  110. }
  111. ],
  112. retrievalEmpty:[ //别名新增
  113. {
  114. questionName:'',
  115. questionId:'',
  116. retrievalName:'',
  117. retrievalSpell:'',
  118. retrievalType:2
  119. }
  120. ],
  121. sonEmpty:[ //子项新增
  122. {
  123. questionName:'',
  124. questionId:'',
  125. retrievalName:'',
  126. retrievalSpell:'',
  127. retrievalType:3
  128. }
  129. ],
  130. searchDatas:[],
  131. searchStr:'',
  132. showFlag:false,
  133. typeList:[]
  134. }
  135. },
  136. created(){
  137. const id = this.$route.params.id;
  138. // const optionList = this.$route.params.optionList;//归属类型
  139. this.getOptions();//获取归属类型,其他页面也会跳转至此
  140. if(id){
  141. this.id = id;
  142. this.name = this.$route.params.name;
  143. this.selfEmpty[0].questionId = this.retrievalEmpty[0].questionId = this.sonEmpty[0].questionId = this.$route.params.id;
  144. this.selfEmpty[0].questionName = this.retrievalEmpty[0].questionName = this.sonEmpty[0].questionName = this.$route.params.name;
  145. this.flag = true;
  146. this.minTitle = "别名维护-修改别名";
  147. this.getDetail();
  148. }
  149. /*if(optionList.length>0){
  150. for(let i=0; i<optionList.length; i++){
  151. this.typeList[+optionList[i].val] = optionList[i].name;
  152. }
  153. }*/
  154. },
  155. methods:{
  156. getOptions(){//归属枚举
  157. api.getDropList().then((res)=>{
  158. const list = res.data;
  159. if(list.code==0){
  160. // this.optionList = list.data[1];
  161. const optionList = list.data[1];
  162. if(optionList.length>0){
  163. for(let i=0; i<optionList.length; i++){
  164. this.typeList[+optionList[i].val] = optionList[i].name;
  165. }
  166. }
  167. }else{
  168. this.$message({
  169. message:list.msg || '获取归属类型失败',
  170. type:'warning'
  171. });
  172. }
  173. })
  174. },
  175. getDetail(){
  176. const param = {'questionId':this.id,'questionName':this.name}
  177. api.similarNameDetl(param).then((res)=>{
  178. let result = res.data;
  179. if(result.code==0){
  180. const data = result.data;
  181. for(let i in data){
  182. if(i==1){
  183. this.selfName = data[i];
  184. }else if(i==2){
  185. this.retrievalNames = data[i];
  186. }else if(i==3){
  187. this.retrievalSonNames = data[i];
  188. }
  189. }
  190. }else{
  191. this.$message({
  192. message:result.msg,
  193. type:'warning'
  194. });
  195. }
  196. })
  197. },
  198. addSpan(type){
  199. let emptySpan = {
  200. questionName:this.name,
  201. questionId:this.id,
  202. retrievalName:'',
  203. retrievalSpell:'',
  204. retrievalType:type
  205. }
  206. if(type == 2){
  207. this.retrievalEmpty.push(emptySpan);
  208. }else if(type == 3){
  209. this.sonEmpty.push(emptySpan);
  210. }
  211. },
  212. comfirn(){
  213. const {selfName,selfEmpty,retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty} = this;
  214. let dataList = [];
  215. if(this.flag){ //修改
  216. if(!selfName[0].retrievalSpell){
  217. this.$message({
  218. message:"本体拼音不能为空",
  219. type:'warning'
  220. });
  221. return
  222. }
  223. dataList = selfName.concat(retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty);
  224. this.toast = "修改成功";
  225. }else{
  226. if(!selfEmpty[0].retrievalSpell){
  227. this.$message({
  228. message:"本体拼音不能为空",
  229. type:'warning'
  230. });
  231. return
  232. }
  233. dataList = selfEmpty.concat(retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty);
  234. this.toast = "添加成功";
  235. }
  236. // 过滤掉空数据
  237. let filterData = dataList.filter((item)=>{
  238. return item.retrievalName||item.retrievalSpell;
  239. })
  240. let emptyData = filterData.filter((item)=>{
  241. return !item.retrievalName|| !item.retrievalSpell;
  242. })
  243. if(emptyData&&emptyData.length>0){//判断是否有未填项
  244. this.$message({
  245. message:'标签名和拼音不能为空',
  246. type:'warning'
  247. });
  248. return
  249. }
  250. const params = {
  251. 'itemList':filterData,
  252. 'questionId':this.id,
  253. 'questionName':this.name
  254. }
  255. api.addSimilarName(params).then((res)=>{
  256. const result = res.data;
  257. if(result.code==0){
  258. this.$message({
  259. message: this.toast,
  260. type: 'success',
  261. });
  262. this.$router.push({path:'LT-YXSJWH-BMWH'});
  263. }else{
  264. this.$message({
  265. message:result.msg,
  266. type:'warning'
  267. });
  268. }
  269. })
  270. },
  271. search(){
  272. const param = {
  273. 'tagName':this.searchStr,
  274. 'notTagType':[8,10,11],
  275. 'notControlType':[99]
  276. }
  277. api.searchLable(param).then((res)=>{
  278. const result = res.data;
  279. if(result.code==0){
  280. this.searchDatas = result.data;
  281. if(result.data&&result.data.length>0){
  282. this.showFlag = true;
  283. }
  284. }else{
  285. // console.log(result.msg);
  286. this.$message({
  287. message:result.msg,
  288. type:'warning'
  289. });
  290. }
  291. })
  292. },
  293. choose(item){
  294. // console.log(item);
  295. this.name = item.tagName;
  296. this.id = item.id;
  297. this.showFlag = false;
  298. this.searchStr = "";
  299. this.selfEmpty[0].retrievalName = this.name;
  300. this.selfEmpty[0].retrievalSpell = pinyin.getCamelChars(this.name);
  301. // console.log("标签拼音:",pinyin.getCamelChars(this.name));
  302. },
  303. close(){
  304. this.showFlag = false;
  305. // this.searchStr = "";
  306. },
  307. handleInput(e){//名字只能输入中文、英文和数字
  308. e.target.value = e.target.value.replace(/[^0-9a-zA-Z\u4e00-\u9fa5]/g,'');
  309. },
  310. handlePinyin(e){//只能输入英文
  311. e.target.value = e.target.value.replace(/[^a-zA-Z]/g,'');
  312. },
  313. handleBlur(index,flag){
  314. if(flag==2){//别名
  315. let current = this.retrievalEmpty[index];
  316. current.retrievalSpell = pinyin.getCamelChars(current.retrievalName);
  317. }else if(flag==3){//子项
  318. let sonCurrent = this.sonEmpty[index];
  319. sonCurrent.retrievalSpell = pinyin.getCamelChars(sonCurrent.retrievalName);
  320. }
  321. }
  322. },
  323. watch:{
  324. name:function(newVal,oldVal){
  325. this.selfEmpty[0].questionName = this.retrievalEmpty[0].questionName = this.sonEmpty[0].questionName = newVal;
  326. }
  327. }
  328. }
  329. </script>
  330. <style lang="less" scoped>
  331. @import "../../less/admin.less";
  332. .content{
  333. background: #fff;
  334. padding: 20px 20px 30px;
  335. color: #545455;
  336. }
  337. .name{
  338. width: 221px;
  339. height: 30px;
  340. margin:20px 0 30px 0;
  341. padding-left: 7px;
  342. }
  343. .search{
  344. display: inline-block;
  345. width: 55px;
  346. height: 32px;
  347. border-left: 1px solid #ccc;
  348. position: relative;
  349. left: -57px;
  350. vertical-align: middle;
  351. line-height: 32px;
  352. bottom: 1px;
  353. text-align: center;
  354. cursor: default;
  355. background: #fff;
  356. }
  357. h3{
  358. font-size: 16px;
  359. }
  360. .subtitle{
  361. // font-size: 12px;
  362. margin: 21px 0 10px 0;
  363. }
  364. .deptbox{
  365. // width: 100%;
  366. background: #fff;
  367. padding: 20px 10px 30px;
  368. font-size: 14px;
  369. text-align: left;
  370. border-collapse: collapse;
  371. >tr{
  372. height: 30px;
  373. td{
  374. width: 111px;
  375. border: 1px solid #666;
  376. padding-left: 7px;
  377. }
  378. input{
  379. border:none;
  380. width: 100%;
  381. }
  382. }
  383. .addSpan{
  384. text-align: center;
  385. cursor: pointer;
  386. }
  387. }
  388. .btn {
  389. text-align: right;
  390. }
  391. .ename{
  392. height: 20px;
  393. margin-top: 10px;
  394. }
  395. .searchBox{
  396. position: relative;
  397. ul{
  398. width: 175px;
  399. position: absolute;
  400. top: 55px;
  401. border:1px solid #ccc;
  402. background: #fff;
  403. max-height: 291px;
  404. overflow-y: auto;
  405. li{
  406. border:1px solid #fff;
  407. padding-left: 7px;
  408. height: 27px;
  409. line-height: 27px;
  410. overflow: hidden;
  411. white-space: nowrap;
  412. text-overflow: ellipsis;
  413. }
  414. li:hover{
  415. background: #f5f7fa;
  416. }
  417. }
  418. }
  419. </style>