gqExchangeData.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div class="exchangedata-wrap">
  3. <span class="slide-btn-icon" :class="{'slide-left':isLeftWrapShow,'slide-right':!isLeftWrapShow}"
  4. @click="isLeftWrapShow = !isLeftWrapShow">
  5. <i :class="{'el-icon-d-arrow-left':isLeftWrapShow,'el-icon-d-arrow-right':!isLeftWrapShow}"></i>
  6. </span>
  7. <div class="left-wrap box" v-show="isLeftWrapShow">
  8. <el-date-picker style="width:100%" v-model="time" type="date" placeholder="选择日期"
  9. value-format="yyyy-MM-dd" :clearable="false" @change="handleTimeChange">
  10. </el-date-picker>
  11. <div class="scroll-wrap">
  12. <el-tree ref="treeRef" class="target_tree custom-tree" :data="typeList"
  13. node-key="BaseFromTradeGuangzhouClassifyId" :default-expanded-keys="defaultShowNodes"
  14. :props="{
  15. label: 'ClassifyName',
  16. children: 'Children',
  17. }"
  18. :current-node-key="type" empty-text="暂无分类" @current-change="handleChangeType">
  19. <span slot-scope="{ node, data }">{{ data.ClassifyName }}</span>
  20. </el-tree>
  21. </div>
  22. </div>
  23. <div class="right-wrap box" v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading">
  24. <el-button v-if="list.length>0 && haveSummation && (!summationView)"
  25. class="export-button" type="primary" plain @click="excelExport" :loading="exportBtnload">导出Excel</el-button>
  26. <div class="content" v-if="list.length>0">
  27. <table width="auto" border="0">
  28. <thead class="border-head">
  29. <tr>
  30. <td v-for="(val,index) in labelArr" :key="`${val}_${index}`">
  31. {{ val }}
  32. </td>
  33. <td v-if="haveSummation && summationView">操作</td>
  34. </tr>
  35. </thead>
  36. <tbody>
  37. <tr v-for="item in list" :key="item.BaseFromTradeGuangzhouIndexId">
  38. <td v-for="(val,key) in labelArr" :key="key">{{item[key]}}</td>
  39. <td v-if="haveSummation && summationView">
  40. <el-button type="text" @click="detailView(item)">查看详情</el-button>
  41. </td>
  42. </tr>
  43. </tbody>
  44. </table>
  45. </div>
  46. <div class="empty-wrap" v-else>
  47. <tableNoData text="暂无数据"/>
  48. </div>
  49. <div class="num-warp" v-if="numList.length>0">
  50. <div v-for="item in numList" :key="item.BaseFromTradeGuangzhouContractId"
  51. :class="['num-box',num===item.BaseFromTradeGuangzhouContractId&&'num-active']" @click="handleChangeNum(item)">
  52. {{item.Contract}}
  53. </div>
  54. </div>
  55. </div>
  56. </div>
  57. </template>
  58. <script>
  59. // 广期所数据
  60. import { guangqiInterface } from "@/api/api.js";
  61. import {waitRequestReturn} from '@/utils/common.js'
  62. export default {
  63. name: "gqExchangeData",
  64. data() {
  65. return {
  66. isLeftWrapShow:true,
  67. labelArr: {
  68. IndexCode: "指标ID",
  69. IndexName: "指标名称",
  70. Value: "数值",
  71. Unit: "单位",
  72. Frequency: "频度",
  73. StartDate: "起始日期",
  74. EndDate: "最新日期",
  75. // Operations:"操作"
  76. },
  77. summationView:true,// 当前是否是合计
  78. haveSummation:false, // 是否有合计
  79. time:'',
  80. topLevelType:'',
  81. type:'',
  82. typeList:[],
  83. defaultShowNodes:[],
  84. numList:[],
  85. num:'',
  86. list:[],
  87. loading:false,
  88. tradeIndexId:'',
  89. exportApi:process.env.VUE_APP_API_ROOT + "/data_source/gfex/index/detail/export",
  90. exportBtnload:false
  91. };
  92. },
  93. watch:{
  94. type(value){
  95. this.summationView=true
  96. },
  97. time(value){
  98. this.summationView=true
  99. }
  100. },
  101. computed:{
  102. exportUrl(){
  103. let url=this.exportApi +
  104. `?${localStorage.getItem("auth") || ""}&BaseFromTradeGuangzhouIndexId=${this.tradeIndexId}&TradeDate=${this.time}`
  105. return this.escapeStr(url);
  106. }
  107. },
  108. created () {
  109. this.getClassifyListFun()
  110. this.getNewtestDateFun()
  111. waitRequestReturn(()=> this.type && this.time,this.getNumList,10)
  112. },
  113. methods: {
  114. escapeStr(str) {
  115. return str.replace(/#/g, escape("#")).replace(/;/g, escape(";"));
  116. },
  117. handleChangeNum(e){
  118. this.num=e.BaseFromTradeGuangzhouContractId
  119. this.getData()
  120. },
  121. // 时间切换
  122. handleTimeChange(){
  123. this.getNumList()
  124. },
  125. // 获取分类
  126. getClassifyListFun(){
  127. guangqiInterface.getClassifyList().then(res=>{
  128. if(res.Ret===200){
  129. this.typeList=res.Data || []
  130. try {
  131. this.type=this.typeList[0].Children[0].BaseFromTradeGuangzhouClassifyId
  132. this.topLevelType = this.typeList[0].BaseFromTradeGuangzhouClassifyId
  133. this.$nextTick(() => {
  134. this.$refs.treeRef.setCurrentKey(this.type);
  135. });
  136. this.defaultShowNodes=[this.typeList[0].BaseFromTradeGuangzhouClassifyId,this.typeList[0].Children[0].BaseFromTradeGuangzhouClassifyId]
  137. } catch (error) {
  138. console.error('Data的返回存在问题或为空');
  139. }
  140. }
  141. })
  142. },
  143. // 获取最新日期
  144. getNewtestDateFun(){
  145. guangqiInterface.getNewtestDate().then(res=>{
  146. if(res.Ret == 200){
  147. this.time=res.Data || this.$moment(new Date()).format('YYYY-MM-DD')
  148. }
  149. })
  150. },
  151. handleChangeType(data, node) {
  152. if (data.BaseFromTradeGuangzhouClassifyId == this.type || (!data.ParentId)) return;
  153. this.type = data.BaseFromTradeGuangzhouClassifyId
  154. this.topLevelType = data.ParentId
  155. this.getNumList()
  156. },
  157. // 获取合约号
  158. async getNumList(){
  159. this.loading=true
  160. guangqiInterface.getContractList({
  161. BaseFromTradeGuangzhouClassifyId:this.type,
  162. TradeDate:this.time,
  163. }).then(res=>{
  164. if(res.Ret===200){
  165. this.numList=res.Data||[]
  166. this.num=this.numList[0]?this.numList[0].BaseFromTradeGuangzhouContractId||'':''
  167. this.getData()
  168. }else{
  169. this.loading=false
  170. }
  171. }).catch(()=>{
  172. this.loading=false
  173. })
  174. },
  175. getData(){
  176. $('.content').animate({scrollTop:0},0)
  177. this.loading=true
  178. guangqiInterface.getIndexDataList({
  179. BaseFromTradeGuangzhouClassifyId:this.type,
  180. TradeDate:this.time,
  181. BaseFromTradeGuangzhouContractId:this.num
  182. }).then(res =>{
  183. if(res.Ret===200){
  184. this.list=res.Data || []
  185. }
  186. }).finally(()=>{
  187. this.haveSummation = this.topLevelType == 4
  188. this.loading=false
  189. })
  190. },
  191. detailView(item){
  192. this.loading=true
  193. this.tradeIndexId = item.BaseFromTradeGuangzhouIndexId
  194. let params={
  195. BaseFromTradeGuangzhouIndexId:item.BaseFromTradeGuangzhouIndexId,
  196. TradeDate:this.time
  197. }
  198. guangqiInterface.getIndexDataDetail(params).then(res=>{
  199. if(res.Ret == 200){
  200. this.list=res.Data || []
  201. this.summationView=false
  202. }
  203. })
  204. .finally(()=>{
  205. this.loading=false
  206. })
  207. },
  208. excelExport(){
  209. this.exportBtnload = true;
  210. const link = document.createElement("a");
  211. link.href = this.exportUrl;
  212. link.download = "";
  213. link.click();
  214. setTimeout(() => {
  215. this.exportBtnload = false;
  216. }, 2000);
  217. }
  218. }
  219. };
  220. </script>
  221. <style lang="scss" scoped>
  222. @import "../css/exchangedata.scss";
  223. .exchangedata-wrap{
  224. .right-wrap{
  225. display: flex;
  226. flex-direction: column;
  227. .export-button{
  228. align-self: flex-start;
  229. padding:0 40px;
  230. margin-bottom: 20px;
  231. height: 40px;
  232. }
  233. .content{
  234. flex-grow: 1;
  235. min-height: 90%;
  236. }
  237. .empty-wrap{
  238. min-height: 90%;
  239. flex-grow: 1;
  240. }
  241. }
  242. .slide-btn-icon{
  243. &.slide-left{
  244. left:285px;
  245. }
  246. &.slide-right{
  247. left: 0;
  248. }
  249. }
  250. .left-wrap{
  251. width: 300px;
  252. }
  253. }
  254. .scroll-wrap {
  255. margin: 20px 0;
  256. height: calc(100vh - 250px);
  257. overflow-y: auto;
  258. .target_tree {
  259. color: #333;
  260. }
  261. }
  262. thead{
  263. position: sticky;
  264. top: 0;
  265. left: 0;
  266. border-top: 1px solid #dcdfe6;
  267. }
  268. </style>
  269. <style lang="scss">
  270. @import "../css/customtree.scss";
  271. </style>