customerCountList.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false" class="customerCountList-wrap searchBoxNormal">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper" ref="tableSearch">
  6. <a-form-model
  7. id="customerCountList-form"
  8. ref="ruleForm"
  9. class="form-model-con"
  10. layout="inline"
  11. :model="queryParam">
  12. <a-row :gutter="15">
  13. <a-col :md="6" :sm="24">
  14. <a-form-model-item label="月份" required>
  15. <a-range-picker
  16. id="customerCountList-monthBox"
  17. class="monthBox"
  18. :placeholder="['开始月份', '结束月份']"
  19. format="YYYY-MM"
  20. v-model="monthVal"
  21. :mode="mode"
  22. @panelChange="handlePanelChange"
  23. />
  24. </a-form-model-item>
  25. </a-col>
  26. <a-col :md="6" :sm="24">
  27. <a-form-model-item label="客户名称">
  28. <dealerSubareaScopeList ref="dealerSubareaScopeList" id="customerCountList-dealerName" @change="custChange" />
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-model-item label="客户级别">
  33. <v-select
  34. v-model="queryParam.dealerLevel"
  35. ref="dealerLevel"
  36. id="customerCountList-dealerLevel"
  37. code="DEALER_LEVEL"
  38. placeholder="请选择客户级别"
  39. allowClear></v-select>
  40. </a-form-model-item>
  41. </a-col>
  42. <template v-if="advanced">
  43. <a-col :md="6" :sm="24">
  44. <a-form-item label="所在区域">
  45. <subarea id="customerCountList-subarea" ref="subarea" @change="subareaChange"></subarea>
  46. </a-form-item>
  47. </a-col>
  48. <a-col :md="6" :sm="24">
  49. <a-form-model-item label="区域负责人">
  50. <BizUser id="customerCountList-bizUserSn" v-model="queryParam.subareaArea.bizUserSn"></BizUser>
  51. </a-form-model-item>
  52. </a-col>
  53. <a-col :md="6" :sm="24">
  54. <a-form-model-item label="地区">
  55. <AreaList id="customerCountList-areaList" changeOnSelect ref="areaList" @change="areaChange" defValKey="id"></AreaList>
  56. </a-form-model-item>
  57. </a-col>
  58. <a-col :md="6" :sm="24">
  59. <a-form-model-item label="客服">
  60. <customerService ref="customerName" id="customerCountList-customerName" v-model="queryParam.subareaArea.kfSn"></customerService>
  61. </a-form-model-item>
  62. </a-col>
  63. </template>
  64. <a-col :md="6" :sm="24">
  65. <a-button
  66. type="primary"
  67. @click="handleSearch"
  68. :disabled="disabled"
  69. id="customerCountList-refresh">查询</a-button>
  70. <a-button
  71. style="margin-left: 8px"
  72. @click="resetSearchForm"
  73. :disabled="disabled"
  74. id="customerCountList-reset">重置</a-button>
  75. <a-button
  76. style="margin-left: 10px"
  77. type="primary"
  78. class="button-warning"
  79. @click="handleExport"
  80. :disabled="disabled"
  81. :loading="exportLoading"
  82. v-if="$hasPermissions('B_billingStatisticsExport')"
  83. id="customerCountList-export">导出</a-button>
  84. <a @click="advanced=!advanced" style="margin-left: 5px">
  85. {{ advanced ? '收起' : '展开' }}
  86. <a-icon :type="advanced ? 'up' : 'down'" />
  87. </a>
  88. </a-col>
  89. </a-row>
  90. </a-form-model>
  91. </div>
  92. </a-card>
  93. <a-card size="small" :bordered="false">
  94. <a-spin :spinning="spinning" tip="Loading...">
  95. <!-- 列表 -->
  96. <s-table
  97. class="sTable fixPagination"
  98. ref="table"
  99. size="small"
  100. :rowKey="(record) => record.no"
  101. rowKeyName="no"
  102. :style="{ height: tableHeight+70+'px' }"
  103. :columns="columns"
  104. :data="loadData"
  105. :scroll="{x:2200, y: tableHeight-130}"
  106. :defaultLoadData="false"
  107. bordered>
  108. <template slot="footer" v-if="totalData&&totalData.length">
  109. <a-row :gutter="15">
  110. <a-col span="24">合计:</a-col>
  111. <a-col span="24">
  112. <a-col span="4" v-for="item in totalData" :key="item.key">
  113. {{ item.title }}:{{ item[item.key] ||item[item.key] ==0?toThousands(item[item.key]) :'--' }}
  114. </a-col>
  115. </a-col>
  116. </a-row>
  117. </template>
  118. </s-table>
  119. </a-spin>
  120. </a-card>
  121. </div>
  122. </template>
  123. <script>
  124. import { commonMixin } from '@/utils/mixin'
  125. import { hdExportExcel } from '@/libs/exportExcel'
  126. import moment from 'moment'
  127. // 组件
  128. import { STable, VSelect } from '@/components'
  129. import subarea from '@/views/common/subarea.js'
  130. import AreaList from '@/views/common/areaList.js'
  131. import dealerSubareaScopeList from '@/views/common/dealerSubareaScopeList.vue'
  132. import BizUser from '@/views/common/bizUser.js'
  133. import customerService from '@/views/common/customerService.vue'
  134. // 接口
  135. import { salesStatsDealerList, salesStatsDealerCount, salesStatsDealerExport } from '@/api/reportData'
  136. export default {
  137. name: 'CustomerCountList',
  138. mixins: [commonMixin],
  139. components: { STable, VSelect, subarea, AreaList, dealerSubareaScopeList, BizUser, customerService },
  140. props: {
  141. removeReportFlag: {
  142. type: [String, Number],
  143. default: '0'
  144. },
  145. tableTitle: {
  146. type: Object,
  147. default: () => {}
  148. }
  149. },
  150. data () {
  151. return {
  152. spinning: false,
  153. disabled: false, // 查询、重置按钮是否可操作
  154. advanced: true, // 高级搜索 展开/关闭
  155. tableHeight: 0, // 表格高度
  156. exportLoading: false, // 导出按钮加载状态
  157. monthVal: [moment().format('YYYY-MM'), moment().format('YYYY-MM')], // 初始化月份值
  158. mode: ['month', 'month'],
  159. // 查询条件
  160. queryParam: {
  161. beginDate: '', // 月份开始时间
  162. endDate: '', // 月份结束时间
  163. dealerLevel: undefined, // 客户等级
  164. dealerSn: undefined, // 客户sn
  165. dealerName: undefined, // 客户名称
  166. provinceSn: undefined, // 省
  167. citySn: undefined, // 市
  168. districtSn: undefined, // 区
  169. subareaArea: {
  170. subareaSn: '', // 区域
  171. subareaAreaSn: '', // 分区
  172. bizUserSn: undefined, // 区域负责人
  173. kfSn: undefined// 客服
  174. }
  175. },
  176. columns: [], // 表格 列数据
  177. totalData: null, // 合计
  178. // 加载数据方法 必须为 Promise 对象
  179. loadData: parameter => {
  180. this.disabled = true
  181. this.spinning = true
  182. if (this.monthVal) {
  183. this.queryParam.beginDate = this.getMonthRange(this.monthVal[0]).firstDay
  184. this.queryParam.endDate = this.getMonthRange(this.monthVal[1]).lastDay
  185. } else {
  186. this.queryParam.beginDate = undefined
  187. this.queryParam.endDate = undefined
  188. }
  189. const params = Object.assign(parameter, this.queryParam)
  190. params.removeReportFlag = this.removeReportFlag
  191. // 获取列表数据 有分页
  192. return salesStatsDealerList(params).then(res => {
  193. let data
  194. if (res.status == 200) {
  195. data = res.data
  196. // 计算表格序号
  197. const no = (data.pageNo - 1) * data.pageSize
  198. for (var i = 0; i < data.list.length; i++) {
  199. data.list[i].no = no + i + 1
  200. }
  201. this.disabled = false
  202. this.getCount(params)
  203. }
  204. this.spinning = false
  205. return data
  206. })
  207. }
  208. }
  209. },
  210. watch: {
  211. advanced (newValue, oldValue) {
  212. const _this = this
  213. this.$nextTick(() => { // 页面渲染完成后的回调
  214. _this.setTableH()
  215. })
  216. },
  217. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  218. this.setTableH()
  219. }
  220. },
  221. methods: {
  222. handlePanelChange (value, mode) {
  223. this.monthVal = value
  224. this.mode = [mode[0] === 'date' ? 'month' : mode[0], mode[1] === 'date' ? 'month' : mode[1]]
  225. },
  226. // 获取指定月份 第一天和最后一天
  227. getMonthRange (targetMonth) {
  228. // 获取指定月第一天(格式化为 YYYY-MM-DD)
  229. const firstDay = moment(targetMonth).startOf('month').format('YYYY-MM-DD') + ' 00:00:00'
  230. // 获取指定月最后一天(格式化为 YYYY-MM-DD)
  231. const lastDay = moment(targetMonth).endOf('month').format('YYYY-MM-DD') + ' 23:59:59'
  232. return { firstDay, lastDay }
  233. },
  234. // 获取表头
  235. async getTableTitle () {
  236. const _this = this
  237. this.columns = _this.tableTitle.list
  238. this.countLabel = _this.tableTitle.count
  239. this.columns.map(item => {
  240. item.titleNum = item.title
  241. const mw = item.customRender == 'amount' ? 15 : 17
  242. const textLen = typeof item.title === 'string' ? item.title.length : (item.title.children && item.title.children[0].text && item.title.children[0].text.length)
  243. const w = textLen * mw
  244. const tw = w <= 80 ? mw * 5 : w
  245. if (item.customRender == 'amount') {
  246. if (item.colour && item.colour === 'red') {
  247. item.title = <span style="color:red;">{ item.title }</span>
  248. item.customRender = (text) => { return <span style="color:red;">{(text || text == 0) ? _this.toThousands(text) : '--'}</span> }
  249. } else {
  250. item.customRender = function (text) { return (text || text == 0) ? _this.toThousands(text) : '--' }
  251. }
  252. } else {
  253. item.customRender = function (text) { return text || '--' }
  254. }
  255. item.width = tw + 'px'
  256. this.tableWidth = this.tableWidth + tw
  257. })
  258. this.resetSearchForm()
  259. },
  260. // 查询
  261. handleSearch () {
  262. const date = this.monthVal
  263. if (date && date[0] && date[1]) {
  264. this.$refs.table.refresh(true)
  265. } else {
  266. this.$message.error('请选择查询月份')
  267. }
  268. },
  269. // 客户名称 change
  270. custChange (val) {
  271. this.queryParam.dealerName = val.name
  272. this.queryParam.dealerSn = val.key
  273. },
  274. // 统计
  275. getCount (params) {
  276. salesStatsDealerCount(params).then(res => {
  277. if (res.status == 200 && res.data) {
  278. const mergedList = this.countLabel.map(item => {
  279. const key = item.key
  280. return key in res.data
  281. ? { ...item, [key]: res.data[key] }
  282. : item
  283. })
  284. this.totalData = mergedList
  285. } else {
  286. this.totalData = null
  287. }
  288. })
  289. },
  290. // 地区
  291. areaChange (val) {
  292. this.queryParam.provinceSn = val[0] ? val[0] : undefined
  293. this.queryParam.citySn = val[1] ? val[1] : undefined
  294. this.queryParam.districtSn = val[2] ? val[2] : undefined
  295. },
  296. // 区域分区 change
  297. subareaChange (val) {
  298. this.queryParam.subareaArea.subareaSn = val[0] ? val[0] : ''
  299. this.queryParam.subareaArea.subareaAreaSn = val[1] ? val[1] : ''
  300. },
  301. // 重置
  302. resetSearchForm () {
  303. this.queryParam.beginDate = ''
  304. this.queryParam.endDate = ''
  305. this.monthVal = [moment().format('YYYY-MM'), moment().format('YYYY-MM')]
  306. this.queryParam.provinceSn = undefined
  307. this.queryParam.citySn = undefined
  308. this.queryParam.districtSn = undefined
  309. this.queryParam.dealerName = undefined
  310. this.queryParam.dealerSn = undefined
  311. this.queryParam.bizUserSn = undefined
  312. this.queryParam.subareaArea.subareaSn = ''
  313. this.queryParam.subareaArea.subareaAreaSn = ''
  314. this.queryParam.subareaArea.bizUserSn = undefined
  315. this.queryParam.subareaArea.kfSn = undefined
  316. this.queryParam.dealerLevel = undefined
  317. if (this.advanced) {
  318. this.$refs.subarea.clearData()
  319. this.$refs.dealerSubareaScopeList.resetForm()
  320. this.$refs.areaList.clearData()
  321. }
  322. this.totalData = null
  323. this.$refs.table.clearTable()
  324. this.$refs.ruleForm.resetFields()
  325. },
  326. // 导出 必填判断
  327. handleExport () {
  328. const _this = this
  329. this.$refs.ruleForm.validate(valid => {
  330. if (valid) {
  331. _this.exportList()
  332. } else {
  333. _this.$message.error('请选择查询月份')
  334. return false
  335. }
  336. })
  337. },
  338. // 导出
  339. exportList () {
  340. const _this = this
  341. const params = JSON.parse(JSON.stringify(_this.queryParam))
  342. params.removeReportFlag = this.removeReportFlag
  343. _this.exportLoading = true
  344. _this.spinning = true
  345. hdExportExcel(salesStatsDealerExport, params, '开单统计报表(客户)', function () {
  346. _this.exportLoading = false
  347. _this.spinning = false
  348. })
  349. },
  350. // 初始化
  351. pageInit () {
  352. this.$nextTick(() => { // 页面渲染完成后的回调
  353. this.setTableH()
  354. this.resetSearchForm()
  355. this.getTableTitle()
  356. })
  357. },
  358. // 计算表格高度
  359. setTableH () {
  360. const tableSearchH = this.$refs.tableSearch.offsetHeight
  361. this.tableHeight = window.innerHeight - tableSearchH - 280
  362. }
  363. },
  364. mounted () {
  365. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  366. this.pageInit()
  367. }
  368. },
  369. activated () {
  370. // 如果是新页签打开,则重置当前页面
  371. if (this.$store.state.app.isNewTab) {
  372. this.pageInit()
  373. }
  374. }
  375. }
  376. </script>
  377. <style lang="less" scoped>
  378. .monthBox{
  379. width: 100%;
  380. /deep/.ant-calendar-picker-icon{
  381. display:none !important;
  382. }
  383. /deep/.ant-calendar-picker input{
  384. text-align:center;
  385. }
  386. }
  387. </style>