batchAddIndicsDia.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <!-- 批量添加至指标库 -->
  3. <el-dialog
  4. :visible.sync="isOpenDialog"
  5. :close-on-click-modal="false"
  6. :modal-append-to-body="false"
  7. top="5vh"
  8. :title="$t('SteelChemicalPage.batch_add_edb_btn')"
  9. @close="$emit('close')"
  10. custom-class="batch-add-edb-dia"
  11. center
  12. width="70%"
  13. v-dialogDrag
  14. >
  15. <div class="dialog-container">
  16. <div class="select-box">
  17. <cascader
  18. style="display: inline-block"
  19. v-model="searchClassify"
  20. :options="classifyList"
  21. :placeholder="$t('Edb.InputHolderAll.input_classify')"
  22. @changeVal="getEdbList"
  23. :config="{
  24. multiple: true,
  25. emitPath: false,
  26. value: 'BaseFromMysteelChemicalClassifyId',
  27. }"
  28. />
  29. <el-input style="width:240px;" v-model="searchName"
  30. :placeholder="$t('Edb.InputHolderAll.input_name_orid')"
  31. prefix-icon="el-icon-search"
  32. @input="getEdbList"
  33. />
  34. </div>
  35. <div class="select-table">
  36. <el-table :data="edbList" border
  37. :row-class-name="tableRowClassName"
  38. @selection-change="handleSelectionChange"
  39. v-loading="tableLoading">
  40. <el-table-column type="selection" width="55" align="center"></el-table-column>
  41. <el-table-column :label="$t('Edb.Detail.e_id')" align="center" width="120" prop="edbId"></el-table-column>
  42. <el-table-column :label="$t('Table.edb_name')" align="center">
  43. <template slot-scope="{row}">
  44. <el-input v-model="row.edbName" :placeholder="$t('Table.edb_name')"></el-input>
  45. </template>
  46. </el-table-column>
  47. <el-table-column :label="$t('Edb.Detail.e_fre')" align="center" width="140">
  48. <template slot-scope="{row}">
  49. <el-select
  50. v-model="row.frequency"
  51. :placeholder="$t('CustomAnalysisPage.select_frequency')"
  52. clearable>
  53. <el-option
  54. v-for="item in frequencyArr"
  55. :key="item.value"
  56. :label="item.label"
  57. :value="item.value">
  58. </el-option>
  59. </el-select>
  60. </template>
  61. </el-table-column>
  62. <el-table-column :label="$t('Edb.Detail.e_unit')" align="center" width="140">
  63. <template slot-scope="{row}">
  64. <selectUnit v-model="row.unit" />
  65. </template>
  66. </el-table-column>
  67. <!-- 操作 -->
  68. <el-table-column align="center">
  69. <template slot="header" slot-scope="{row}">
  70. <!-- <span>{{$t('EtaBasePage.catalogue_directory')}}</span> -->
  71. <el-radio-group v-model="classifyType" @change="handleClassifyTypeChange">
  72. <el-radio :label="1" style="margin-right:5px"><!-- 分目录 -->{{$t('EtaBasePage.subdirectory_radio')}}</el-radio>
  73. <el-radio :label="2"><!-- 同目录 -->{{$t('EtaBasePage.directory_radio')}}</el-radio>
  74. </el-radio-group>
  75. <cascader
  76. v-if="classifyType === 2"
  77. v-model="selectClassify"
  78. :options="edbClassifyList"
  79. :placeholder="$t('SteelChemicalPage.batch_add_placeholder')"
  80. :config="{ checkStrictly: true, emitPath: false }"
  81. />
  82. </template>
  83. <template slot-scope="{row,$index}">
  84. <cascader
  85. v-model="row.classify"
  86. :options="edbClassifyList"
  87. :placeholder="$t('SteelChemicalPage.batch_add_placeholder')"
  88. cascaderWidth="width:100%;"
  89. :disabled="classifyType === 2"
  90. :config="{ checkStrictly: true, emitPath: false }"
  91. />
  92. </template>
  93. </el-table-column>
  94. <div class="no-data" slot="empty">
  95. <tableNoData :text="$t('Table.prompt_slogan')"/>
  96. </div>
  97. </el-table>
  98. </div>
  99. </div>
  100. <div class="footer-container" slot="footer">
  101. <el-button type="primary" plain @click="$emit('close')">{{ $t('Dialog.cancel_btn') }}</el-button>
  102. <el-button type="primary" @click="handleAddEdb" :loading="btnloading">{{ $t('ManualEdbListPage.add_tobase_btn') }}</el-button>
  103. </div>
  104. <!-- 操作提示弹窗 -->
  105. <el-dialog
  106. :title="$t('BloombergPage.operation_prompt')"
  107. :visible.sync="isHintDiaShow"
  108. :close-on-click-modal="false"
  109. :modal-append-to-body="false"
  110. @close="handleCloseDia"
  111. width="578px"
  112. v-dialogDrag
  113. center>
  114. <div class="hint-dialog-wrap">
  115. <p style="margin-bottom: 20px;">{{ hintText }}</p>
  116. <ul>
  117. <li v-for="(item,index) in hintList" :key="index" class="hint-item" @click="gotoEdbDetail(item)">
  118. {{ index+1 }}、{{ item.IndexName }}({{ item.IndexCode }})
  119. </li>
  120. </ul>
  121. </div>
  122. <div style="text-align: center;margin-bottom: 30px;">
  123. <el-button type="primary" @click="handleCloseDia">{{$t('Dialog.known')}}</el-button>
  124. </div>
  125. </el-dialog>
  126. </el-dialog>
  127. </template>
  128. <script>
  129. import { steelInterface } from "@/api/modules/thirdBaseApi";
  130. import { dataBaseInterface } from '@/api/api.js';
  131. import selectUnit from '@/components/selectUnit.vue';
  132. import { frequencySelectList } from '@/utils/defaultOptions';
  133. export default {
  134. components:{ selectUnit },
  135. props:{
  136. isOpenDialog:{
  137. type:Boolean,
  138. default:false
  139. }
  140. },
  141. watch:{
  142. isOpenDialog(newval){
  143. if(newval){
  144. this.initDia()
  145. }
  146. }
  147. },
  148. data() {
  149. return {
  150. classifyList:[],//钢联化工数据库的目录
  151. searchName:'',
  152. searchClassify:'',
  153. classifyType:1,//1分目录 2同目录
  154. selectClassify:'',
  155. frequencyArr:frequencySelectList(),
  156. edbList:[
  157. /* {
  158. edbId:'123456',
  159. edbName:'指标名称指标名称',
  160. frequency:'日度',
  161. unit:'吨',
  162. classify:'',
  163. isHighlight:false
  164. }, */
  165. ],
  166. tableLoading:false,
  167. edbClassifyList:[],//指标库目录
  168. selectEdbList:[],//勾选的指标
  169. isHintDiaShow:false,
  170. hintList:[],
  171. hintText:'',
  172. btnloading:false,
  173. };
  174. },
  175. methods: {
  176. tableRowClassName({row}){
  177. return row.isHighlight?'highlight-row':''
  178. },
  179. initDia(){
  180. this.getClassifyList()
  181. this.getClassifyOpt()
  182. this.searchClassify = ''
  183. this.searchName = ''
  184. this.edbList = []
  185. this.selectEdbList = []
  186. this.selectClassify=''
  187. this.btnloading=false
  188. },
  189. //获取钢联化工数据库目录
  190. getClassifyList(){
  191. steelInterface.classifyList().then((res) => {
  192. if(res.Ret!==200) return
  193. this.classifyList = res.Data||[]
  194. })
  195. },
  196. filterNodes(arr) {
  197. arr.length &&
  198. arr.forEach((item) => {
  199. item.Children.length && this.filterNodes(item.Children);
  200. if (!item.Children.length) {
  201. delete item.Children;
  202. }
  203. });
  204. },
  205. // 获取指标分类列表
  206. async getClassifyOpt(){
  207. const res=await dataBaseInterface.menuListV3()
  208. if (res.Ret !== 200) return
  209. this.filterNodes(res.Data.AllNodes||[]);
  210. this.edbClassifyList = res.Data.AllNodes || [];
  211. },
  212. //获取对应目录下的钢联化工指标
  213. getEdbList(){
  214. //每一次筛选项改变清空选择框
  215. this.selectEdbList = []
  216. this.classifyType = 1
  217. //tableData
  218. this.tableLoading = true
  219. steelInterface.searchEdbBatch({
  220. BaseFromMysteelChemicalClassifyIds:Array.isArray(this.searchClassify)?this.searchClassify.join(','):'',
  221. Keyword:this.searchName||''
  222. }).then(res=>{
  223. this.tableLoading = false
  224. if(res.Ret!==200) return
  225. this.edbList = res.Data?res.Data.map(item=>{
  226. return {
  227. edbId:item.IndexCode||'',
  228. edbName:item.IndexName||'',
  229. frequency:item.FrequencyName||'',
  230. unit:item.UnitName||'',
  231. classify:'',
  232. isHighlight:false
  233. }
  234. }):[]
  235. })
  236. },
  237. handleSelectionChange(val){
  238. this.selectEdbList = val
  239. },
  240. handleAddEdb(){
  241. //校验所选指标
  242. if(!this.selectEdbList.length){
  243. return this.$message.warning(this.$t('Edb.InputHolderAll.input_select_edb'))
  244. }
  245. if(this.selectEdbList.length>30){
  246. return this.$message.warning(this.$t('SteelChemicalPage.batch_add_max_msg'))
  247. }
  248. //校验所选指标信息是否完整
  249. if(this.classifyType===2&&!this.selectClassify){
  250. return this.$message.warning(this.$t('CustomAnalysisPage.select_appropriate_category'))
  251. }
  252. //重置tableData的高亮
  253. this.edbList.forEach(i=>i.isHighlight=false)
  254. let messageList = [] //有问题的列表
  255. this.selectEdbList.forEach((item)=>{
  256. item.isHighlight=false
  257. if(!this.checkEdbData(item)){
  258. item.isHighlight = true
  259. messageList.push(item)
  260. }
  261. })
  262. //message轻提示 同时标出不完整的行
  263. if(messageList.length){
  264. return this.$message.warning(/* '部分指标信息未填写完整,请检查' */this.$t('SteelChemicalPage.batch_add_hint1'))
  265. }
  266. this.btnloading = true
  267. //添加检测
  268. steelInterface.batchAddEdbCheck({
  269. IndexCodes:this.selectEdbList.map(i=>i.edbId)
  270. }).then(res=>{
  271. if(res.Ret!==200) return (this.btnloading=false)
  272. const edbList = res.Data||[]
  273. const afterAddList = edbList.filter(i=>i.EdbExist===1) //已添加进指标库的指标
  274. const beforeAddList = edbList.filter(i=>i.EdbExist===0) //需要添加进指标库的指标
  275. //已选择的指标均添加进指标库 弹窗提示
  276. if(!beforeAddList.length){
  277. return this.showHintDialog('all',afterAddList)
  278. }
  279. //剩余指标进行重名校验
  280. this.batchNameCheck(afterAddList,beforeAddList)
  281. })
  282. },
  283. //重名检测
  284. batchNameCheck(afterAddList,beforeAddList){
  285. const indexCodeList = beforeAddList.map(i=>i.IndexCode)
  286. let checkList = []
  287. indexCodeList.forEach(i=>{
  288. const item = this.selectEdbList.find(s=>s.edbId===i)
  289. item&&checkList.push(item)
  290. })
  291. steelInterface.batchCheckEdbName(checkList.map(i=>{
  292. return {
  293. EdbCode:i.edbId,
  294. EdbName:i.edbName,
  295. Frequency:i.frequency
  296. }
  297. })).then(res=>{
  298. if(res.Ret!==200) return (this.btnloading=false)
  299. const checkedList = res.Data.filter(i=>i.Exist)
  300. if(checkedList.length){
  301. checkedList.forEach(i=>{
  302. const item = this.selectEdbList.find(s=>s.edbId===i.EdbCode)
  303. item&&(item.isHighlight = true)
  304. })
  305. return this.$message.warning(/* '部分指标名称已存在,请重新填写' */this.$t('SteelChemicalPage.batch_add_hint2'))&&(this.btnloading=false)
  306. }else{
  307. //通过重名校验后添加进指标库
  308. this.batchAddEdb(afterAddList,checkList)
  309. }
  310. })
  311. },
  312. checkEdbData(edbData){
  313. return edbData.edbName&&edbData.frequency&&edbData.unit&&(this.classifyType===1?edbData.classify:true)
  314. },
  315. //显示操作提示弹窗
  316. showHintDialog(type,list){
  317. this.btnloading = false
  318. this.isHintDiaShow = true
  319. this.hintList = list
  320. this.hintText = type==='all'
  321. ?this.$t('YsDataPage.haved_all_msg') //本次添加的指标均已在指标库中,请勿重复添加!
  322. :this.$t('YsDataPage.haved_some_msg') //指标库中已存在以下指标,会自动过滤!
  323. },
  324. //添加进指标库
  325. batchAddEdb(afterAddList=[],checkList){
  326. //checkList
  327. steelInterface.batchAddToLib(checkList.map(i=>{
  328. return {
  329. EdbCode:i.edbId,
  330. EdbName:i.edbName,
  331. Unit:i.unit,
  332. Frequency:i.frequency,
  333. ClassifyId:this.classifyType===1?Number(i.classify):Number(this.selectClassify),
  334. }
  335. })).then(res=>{
  336. if(res.Ret!==200) return (this.btnloading=false)
  337. //若afterAddList有值 弹窗提示部分指标已加入
  338. if(afterAddList.length){
  339. this.showHintDialog('',afterAddList)
  340. }else{
  341. this.$message.success(this.$t('MsgPrompt.add_msg2'))
  342. this.$emit('close')
  343. }
  344. })
  345. },
  346. //跳转至指标库
  347. gotoEdbDetail(data){
  348. const {EdbClassifyId,EdbInfoId,EdbUniqueCode} = data||{}
  349. const href = this.$router.resolve({
  350. path:'/database',
  351. query:{
  352. code:EdbUniqueCode,
  353. id:EdbInfoId,
  354. classifyId:EdbClassifyId,
  355. }
  356. }).href
  357. window.open(href,"_blank")
  358. },
  359. handleCloseDia(){
  360. //两个弹窗都关掉
  361. this.isHintDiaShow=false
  362. this.$emit('close')
  363. }
  364. },
  365. };
  366. </script>
  367. <style lang="scss">
  368. .batch-add-edb-dia{
  369. .dialog-container{
  370. .el-input{
  371. width:100%;
  372. }
  373. .el-table .highlight-row{
  374. background-color:#fef0f0 !important;
  375. }
  376. }
  377. }
  378. </style>
  379. <style scoped lang="scss">
  380. .batch-add-edb-dia{
  381. .dialog-container{
  382. .select-box{
  383. margin-bottom:20px;
  384. }
  385. .select-table{
  386. max-height:600px;
  387. overflow-y:auto;
  388. }
  389. }
  390. .hint-dialog-wrap{
  391. padding-bottom:30px;
  392. .hint-item{
  393. cursor: pointer;
  394. margin-bottom: 10px;
  395. &:hover{
  396. color:#409EFF;
  397. text-decoration: underline;
  398. }
  399. }
  400. }
  401. }
  402. </style>