AddSimilarName.vue 12 KB

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