import{i as D,L as z}from"./echarts.0aac64e0.js";import{d as A,p as I,b as R}from"./tools.f354a0b4.js";import{X as p}from"./index.c1ad757b.js";import O from"./index.119d01d0.js";import{e as T}from"./emitter.2a47143e.js";import{d as q,r as d,k as B,j as U,p as N,w as P,a8 as L,ae as j,H as G,o as X,c as $,M as u,G as f,K as v,a as H}from"./vue.95e072e2.js";import{_ as K}from"./_plugin-vue_export-helper.c27b6911.js";import"./elementPlus.2ca9dd27.js";import"./mCard.1589320b.js";import"./index.df979911.js";const Q=q({name:"DataTendencyChart",__name:"index",props:{fetchCard:{},fetchCardWeek:{},fetchCardMonth:{},fetchLine:{},fetchLineMonth:{},fetchLineWeek:{},query:{},initMetric:{default:()=>[{metric:"sales",color:"#0085ff",label:"销售额"},{metric:"ad_sales",color:"#ff9500",label:"广告销售额"},{metric:"ad_cost",color:"#3fd4cf",label:"广告花费"}]},metricEnum:{default:()=>A}},emits:["changeStatDim"],setup(C,{emit:F}){const t=C,s=d(t.initMetric),h=d([]);let l;const _=d(),i=d("day"),n={dataset:{source:[]},tooltip:{trigger:"axis",axisPointer:{label:{backgroundColor:"#6a7985"}}},legend:{selected:{},show:!1},grid:{top:50,right:150,bottom:30,left:65},xAxis:{type:"category"},yAxis:[{id:0,type:"value",name:"",splitLine:{show:!0},axisLine:{show:!0,lineStyle:{color:""}},show:!0},{id:1,type:"value",name:"",position:"right",splitLine:{show:!1},axisLine:{show:!0,lineStyle:{color:""}},show:!0},{id:2,type:"value",position:"right",offset:90,name:"",splitLine:{show:!1},axisLine:{show:!0,lineStyle:{color:""}},show:!0}],series:[{id:0,name:"",type:"bar",encode:{x:"data_datetime",y:""},barWidth:"18px",yAxisIndex:0,itemStyle:{color:"",borderRadius:4}},{id:1,name:"",type:"bar",encode:{x:"data_datetime",y:""},barWidth:"18px",yAxisIndex:0,itemStyle:{color:"",borderRadius:4}},{id:2,name:"",type:"line",encode:{x:"data_datetime",y:""},symbolSize:6,symbol:"circle",smooth:!0,yAxisIndex:2,itemStyle:{},areaStyle:{},emphasis:{focus:"series"}}]},m=d(!0),c=B(()=>I(t.query));U(()=>{w(),E(),setTimeout(()=>{k()},0)}),N(()=>{l&&(l.dispose(),l=null),V()});const k=async()=>{l=D(_.value);const o=await b();n.dataset.source=o,p.arrayEach(n.series,(e,a)=>{const r=s.value[a].color;e.name=s.value[a].label,e.encode.y=s.value[a].metric,e.type==="bar"?e.itemStyle.color=r:(e.itemStyle={color:r,borderColor:r},e.areaStyle={color:new z(0,0,0,1,[{offset:0,color:r+"53"},{offset:1,color:r+"03"}])})}),p.arrayEach(n.yAxis,(e,a)=>{e.name=s.value[a].label,e.axisLine.lineStyle.color=s.value[a].color}),p.arrayEach(t.metricEnum,e=>{n.legend.selected[e.label]=!1});for(const e of s.value)n.legend.selected[e.label]=!0;l.setOption(n),m.value=!1},b=async()=>{if(i.value==="week"){if(t.fetchLineWeek)return(await t.fetchLineWeek(c.value)).data}else if(i.value==="month"){if(t.fetchLineMonth)return(await t.fetchLineMonth(c.value)).data}else return(await t.fetchLine(c.value)).data},w=async()=>{let o;i.value==="week"&&t.fetchCardWeek?o=await t.fetchCardWeek(c.value):i.value==="month"&&t.fetchCardMonth?o=await t.fetchCardMonth(c.value):t.fetchCard&&(o=await t.fetchCard(c.value));const e=o.data;h.value.length=0,p.arrayEach(t.metricEnum,a=>{const r={label:a.label,value:a.value,metricVal:e[a.value],gapVal:e[`gap${a.value}`],preVal:e[`prev${a.value}`]};h.value.push(r)})},M=()=>{const o=R(n,s.value);l.setOption(o)},S=async()=>{T.emit("DateTendency-dateChange",i.value)};let g=!1;P(t.query,async()=>{if(!g){g=!0;return}m.value=!0,await w();const e={dataset:{source:await b()}};l.setOption(e),m.value=!1});const x=()=>{l.resize()},E=()=>{window.addEventListener("resize",x)},V=()=>{window.removeEventListener("resize",x)};return(o,e)=>{const a=L("el-radio-button"),r=L("el-radio-group"),W=j("loading");return G((X(),$("div",null,[u(O,{modelValue:s.value,"onUpdate:modelValue":e[0]||(e[0]=y=>s.value=y),"metric-items":h.value,onChange:M},null,8,["modelValue","metric-items"]),u(r,{modelValue:i.value,"onUpdate:modelValue":e[1]||(e[1]=y=>i.value=y),class:"chart-button-group",onChange:S},{default:f(()=>[u(a,{label:"day"},{default:f(()=>[v("日")]),_:1}),u(a,{disabled:!t.fetchLineWeek,label:"week"},{default:f(()=>[v("周")]),_:1},8,["disabled"]),u(a,{disabled:!t.fetchLineWeek,label:"month"},{default:f(()=>[v("月")]),_:1},8,["disabled"])]),_:1},8,["modelValue"]),H("div",{ref_key:"chartRef",ref:_,style:{height:"350px"}},null,512)])),[[W,m.value]])}}});const ie=K(Q,[["__scopeId","data-v-4cd91ef3"]]);export{ie as default};