storePayment.vue 7.4 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 filterable v-model="userIds" placeholder="请选择员工" clearable size="small">
  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="storePayment">搜索</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="orderCount"
  54. label="订单数">
  55. </el-table-column>
  56. <el-table-column
  57. prop="payMoney"
  58. label="订单金额">
  59. </el-table-column>
  60. </el-table>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. </template>
  66. <script>
  67. import { storePayment,exportStorePayment } from "@/api/store/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. chart: null,
  89. options: [{
  90. value: '1',
  91. label: '今天'
  92. }, {
  93. value: '2',
  94. label: '昨天'
  95. }, {
  96. value: '3',
  97. label: '本周'
  98. }, {
  99. value: '4',
  100. label: '上周'
  101. }, {
  102. value: '5',
  103. label: '本月'
  104. }
  105. , {
  106. value: '6',
  107. label: '上月'
  108. }
  109. , {
  110. value: '7',
  111. label: '本季度'
  112. }
  113. , {
  114. value: '8',
  115. label: '上季度'
  116. }
  117. , {
  118. value: '9',
  119. label: '本年'
  120. }
  121. , {
  122. value: '10',
  123. label: '上年'
  124. }],
  125. value: '5',
  126. list:[],
  127. dates:[],
  128. orderCount:[],
  129. payMoney:[],
  130. }
  131. },
  132. created() {
  133. this.getTreeselect();
  134. },
  135. methods: {
  136. currDeptChange(val){
  137. console.log(val)
  138. this.deptId=val;
  139. this.getUserListByDeptId();
  140. },
  141. /** 查询部门下拉树结构 */
  142. getTreeselect() {
  143. var that=this;
  144. treeselect().then((response) => {
  145. this.deptOptions = response.data;
  146. console.log(this.deptOptions)
  147. if(response.data!=null&&response.data.length>0){
  148. this.deptId=response.data[0].id;
  149. that.storePayment()
  150. }
  151. });
  152. },
  153. handleExport(){
  154. var data;
  155. if(this.userIds!=undefined){
  156. data={type:this.value,userIds:this.userIds+"",deptId:this.deptId}
  157. }
  158. else{
  159. data={type:this.value,deptId:this.deptId}
  160. }
  161. exportStorePayment(data).then((response) => {
  162. console.log(response)
  163. this.download(response.msg);
  164. });
  165. },
  166. getUserListByDeptId() {
  167. this.userIds=undefined;
  168. var data={deptId:this.deptId};
  169. getUserListByDeptId(data).then(response => {
  170. this.users = response.data;
  171. });
  172. },
  173. storePayment(){
  174. var data;
  175. if(this.userIds!=undefined){
  176. data={type:this.value,userIds:this.userIds+"",deptId:this.deptId}
  177. }
  178. else{
  179. data={type:this.value,deptId:this.deptId}
  180. }
  181. storePayment(data).then((response) => {
  182. this.list=response.list;
  183. this.dates=response.dates;
  184. this.orderCount=response.orderCount;
  185. this.payMoney=response.payMoney;
  186. setTimeout(() => {
  187. this.initEchart();
  188. }, 500);
  189. });
  190. },
  191. initEchart(){
  192. var option = {
  193. tooltip: {
  194. trigger: 'axis',
  195. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  196. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  197. }
  198. },
  199. legend: {
  200. data: ['订单数', '订单金额' ]
  201. },
  202. grid: {
  203. left: '3%',
  204. right: '4%',
  205. bottom: '3%',
  206. containLabel: true
  207. },
  208. xAxis: [
  209. {
  210. type: 'category',
  211. data: this.dates
  212. }
  213. ],
  214. yAxis: [
  215. {
  216. type: 'value',
  217. axisLabel:{
  218. formatter:'{value}'
  219. }
  220. }
  221. ],
  222. series: [
  223. {
  224. name: '订单数',
  225. type: 'bar',
  226. emphasis: {
  227. focus: 'series'
  228. },
  229. data: this.orderCount
  230. },
  231. {
  232. name: '订单金额',
  233. type: 'bar',
  234. emphasis: {
  235. focus: 'series'
  236. },
  237. data: this.payMoney
  238. }
  239. ]
  240. };
  241. this.chart=echarts.init(document.getElementById("echart-customer"));
  242. this.chart.setOption(option,true);
  243. },
  244. getSummaries(param) {
  245. const { columns, data } = param;
  246. const sums = [];
  247. columns.forEach((column, index) => {
  248. if (index === 0) {
  249. sums[index] = '总计';
  250. return;
  251. }
  252. const values = data.map(item => Number(item[column.property]));
  253. if (!values.every(value => isNaN(value))) {
  254. sums[index] = values.reduce((prev, curr) => {
  255. const value = Number(curr);
  256. if (!isNaN(value)) {
  257. return prev + curr;
  258. } else {
  259. return prev;
  260. }
  261. }, 0);
  262. sums[index] += ' ';
  263. } else {
  264. sums[index] = '';
  265. }
  266. });
  267. return sums;
  268. }
  269. }
  270. }
  271. </script>
  272. <style lang="scss" scoped>
  273. .app-container{
  274. border: 1px solid #e6e6e6;
  275. padding: 12px;
  276. .app-content{
  277. background-color: white;
  278. .title{
  279. padding: 20px 30px 0px 30px;
  280. font-size: 18px;
  281. font-weight: bold;
  282. color: black;
  283. }
  284. .search-form{
  285. margin: 20px 30px 0px 30px;
  286. }
  287. .data-box{
  288. padding: 30px;
  289. background-color: rgb(255, 255, 255);
  290. height: 100%;
  291. .echart-box{
  292. margin: 0 auto;
  293. text-align: center;
  294. }
  295. .el-select{
  296. margin: 5px 10px;
  297. }
  298. .table-box{
  299. margin-top: 15px;
  300. .export{
  301. float: right;
  302. margin: 10px 0px;
  303. }
  304. }
  305. }
  306. }
  307. }
  308. #echart-customer{
  309. width:100%;
  310. height:320px
  311. }
  312. .vue-treeselect{
  313. width: 217px;
  314. height: 36px;
  315. }
  316. </style>
  317. <style>
  318. .vue-treeselect__control{
  319. display: block;
  320. }
  321. </style>