analysis.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('components/my-table', __DIR__);
  4. ComponentHelper::loadComponentView('components/screen-contain', __DIR__);
  5. ComponentHelper::loadComponentView('components/header-time', __DIR__);
  6. ?>
  7. <style>
  8. .screen-container {
  9. min-width: 100%;
  10. }
  11. .analysis-table-box {
  12. width: calc(100% - 140px);
  13. min-height: 800px;
  14. margin: 20px 70px;
  15. padding: 2px 0;
  16. color: #F8F8F8;
  17. background: linear-gradient(137deg, #0034E4 0%, #001A72 51%, #0034E4 100%);
  18. border-radius: 16px;
  19. }
  20. .table-content {
  21. width: 100%;
  22. min-height: 800px;
  23. /* border: 2px solid hotpink; */
  24. border-radius: 16px;
  25. background: #030317;
  26. width: calc(100% - 4px);
  27. margin: 0 2px;
  28. /* padding: 20px 0; */
  29. }
  30. .analysis-table-item {
  31. padding: 30px 20px 0;
  32. }
  33. .lf-item {
  34. position: relative;
  35. font-size: 26px;
  36. color: #CCCFDA;
  37. padding-bottom: 10px;
  38. margin-right: 38px;
  39. cursor: pointer;
  40. }
  41. .activeItem {
  42. color: #F8F8F8;
  43. }
  44. .activeItem::before {
  45. position: absolute;
  46. content: "";
  47. bottom: 0;
  48. left: 50%;
  49. transform: translateX(-50%);
  50. width: 100px;
  51. height: 4px;
  52. background: linear-gradient(90deg, rgba(0, 52, 228, 0.02) 0%, #0034E4 52%, rgba(0, 52, 228, 0.02) 100%);
  53. }
  54. .export-text {
  55. color: #CCCFDA;
  56. font-size: 18px;
  57. cursor: pointer;
  58. }
  59. .high-low {
  60. padding: 32px 0;
  61. }
  62. .high-low span {
  63. font-size: 18px;
  64. color: #CCCFDA;
  65. }
  66. .high-low-line {
  67. width: 120px;
  68. height: 24px;
  69. background: linear-gradient(135deg, #0034E4 0%, #151634 100%);
  70. margin: 0 12px;
  71. }
  72. .table-content-right .el-radio-button__inner {
  73. background: transparent;
  74. color: #CCCFDA;
  75. }
  76. .table-content-right .el-radio-button__orig-radio:checked+.el-radio-button__inner {
  77. background: #0034E4;
  78. border-color: #fff;
  79. box-shadow: -1px 0 0 0 #fff;
  80. }
  81. .table-title {
  82. text-align: center;
  83. font-size: 22px;
  84. padding-bottom: 20px;
  85. }
  86. .table-headers {
  87. text-align: center;
  88. }
  89. .header-tr,
  90. .header-bd {
  91. display: flex;
  92. align-items: center;
  93. justify-content: center;
  94. font-size: 18px;
  95. /* width: 242px; */
  96. flex: 1;
  97. height: 81px;
  98. border: 1px solid #141439;
  99. }
  100. .bodys-tags {
  101. width: 80px;
  102. height: 24px;
  103. background: #F8F8F8;
  104. opacity: 1;
  105. border-radius: 12px 12px 12px 0px;
  106. color: #0034E4;
  107. font-size: 13px;
  108. text-align: center;
  109. line-height: 24px;
  110. margin-left: 5px;
  111. }
  112. </style>
  113. <div id="app" v-cloak>
  114. <screen-contain text-left="价值分析">
  115. <template v-slot:right>
  116. <header-time></header-time>
  117. </template>
  118. <div class="analysis-table-box">
  119. <div class="table-content">
  120. <!-- tab切换 -->
  121. <div class="analysis-table-item" flex="main:justify">
  122. <div class="table-content-left" flex="cross:center">
  123. <div class="lf-item" :class="{'activeItem': tabIndex == index}" v-for="(item, index) in tabArr" :key="index" @click="tabClick(item, index)">{{ item.value }}</div>
  124. </div>
  125. <div class="table-content-right">
  126. <el-radio-group v-model="typeKey">
  127. <el-radio-button v-for="(item, index) in radioTab" :key="index" :label="item.label">{{ item.value }}</el-radio-button>
  128. </el-radio-group>
  129. </div>
  130. </div>
  131. <!-- 高 低 -->
  132. <div class="analysis-table-item" flex="main:justify cross:center">
  133. <div class="high-low" flex="cross:center">
  134. <span>{{typeText[tabIndex].analysisText[0]}}</span>
  135. <div class="high-low-line"></div>
  136. <span>{{typeText[tabIndex].analysisText[1]}}</span>
  137. </div>
  138. <!-- <div class="export-text">
  139. <i style="font-size: 22px;" class="iconfont icon-daochu"></i>
  140. <span>导出</span>
  141. </div> -->
  142. </div>
  143. <!-- 表格 -->
  144. <div class="table-data-box">
  145. <div class="table-title">{{typeText[tabIndex].title}}</div>
  146. <div style="width: 100%;height: 100%;flex:1">
  147. <div class="">
  148. <div class="table-headers" flex>
  149. <div class="header-tr" v-for="(it, i) in options" :key="i">{{ it.label }}</div>
  150. </div>
  151. <div flex v-for="(item, index) in tabData" :key="index">
  152. <div style="flex: 1;" flex v-for="(it, i) in options" :key="i">
  153. <div v-if="it.props == 'time'" class="header-bd">{{ item[it.props] }}</div>
  154. <div v-else-if="it.props === 'rowSum'" class="header-bd" flex="cross:center">
  155. <span>{{ sumAdd(item) }}{{typeKey == typeText[tabIndex].keys[0]?'人':'元'}}</span>
  156. </div>
  157. <div v-else class="header-bd" :style="{'background': getLightenDarkenColor(it.color,(index*20)*-1)}" flex="cross:center">
  158. <span>{{ item[typeKey+it.num] }} {{typeKey == typeText[tabIndex].keys[0]?'人':'元'}}</span>
  159. </div>
  160. </div>
  161. </div>
  162. <div flex>
  163. <div style="flex: 1;" flex v-for="(it, i) in options" :key="i">
  164. <div class="header-bd" flex="cross:center">
  165. <span>{{ totlaData[it.props] }}</span>
  166. <span>{{ totlaData[typeKey+it.num] }}</span>
  167. <span v-if="it.props == 'rowSum'">{{ sumAdd(totlaData,it.num) }}</span>
  168. <span v-if="it.props != 'time'">{{typeKey == typeText[tabIndex].keys[0]?'人':'元'}}</span>
  169. </div>
  170. </div>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. <div style="height: 30px;"></div>
  178. </screen-contain>
  179. </div>
  180. <script>
  181. const app = new Vue({
  182. el: '#app',
  183. data() {
  184. return {
  185. tabIndex: 0,
  186. typeKey: 'f_users',
  187. tabArr: [{
  188. label: 0,
  189. value: 'RF分析'
  190. },
  191. {
  192. label: 1,
  193. value: 'RM分析'
  194. }
  195. ],
  196. radioTab: [{
  197. label: 'f_users',
  198. value: '客户数占比'
  199. },
  200. {
  201. label: 'f_total_pay_money',
  202. value: '累计支付金额'
  203. },
  204. {
  205. label: 'unit_price',
  206. value: '客单价'
  207. },
  208. ],
  209. options: [{
  210. props: 'time',
  211. label: 'R - 购买间隔时间 (天)'
  212. },
  213. {
  214. props: 'f5',
  215. label: 'F≥5',
  216. color: '#0034E4',
  217. num: '5',
  218. },
  219. {
  220. props: 'f4',
  221. label: 'F=4',
  222. color: '#062CB5',
  223. num: '4',
  224. },
  225. {
  226. props: 'f3',
  227. label: 'F=3',
  228. color: '#09289B',
  229. num: '3',
  230. },
  231. {
  232. props: 'f2',
  233. label: 'F=2',
  234. color: '#0C237F',
  235. num: '2',
  236. },
  237. {
  238. props: 'f1',
  239. label: 'F=1',
  240. color: '#0F1E63',
  241. num: '1',
  242. },
  243. {
  244. props: 'rowSum',
  245. label: '行合计'
  246. }
  247. ],
  248. timeArr: ['R<30','30≤R<90','30≤R<180','180≤R<365','R≥365',],
  249. tabData: [],
  250. typeText: [
  251. {
  252. analysisText: ['高活跃度','低活跃度'],
  253. tabThText: ['R - 购买间隔时间 (天)','F≥5','F=4','F=3','F=2','F=1'],
  254. title: "F-购买频率(次)",
  255. keys: ['f_users','f_total_pay_money'],
  256. },
  257. {
  258. analysisText: ['高购买力','低购买力'],
  259. tabThText: ['R - 购买间隔时间 (天)','M≥2000','1000≤M<2000','500≤M<1000','200≤M<500','M<200'],
  260. title: "M-消费金额(元)",
  261. keys: ['m_users','m_total_pay_money'],
  262. },
  263. ]
  264. }
  265. },
  266. computed: {
  267. totlaData() {
  268. let obj = {}
  269. this.tabData.forEach((it, i) => {
  270. for(var k in it) {
  271. if (typeof it[k] === 'number') {
  272. if (!obj[k]) obj[k] = 0
  273. obj[k] += it[k]
  274. if(this.typeKey != 'm_users'){
  275. obj[k] = Number(obj[k].toFixed(2));
  276. }
  277. }
  278. }
  279. })
  280. console.info(obj);
  281. return {
  282. time: '列合计',
  283. ...obj
  284. }
  285. }
  286. },
  287. created(){
  288. this.getData();
  289. },
  290. methods: {
  291. getData(){
  292. let that = this;
  293. this.tabData = [];
  294. request({
  295. params: {
  296. r: 'mall/statistics/car-analysis',
  297. type: this.tabIndex+1,
  298. },
  299. method: 'get'
  300. }).then(e => {
  301. if (e.data.code === 0) {
  302. console.info(e.data.data);
  303. let arr = e.data.data;
  304. arr.forEach((val,index) => {
  305. val.time = that.timeArr[index]
  306. that.tabData.push(val);
  307. })
  308. } else {
  309. this.$message.error(e.data.msg);
  310. }
  311. });
  312. },
  313. tabClick(it, i) {
  314. this.tabIndex = i;
  315. this.options.forEach((val,index) => {
  316. val.label = this.typeText[this.tabIndex].tabThText[index];
  317. })
  318. let index = this.radioTab.findIndex(v => v.label == this.typeKey);
  319. console.info(index);
  320. this.radioTab[0].label = this.typeText[this.tabIndex].keys[0];
  321. this.radioTab[1].label = this.typeText[this.tabIndex].keys[1];
  322. if(index!=-1){
  323. this.typeKey = this.radioTab[index].label;
  324. }
  325. this.getData();
  326. },
  327. sumAdd(item) {
  328. let total = 0;
  329. let that = this;
  330. let index = 1;
  331. for (const key in item) {
  332. let numKey = that.typeKey + index;
  333. if (typeof item[numKey] === 'number') {
  334. total += item[numKey];
  335. index++;
  336. }
  337. }
  338. let typeIndex = this.radioTab.findIndex(v => v.label == this.typeKey);
  339. if(typeIndex != 0){
  340. total = total.toFixed(2);
  341. }
  342. return total
  343. },
  344. hexToRgb(hex) {
  345. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  346. return result ? {
  347. r: parseInt(result[1], 16),
  348. g: parseInt(result[2], 16),
  349. b: parseInt(result[3], 16)
  350. } : null;
  351. },
  352. getLightenDarkenColor(col, amt) {
  353. if(!col.length) return '';
  354. var result = this.hexToRgb(col);
  355. return `rgba(${result.r+amt},${result.g+amt},${result.b+amt})`
  356. },
  357. }
  358. })
  359. </script>