charts.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view class="container">
  3. <qiun-title-bar title="浓度超标次数统计图" />
  4. <u--form labelPosition="left">
  5. <u-form-item
  6. label="查询日期"
  7. labelWidth="80"
  8. borderBottom
  9. @click="
  10. showCalendarFun(0);
  11. hideKeyboard();
  12. "
  13. >
  14. <u--input v-model="date1_1" disabled disabledColor="#ffffff" placeholder="请选择查询日期" border="none"></u--input>
  15. <u-icon slot="right" name="arrow-right"></u-icon>
  16. </u-form-item>
  17. </u--form>
  18. <view class="charts-box"><qiun-data-charts :canvas2d="isCanvas2d" canvasId="chart41" type="line" :opts="{ dataLabel: true, legend: {}, xAxis: { disableGrid: true }, yAxis: { gridType: 'dash', dashLength: 2 }, extra: { line: { type: 'straight', width: 2 } } }" :chartData="data1" /></view>
  19. <qiun-title-bar title="商户排放总量统计" />
  20. <u--form labelPosition="left">
  21. <u-form-item
  22. label="查询日期"
  23. labelWidth="80"
  24. borderBottom
  25. @click="
  26. showCalendarFun(1);
  27. hideKeyboard();
  28. "
  29. >
  30. <u--input v-model="date2_1" disabled disabledColor="#ffffff" placeholder="请选择查询日期" border="none"></u--input>
  31. <u-icon slot="right" name="arrow-right"></u-icon>
  32. </u-form-item>
  33. </u--form>
  34. <view class="charts-box">
  35. <qiun-data-charts
  36. type="area"
  37. :canvas2d="isCanvas2d"
  38. canvasId="chart2"
  39. :opts="{
  40. dataLabel: false,
  41. legend: {},
  42. xAxis: { disableGrid: true },
  43. yAxis: { gridType: 'dash', dashLength: 2 },
  44. extra: {
  45. area: {
  46. type: 'curve',
  47. opacity: 0.2,
  48. addLine: true,
  49. width: 2,
  50. gradient: true,
  51. },
  52. },
  53. }"
  54. :chartData="data2"
  55. />
  56. </view>
  57. <u-calendar :show="showCalendar" :defaultDate="alarmDateArr" :minDate="calendarMinDate" :maxDate="calendarMaxDate" :allowSameDay="true" :closeOnClickOverlay="true" mode="range" @confirm="calendarConfirm" :maxRange="7" @close="calendarClose" startText="开始时间" endText="结束时间" confirmDisabledText="请选择查询日期范围"></u-calendar>
  58. </view>
  59. </template>
  60. <script>
  61. import moment from "moment";
  62. import api from "@/common/api.js";
  63. export default {
  64. data() {
  65. return {
  66. date1: [moment().add(-3, "d"), moment()],
  67. data1: { categories: [], series: [] },
  68. date2: [moment().add(-3, "d"), moment()],
  69. data2: { categories: [], series: [] },
  70. alarmDateArr: [],
  71. calendarMinDate: moment()
  72. .add(-10, "d")
  73. .format("YYYY-MM-DD"),
  74. calendarMaxDate: moment()
  75. .add(1, "d")
  76. .format("YYYY-MM-DD"),
  77. showCalendar: false,
  78. calendarIndex: 0,
  79. //#ifndef MP-WEIXIN
  80. isCanvas2d: false,
  81. //#endif
  82. //#ifdef MP-WEIXIN
  83. isCanvas2d: true,
  84. //#endif
  85. };
  86. },
  87. onLoad() {},
  88. computed: {
  89. date1_1: {
  90. get() {
  91. return `${this.date1[0].format("YYYY-MM-DD")} 至 ${this.date1[1].format("YYYY-MM-DD")}`;
  92. },
  93. set() {},
  94. },
  95. date2_1: {
  96. get() {
  97. return `${this.date2[0].format("YYYY-MM-DD")} 至 ${this.date2[1].format("YYYY-MM-DD")}`;
  98. },
  99. set() {},
  100. },
  101. },
  102. props: {
  103. companyId: {
  104. type: String,
  105. required: true,
  106. },
  107. },
  108. mounted() {
  109. this.date1 = [moment().add(-6, "d"), moment()];
  110. this.date2 = [moment().add(-6, "d"), moment()];
  111. //#ifdef MP-WEIXIN
  112. this.isCanvas2d = true;
  113. //#endif
  114. console.log(this.isCanvas2d);
  115. },
  116. watch: {
  117. date1() {
  118. this.getInfo1();
  119. },
  120. date2() {
  121. this.getInfo2();
  122. },
  123. },
  124. methods: {
  125. getInfo1() {
  126. api.getOverWarnBar(`10_${this.companyId}`, this.date1[0].format("YYYYMMDD"), this.date1[1].format("YYYYMMDD")).then(({ data }) => {
  127. this.data1 = data.chartData[0];
  128. });
  129. },
  130. getInfo2() {
  131. api.getOverWarnBar(`10_${this.companyId}`, this.date2[0].format("YYYYMMDD"), this.date2[1].format("YYYYMMDD")).then(({ data }) => {
  132. this.data2 = data.chartData[0];
  133. });
  134. },
  135. hideKeyboard() {
  136. uni.hideKeyboard();
  137. },
  138. showCalendarFun(index) {
  139. this.showCalendar = true;
  140. this.calendarIndex = index;
  141. switch (this.calendarIndex) {
  142. case 0:
  143. this.alarmDateArr = Object.assign([], this.date1);
  144. break;
  145. case 1:
  146. this.alarmDateArr = Object.assign([], this.date2);
  147. break;
  148. }
  149. },
  150. calendarConfirm(e) {
  151. this.showCalendar = false;
  152. switch (this.calendarIndex) {
  153. case 0:
  154. this.date1 = [moment(e[0]), moment(e[e.length - 1])];
  155. break;
  156. case 1:
  157. this.date2 = [moment(e[0]), moment(e[e.length - 1])];
  158. break;
  159. }
  160. },
  161. calendarClose() {
  162. this.showCalendar = false;
  163. },
  164. },
  165. };
  166. </script>
  167. <style>
  168. .container {
  169. padding: 0 10px;
  170. font-size: 14px;
  171. line-height: 24px;
  172. }
  173. .charts-box {
  174. width: 100%;
  175. height: 260px;
  176. }
  177. </style>