echarts.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <div style="height:100%;padding:0 20px;">
  3. <div>
  4. <div style="display:flex;justify-content: space-between;">
  5. <el-form :inline="true">
  6. <el-form-item label="时间">
  7. <el-select v-model="queryParams.timeUnit" @change="changeEcharts()" placeholder="请选择时间">
  8. <el-option
  9. v-for="item in timeList"
  10. :key="item.value"
  11. :label="item.label"
  12. :value="item.value">
  13. </el-option>
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="地区">
  17. <el-select v-model="queryParams.area" @change="changeEcharts()" clearable placeholder="请选择地区">
  18. <el-option
  19. v-for="item in areaList"
  20. :key="item"
  21. :label="item"
  22. :value="item">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="公司" v-if="type == 1">
  27. <el-select v-model="queryParams.companyName" @change="changeEcharts()" clearable placeholder="请选择公司">
  28. <el-option
  29. v-for="item in companyList"
  30. :key="item"
  31. :label="item"
  32. :value="item">
  33. </el-option>
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="趋势图">
  37. <el-select v-model="queryParams.relation" @change="changeRelation()" placeholder="请选择公司">
  38. <el-option
  39. v-for="item in relationList"
  40. :key="item.value"
  41. :label="item.label.xStr+'与'+item.label.yStr"
  42. :value="item.value">
  43. </el-option>
  44. </el-select>
  45. </el-form-item>
  46. </el-form>
  47. </div>
  48. </div>
  49. <div>
  50. <component v-if="type == 1" :is="component" :ref="components" :domId="components" ></component>
  51. <component :is='component' :ref="component"></component>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { commonMethods } from './echarts'
  57. export default {
  58. mixins:[commonMethods],
  59. props:['id','type','name'],
  60. components:{
  61. },
  62. data() {
  63. return {
  64. height:'400px',
  65. ChartData:[],
  66. component:'MultipleLine',
  67. components:'MultipleLineAll',
  68. queryParams:{
  69. timeUnit:0,
  70. relation:1
  71. },
  72. relationList:[
  73. {
  74. label:{
  75. x:'marketDate',
  76. xStr:'时间',
  77. y:'saleMoneyTotal',
  78. yStr:'销售额'
  79. },
  80. value:1
  81. },
  82. {
  83. label:{
  84. x:'marketDate',
  85. xStr:'时间',
  86. y:'customLicenseMoney',
  87. yStr:'自定义许可费'
  88. },
  89. value:2
  90. },
  91. ],
  92. timeList:[
  93. {
  94. value:0,
  95. groupValue:'groupMonthTime',
  96. label:'月'
  97. },
  98. {
  99. value:1,
  100. groupValue:'groupSeasonTime',
  101. label:'季度'
  102. },
  103. {
  104. value:2,
  105. groupValue:'groupYearTime',
  106. label:'年'
  107. },
  108. ],
  109. areaList:[],
  110. companyList:[],
  111. }
  112. },
  113. watch:{
  114. id(val){
  115. this.init()
  116. },
  117. type(val){},
  118. name(){}
  119. },
  120. mounted() {
  121. // this.handleAdd()
  122. this.init()
  123. },
  124. methods: {
  125. changeRelation(){
  126. var relation = this.relationList.find(i=>{
  127. return i.value == this.queryParams.relation
  128. })
  129. var name = this.name + (this.type==1?'产品类别':'产品') + '趋势图'
  130. if(this.type==1){
  131. this.$refs[this.components].open(this.chartData.filter(item=>{
  132. return !item.productId
  133. }),'趋势总图',relation.label,this.queryParams.timeUnit)
  134. this.$refs[this.component].open(this.chartData.filter(item=>{
  135. return item.productId
  136. }),name,relation.label,this.queryParams.timeUnit)
  137. }else{
  138. this.$refs[this.component].open(this.chartData,name,relation.label,this.queryParams.timeUnit)
  139. }
  140. },
  141. async changeEcharts(){
  142. var chartData =await this.getData()
  143. this.chartData = chartData?chartData:[]
  144. this.changeRelation()
  145. },
  146. async init(){
  147. const [chartData,companyAndArea] = await Promise.allSettled([this.getData(),this.getAllCompanyAndArea()])
  148. this.chartData = chartData.status =='fulfilled'?chartData.value:[]
  149. this.areaList= companyAndArea.status =='fulfilled'?companyAndArea.value.saleAreas:[]
  150. this.companyList= companyAndArea.status =='fulfilled'?companyAndArea.value.companyNames:[]
  151. this.changeRelation()
  152. },
  153. async getData(){
  154. var params= {
  155. saleArea:this.queryParams.area,
  156. companyName:this.queryParams.companyName,
  157. }
  158. if(this.type == 1){
  159. params.categoryId = this.id
  160. }else{
  161. params.productId = this.id
  162. }
  163. var queryParams = {
  164. size:99999,
  165. current:1,
  166. searchQuery:this.$commonJS.objectToString(params),
  167. groupBy:this.timeList.find(item=>{
  168. return item.value == this.queryParams.timeUnit
  169. }).groupValue,
  170. orderDTOList:[
  171. {
  172. "orderBy": "saleTime",
  173. "orderType": 0
  174. }
  175. ]
  176. }
  177. return await this.$api.groupProductMarketData(queryParams).then( async response=>await response.data.data.values)
  178. },
  179. //获取所有公司和地区
  180. getAllCompanyAndArea(){
  181. var params = {}
  182. if(this.type == 1){
  183. params.categoryId = this.id
  184. }else{
  185. params.productId = this.id
  186. }
  187. return this.$api.getAllCompanyAndArea(params).then(response=> response.data)
  188. },
  189. },
  190. }
  191. </script>