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