storePayment.vue 7.7 KB

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