contract.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar title="合同统计" />
  6. <view class="filter-tab">
  7. <view class="filter-box user" @click="handleOpenFilter('userOrDept')">
  8. <text class="text">
  9. {{ filterDataTypeLabel }}
  10. </text>
  11. <text class="icon" />
  12. </view>
  13. <view class="line" />
  14. <view class="filter-box time" @click="handleOpenFilter('time')">
  15. <text class="text">
  16. {{ filterTimeLabel }}
  17. </text>
  18. <text class="icon" />
  19. </view>
  20. </view>
  21. <scroll-view
  22. scroll-y
  23. class="container">
  24. <view class="statistics">
  25. <view class="row">
  26. <view class="column">
  27. <view class="text">
  28. <text class="number yellow">
  29. {{ statisticsData.contractMoney }}
  30. </text>
  31. </view>
  32. <view class="desc">
  33. 合同总金额
  34. </view>
  35. </view>
  36. <view class="line" />
  37. <view class="column">
  38. <view class="text">
  39. <text class="number yellow">
  40. {{ statisticsData.receivablesMoney }}
  41. </text>
  42. </view>
  43. <view class="desc">
  44. 回款总金额
  45. </view>
  46. </view>
  47. </view>
  48. <view class="row">
  49. <view class="column">
  50. <view class="text">
  51. <text class="number">
  52. {{ statisticsData.allContract }}
  53. </text>
  54. <text class="unit">
  55. </text>
  56. </view>
  57. <view class="desc">
  58. 签约合同数
  59. </view>
  60. </view>
  61. <view class="line" />
  62. <view class="column">
  63. <view class="text">
  64. <text class="number">
  65. {{ statisticsData.dealCustomer }}
  66. </text>
  67. <text class="unit">
  68. </text>
  69. </view>
  70. <view class="desc">
  71. 成交客户数
  72. </view>
  73. </view>
  74. </view>
  75. <view class="row">
  76. <view class="column">
  77. <view class="text">
  78. <text class="number">
  79. {{ statisticsData.endContract }}
  80. </text>
  81. <text class="unit">
  82. </text>
  83. </view>
  84. <view class="desc">
  85. 已到期的合同
  86. </view>
  87. </view>
  88. <view class="line" />
  89. <view class="column">
  90. <view class="text">
  91. <text class="number">
  92. {{ statisticsData.expireContract }}
  93. </text>
  94. <text class="unit">
  95. </text>
  96. </view>
  97. <view class="desc">
  98. 即将到期的合同
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="section-item">
  104. <view class="section-title">
  105. <view class="left">
  106. <image :src="$static('images/home/icon_statis.png')" class="icon" />
  107. <text class="text">
  108. 趋势分析
  109. </text>
  110. </view>
  111. </view>
  112. <view class="chart-core">
  113. <!--#ifdef MP-ALIPAY -->
  114. <canvas
  115. id="contractStatistics"
  116. canvas-id="contractStatistics"
  117. type="2d"
  118. class="charts"
  119. :width="cWidth*pixelRatio"
  120. :height="cHeight*pixelRatio"
  121. :style="{'width':cWidth+'px','height':cHeight+'px'}"
  122. @touchstart="touchMix"
  123. @touchmove="moveMix"
  124. @touchend="touchEndMix" />
  125. <!--#endif-->
  126. <!--#ifndef MP-ALIPAY -->
  127. <canvas
  128. id="contractStatistics"
  129. :style="{
  130. width: cWidth + 'px',
  131. height: cHeight + 'px'
  132. }"
  133. canvas-id="contractStatistics"
  134. type="2d"
  135. class="charts"
  136. :disable-scroll="true"
  137. @touchstart="touchMix"
  138. @touchmove="moveMix"
  139. @touchend="touchEndMix" />
  140. <!--#endif-->
  141. </view>
  142. </view>
  143. <!-- <view class="section-item">
  144. <view class="section-title">
  145. <view class="left">
  146. <image :src="$static('images/home/icon_statis.png')" class="icon"></image>
  147. <text class="text">合同类型分析</text>
  148. </view>
  149. </view>
  150. <view class="section-body">
  151. <view class="cell">
  152. <view class="cell-left">直销合同</view>
  153. <view class="cell-right">5单(¥50052)</view>
  154. </view>
  155. <view class="cell">
  156. <view class="cell-left">代理合同</view>
  157. <view class="cell-right">155单(¥50052)</view>
  158. </view>
  159. <view class="cell">
  160. <view class="cell-left">服务合同</view>
  161. <view class="cell-right">15单(¥50052)</view>
  162. </view>
  163. <view class="cell">
  164. <view class="cell-left">快销合同</view>
  165. <view class="cell-right">32单(¥50052)</view>
  166. </view>
  167. </view>
  168. </view> -->
  169. </scroll-view>
  170. <uni-popup
  171. ref="filterPopup"
  172. :mask-click="filterPopupMaskFlag"
  173. radius="20rpx 20rpx 0 0"
  174. type="bottom"
  175. @mask-close="filterMaskClick">
  176. <workbench-filter
  177. ref="workbenchFilter"
  178. :filter-data="filterObj"
  179. :default-tab="filterDefaultTab"
  180. @popup-change="childPopupChange"
  181. @change="handleChangeFilter"
  182. @close="handleCloseFilter" />
  183. </uni-popup>
  184. </view>
  185. </view>
  186. </template>
  187. <script>
  188. import { crmInstrumentSalesTrend, QueryDataInfo } from 'API/crm/work'
  189. import WorkbenchFilter from '@/components/base/workbench-filter.vue'
  190. import mixins from './mixins.js'
  191. import uCharts from '@/components/u-charts/u-charts.js'
  192. let contractStatisticsChart = null
  193. export default {
  194. name: 'ContractStatistics',
  195. components: {
  196. WorkbenchFilter
  197. },
  198. mixins: [mixins],
  199. data() {
  200. return {
  201. statisticsData: {},
  202. chartInstance: null,
  203. }
  204. },
  205. mounted() {
  206. const _self = this;
  207. // #ifdef MP-ALIPAY
  208. uni.getSystemInfo({
  209. success: function(res) {
  210. if (res.pixelRatio > 1) {
  211. // 正常这里给2就行,如果pixelRatio=3性能会降低一点
  212. // _self.pixelRatio =res.pixelRatio;
  213. _self.pixelRatio = 2;
  214. }
  215. }
  216. });
  217. // #endif
  218. this.cWidth = uni.upx2px(686)
  219. this.cHeight = uni.upx2px(450)
  220. this.getData()
  221. },
  222. methods: {
  223. getData() {
  224. if (this.loading) return
  225. this.loading = true
  226. QueryDataInfo({
  227. ...this.filterData
  228. }).then(res => {
  229. this.loading = false
  230. this.statisticsData = res
  231. }).catch(() => {
  232. this.loading = false
  233. })
  234. Promise.all([
  235. crmInstrumentSalesTrend({
  236. ...this.filterData,
  237. type: 1 // 合同
  238. }),
  239. crmInstrumentSalesTrend({
  240. ...this.filterData,
  241. type: 2 // 回款
  242. }),
  243. ]).then(resArr => {
  244. console.log('resArr', resArr)
  245. if (resArr[0][0].type.length >= 8) {
  246. this.forMatter(resArr)
  247. }
  248. this.loading = false
  249. const contractList = resArr[0]
  250. const refundList = resArr[1]
  251. const data = []
  252. contractList.forEach(item => {
  253. const findRes = refundList.find(o => o.type === item.type)
  254. if (findRes) {
  255. data.push({
  256. type: item.type,
  257. contractMoney: item.money,
  258. refundMoney: findRes.money
  259. })
  260. }
  261. })
  262. this.initChart('contractStatistics', data)
  263. }).catch(() => {
  264. this.loading = false
  265. })
  266. },
  267. forMatter(res) {
  268. res.forEach(item => {
  269. item.forEach(val => {
  270. val.type = val.type.split(' ')[0]
  271. })
  272. })
  273. },
  274. initChart(canvasId, chartData) {
  275. const _self = this
  276. const options = {
  277. $this: _self,
  278. canvasId: canvasId,
  279. width: _self.cWidth * _self.pixelRatio,
  280. height: _self.cHeight * _self.pixelRatio,
  281. type: 'column',
  282. pixelRatio: _self.pixelRatio,
  283. background: '#FFFFFF',
  284. fontSize: 11,
  285. animation: true,
  286. dataLabel: false,
  287. padding: [15, 0, 0, 0],
  288. legend: { // 图例
  289. show: true,
  290. position: 'bottom',
  291. float: 'center'
  292. },
  293. xAxis: {
  294. labelCount: 5,
  295. axisLine: false,
  296. disableGrid: true,
  297. itemCount: 3,
  298. scrollShow: true,
  299. scrollAlign: 'left'
  300. },
  301. yAxis: {
  302. gridType: 'dash',
  303. min: 0
  304. },
  305. enableScroll: true,
  306. extra: {
  307. column: {
  308. type: 'group',
  309. width: 15
  310. }
  311. },
  312. categories: chartData.map(o => o.type),
  313. series: [
  314. {
  315. name: '合同总金额',
  316. color: '#6ca2ff',
  317. data: chartData.map(o => o.contractMoney),
  318. type: 'column'
  319. },
  320. {
  321. name: '回款总金额',
  322. color: '#FF7300',
  323. data: chartData.map(o => o.refundMoney),
  324. type: 'column'
  325. },
  326. ]
  327. }
  328. // #ifdef MP-WEIXIN
  329. this.$nextTick(function() {
  330. const query = uni.createSelectorQuery().in(this)
  331. query.select('#' + canvasId)
  332. .fields({ node: true, size: true })
  333. .exec(res => {
  334. // console.log('res: ', res[0])
  335. const data = res[0]
  336. const canvas = res[0].node
  337. const ctx = canvas.getContext('2d')
  338. options.context = ctx
  339. options.canvas2d = true
  340. const dpr = wx.getSystemInfoSync().pixelRatio
  341. options.width = _self.cWidth * dpr
  342. options.height = _self.cHeight * dpr
  343. options.pixelRatio = dpr
  344. options.extra.column.width = options.extra.column.width * dpr
  345. canvas.width = options.width
  346. canvas.height = options.height
  347. // eslint-disable-next-line new-cap
  348. contractStatisticsChart = new uCharts(options)
  349. })
  350. })
  351. // #endif
  352. // #ifndef MP-WEIXIN
  353. // eslint-disable-next-line new-cap
  354. contractStatisticsChart = new uCharts(options)
  355. // #endif
  356. },
  357. touchMix(e) {
  358. contractStatisticsChart.scrollStart(e);
  359. },
  360. moveMix(e) {
  361. contractStatisticsChart.scroll(e);
  362. },
  363. touchEndMix(e) {
  364. contractStatisticsChart.scrollEnd(e);
  365. contractStatisticsChart.touchLegend(e);
  366. // 下面是toolTip事件,如果滚动后不需要显示,可不填写
  367. contractStatisticsChart.showToolTip(e, {
  368. format: function(item, category) {
  369. // console.log(item)
  370. return category + ' ' + item.name + ':' + item.data + '元'
  371. }
  372. });
  373. }
  374. }
  375. }
  376. </script>
  377. <style scoped lang="scss">
  378. @import "./style.scss";
  379. .section-body {
  380. padding-top: 15rpx;
  381. .cell {
  382. width: 100%;
  383. font-size: $wk-font-base;
  384. padding: 20rpx 0;
  385. @include left;
  386. .cell-left {
  387. width: 200rpx;
  388. color: $dark;
  389. }
  390. .cell-right {
  391. flex: 1;
  392. color: $gray;
  393. @include right;
  394. }
  395. }
  396. }
  397. </style>