batchAddEdbDia.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <template>
  2. <el-dialog
  3. :visible.sync="isOpenDialog"
  4. :close-on-click-modal="false"
  5. :modal-append-to-body="false"
  6. top="5vh"
  7. title="添加指标"
  8. @close="cancelHandle"
  9. custom-class="dialog"
  10. center
  11. width="780px"
  12. v-dialogDrag
  13. >
  14. <div
  15. v-loading="isAddLoading"
  16. element-loading-text="加载时间大概五分钟,关闭弹窗不影响加载"
  17. element-loading-spinner="el-icon-loading">
  18. <div class="dialog-main">
  19. <el-row :gutter="10" class="row" style="margin-bottom: 15px;">
  20. <el-col style="width: 250px;" class="col title-col">指标ID</el-col>
  21. <el-col style="width: 382px;" class="col title-col">所属分类</el-col>
  22. </el-row>
  23. <el-form :model="edbForm" ref="edbFormDataListRef" >
  24. <div class="form-box" ref="formBoxRef">
  25. <el-row v-for="(item,index) in edbForm.edbDataList" :key="item.edbIndex" :gutter="10" class="row">
  26. <el-col class="col edb-col">
  27. <el-form-item :prop="`edbDataList.${index}.IndexCode`"
  28. :rules="[{required:true,message:'指标ID不能为空',trigger:'blur'},
  29. {validator:checkAge,trigger:'blur'}]">
  30. <el-input v-model.trim="item.IndexCode" placeholder="请输入指标ID"></el-input>
  31. </el-form-item>
  32. </el-col>
  33. <el-col class="col classify-col">
  34. <el-form-item :prop="`edbDataList.${index}.BaseFromMysteelChemicalClassifyId`"
  35. :rules="{required:true,message:'所属分类不能为空',trigger:'change'}">
  36. <el-cascader
  37. class="classify-cascader"
  38. :ref="'classifyCascader'+item.edbIndex"
  39. v-model="item.BaseFromMysteelChemicalClassifyId"
  40. :options="classifyOptions"
  41. :key="item.edbIndex"
  42. :props="{
  43. label: 'ClassifyName',
  44. value: 'BaseFromMysteelChemicalClassifyId',
  45. children: 'Children',
  46. emitPath: false,
  47. }"
  48. placeholder="请选择分类"
  49. />
  50. </el-form-item>
  51. </el-col>
  52. <img src="~@/assets/img/delete-minus-red.png" @click="delEdbItem(index)" v-if="edbForm.edbDataList.length>1" />
  53. </el-row>
  54. </div>
  55. <div class="add-box" @click="addEdbItem">
  56. <img src="~@/assets/img/add-quadrate-blue.png"/>
  57. <span>添加</span>
  58. </div>
  59. </el-form>
  60. </div>
  61. <div class="dia-bot">
  62. <el-button type="primary" style="margin-right: 20px" @click="saveHandle"
  63. >保存</el-button
  64. >
  65. <el-button type="primary" plain @click="cancelHandle">取消</el-button>
  66. </div>
  67. </div>
  68. </el-dialog>
  69. </template>
  70. <script>
  71. import { steelInterface } from "@/api/modules/thirdBaseApi";
  72. export default {
  73. props: {
  74. isOpenDialog: {
  75. type: Boolean,
  76. },
  77. classifyList: {
  78. type: Array,
  79. },
  80. },
  81. watch: {
  82. isOpenDialog(newval) {
  83. if (newval) {
  84. let classifyArr = _.cloneDeep(this.classifyList);
  85. this.filterNodes(classifyArr);
  86. this.classifyOptions = classifyArr;
  87. }
  88. },
  89. },
  90. data(){
  91. this.checkAge=(rule, value, callback) => {
  92. // 不能输入中文和空格
  93. let reg = /[\u4e00-\u9fa5]+|\s+/
  94. if(reg.test(value)){
  95. callback(new Error('不能输入中文和空格'))
  96. }else{
  97. callback()
  98. }
  99. }
  100. return{
  101. isAddLoading: false,
  102. classifyOptions:[],
  103. // edbIndex 仅前端使用的唯一标识
  104. edbForm:{edbDataList:[{edbIndex:1,IndexCode:'',BaseFromMysteelChemicalClassifyId:''}]},
  105. timer:null,
  106. emitParams:{},
  107. getAddBack:false
  108. }
  109. },
  110. methods:{
  111. saveHandle(){
  112. this.$refs.edbFormDataListRef.validate((valid)=>{
  113. if(valid){
  114. // console.log(this.edbForm.edbDataList);
  115. steelInterface.edbAdd({List:this.edbForm.edbDataList}).then(res=>{
  116. if (res.Ret !== 200) return;
  117. this.isAddLoading = true;
  118. console.log(this.edbForm.edbDataList);
  119. let edbItem = this.edbForm.edbDataList.find(it => it.IndexCode.toUpperCase() == res.Data.IndexCode.toUpperCase())
  120. if(!edbItem) return
  121. let edbIndexCurrent = edbItem?edbItem.edbIndex:0
  122. let selectClassifyNodes=this.$refs['classifyCascader'+edbIndexCurrent][0].getCheckedNodes()[0].path
  123. this.emitParams={
  124. code: res.Data.UniqueCode,
  125. id: res.Data.BaseFromMysteelChemicalIndexId,
  126. selectClassifyNodes
  127. }
  128. this.getAddBack=true
  129. setTimeout(() => {
  130. this.cancelHandle();
  131. }, 5*60000);
  132. })
  133. }else{
  134. this.$message.error("验证不通过,请检查")
  135. let errorElDom = this.$refs.edbFormDataListRef.fields.filter((item) => {
  136. return item.validateState === 'error';
  137. });
  138. let errorOffsetTops = errorElDom.map((item) => {
  139. return item.$el
  140. })
  141. // 滚动到指定节点
  142. errorOffsetTops[0].scrollIntoView({
  143. // 值有start,center,end,nearest
  144. block: 'start'
  145. })
  146. }
  147. })
  148. },
  149. /* 取消 */
  150. cancelHandle() {
  151. this.isAddLoading = false;
  152. this.edbForm={edbDataList:[{edbIndex:1,IndexCode:'',BaseFromMysteelChemicalClassifyId:''}]}
  153. this.$refs.edbFormDataListRef.resetFields();
  154. this.$emit("update:isOpenDialog", false);
  155. if(this.getAddBack){
  156. this.$emit("successCallback", this.emitParams);
  157. clearTimeout(this.timer)
  158. this.getAddBack=false
  159. }
  160. },
  161. // 递归改变第三级目录结构
  162. filterNodes(arr) {
  163. arr.length &&
  164. arr.forEach((item) => {
  165. item.Children &&
  166. item.Children.length &&
  167. this.filterNodes(item.Children);
  168. if (item.Level === 2) {
  169. delete item.Children;
  170. }
  171. });
  172. },
  173. addEdbItem(){
  174. this.$refs.edbFormDataListRef.validate(valid=>{
  175. if(valid){
  176. if(this.edbForm.edbDataList.length>=100){
  177. this.$message.warning('添加数量已达上限(上限100)!')
  178. return
  179. }
  180. let lastItem = this.edbForm.edbDataList[this.edbForm.edbDataList.length-1]
  181. this.edbForm.edbDataList.push({
  182. edbIndex:lastItem?1+lastItem.edbIndex:1,
  183. IndexCode:'',
  184. BaseFromMysteelChemicalClassifyId:lastItem?lastItem.BaseFromMysteelChemicalClassifyId:''
  185. })
  186. this.$nextTick(()=>{
  187. // console.log(this.$refs.formBoxRef.scrollTop,this.$refs.formBoxRef.scrollHeight,'');
  188. this.$refs.formBoxRef.scrollTop = this.$refs.formBoxRef.scrollHeight
  189. })
  190. }else{
  191. // console.log(this.$refs.edbFormDataListRef.fields,'this.$refs.edbFormDataListRef.fields');
  192. let errorElDom = this.$refs.edbFormDataListRef.fields.filter((item) => {
  193. return item.validateState === 'error';
  194. });
  195. let errorOffsetTops = errorElDom.map((item) => {
  196. return item.$el
  197. })
  198. // 滚动到指定节点
  199. errorOffsetTops[0].scrollIntoView({
  200. // 值有start,center,end,nearest
  201. block: 'start'
  202. })
  203. }
  204. })
  205. },
  206. delEdbItem(index){
  207. this.edbForm.edbDataList.splice(index,1)
  208. }
  209. },
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .dialog-main {
  214. padding: 0 35px;
  215. .form-box{
  216. max-height: 450px;
  217. overflow-y: auto;
  218. overflow-x: hidden;
  219. scroll-behavior: smooth;
  220. }
  221. .add-box{
  222. display: flex;
  223. align-items: center;
  224. cursor: pointer;
  225. margin-top: 10px;
  226. img{
  227. height: 18px;
  228. width: 18px;
  229. margin-right: 7px;
  230. }
  231. span{
  232. font-size: 14px;
  233. color: #0052D9;
  234. }
  235. }
  236. .row{
  237. .title-col{
  238. color: #333333;
  239. }
  240. .edb-col{
  241. width: 250px;
  242. }
  243. .classify-col{
  244. width: 382px;
  245. }
  246. img{
  247. height: 18px;
  248. width: 18px;
  249. margin: 10px 0 0 8px;
  250. cursor: pointer;
  251. }
  252. }
  253. }
  254. .dia-bot {
  255. margin: 52px 0 30px;
  256. display: flex;
  257. justify-content: center;
  258. }
  259. </style>
  260. <style lang="scss">
  261. .form-box{
  262. .el-form-item{
  263. margin-bottom: 18px;
  264. }
  265. }
  266. .col{
  267. .el-input{
  268. width: 100%;
  269. height: 38px;
  270. .el-input__inner{
  271. height: 38px;
  272. }
  273. }
  274. .classify-cascader{
  275. min-width: 100%;
  276. }
  277. }
  278. </style>