business.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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.businessMoney }}
  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">
  40. {{ statisticsData.allBusiness }}
  41. </text>
  42. <text class="unit">
  43. </text>
  44. </view>
  45. <view class="desc">
  46. 商机总数
  47. </view>
  48. </view>
  49. </view>
  50. <view class="row">
  51. <view class="column">
  52. <view class="text">
  53. <text class="number">
  54. {{ statisticsData.endBusiness }}
  55. </text>
  56. <text class="unit">
  57. </text>
  58. </view>
  59. <view class="desc">
  60. 赢单
  61. </view>
  62. </view>
  63. <view class="line" />
  64. <view class="column">
  65. <view class="text">
  66. <text class="number">
  67. {{ statisticsData.loseBusiness }}
  68. </text>
  69. <text class="unit">
  70. </text>
  71. </view>
  72. <view class="desc">
  73. 输单
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <view class="section-item">
  79. <view class="section-title">
  80. <view class="left">
  81. <image :src="$static('images/home/icon_funnel.png')" class="icon" />
  82. <text class="text">
  83. 销售漏斗
  84. </text>
  85. </view>
  86. <wk-drop
  87. v-if="dropOptions.length > 0"
  88. v-model="dropVal"
  89. :list="dropOptions"
  90. @change="handleDropChange" />
  91. </view>
  92. <view class="chart-core">
  93. <!--#ifdef MP-ALIPAY -->
  94. <canvas
  95. id="funnelChart"
  96. canvas-id="funnelChart"
  97. class="charts"
  98. :width="cWidth*pixelRatio"
  99. :height="cHeight*pixelRatio"
  100. :style="{'width':cWidth+'px','height':cHeight+'px'}"
  101. @touchstart="touchPie" />
  102. <!--#endif-->
  103. <!--#ifndef MP-ALIPAY -->
  104. <canvas
  105. id="funnelChart"
  106. :style="{
  107. width: cWidth + 'px',
  108. height: cHeight + 'px'
  109. }"
  110. canvas-id="funnelChart"
  111. type="2d"
  112. class="charts"
  113. @touchstart="touchPie" />
  114. <!--#endif-->
  115. </view>
  116. <view class="info-box">
  117. <view class="box">
  118. <text class="info" style="color: #FF7300">
  119. {{ funnelData.winSingle || '0.00' }}元
  120. </text>
  121. <text class="mini-title">
  122. 赢单金额
  123. </text>
  124. </view>
  125. <view class="box">
  126. <text class="info">
  127. {{ funnelData.loseSingle || '0.00' }}元
  128. </text>
  129. <text class="mini-title">
  130. 输单金额
  131. </text>
  132. </view>
  133. </view>
  134. </view>
  135. </scroll-view>
  136. <uni-popup
  137. ref="filterPopup"
  138. :mask-click="filterPopupMaskFlag"
  139. radius="20rpx 20rpx 0 0"
  140. type="bottom"
  141. @mask-close="filterMaskClick">
  142. <workbench-filter
  143. ref="workbenchFilter"
  144. :filter-data="filterObj"
  145. :default-tab="filterDefaultTab"
  146. @popup-change="childPopupChange"
  147. @change="handleChangeFilter"
  148. @close="handleCloseFilter" />
  149. </uni-popup>
  150. </view>
  151. </view>
  152. </template>
  153. <script>
  154. import { crmInstrumentSellFunnel, QueryDataInfo } from 'API/crm/work'
  155. import { BusinessStatusOptions } from 'API/crm/business'
  156. import WorkbenchFilter from '@/components/base/workbench-filter.vue'
  157. import mixins from './mixins.js'
  158. import uCharts from '@/components/u-charts/u-charts.js'
  159. let funnelStatisticsChart = null
  160. export default {
  161. name: 'BusinessStatistics',
  162. components: {
  163. WorkbenchFilter
  164. },
  165. mixins: [mixins],
  166. data() {
  167. return {
  168. statisticsData: {},
  169. funnelChart: null,
  170. funnelData: {},
  171. dropVal: null,
  172. dropOptions: []
  173. }
  174. },
  175. mounted() {
  176. const _self = this;
  177. // #ifdef MP-ALIPAY
  178. uni.getSystemInfo({
  179. success: function(res) {
  180. if (res.pixelRatio > 1) {
  181. // 正常这里给2就行,如果pixelRatio=3性能会降低一点
  182. // _self.pixelRatio =res.pixelRatio;
  183. _self.pixelRatio = 2;
  184. }
  185. }
  186. });
  187. // #endif
  188. this.cWidth = uni.upx2px(710);
  189. this.cHeight = uni.upx2px(380);
  190. this.getBusinessOptions();
  191. },
  192. methods: {
  193. getBusinessOptions() {
  194. if (this.loading) return
  195. this.loading = true
  196. BusinessStatusOptions().then(res => {
  197. console.log(res, 'res', true)
  198. this.loading = false
  199. if (res.length > 0) {
  200. this.handleDropChange(res[0].flowId)
  201. this.dropOptions = res.map(item => {
  202. return {
  203. label: item.flowName,
  204. value: item.flowId
  205. }
  206. })
  207. }
  208. }).catch(() => {
  209. this.loading = false
  210. })
  211. },
  212. getData() {
  213. if (this.loading) return
  214. this.loading = true
  215. QueryDataInfo({
  216. ...this.filterData
  217. }).then(res => {
  218. this.loading = false
  219. this.statisticsData = res
  220. }).catch(() => {
  221. this.loading = false
  222. })
  223. crmInstrumentSellFunnel({
  224. ...this.filterData,
  225. typeId: this.dropVal
  226. }).then(res => {
  227. this.loading = false
  228. console.log('销售漏斗:', res)
  229. res.forEach(item => {
  230. if (item.settingName == '赢单') {
  231. this.funnelData['winSingle'] = item.businessMoney
  232. } else if (item.settingName == '输单') {
  233. this.funnelData['loseSingle'] = item.businessMoney
  234. }
  235. })
  236. this.initChart('funnelChart', res || [])
  237. }).catch(() => {
  238. this.loading = false
  239. })
  240. },
  241. handleDropChange(typeId) {
  242. console.log('handleDropChange', typeId)
  243. this.dropVal = typeId
  244. this.getData()
  245. },
  246. initChart(canvasId, chartData) {
  247. const _self = this
  248. const seriesData = chartData.map((o, i) => {
  249. return {
  250. name: o.settingName,
  251. data: o.businessNum,
  252. money: o.businessMoney
  253. }
  254. })
  255. const options = {
  256. $this: _self,
  257. canvasId: canvasId,
  258. width: _self.cWidth * _self.pixelRatio,
  259. height: _self.cHeight * _self.pixelRatio,
  260. type: 'funnel',
  261. pixelRatio: _self.pixelRatio,
  262. background: '#FFFFFF',
  263. fontSize: 12,
  264. animation: false,
  265. dataLabel: true,
  266. extra: {
  267. funnel: {
  268. border: true,
  269. activeWidth: 5,
  270. borderWidth: 2,
  271. borderColor: '#FFFFFF'
  272. },
  273. tooltip: {}
  274. },
  275. series: seriesData
  276. }
  277. // #ifdef MP-WEIXIN
  278. this.$nextTick(function() {
  279. const query = uni.createSelectorQuery().in(this)
  280. query.select('#' + canvasId)
  281. .fields({ node: true, size: true })
  282. .exec(res => {
  283. // console.log('res: ', res[0])
  284. const data = res[0]
  285. const canvas = res[0].node
  286. const ctx = canvas.getContext('2d')
  287. options.context = ctx
  288. options.canvas2d = true
  289. const dpr = wx.getSystemInfoSync().pixelRatio
  290. options.width = _self.cWidth * dpr
  291. options.height = _self.cHeight * dpr
  292. options.pixelRatio = dpr
  293. canvas.width = options.width
  294. canvas.height = options.height
  295. // eslint-disable-next-line new-cap
  296. funnelStatisticsChart = new uCharts(options)
  297. })
  298. })
  299. // #endif
  300. // #ifndef MP-WEIXIN
  301. // eslint-disable-next-line new-cap
  302. funnelStatisticsChart = new uCharts(options)
  303. // #endif
  304. console.log('funnelChart', funnelStatisticsChart)
  305. },
  306. touchPie(e) {
  307. funnelStatisticsChart.showToolTip(e, {
  308. textList: [
  309. { text: '' },
  310. { text: '' }
  311. ],
  312. format: function(item, category) {
  313. console.log('item', item)
  314. console.log('category', category)
  315. this.textList = [
  316. { text: `${item.name}(${item.data})`, color: item.color },
  317. { text: `金额:${item.money}元`, color: null }
  318. ]
  319. return this.textList
  320. }
  321. })
  322. }
  323. }
  324. }
  325. </script>
  326. <style scoped lang="scss">
  327. @import "./style.scss";
  328. .info-box {
  329. width: 100%;
  330. @include center;
  331. .box {
  332. width: 40%;
  333. color: $dark;
  334. flex-direction: column;
  335. @include center;
  336. .info {
  337. font-weight: 500;
  338. font-size: 30rpx;
  339. }
  340. .mini-title {
  341. font-size: 24rpx;
  342. margin-top: 10rpx;
  343. }
  344. }
  345. }
  346. </style>