| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <template>
- <div>
- <borderTemplate borderBox="width: 17.083vw;height: 12.500vw;" title="营销费用统计" detailTitle="查看详情" @dialog="$emit('dialog')" systemappid="290" push_path="/salerpriceData">
- <template slot="content">
- <div>
- <div style="display: flex;justify-content: space-between;margin-bottom: 0.364vw">
- <el-button type="text" class="inline-16 btn-title-style" @click="onChange(true)" >{{$t(`切换`)}}{{$t(btnTitle)}}</el-button>
- <el-select v-model="param.content.dateType" class="inline-16" size="small" @change="onChange(false)" :popper-append-to-body="false" >
- <el-option :label="$t('全部')" value="全部"></el-option>
- <el-option :label="$t('本年')" value="本年"></el-option>
- </el-select>
- </div>
- <div v-show="btnTitle == '项目'" style="width: 16.025vw;height: 6.633vw;margin-top: 0.264vw;" ref="customerRefChar">
- </div>
- <div v-show="btnTitle == '客户'" style="width: 16.025vw;height: 6.633vw;margin-top: 0.264vw;" ref="projectRefChar">
- </div>
- </div>
- </template>
- </borderTemplate>
- </div>
- </template>
- <script>
- import borderTemplate from '../components/borderTemplate'
- import {Pie} from "@antv/g2plot";
- export default {
- name: "marketingExpenseStatistics",
- components:{borderTemplate},
- data(){
- return {
- dateType:'本年',
- btnTitle:'项目',
- param:{
- id:2024062615133802,
- content:{
- dataid:'',
- dateType:'本年',
- ownertable:'sa_customers',
- type:'',
- where:{
- isleave:'1',
- }
- }
- },
- cusData:'',
- proData:'',
- cusMap:'',
- proMap:''
- }
- },
- methods:{
- async cusInit(init){
- this.param.id = 2024062615133802
- this.param.content.ownertable = 'sa_customers'
- let res = await this.$api.requested(this.param)
- // this.mapData = res.data[0].ratio
- this.cusData = res.data[0].ratio.map(item=>{
- return {
- "totalamount": res.data[0].ratio[0].total,//值
- "type": item.type,
- "rowindex": item.rowindex,
- "ratio": Math.round(((item.ratio * 100)*100)/100), //比例
- "value":item.value
- }
- })
- console.log('客户类型数据',this.cusData)
- if (init) {
- this.cusMap = new Pie(this.$refs.customerRefChar, {
- appendPadding: 2,
- data:this.cusData,
- angleField: 'ratio',
- colorField: 'type',
- radius: 1,
- innerRadius: 0.79,
- label:{
- style:{
- fill:'#CFDCE5'
- },
- /*type: 'inner',
- offset: '-50%',
- style: {
- textAlign: 'center',
- },
- autoRotate: false,*/
- formatter: (datum) => `${datum.ratio}%`
- },
- tooltip:{
- formatter: (datum) => {
- return { name: datum.type, value: datum.ratio + '%' };
- },
- style: {
- fontSize:'0.733vw',
- color:'#f60b44'
- },
- },
- statistic: {
- title: {
- offsetY: -4,
- style: {
- fontSize:'0.733vw',
- color:'#E6F4FF'
- },
- content:'客户营销费用'
- },
- content: {
- offsetY: 4,
- style: {
- whiteSpace: 'pre-wrap',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- fontSize:'0.833vw',
- color:'#FFFFFF'
- },
- customHtml: (container, view, datum, data) => {
- const text = '¥'+this.tool.formatAmount(this.tool.unitConversion(data[0].totalamount,10000),2)+this.$t('万')
- return text
- },
- },
- },
- legend: {
- position:'right',
- offsetY:2,
- itemName:{
- style:{
- fill:'#CFDCE5'
- }
- },
- pageNavigator:{
- marker: {
- style: {
- // 非激活,不可点击态时的填充色设置
- inactiveFill: '#fff',
- inactiveOpacity: 1,
- // 默认填充色设置
- fill: '#fff',
- opacity: 1,
- size: 10,
- },
- },
- text: {
- style: {
- // 非激活,不可点击态时的填充色设置
- inactiveFill: '#fff',
- inactiveOpacity: 1,
- // 默认填充色设置
- fill: '#fff',
- opacity: 1,
- size: 10,
- },
- },
- }
- },
- // 添加 中心统计文本 交互
- // interactions: [{ type: 'element-single-selected' },{ type: 'element-active' }],
- });
- this.cusMap.render();
- } else {
- this.cusMap.changeData(this.cusData)
- }
- },
- async proInit(init){
- this.param.id = 2024062915152702
- this.param.content.ownertable = 'sa_project'
- let res = await this.$api.requested(this.param)
- // this.mapData = res.data[0].ratio
- this.proData = res.data[0].ratio.map(item=>{
- return {
- "totalamount": res.data[0].ratio[0].total,//值
- "type": item.type,
- "rowindex": item.rowindex,
- "ratio": Math.round(((item.ratio * 100)*100)/100), //比例
- "value":item.value
- }
- })
- console.log('项目类型数据',this.proData)
- if (init) {
- this.proMap = new Pie(this.$refs.projectRefChar, {
- appendPadding: 2,
- data:this.proData,
- angleField: 'ratio',
- colorField: 'type',
- radius: 1,
- innerRadius: 0.79,
- label:{
- style:{
- fill:'#CFDCE5'
- },
- /*type: 'inner',
- offset: '-50%',
- style: {
- textAlign: 'center',
- },
- autoRotate: false,*/
- formatter: (datum) => `${datum.ratio}%`
- },
- tooltip:{
- formatter: (datum) => {
- return { name: datum.type, value: datum.ratio + '%' };
- },
- },
- statistic: {
- title: {
- offsetY: -4,
- style: {
- fontSize:'0.733vw',
- color:'#E6F4FF'
- },
- content:'项目营销费用'
- },
- content: {
- offsetY: 4,
- style: {
- whiteSpace: 'pre-wrap',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
- fontSize:'0.833vw',
- color:'#FFFFFF'
- },
- customHtml: (container, view, datum, data) => {
- const text = '¥'+this.tool.formatAmount(this.tool.unitConversion(data[0].totalamount,10000),2)+this.$t('万')
- return text
- },
- },
- },
- legend: {
- position:'right',
- offsetY:2,
- itemName:{
- style:{
- fill:'#CFDCE5'
- }
- },
- pageNavigator:{
- marker: {
- style: {
- // 非激活,不可点击态时的填充色设置
- inactiveFill: '#fff',
- inactiveOpacity: 1,
- // 默认填充色设置
- fill: '#fff',
- opacity: 1,
- size: 10,
- },
- text: {
- style: {
- // 非激活,不可点击态时的填充色设置
- inactiveFill: '#fff',
- inactiveOpacity: 1,
- // 默认填充色设置
- fill: '#fff',
- opacity: 1,
- size: 10,
- },
- },
- },
- }
- },
- // 添加 中心统计文本 交互
- // interactions: [{ type: 'element-single-selected' },{ type: 'element-active' }],
- });
- this.proMap.render();
- } else {
- this.proMap.changeData(this.proData)
- }
- },
- onChange(init){
- if (this.btnTitle == '客户'){
- if (init){
- this.btnTitle = '项目'
- this.cusInit(false)
- }else {
- this.proInit(false)
- }
- }else {
- if (init){
- this.btnTitle = '客户'
- this.proInit(false)
- }else {
- this.cusInit(false)
- }
- }
- }
- }
- }
- </script>
- <style scoped>
- .btn-title-style{
- font-weight: 400;
- font-size: 0.729vw;
- color: #6CD2A1;
- text-decoration:underline
- }
- </style>
|