chartDetail.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div
  3. :class="[
  4. 'chart-position-analysis-page',
  5. isPcShow ? 'chart-position-analysis-page-pc' : '',
  6. ]"
  7. v-loading="pageLoading"
  8. element-loading-text="加载中"
  9. >
  10. <div class="chart-wrap-box">
  11. <div class="wrap-top">
  12. <div>
  13. <el-radio-group
  14. v-model="tabKey"
  15. @change="chartItemInfo = chartListState[tabKey]"
  16. v-show="chartListState.BuyList.List"
  17. >
  18. <el-radio-button
  19. :label="tab.key"
  20. v-for="tab in tabKeys"
  21. :key="tab.key"
  22. >{{ tab.label }}</el-radio-button
  23. >
  24. </el-radio-group>
  25. </div>
  26. <div>
  27. <el-date-picker
  28. v-model="selectDate"
  29. type="date"
  30. placeholder="请选择日期"
  31. value-format="yyyy-MM-dd"
  32. :picker-options="pickerOption"
  33. @change="$emit('handleOpt','date')"
  34. style="margin-right: 10px"
  35. />
  36. <el-button type="primary" plain @click="$emit('handleOpt','beforeDate')">查看前一天</el-button>
  37. <el-button type="primary" plain @click="$emit('handleOpt','nextDate')" :disabled="disabledNextBtn">查看后一天</el-button>
  38. </div>
  39. </div>
  40. <div
  41. class="chart-wrap"
  42. v-if="chartItemInfo&&chartItemInfo.List && chartListState.BuyList.List"
  43. >
  44. <div class="top-info-box">
  45. <span>{{$route.query.classify_type}}</span>
  46. <span>{{ chartItemInfo.name }}</span>
  47. <span
  48. ><span style="color: #999; margin-right: 2px">总计 </span
  49. >{{ chartItemInfo.TotalDealValue }}</span
  50. >
  51. <span
  52. ><span style="color: #999; margin-right: 2px">较昨日 </span
  53. >{{ chartItemInfo.TotalDealChange }}</span
  54. >
  55. </div>
  56. <chart-box :keyVal="tabKey" :data="chartItemInfo" />
  57. </div>
  58. <div class="empty-wrap" v-else>
  59. <tableNoData text="该日期无数据" />
  60. </div>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import {
  66. apiPositionAnalysisInfo,
  67. apiPositionAnalysisList,
  68. } from "@/api/modules/positionAnalysis";
  69. import chartBox from "./chartBox.vue";
  70. export default {
  71. components: { chartBox },
  72. watch: {
  73. "$route.query": {
  74. handler(nval) {
  75. this.selectDate = "";
  76. this.getInfo();
  77. },
  78. },
  79. },
  80. props:{
  81. disabledNextBtn:Boolean,
  82. selectDate:String,
  83. pickerOption:Object
  84. },
  85. data() {
  86. return {
  87. isPcShow: true,
  88. isRefresh: false,
  89. minDate: new Date("2000/01/01"),
  90. latestDate: "", //
  91. selectDate: "",
  92. allClassifyTypeList: [],
  93. pageLoading: false,
  94. chartListState: {
  95. BuyList: {
  96. name: "多单",
  97. labelName: "持多单量",
  98. },
  99. SoldList: {
  100. name: "空单",
  101. labelName: "持空单量",
  102. },
  103. CleanBuyList: {
  104. name: "净多单",
  105. labelName: "净多单量",
  106. },
  107. CleanSoldList: {
  108. name: "净空单",
  109. labelName: "净空单量",
  110. },
  111. },
  112. tabKeys: [
  113. { label: "多单", key: "BuyList" },
  114. { label: "空单", key: "SoldList" },
  115. { label: "净多单", key: "CleanBuyList" },
  116. { label: "净空单", key: "CleanSoldList" },
  117. ],
  118. tabKey: "BuyList",
  119. chartItemInfo: null,
  120. };
  121. },
  122. methods: {
  123. getAllClassifyType() {
  124. apiPositionAnalysisList().then((res) => {
  125. if (res.Ret !== 200) return;
  126. const arr = res.Data || [];
  127. // 将数据展开
  128. arr.forEach((item) => {
  129. item.Items &&
  130. item.Items.forEach((itemC1) => {
  131. itemC1.Items &&
  132. itemC1.Items.forEach((itemC2) => {
  133. this.allClassifyTypeList.push({
  134. exchange: item.Exchange,
  135. classify_name: itemC1.ClassifyName,
  136. classify_type: itemC2.ClassifyType,
  137. });
  138. });
  139. });
  140. });
  141. });
  142. },
  143. handleClassifyTypeChange(type) {
  144. if (!this.allClassifyTypeList.length) return;
  145. const currentExchange = this.$route.query.exchange;
  146. const currentClassifyName = this.$route.query.classify_name;
  147. const currentClassifyType = this.$route.query.classify_type;
  148. // 找index
  149. let indexNum = 0;
  150. this.allClassifyTypeList.forEach((item, index) => {
  151. if (
  152. item.exchange === currentExchange &&
  153. item.classify_name === currentClassifyName &&
  154. item.classify_type === currentClassifyType
  155. )
  156. indexNum = index;
  157. });
  158. // console.log(indexNum);
  159. let obj = {};
  160. if (type === "before") {
  161. obj =
  162. this.allClassifyTypeList[
  163. indexNum === 0 ? this.allClassifyTypeList.length - 1 : indexNum - 1
  164. ];
  165. } else {
  166. obj =
  167. this.allClassifyTypeList[
  168. indexNum === this.allClassifyTypeList.length - 1 ? 0 : indexNum + 1
  169. ];
  170. }
  171. // console.log(obj);
  172. this.$router.replace({
  173. query: {
  174. ...this.$route.query,
  175. exchange: obj.exchange,
  176. classify_name: obj.classify_name,
  177. classify_type: obj.classify_type,
  178. },
  179. });
  180. // window.location.reload();
  181. },
  182. //切换 前一天\后一天 如果遇到周六日则跳过
  183. handleDateChange(type) {
  184. let num = 1;
  185. if (type === "before") {
  186. if (this.$moment(this.selectDate).isoWeekday() === 1) {
  187. //向前一天时 当前为周一则 跳到 上周五
  188. num = 3;
  189. }
  190. this.selectDate = this.$moment(this.selectDate)
  191. .add(-num, "days")
  192. .format("YYYY-MM-DD");
  193. } else {
  194. if (this.$moment(this.selectDate).isoWeekday() === 5) {
  195. //向前一天时 当前为周五则 跳到 下周一
  196. num = 3;
  197. }
  198. this.selectDate = this.$moment(this.selectDate)
  199. .add(num, "days")
  200. .format("YYYY-MM-DD");
  201. }
  202. this.getInfo();
  203. },
  204. async getInfo() {
  205. this.pageLoading = true;
  206. const res = await apiPositionAnalysisInfo({
  207. DataTime: this.selectDate || "",
  208. ClassifyName: this.$route.query.classify_name,
  209. ClassifyType: this.$route.query.classify_type,
  210. Exchange: this.$route.query.exchange,
  211. });
  212. this.pageLoading = false;
  213. if (res.Ret === 200) {
  214. const obj = res.Data || {};
  215. for (let key in this.chartListState) {
  216. this.chartListState[key] = {
  217. ...this.chartListState[key],
  218. ...obj[key],
  219. };
  220. }
  221. this.chartItemInfo = this.chartListState[this.tabKey];
  222. this.latestDate = res.Data.LastDataTime;
  223. if (res.Data.DataTime) {
  224. this.selectDate = this.$moment(res.Data.DataTime).format(
  225. "YYYY-MM-DD"
  226. );
  227. this.$emit('setInfo',{date: this.selectDate})
  228. }
  229. this.$store.commit(
  230. "SET_TITLE",
  231. `${this.$route.query.classify_type} ${this.$moment(
  232. this.selectDate
  233. ).format("YYYYMMDD")}持仓`
  234. );
  235. } else {
  236. // 清空数据
  237. for (let key in this.chartListState) {
  238. this.chartListState[key].List = null;
  239. }
  240. }
  241. },
  242. getHandles(data) {
  243. // 监听选择的日期改变
  244. if (data.opt == "date") {
  245. this.selectDate = data.val;
  246. this.getInfo();
  247. } else if (data.opt === "beforeDate") {
  248. this.handleDateChange("before");
  249. } else if (data.opt === "nextDate") {
  250. this.handleDateChange("next");
  251. } else if (data.opt === "beforeClassifyType") {
  252. this.handleClassifyTypeChange("before");
  253. } else if (data.opt === "nextClassifyType") {
  254. this.handleClassifyTypeChange("next");
  255. }
  256. },
  257. },
  258. mounted() {
  259. this.getAllClassifyType();
  260. this.getInfo();
  261. },
  262. };
  263. </script>
  264. <style lang="scss" scoped>
  265. .chart-position-analysis-page {
  266. padding-bottom: calc(160px + constant(safe-area-inset-bottom));
  267. padding-bottom: calc(160px + env(safe-area-inset-bottom));
  268. }
  269. .chart-wrap {
  270. width: 100%;
  271. margin-bottom: 60px;
  272. .top-info-box {
  273. padding: 0 34px 30px 34px;
  274. text-align: center;
  275. span {
  276. display: inline-block;
  277. margin-right: 50px;
  278. }
  279. }
  280. }
  281. .wrap-top {
  282. display: flex;
  283. justify-content: space-between;
  284. margin-bottom: 20px;
  285. }
  286. .empty-wrap {
  287. text-align: center;
  288. padding: 150px 0;
  289. }
  290. // @media (min-width: 600px){
  291. .chart-position-analysis-page-pc {
  292. padding: 0;
  293. .top-sticky-wrap {
  294. display: none;
  295. }
  296. .bot-fixed-wrap {
  297. display: none;
  298. }
  299. .empty-wrap {
  300. font-size: 16px;
  301. }
  302. .chart-wrap {
  303. margin-bottom: 60px;
  304. .top-info-box {
  305. padding: 0 20px 20px;
  306. text-align: center;
  307. font-size: 20px;
  308. span {
  309. display: inline-block;
  310. margin-right: 30px;
  311. }
  312. }
  313. }
  314. }
  315. // }
  316. </style>