customerNum.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div class="app-container">
  3. <div class="app-content">
  4. <div class="title">
  5. 客户总量统计
  6. </div>
  7. <el-form class="search-form" :inline="true" >
  8. <el-form-item >
  9. <el-select v-model="value" placeholder="请选择日期">
  10. <el-option
  11. v-for="item in options"
  12. :key="item.value"
  13. :label="item.label"
  14. :value="item.value">
  15. </el-option>
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item >
  19. <treeselect :clearable="false" v-model="deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
  20. </el-form-item>
  21. <el-form-item>
  22. <el-select v-model="userIds" multiple placeholder="请选择员工">
  23. <el-option
  24. v-for="item in users"
  25. :key="item.userId"
  26. :label="item.nickName"
  27. :value="item.userId">
  28. </el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="cyan" icon="el-icon-search" @click="customer">搜索</el-button>
  33. </el-form-item>
  34. </el-form>
  35. <div class="data-box">
  36. <div class="echart-box">
  37. <div id="echart-customer"></div>
  38. </div>
  39. <div class="table-box">
  40. <el-button class="export" size="small" @click="handleExport" v-hasPermi="['statistics:customer:index']">导出</el-button>
  41. <el-table
  42. :data="list"
  43. border
  44. :summary-method="getSummaries"
  45. show-summary
  46. max-height="500"
  47. style="width: 100%;">
  48. <el-table-column
  49. prop="nickName"
  50. label="员工姓名">
  51. </el-table-column>
  52. <el-table-column
  53. prop="customerOkNum"
  54. label="成交客户数">
  55. </el-table-column>
  56. <el-table-column
  57. prop="customerNum"
  58. label="新增客户数">
  59. </el-table-column>
  60. </el-table>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import { customerNum,exportCustomerNum } from "@/api/crm/statistics";
  68. import { getUserListByDeptId} from "@/api/company/companyUser";
  69. import echarts from 'echarts'
  70. import resize from '../../dashboard/mixins/resize'
  71. import { treeselect } from "@/api/company/companyDept";
  72. import Treeselect from "@riophae/vue-treeselect";
  73. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  74. export default {
  75. name: 'Index',
  76. mixins: [resize],
  77. components: { Treeselect },
  78. watch: {
  79. // 监听deptId
  80. 'deptId': 'currDeptChange'
  81. },
  82. data() {
  83. return {
  84. deptOptions:[],
  85. deptId:undefined,
  86. userIds:undefined,
  87. users:[],
  88. dateRange:[],
  89. chart: null,
  90. options: [{
  91. value: '1',
  92. label: '今天'
  93. }, {
  94. value: '2',
  95. label: '昨天'
  96. }, {
  97. value: '3',
  98. label: '本周'
  99. }, {
  100. value: '4',
  101. label: '上周'
  102. }, {
  103. value: '5',
  104. label: '本月'
  105. }
  106. , {
  107. value: '6',
  108. label: '上月'
  109. }
  110. , {
  111. value: '7',
  112. label: '本季度'
  113. }
  114. , {
  115. value: '8',
  116. label: '上季度'
  117. }
  118. , {
  119. value: '9',
  120. label: '本年'
  121. }
  122. , {
  123. value: '10',
  124. label: '上年'
  125. }],
  126. value: '5',
  127. list:[],
  128. dates:[],
  129. customerNum:[],
  130. customerOkNum:[],
  131. }
  132. },
  133. created() {
  134. this.getTreeselect();
  135. },
  136. methods: {
  137. currDeptChange(val){
  138. console.log(val)
  139. this.deptId=val;
  140. this.getUserListByDeptId();
  141. },
  142. /** 查询部门下拉树结构 */
  143. getTreeselect() {
  144. var that=this;
  145. treeselect().then((response) => {
  146. this.deptOptions = response.data;
  147. console.log(this.deptOptions)
  148. if(response.data!=null&&response.data.length>0){
  149. this.deptId=response.data[0].id;
  150. that.customer()
  151. }
  152. });
  153. },
  154. handleExport(){
  155. var data;
  156. if(this.userIds!=undefined){
  157. data={type:this.value,userIds:this.userIds+"",deptId:this.deptId}
  158. }
  159. else{
  160. data={type:this.value,deptId:this.deptId}
  161. }
  162. exportCustomerNum(data).then((response) => {
  163. console.log(response)
  164. this.download(response.msg);
  165. });
  166. },
  167. getUserListByDeptId() {
  168. this.userIds=undefined;
  169. var data={deptId:this.deptId};
  170. getUserListByDeptId(data).then(response => {
  171. this.users = response.data;
  172. });
  173. },
  174. customer(){
  175. var data;
  176. if(this.userIds!=undefined){
  177. data={type:this.value,userIds:this.userIds+"",deptId:this.deptId}
  178. }
  179. else{
  180. data={type:this.value,deptId:this.deptId}
  181. }
  182. customerNum(data).then((response) => {
  183. this.list=response.list;
  184. this.dates=response.dates;
  185. this.customerOkNum=response.customerOkNum;
  186. this.customerNum=response.customerNum;
  187. setTimeout(() => {
  188. this.initEchart();
  189. }, 500);
  190. });
  191. },
  192. initEchart(){
  193. var option = {
  194. tooltip: {
  195. trigger: 'axis',
  196. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  197. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  198. }
  199. },
  200. legend: {
  201. data: ['成交客户数', '新增客户数' ]
  202. },
  203. grid: {
  204. left: '3%',
  205. right: '4%',
  206. bottom: '3%',
  207. containLabel: true
  208. },
  209. xAxis: [
  210. {
  211. type: 'category',
  212. data: this.dates
  213. }
  214. ],
  215. yAxis: [
  216. {
  217. type: 'value',
  218. axisLabel:{
  219. formatter:'{value}'
  220. }
  221. }
  222. ],
  223. series: [
  224. {
  225. name: '成交客户数',
  226. type: 'line',
  227. emphasis: {
  228. focus: 'series'
  229. },
  230. data: this.customerOkNum
  231. },
  232. {
  233. name: '新增客户数',
  234. type: 'line',
  235. emphasis: {
  236. focus: 'series'
  237. },
  238. data: this.customerNum
  239. }
  240. ]
  241. };
  242. this.chart=echarts.init(document.getElementById("echart-customer"));
  243. this.chart.setOption(option,true);
  244. },
  245. getSummaries(param) {
  246. const { columns, data } = param;
  247. const sums = [];
  248. columns.forEach((column, index) => {
  249. if (index === 0) {
  250. sums[index] = '总计';
  251. return;
  252. }
  253. const values = data.map(item => Number(item[column.property]));
  254. if (!values.every(value => isNaN(value))) {
  255. sums[index] = values.reduce((prev, curr) => {
  256. const value = Number(curr);
  257. if (!isNaN(value)) {
  258. return prev + curr;
  259. } else {
  260. return prev;
  261. }
  262. }, 0);
  263. sums[index] += ' ';
  264. } else {
  265. sums[index] = '';
  266. }
  267. });
  268. return sums;
  269. }
  270. }
  271. }
  272. </script>
  273. <style lang="scss" scoped>
  274. .app-container{
  275. border: 1px solid #e6e6e6;
  276. padding: 12px;
  277. .app-content{
  278. background-color: white;
  279. .title{
  280. padding: 20px 30px 0px 30px;
  281. font-size: 18px;
  282. font-weight: bold;
  283. color: black;
  284. }
  285. .search-form{
  286. margin: 20px 30px 0px 30px;
  287. }
  288. .data-box{
  289. padding: 30px;
  290. background-color: rgb(255, 255, 255);
  291. height: 100%;
  292. .echart-box{
  293. margin: 0 auto;
  294. text-align: center;
  295. }
  296. .el-select{
  297. margin: 5px 10px;
  298. }
  299. .table-box{
  300. margin-top: 15px;
  301. .export{
  302. float: right;
  303. margin: 10px 0px;
  304. }
  305. }
  306. }
  307. }
  308. }
  309. #echart-customer{
  310. width:100%;
  311. height:320px
  312. }
  313. .vue-treeselect{
  314. width: 217px;
  315. height: 36px;
  316. }
  317. </style>
  318. <style>
  319. .vue-treeselect__control{
  320. display: block;
  321. }
  322. </style>