member_income.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. let couponChart = null;
  2. let couponChartOption = {
  3. tooltip: {
  4. trigger: 'axis'
  5. },
  6. grid: {
  7. right: 35,
  8. bottom: 25
  9. },
  10. xAxis: {
  11. type: 'category',
  12. data: []
  13. },
  14. yAxis: [
  15. {
  16. type: 'value',
  17. splitLine: {
  18. show: true,
  19. lineStyle: {
  20. type: 'dashed',
  21. color: "#f0f3f6",
  22. opacity: 1
  23. }
  24. },
  25. axisLabel:{
  26. formatter:function(value,index){
  27. return value.toFixed(2)
  28. }
  29. }
  30. },
  31. {
  32. type: 'value',
  33. position: "right",
  34. splitLine: {
  35. show: true,
  36. lineStyle: {
  37. type: 'dashed',
  38. color: "#f0f3f6",
  39. opacity: 1
  40. }
  41. }
  42. }
  43. ],
  44. series: [{
  45. data: [],
  46. type: 'line'
  47. }]
  48. }
  49. const mixin = {
  50. mounted() {
  51. couponChart = echarts.init(this.$refs['couponChart']);
  52. couponChart.setOption(couponChartOption);
  53. this.getMemberIncomeData();
  54. this.getCouponStatisticsData();
  55. this.getCouponRankData();
  56. },
  57. data() {
  58. return {
  59. overall: {
  60. givenCoupon: 0,
  61. usedCoupon: 0,
  62. expiredCoupon: 0,
  63. receiveCoupon: 0
  64. },
  65. memberIncome: {
  66. dataTime: null,
  67. type:null,
  68. data: []
  69. },
  70. memberIncomeRank: {
  71. pagination: {
  72. pages: 1,
  73. limit: 10,
  74. total: 50
  75. },
  76. data: []
  77. },
  78. // 会员收入汇总
  79. search:{
  80. member_id:"",
  81. member:""
  82. },
  83. date:"",
  84. // 字段列表数据
  85. income_comment:[],
  86. dialogVisible:false,
  87. selectFielList:[],
  88. incomeSummary:[],
  89. choose_income:[]
  90. }
  91. },
  92. methods: {
  93. getMemberIncomeData() {
  94. this.fetchData(GetIncomeOverallDataUrl).then(res => {
  95. this.overall = res.statistics;
  96. });
  97. },
  98. getCouponStatisticsData(timeList) {
  99. couponChart.showLoading();
  100. this.fetchData(GetIncomeStatisticsDataUrl, {
  101. time: timeList !== undefined ? timeList.timeRange ? timeList.timeRange / 1000 : null : null,
  102. time_type: timeList !== undefined ? timeList.timeRangeType : null,
  103. }).then(data => {
  104. let legendData = [];
  105. let xAxisData = null;
  106. let series = [];
  107. let memberIncomeData = [];
  108. for (const key in data) {
  109. if (Object.hasOwnProperty.call(data, key)) {
  110. const dataItem = data[key];
  111. legendData.push(dataItem['name']);
  112. if (xAxisData === null) {
  113. xAxisData = dataItem['x_axis'];
  114. }
  115. memberIncomeData.push({
  116. title: dataItem.name,
  117. tip: dataItem.tips,
  118. count: dataItem.value,
  119. key,
  120. decimals:this.getDecimals(dataItem.value)
  121. })
  122. series.push({
  123. name: dataItem.name,
  124. data: dataItem.series,
  125. type: "line",
  126. })
  127. }
  128. }
  129. this.memberIncome.data = memberIncomeData;
  130. for(const item of series){
  131. if(item.name == "收入笔数"){
  132. item.yAxisIndex = 1
  133. }
  134. }
  135. couponChart.setOption({
  136. legend: {
  137. data: legendData
  138. },
  139. xAxis: {
  140. data: xAxisData
  141. },
  142. series
  143. });
  144. couponChart.hideLoading();
  145. });
  146. },
  147. getCouponRankData(page = this.memberIncomeRank.pagination.pages) {
  148. let loading = this.$loading({
  149. target: "#couponRankPanel"
  150. })
  151. this.memberIncomeRank.pagination.pages = page;
  152. this.fetchData(GetIncomeRankDataUrl, {
  153. page,
  154. search:{
  155. ...this.search,
  156. start_time:this.date !== null ? this.date[0] / 1000 : "",
  157. end_time:this.date !== null ? this.date[1] / 1000 : ""
  158. }
  159. }).then(({choose_income,income_comment,page_list}) => {
  160. let {data,total,per_page} = page_list
  161. this.memberIncomeRank.pagination.limit = per_page;
  162. this.memberIncomeRank.pagination.total = total;
  163. for (let index = 0; index < data.length; index++) {
  164. data[index]['rank'] = (this.memberIncomeRank.pagination.pages - 1) * this.memberIncomeRank.pagination.limit + index + 1;
  165. }
  166. this.memberIncomeRank.data = data;
  167. let income_comment_array = []
  168. for(let key in income_comment){
  169. income_comment[key].state = false
  170. income_comment_array.push(income_comment[key])
  171. }
  172. this.income_comment = income_comment_array
  173. this.choose_income = choose_income
  174. this.filterChooseIncome(choose_income,income_comment_array)
  175. loading.close();
  176. }).catch(() => {
  177. loading.close();
  178. })
  179. },
  180. // 处理默认的6个字段数据
  181. filterChooseIncome(choose_income,income_comment_array){
  182. if(this.selectFielList.length === 0){
  183. let newArray = income_comment_array.filter((item) => choose_income.some((item2) => item2 === item.type));
  184. this.selectFielList = newArray
  185. }else{
  186. let newArray = income_comment_array.filter((item) => this.selectFielList.some((item2) => item2.type === item.type));
  187. this.selectFielList = newArray
  188. }
  189. },
  190. // 选择列表字段
  191. selectField(){
  192. this.dialogVisible = true
  193. },
  194. getCheckFielList(data){
  195. this.dialogVisible = data.status
  196. this.selectFielList = data.data ? data.data : this.selectFielList
  197. },
  198. // 导出
  199. exportData(){
  200. let url = GetExportDataUrl +'&search[member_id]='+ this.search.member_id + '&search[member]=' + this.search.member + '&search[start_time]=' + `${ this.date ? this.date[0] / 1000 : ""}` + '&search[end_time]=' + `${this.date ? this.date[1] / 1000 : ""}`;
  201. window.location.href = url;
  202. },
  203. // 跳转到收入详情
  204. goIncomeDetail(id){
  205. let link = GoIncomeDetailUrl + `&search[member_id]=` +id ;
  206. window.location.href = link;
  207. }
  208. }
  209. }