list.vue 14 KB

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