batchComputedSave.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <div class="batch-computed-save-wrap">
  3. <el-table
  4. :data="list"
  5. border
  6. height="500px"
  7. >
  8. <el-table-column label="指标全称" align="center" prop="EdbName"/>
  9. <el-table-column label="生成指标名称" align="center">
  10. <template slot-scope="scope">
  11. <el-input :disabled="operationForm.view" v-model="scope.row.name" placeholder="请填写指标名称" style="width:100%"/>
  12. </template>
  13. </el-table-column>
  14. <el-table-column label="单位" align="center" width="200px">
  15. <template slot-scope="scope">
  16. <selectUnit :disabled="operationForm.view||[6].includes(sourceTypeVal)" v-model="scope.row.unit"/>
  17. </template>
  18. </el-table-column>
  19. <el-table-column label="频度" align="center" width="200px">
  20. <template slot-scope="scope">
  21. <el-select
  22. v-model="scope.row.frequency"
  23. placeholder="请选择频率"
  24. @change="handleFrequencyChange(scope)"
  25. :disabled="operationForm.view||[5,6,14,61,63].includes(sourceTypeVal)"
  26. >
  27. <el-option
  28. v-for="item in frequencyArr"
  29. :key="item"
  30. :label="item"
  31. :value="item"
  32. >
  33. </el-option>
  34. </el-select>
  35. </template>
  36. </el-table-column>
  37. <el-table-column align="center" width="300px">
  38. <template slot="header" slot-scope="scope">
  39. <span style="margin-right:40px;display:inline-block">目录</span>
  40. <el-radio-group :disabled="operationForm.view" v-model="classifyType" @change="handleClassifyTypeChange">
  41. <el-radio :label="0">分目录</el-radio>
  42. <el-radio :label="1">同目录</el-radio>
  43. </el-radio-group>
  44. </template>
  45. <template slot-scope="{row,$index}">
  46. <el-cascader
  47. v-model="row.classify"
  48. :options="classifyOpt"
  49. :props="levelProps"
  50. placeholder="请选择指标目录"
  51. :disabled="(classifyType===1&&$index>0)||operationForm.view"
  52. @change="handleClassifyChange(row,$index)"
  53. />
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <div style="text-align:center;margin:60px 0 40px 0" v-if="!operationForm.view">
  58. <el-button type="primary" plain @click="handleClose">取消</el-button>
  59. <el-button type="primary" @click="handleSubmit" :loading="loading">{{loading ? '批量计算中...' : '批量计算'}}</el-button>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import { dataBaseInterface } from '@/api/api.js';
  65. import {generateSeriesArray} from './util'
  66. const tag_arr = generateSeriesArray();
  67. export default {
  68. props:{
  69. computedType:null,
  70. subComputedType:null,
  71. selectList:null,
  72. formData:null,
  73. select_target:null,
  74. operationForm:null,
  75. isEdit:false
  76. },
  77. computed: {
  78. sourceTypeVal(){
  79. if(!this.computedType) return 0
  80. if(this.subComputedType) return this.subComputedType
  81. return ['withNum','withEDB'].includes(this.computedType)?4:this.computedType
  82. }
  83. },
  84. data() {
  85. return {
  86. frequencyArr: ['日度', '周度','旬度','月度', '季度', '年度'],
  87. list:[],
  88. classifyType:0,
  89. classifyOpt: [],
  90. levelProps: {
  91. label: 'ClassifyName',
  92. value: 'ClassifyId',
  93. children: 'Children',
  94. checkStrictly: true,
  95. emitPath:false
  96. },
  97. loading:false,
  98. computedArr:[],//多指标求和\平均的指标数组
  99. }
  100. },
  101. mounted() {
  102. this.initData()
  103. this.getClassifyOpt()
  104. },
  105. methods: {
  106. // 初始化数据
  107. initData(){
  108. let arr=[]
  109. // 如果是多指标求和\平均
  110. if(this.computedType==='multipleEDB'){
  111. this.computedArr=this.selectList
  112. // 如果是编辑时
  113. if(this.isEdit){
  114. this.list=[{
  115. EdbName:this.operationForm.EdbInfoDetail.EdbName,
  116. EdbInfoId:this.operationForm.EdbInfoDetail.EdbInfoId,
  117. name:this.operationForm.EdbInfoDetail.EdbName,
  118. unit:this.operationForm.EdbInfoDetail.Unit,
  119. frequency:this.operationForm.EdbInfoDetail.Frequency,
  120. classify:this.operationForm.EdbInfoDetail.ClassifyId
  121. }]
  122. return
  123. }
  124. arr=[{...this.selectList[0]}]
  125. }else{
  126. arr=this.selectList
  127. }
  128. arr.forEach(item=>{
  129. this.setDefaultVal(item)
  130. })
  131. },
  132. // 设置默认值
  133. setDefaultVal(item){
  134. const obj={
  135. EdbName:item.EdbName,
  136. EdbInfoId:item.EdbInfoId,
  137. name:'',
  138. unit:'',
  139. frequency:'',
  140. classify:''
  141. }
  142. const tMap=new Map([
  143. ['日度','D'],
  144. ['周度','W'],
  145. ['旬度','T'],
  146. ['月度','M'],
  147. ['季度','Q'],
  148. ['年度','Y'],
  149. ])
  150. const name_map = {
  151. 4:item.EdbName,
  152. 5: `${item.EdbName}转月值`,
  153. 8: `${item.EdbName}/${this.formData.nNum}${tMap.get(item.Frequency)}MA`,
  154. 14: `${item.EdbName}/日频`,
  155. 6: `${item.EdbName}同比`,
  156. 7: `${item.EdbName}同差`,
  157. 12: `${item.EdbName}${this.formData.nNum}${item.Frequency.slice(0,1)}环比`,
  158. 13: `${item.EdbName}${this.formData.nNum}${item.Frequency.slice(0,1)}环差`,
  159. 35: `${item.EdbName}超季节性/${this.formData.nNum}年${this.formData.calendarType==='公历'?'':'/'+this.formData.calendarType}`,
  160. 52: `${item.EdbName}年化值`,
  161. 51: `${item.EdbName}/${this.formData.frequency.substr(0,1)}频`,
  162. 61: `${item.EdbName}转季值`,
  163. 62: `${item.EdbName}累计值/${this.formData.frequency}`,
  164. 63: `${item.EdbName}年初至今累计值`,
  165. 72:`${item.EdbName}指数修匀`,
  166. 75: `${item.EdbName}日均值`,
  167. 81:item.EdbName,
  168. 82:item.EdbName,
  169. }
  170. let frequerncyMap = {
  171. 14: '日度',
  172. 61: '季度',
  173. 62:this.formData.frequency,
  174. 51:this.formData.frequency,
  175. }
  176. obj.name=name_map[this.sourceTypeVal] || ''
  177. obj.frequency=frequerncyMap[this.sourceTypeVal]|| item.Frequency
  178. obj.classify=item.ClassifyId||''
  179. if([5,8,14,7,35,75].includes(this.sourceTypeVal)){
  180. obj.unit=item.Unit
  181. }else if([4].includes(this.sourceTypeVal)){
  182. obj.unit=''
  183. }else{
  184. obj.unit='无'
  185. }
  186. this.list.push(obj)
  187. },
  188. // 频度变化 修改指标名
  189. handleFrequencyChange(e){
  190. if(!this.sourceTypeVal||![51,62].includes(this.sourceTypeVal)) return;
  191. const obj=this.list[e.$index]
  192. const name_map = {
  193. 51: `${obj.EdbName}/${obj.frequency.substr(0,1)}频`,
  194. 62: `${obj.EdbName}累计值/${obj.frequency}`,
  195. }
  196. this.list[e.$index].name=name_map[this.sourceTypeVal]
  197. },
  198. // 同目录修改
  199. handleClassifyChange(e,index){
  200. if(this.classifyType===1){
  201. // 修改所有的指标的目录为第一个
  202. this.list.forEach(item=>{
  203. item.classify=e.classify
  204. })
  205. }
  206. },
  207. handleClassifyTypeChange(){
  208. this.handleClassifyChange(this.list[0])
  209. },
  210. // 提交计算
  211. async handleSubmit(){
  212. const edbList=this.list.map((item,index)=>{
  213. return{
  214. CalculateId:tag_arr[index],
  215. ClassifyId:item.classify,
  216. EdbName:item.name,
  217. Frequency:item.frequency,
  218. Unit:item.unit,
  219. FromEdbInfoId:this.isEdit?0:item.EdbInfoId,
  220. EdbInfoId:this.isEdit?item.EdbInfoId:0
  221. }
  222. })
  223. const valueMap = {
  224. 51: 'valueType',
  225. 72:'alphaValue'
  226. }
  227. const params={
  228. EdbList:edbList,
  229. Formula:valueMap[this.sourceTypeVal] ? String(this.formData[valueMap[this.sourceTypeVal]]) : String(this.formData.nNum),
  230. Source:this.sourceTypeVal,
  231. CalculateFormula:this.sourceTypeVal===4? JSON.stringify([{f:this.formData.formula,d:''}]) : this.formData.formula,
  232. EdbInfoIdArr:this.select_target?[{EdbInfoId:this.select_target,FromTag:'B'}]:[],
  233. MoveType:0,
  234. MoveFrequency:'',
  235. Calendar:this.formData.calendarType,
  236. EmptyType: this.formData.nullValueWay,
  237. MaxEmptyType: this.formData.maxNullWay,
  238. Extra:JSON.stringify({
  239. LastValType:this.formData.newValue,
  240. DateTag:this.formData.timeSeriesVal
  241. })
  242. }
  243. // 处理多指标求和\平均 情况的数据
  244. if(this.computedType==='multipleEDB'){
  245. const arr=this.computedArr.map((item,index)=>{
  246. return{
  247. EdbInfoId:item.EdbInfoId,
  248. FromTag:tag_arr[index]
  249. }
  250. })
  251. params.EdbInfoIdArr=arr
  252. }
  253. console.log(params);
  254. let isEnough = params.EdbList.every(item => item.EdbName&&item.Unit&&item.ClassifyId&&item.Frequency)
  255. if(!isEnough) return this.$message.warning('请填写完整信息');
  256. this.loading=true
  257. const tipMsg=setTimeout(() => {
  258. this.$message.success('请等待计算完成,该过程可能持续2-3分钟')
  259. }, 500);
  260. const res=this.isEdit?await dataBaseInterface.batchCalculateTargetEdit(params) : await dataBaseInterface.batchCalculateTargetAdd(params)
  261. this.loading=false
  262. clearTimeout(tipMsg)
  263. if(res.Ret !== 200) return
  264. const { Fail,Success } = res.Data;
  265. if(Fail.length) {
  266. let message = '';
  267. Fail.forEach(item => {
  268. message+=`${item.CalculateId}:${item.Msg}</br>`
  269. })
  270. this.$message({
  271. dangerouslyUseHTMLString: true,
  272. message,
  273. type: 'error'
  274. })
  275. this.dealFailHandle(Fail)
  276. }else {
  277. this.$message.success('添加成功');
  278. // this.init();
  279. this.$emit('addCallBack','add',{ code:Success[0].UniqueCode,id:Success[0].EdbInfoId,classifyId:Success[0].ClassifyId});
  280. }
  281. },
  282. // 处理批量添加失败的指标
  283. dealFailHandle(data){
  284. let temarr=[]
  285. data.forEach(item=>{
  286. const index=tag_arr.indexOf(item.CalculateId)
  287. temarr.push(this.list[index])
  288. })
  289. this.list=temarr
  290. },
  291. handleClose(){
  292. this.$emit('close')
  293. },
  294. filterNodes(arr) {
  295. arr.length &&
  296. arr.forEach((item) => {
  297. item.Children.length && this.filterNodes(item.Children);
  298. if (!item.Children.length) {
  299. delete item.Children;
  300. }
  301. });
  302. },
  303. // 获取指标分类
  304. async getClassifyOpt(){
  305. const res=await dataBaseInterface.menuListV3()
  306. if (res.Ret !== 200) return
  307. this.filterNodes(res.Data.AllNodes||[]);
  308. this.classifyOpt = res.Data.AllNodes || [];
  309. },
  310. },
  311. }
  312. </script>
  313. <style lang="scss">
  314. .batch-computed-save-wrap{
  315. .el-input{
  316. input{
  317. border: none;
  318. text-align: center;
  319. }
  320. }
  321. .el-table tr{
  322. background-color: #fff !important;
  323. &:hover>td{
  324. background-color: transparent !important; /* 或者其他想要的颜色值 */
  325. }
  326. }
  327. }
  328. </style>