AddSimilarName.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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.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. if(id){
  140. this.id = id;
  141. this.name = this.$route.params.name;
  142. this.selfEmpty[0].questionId = this.retrievalEmpty[0].questionId = this.sonEmpty[0].questionId = this.$route.params.id;
  143. this.selfEmpty[0].questionName = this.retrievalEmpty[0].questionName = this.sonEmpty[0].questionName = this.$route.params.name;
  144. this.flag = true;
  145. this.minTitle = "别名维护-修改别名";
  146. this.getDetail();
  147. }
  148. if(optionList.length>0){
  149. for(let i=0; i<optionList.length; i++){
  150. this.typeList[+optionList[i].val] = optionList[i].name;
  151. }
  152. }
  153. },
  154. methods:{
  155. getDetail(){
  156. const param = {'questionId':this.id,'questionName':this.name}
  157. api.similarNameDetl(param).then((res)=>{
  158. let result = res.data;
  159. if(result.code==0){
  160. const data = result.data;
  161. for(let i in data){
  162. if(i==1){
  163. this.selfName = data[i];
  164. }else if(i==2){
  165. this.retrievalNames = data[i];
  166. }else if(i==3){
  167. this.retrievalSonNames = data[i];
  168. }
  169. }
  170. }else{
  171. this.$message({
  172. message:result.msg,
  173. type:'warning'
  174. });
  175. }
  176. })
  177. },
  178. addSpan(type){
  179. let emptySpan = {
  180. questionName:this.name,
  181. questionId:this.id,
  182. retrievalName:'',
  183. retrievalSpell:'',
  184. retrievalType:type
  185. }
  186. if(type == 2){
  187. this.retrievalEmpty.push(emptySpan);
  188. }else if(type == 3){
  189. this.sonEmpty.push(emptySpan);
  190. }
  191. },
  192. comfirn(){
  193. const {selfName,selfEmpty,retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty} = this;
  194. let dataList = [];
  195. if(this.flag){ //修改
  196. if(!selfName[0].retrievalSpell){
  197. this.$message({
  198. message:"本体拼音不能为空",
  199. type:'warning'
  200. });
  201. return
  202. }
  203. dataList = selfName.concat(retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty);
  204. this.toast = "修改成功";
  205. }else{
  206. if(!selfEmpty[0].retrievalSpell){
  207. this.$message({
  208. message:"本体拼音不能为空",
  209. type:'warning'
  210. });
  211. return
  212. }
  213. dataList = selfEmpty.concat(retrievalNames,retrievalEmpty,retrievalSonNames,sonEmpty);
  214. this.toast = "添加成功";
  215. }
  216. // 过滤掉空数据
  217. let filterData = dataList.filter((item)=>{
  218. return item.retrievalName||item.retrievalSpell;
  219. })
  220. let emptyData = filterData.filter((item)=>{
  221. return !item.retrievalName|| !item.retrievalSpell;
  222. })
  223. if(emptyData&&emptyData.length>0){//判断是否有未填项
  224. this.$message({
  225. message:'标签名和拼音不能为空',
  226. type:'warning'
  227. });
  228. return
  229. }
  230. const params = {
  231. 'itemList':filterData,
  232. 'questionId':this.id,
  233. 'questionName':this.name
  234. }
  235. api.addSimilarName(params).then((res)=>{
  236. const result = res.data;
  237. if(result.code==0){
  238. this.$message({
  239. message: this.toast,
  240. type: 'success',
  241. });
  242. this.$router.push({path:'LT-YXSJWH-BMWH'});
  243. }else{
  244. this.$message({
  245. message:result.msg,
  246. type:'warning'
  247. });
  248. }
  249. })
  250. },
  251. search(){
  252. const param = {
  253. 'tagName':this.searchStr,
  254. 'notTagType':[8,10,11],
  255. 'notControlType':[99]
  256. }
  257. api.searchLable(param).then((res)=>{
  258. const result = res.data;
  259. if(result.code==0){
  260. this.searchDatas = result.data;
  261. if(result.data&&result.data.length>0){
  262. this.showFlag = true;
  263. }
  264. }else{
  265. // console.log(result.msg);
  266. this.$message({
  267. message:result.msg,
  268. type:'warning'
  269. });
  270. }
  271. })
  272. },
  273. choose(item){
  274. console.log(item);
  275. this.name = item.tagName;
  276. this.id = item.id;
  277. this.showFlag = false;
  278. this.searchStr = "";
  279. this.selfEmpty[0].retrievalName = this.name;
  280. this.selfEmpty[0].retrievalSpell = pinyin.getCamelChars(this.name);
  281. // console.log("标签拼音:",pinyin.getCamelChars(this.name));
  282. },
  283. close(){
  284. this.showFlag = false;
  285. // this.searchStr = "";
  286. },
  287. handleInput(e){//名字只能输入中文、英文和数字
  288. e.target.value = e.target.value.replace(/[^0-9a-zA-Z\u4e00-\u9fa5]/g,'');
  289. },
  290. handlePinyin(e){//只能输入英文
  291. e.target.value = e.target.value.replace(/[^a-zA-Z]/g,'');
  292. },
  293. handleBlur(index,flag){
  294. if(flag==2){//别名
  295. let current = this.retrievalEmpty[index];
  296. current.retrievalSpell = pinyin.getCamelChars(current.retrievalName);
  297. }else if(flag==3){//子项
  298. let sonCurrent = this.sonEmpty[index];
  299. sonCurrent.retrievalSpell = pinyin.getCamelChars(sonCurrent.retrievalName);
  300. }
  301. }
  302. },
  303. watch:{
  304. name:function(newVal,oldVal){
  305. this.selfEmpty[0].questionName = this.retrievalEmpty[0].questionName = this.sonEmpty[0].questionName = newVal;
  306. }
  307. }
  308. }
  309. </script>
  310. <style lang="less" scoped>
  311. @import "../../less/admin.less";
  312. .content{
  313. background: #fff;
  314. padding: 20px 20px 30px;
  315. color: #545455;
  316. }
  317. .name{
  318. width: 221px;
  319. height: 30px;
  320. margin:20px 0 30px 0;
  321. padding-left: 7px;
  322. }
  323. .search{
  324. display: inline-block;
  325. width: 55px;
  326. height: 32px;
  327. border-left: 1px solid #ccc;
  328. position: relative;
  329. left: -57px;
  330. vertical-align: middle;
  331. line-height: 32px;
  332. bottom: 1px;
  333. text-align: center;
  334. cursor: default;
  335. background: #fff;
  336. }
  337. h3{
  338. font-size: 16px;
  339. }
  340. .subtitle{
  341. // font-size: 12px;
  342. margin: 21px 0 10px 0;
  343. }
  344. .deptbox{
  345. // width: 100%;
  346. background: #fff;
  347. padding: 20px 10px 30px;
  348. font-size: 14px;
  349. text-align: left;
  350. border-collapse: collapse;
  351. >tr{
  352. height: 30px;
  353. td{
  354. width: 111px;
  355. border: 1px solid #666;
  356. padding-left: 7px;
  357. }
  358. input{
  359. border:none;
  360. width: 100%;
  361. }
  362. }
  363. .addSpan{
  364. text-align: center;
  365. cursor: pointer;
  366. }
  367. }
  368. .btn {
  369. text-align: right;
  370. }
  371. .ename{
  372. height: 20px;
  373. margin-top: 10px;
  374. }
  375. .searchBox{
  376. position: relative;
  377. ul{
  378. width: 175px;
  379. position: absolute;
  380. top: 55px;
  381. border:1px solid #ccc;
  382. background: #fff;
  383. max-height: 291px;
  384. overflow-y: auto;
  385. li{
  386. border:1px solid #fff;
  387. padding-left: 7px;
  388. height: 27px;
  389. line-height: 27px;
  390. overflow: hidden;
  391. white-space: nowrap;
  392. text-overflow: ellipsis;
  393. }
  394. li:hover{
  395. background: #f5f7fa;
  396. }
  397. }
  398. }
  399. </style>