marketingExpenseStatistics.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div>
  3. <borderTemplate borderBox="width: 17.083vw;height: 12.500vw;" title="营销费用统计" detailTitle="查看详情" @dialog="$emit('dialog')" systemappid="290" push_path="/salerpriceData">
  4. <template slot="content">
  5. <div>
  6. <div style="display: flex;justify-content: space-between;margin-bottom: 0.364vw">
  7. <el-button type="text" class="inline-16 btn-title-style" @click="onChange(true)" >{{$t(`切换`)}}{{$t(btnTitle)}}</el-button>
  8. <el-select v-model="param.content.dateType" class="inline-16" size="small" @change="onChange(false)" :popper-append-to-body="false" >
  9. <el-option :label="$t('全部')" value="全部"></el-option>
  10. <el-option :label="$t('本年')" value="本年"></el-option>
  11. </el-select>
  12. </div>
  13. <div v-show="btnTitle == '项目'" style="width: 16.025vw;height: 6.633vw;margin-top: 0.264vw;" ref="customerRefChar">
  14. </div>
  15. <div v-show="btnTitle == '客户'" style="width: 16.025vw;height: 6.633vw;margin-top: 0.264vw;" ref="projectRefChar">
  16. </div>
  17. </div>
  18. </template>
  19. </borderTemplate>
  20. </div>
  21. </template>
  22. <script>
  23. import borderTemplate from '../components/borderTemplate'
  24. import {Pie} from "@antv/g2plot";
  25. export default {
  26. name: "marketingExpenseStatistics",
  27. components:{borderTemplate},
  28. data(){
  29. return {
  30. dateType:'本年',
  31. btnTitle:'项目',
  32. param:{
  33. id:2024062615133802,
  34. content:{
  35. dataid:'',
  36. dateType:'本年',
  37. ownertable:'sa_customers',
  38. type:'',
  39. where:{
  40. isleave:'1',
  41. }
  42. }
  43. },
  44. cusData:'',
  45. proData:'',
  46. cusMap:'',
  47. proMap:''
  48. }
  49. },
  50. methods:{
  51. async cusInit(init){
  52. this.param.id = 2024062615133802
  53. this.param.content.ownertable = 'sa_customers'
  54. let res = await this.$api.requested(this.param)
  55. // this.mapData = res.data[0].ratio
  56. this.cusData = res.data[0].ratio.map(item=>{
  57. return {
  58. "totalamount": res.data[0].ratio[0].total,//值
  59. "type": item.type,
  60. "rowindex": item.rowindex,
  61. "ratio": Math.round(((item.ratio * 100)*100)/100), //比例
  62. "value":item.value
  63. }
  64. })
  65. console.log('客户类型数据',this.cusData)
  66. if (init) {
  67. this.cusMap = new Pie(this.$refs.customerRefChar, {
  68. appendPadding: 2,
  69. data:this.cusData,
  70. angleField: 'ratio',
  71. colorField: 'type',
  72. radius: 1,
  73. innerRadius: 0.79,
  74. label:{
  75. style:{
  76. fill:'#CFDCE5'
  77. },
  78. /*type: 'inner',
  79. offset: '-50%',
  80. style: {
  81. textAlign: 'center',
  82. },
  83. autoRotate: false,*/
  84. formatter: (datum) => `${datum.ratio}%`
  85. },
  86. tooltip:{
  87. formatter: (datum) => {
  88. return { name: datum.type, value: datum.ratio + '%' };
  89. },
  90. style: {
  91. fontSize:'0.733vw',
  92. color:'#f60b44'
  93. },
  94. },
  95. statistic: {
  96. title: {
  97. offsetY: -4,
  98. style: {
  99. fontSize:'0.733vw',
  100. color:'#E6F4FF'
  101. },
  102. content:'客户营销费用'
  103. },
  104. content: {
  105. offsetY: 4,
  106. style: {
  107. whiteSpace: 'pre-wrap',
  108. overflow: 'hidden',
  109. textOverflow: 'ellipsis',
  110. fontSize:'0.833vw',
  111. color:'#FFFFFF'
  112. },
  113. customHtml: (container, view, datum, data) => {
  114. const text = '¥'+this.tool.formatAmount(this.tool.unitConversion(data[0].totalamount,10000),2)+this.$t('万')
  115. return text
  116. },
  117. },
  118. },
  119. legend: {
  120. position:'right',
  121. offsetY:2,
  122. itemName:{
  123. style:{
  124. fill:'#CFDCE5'
  125. }
  126. },
  127. pageNavigator:{
  128. marker: {
  129. style: {
  130. // 非激活,不可点击态时的填充色设置
  131. inactiveFill: '#fff',
  132. inactiveOpacity: 1,
  133. // 默认填充色设置
  134. fill: '#fff',
  135. opacity: 1,
  136. size: 10,
  137. },
  138. },
  139. text: {
  140. style: {
  141. // 非激活,不可点击态时的填充色设置
  142. inactiveFill: '#fff',
  143. inactiveOpacity: 1,
  144. // 默认填充色设置
  145. fill: '#fff',
  146. opacity: 1,
  147. size: 10,
  148. },
  149. },
  150. }
  151. },
  152. // 添加 中心统计文本 交互
  153. // interactions: [{ type: 'element-single-selected' },{ type: 'element-active' }],
  154. });
  155. this.cusMap.render();
  156. } else {
  157. this.cusMap.changeData(this.cusData)
  158. }
  159. },
  160. async proInit(init){
  161. this.param.id = 2024062915152702
  162. this.param.content.ownertable = 'sa_project'
  163. let res = await this.$api.requested(this.param)
  164. // this.mapData = res.data[0].ratio
  165. this.proData = res.data[0].ratio.map(item=>{
  166. return {
  167. "totalamount": res.data[0].ratio[0].total,//值
  168. "type": item.type,
  169. "rowindex": item.rowindex,
  170. "ratio": Math.round(((item.ratio * 100)*100)/100), //比例
  171. "value":item.value
  172. }
  173. })
  174. console.log('项目类型数据',this.proData)
  175. if (init) {
  176. this.proMap = new Pie(this.$refs.projectRefChar, {
  177. appendPadding: 2,
  178. data:this.proData,
  179. angleField: 'ratio',
  180. colorField: 'type',
  181. radius: 1,
  182. innerRadius: 0.79,
  183. label:{
  184. style:{
  185. fill:'#CFDCE5'
  186. },
  187. /*type: 'inner',
  188. offset: '-50%',
  189. style: {
  190. textAlign: 'center',
  191. },
  192. autoRotate: false,*/
  193. formatter: (datum) => `${datum.ratio}%`
  194. },
  195. tooltip:{
  196. formatter: (datum) => {
  197. return { name: datum.type, value: datum.ratio + '%' };
  198. },
  199. },
  200. statistic: {
  201. title: {
  202. offsetY: -4,
  203. style: {
  204. fontSize:'0.733vw',
  205. color:'#E6F4FF'
  206. },
  207. content:'项目营销费用'
  208. },
  209. content: {
  210. offsetY: 4,
  211. style: {
  212. whiteSpace: 'pre-wrap',
  213. overflow: 'hidden',
  214. textOverflow: 'ellipsis',
  215. fontSize:'0.833vw',
  216. color:'#FFFFFF'
  217. },
  218. customHtml: (container, view, datum, data) => {
  219. const text = '¥'+this.tool.formatAmount(this.tool.unitConversion(data[0].totalamount,10000),2)+this.$t('万')
  220. return text
  221. },
  222. },
  223. },
  224. legend: {
  225. position:'right',
  226. offsetY:2,
  227. itemName:{
  228. style:{
  229. fill:'#CFDCE5'
  230. }
  231. },
  232. pageNavigator:{
  233. marker: {
  234. style: {
  235. // 非激活,不可点击态时的填充色设置
  236. inactiveFill: '#fff',
  237. inactiveOpacity: 1,
  238. // 默认填充色设置
  239. fill: '#fff',
  240. opacity: 1,
  241. size: 10,
  242. },
  243. text: {
  244. style: {
  245. // 非激活,不可点击态时的填充色设置
  246. inactiveFill: '#fff',
  247. inactiveOpacity: 1,
  248. // 默认填充色设置
  249. fill: '#fff',
  250. opacity: 1,
  251. size: 10,
  252. },
  253. },
  254. },
  255. }
  256. },
  257. // 添加 中心统计文本 交互
  258. // interactions: [{ type: 'element-single-selected' },{ type: 'element-active' }],
  259. });
  260. this.proMap.render();
  261. } else {
  262. this.proMap.changeData(this.proData)
  263. }
  264. },
  265. onChange(init){
  266. if (this.btnTitle == '客户'){
  267. if (init){
  268. this.btnTitle = '项目'
  269. this.cusInit(false)
  270. }else {
  271. this.proInit(false)
  272. }
  273. }else {
  274. if (init){
  275. this.btnTitle = '客户'
  276. this.proInit(false)
  277. }else {
  278. this.cusInit(false)
  279. }
  280. }
  281. }
  282. }
  283. }
  284. </script>
  285. <style scoped>
  286. .btn-title-style{
  287. font-weight: 400;
  288. font-size: 0.729vw;
  289. color: #6CD2A1;
  290. text-decoration:underline
  291. }
  292. </style>