list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <a-card size="small" :bordered="false" class="customerReportList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form-model
  7. id="customerReportList-form"
  8. ref="ruleForm"
  9. class="form-model-con"
  10. layout="inline"
  11. :model="queryParam"
  12. :rules="rules"
  13. :labelCol="labelCol"
  14. :wrapperCol="wrapperCol"
  15. @keyup.enter.native="handleSearch" >
  16. <a-row :gutter="15">
  17. <a-col :md="6" :sm="24">
  18. <a-form-model-item label="连锁店" prop="tenantId">
  19. <a-select
  20. placeholder="请选择连锁店"
  21. id="customerReportList-tenantId"
  22. allowClear
  23. v-model="queryParam.tenantId"
  24. :showSearch="true"
  25. option-filter-prop="children"
  26. :filter-option="filterOption">
  27. <a-select-option v-for="item in linkageGroupData" :key="item.dealerSn" :value="item.dealerSn">{{ item.dealerName }}</a-select-option>
  28. </a-select>
  29. </a-form-model-item>
  30. </a-col>
  31. <a-col :md="6" :sm="24">
  32. <a-form-model-item label="添加时间" prop="time">
  33. <rangeDate ref="rangeDate" @change="dateChange" />
  34. </a-form-model-item>
  35. </a-col>
  36. <a-col :md="6" :sm="24">
  37. <a-form-model-item label="产品分类">
  38. <a-cascader
  39. @change="changeProductType"
  40. change-on-select
  41. v-model="productType"
  42. expand-trigger="hover"
  43. :options="productTypeList"
  44. :fieldNames="{ label: 'productTypeName', value: 'productTypeSn', children: 'children' }"
  45. id="customerReportList-productType"
  46. placeholder="请选择产品分类"
  47. allowClear />
  48. </a-form-model-item>
  49. </a-col>
  50. <template v-if="advanced">
  51. <a-col :md="10" :sm="24">
  52. <a-row>
  53. <a-form-model-item label="客户所在区" :labelCol="{span: 4}" :wrapperCol="{ span: 20 }" style="margin-bottom: 0!important;">
  54. <a-col span="7">
  55. <a-form-model-item prop="provinceSn" style="margin: 0!important;">
  56. <a-select v-model="queryParam.provinceSn" allowClear @change="getCityList" placeholder="请选择省">
  57. <a-select-option v-for="item in addrProvinceList" :value="item.areaSn" :key="item.areaSn + 'a'">{{ item.name }}</a-select-option>
  58. </a-select>
  59. </a-form-model-item>
  60. </a-col>
  61. <a-col span="7" offset="1">
  62. <a-form-model-item prop="citySn" style="margin: 0!important;">
  63. <a-select v-model="queryParam.citySn" allowClear @change="getAreaList" placeholder="请选择市">
  64. <a-select-option v-for="item in addrCityList" :value="item.areaSn" :key="item.areaSn + 'b'">{{ item.name }}</a-select-option>
  65. </a-select>
  66. </a-form-model-item>
  67. </a-col>
  68. <a-col span="7" offset="1">
  69. <a-form-model-item prop="countySn" style="margin: 0!important;">
  70. <a-select v-model="queryParam.countySn" allowClear placeholder="请选择区/县">
  71. <a-select-option v-for="item in addrDistrictList" :value="item.areaSn" :key="item.areaSn + 'c'">{{ item.name }}</a-select-option>
  72. </a-select>
  73. </a-form-model-item>
  74. </a-col>
  75. </a-form-model-item>
  76. </a-row>
  77. </a-col>
  78. <a-col :md="4" :sm="24">
  79. <a-form-item label="客户类型">
  80. <custType v-model="queryParam.customerTypeSn" allowClear placeholder="请选择客户类型" style="max-width: 240px;"></custType>
  81. </a-form-item>
  82. </a-col>
  83. </template>
  84. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  85. <a-button type="primary" @click="handleSearch" :disabled="disabled" id="customerReportList-refresh">查询</a-button>
  86. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="customerReportList-reset">重置</a-button>
  87. <a @click="advanced=!advanced" style="margin-left: 5px">
  88. {{ advanced ? '收起' : '展开' }}
  89. <a-icon :type="advanced ? 'up' : 'down'"/>
  90. </a>
  91. </a-col>
  92. </a-row>
  93. </a-form-model>
  94. </div>
  95. <!-- 合计 -->
  96. <a-alert type="info" style="margin-bottom:10px">
  97. <div class="ftext" slot="message">
  98. 总交易金额:<strong>{{ (totalData && (totalData.totalAmount || totalData.totalAmount==0)) ? totalData.totalAmount : '--' }}</strong>;
  99. <div style="display: inline-block;" v-if="$hasPermissions('M_ShowAllCost')">
  100. 总毛利:<strong>{{ (totalData && totalData.totalGrossProfit) ? totalData.totalGrossProfit : '--' }}</strong>;
  101. 总毛利率:<strong>{{ (totalData && totalData.percentage) ? totalData.percentage+'%' : '--' }}</strong>;
  102. </div>
  103. </div>
  104. </a-alert>
  105. <!-- 列表 -->
  106. <s-table
  107. class="sTable"
  108. ref="table"
  109. size="small"
  110. :rowKey="(record) => record.salesTargetSn"
  111. :columns="columns"
  112. :data="loadData"
  113. :defaultLoadData="false"
  114. bordered>
  115. </s-table>
  116. </a-spin>
  117. </a-card>
  118. </template>
  119. <script>
  120. import { commonMixin } from '@/utils/mixin'
  121. import { STable, VSelect } from '@/components'
  122. import rangeDate from '@/views/common/rangeDate.vue'
  123. import { getArea } from '@/api/data'
  124. import custType from '@/views/common/custType.js'
  125. import { dealerProductTypeList } from '@/api/dealerProductType'
  126. import { reportBigCustomerLinkageList, reportBigCustomerLinkageCount, linkageGroupList } from '@/api/reportData'
  127. export default {
  128. components: { STable, VSelect, rangeDate, custType },
  129. mixins: [commonMixin],
  130. data () {
  131. return {
  132. spinning: false,
  133. labelCol: { span: 8 },
  134. wrapperCol: { span: 16 },
  135. advanced: true, // 高级搜索 展开/关闭
  136. tableHeight: 0,
  137. queryParam: { // 查询条件
  138. tenantId: undefined,
  139. time: [],
  140. beginDate: '',
  141. endDate: '',
  142. productTypeSn1: '', // 产品一级分类
  143. productTypeSn2: '', // 产品二级分类
  144. productTypeSn3: '', // 产品三级分类
  145. provinceSn: undefined, // 省
  146. citySn: undefined, // 市
  147. countySn: undefined, // 区
  148. customerTypeSn: undefined // 客户类型
  149. },
  150. productType: [],
  151. rules: {
  152. 'tenantId': [{ required: true, message: '请选择连锁店', trigger: 'change' }],
  153. 'time': [{ required: true, message: '请选择添加时间', trigger: 'change' }]
  154. },
  155. disabled: false, // 查询、重置按钮是否可操作
  156. exportLoading: false,
  157. // 加载数据方法 必须为 Promise 对象
  158. loadData: parameter => {
  159. this.disabled = true
  160. const params = Object.assign(parameter, this.queryParam)
  161. this.spinning = true
  162. delete params.time
  163. if (params.beginDate) {
  164. return reportBigCustomerLinkageList(params).then(res => {
  165. let data
  166. if (res.status == 200) {
  167. data = res.data
  168. // 总计
  169. this.getCount(params)
  170. const no = (data.pageNo - 1) * data.pageSize
  171. for (var i = 0; i < data.list.length; i++) {
  172. data.list[i].no = no + i + 1
  173. data.list[i].percentageUnit = data.list[i].percentage ? data.list[i].percentage + '%' : undefined
  174. }
  175. this.disabled = false
  176. }
  177. this.spinning = false
  178. return data
  179. })
  180. } else {
  181. const _this = this
  182. return new Promise(function (resolve, reject) {
  183. const data = {
  184. pageNo: 1,
  185. pageSize: 10,
  186. list: [],
  187. count: 0
  188. }
  189. _this.disabled = false
  190. _this.spinning = false
  191. _this.$message.info('请选择添加时间')
  192. resolve(data)
  193. })
  194. }
  195. },
  196. totalData: null, // 合计
  197. addrProvinceList: [], // 省下拉
  198. addrCityList: [], // 市下拉
  199. addrDistrictList: [], // 区下拉
  200. productTypeList: [], // 分类下拉数据
  201. linkageGroupData: []
  202. }
  203. },
  204. computed: {
  205. columns () {
  206. const arr = [
  207. { title: '序号', dataIndex: 'no', width: '10%', align: 'center' },
  208. { title: '连锁门店', dataIndex: 'dealerName', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  209. { title: '客户名称', dataIndex: 'salesTargetName', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true, sorter: true },
  210. { title: '客户类型', dataIndex: 'customerTypeName', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  211. { title: '交易金额', dataIndex: 'totalAmount', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') }, sorter: true }
  212. ]
  213. if (this.$hasPermissions('M_ShowAllCost')) {
  214. arr.splice(5, 0, { title: '毛利', dataIndex: 'totalGrossProfit', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } })
  215. arr.splice(6, 0, { title: '毛利率', dataIndex: 'percentageUnit', width: '15%', align: 'center', customRender: function (text) { return text || '--' }, sorter: true })
  216. }
  217. return arr
  218. }
  219. },
  220. methods: {
  221. // 合计
  222. getCount (params) {
  223. reportBigCustomerLinkageCount(params).then(res => {
  224. if (res.status == 200) {
  225. this.totalData = res.data
  226. } else {
  227. this.totalData = null
  228. }
  229. })
  230. },
  231. // 创建时间 change
  232. dateChange (date) {
  233. this.queryParam.time = date
  234. this.queryParam.beginDate = date[0] || ''
  235. this.queryParam.endDate = date[1] || ''
  236. },
  237. // 查询
  238. handleSearch () {
  239. this.$refs.ruleForm.validate(valid => {
  240. if (valid) {
  241. this.$refs.table.refresh(true)
  242. } else {
  243. console.log('error submit!!')
  244. return false
  245. }
  246. })
  247. },
  248. // 重置
  249. resetSearchForm () {
  250. this.queryParam.tenantId = undefined
  251. this.$refs.rangeDate.resetDate()
  252. this.queryParam.time = []
  253. this.queryParam.beginDate = ''
  254. this.queryParam.endDate = ''
  255. this.queryParam.productTypeSn1 = ''
  256. this.queryParam.productTypeSn2 = ''
  257. this.queryParam.productTypeSn3 = ''
  258. this.queryParam.provinceSn = undefined
  259. this.queryParam.citySn = undefined
  260. this.queryParam.countySn = undefined
  261. this.queryParam.customerTypeSn = undefined
  262. this.productType = []
  263. this.$refs.ruleForm.resetFields()
  264. this.totalData = null
  265. this.$refs.table.clearTable()
  266. },
  267. filterOption (input, option) {
  268. return (
  269. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  270. )
  271. },
  272. // 产品分类 change
  273. changeProductType (val, opt) {
  274. this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
  275. this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
  276. this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
  277. },
  278. // 产品分类 列表
  279. getProductType () {
  280. dealerProductTypeList({}).then(res => {
  281. if (res.status == 200) {
  282. this.productTypeList = res.data
  283. } else {
  284. this.productTypeList = []
  285. }
  286. })
  287. },
  288. // 获取城市列表
  289. getCityList (val) {
  290. this.addrCityList = []
  291. this.addrDistrictList = []
  292. this.queryParam.citySn = undefined
  293. this.queryParam.countySn = undefined
  294. if (val) {
  295. this.getArea('city', val)
  296. }
  297. },
  298. // 获取区县列表
  299. getAreaList (val) {
  300. this.addrDistrictList = []
  301. this.queryParam.countySn = undefined
  302. if (val) {
  303. this.getArea('district', val)
  304. }
  305. },
  306. // 省/市/区
  307. getArea (leve, sn) {
  308. let params
  309. if (leve == 'province') {
  310. params = { type: '2' }
  311. } else {
  312. params = { parentId: sn, type: leve == 'city' ? '3' : '4' }
  313. }
  314. getArea(params).then(res => {
  315. if (res.status == 200) {
  316. if (leve == 'province') {
  317. this.addrProvinceList = res.data || []
  318. } else if (leve == 'city') {
  319. this.addrCityList = res.data || []
  320. } else if (leve == 'district') {
  321. this.addrDistrictList = res.data || []
  322. }
  323. } else {
  324. if (leve == 'province') {
  325. this.addrProvinceList = []
  326. } else if (leve == 'city') {
  327. this.addrCityList = []
  328. } else if (leve == 'district') {
  329. this.addrDistrictList = []
  330. }
  331. }
  332. })
  333. },
  334. // 连锁店
  335. getLinkageGroup () {
  336. linkageGroupList({}).then(res => {
  337. if (res.status == 200) {
  338. this.linkageGroupData = res.data || []
  339. } else {
  340. this.linkageGroupData = []
  341. }
  342. })
  343. },
  344. pageInit () {
  345. this.getLinkageGroup()
  346. this.getArea('province')
  347. this.getProductType()
  348. }
  349. },
  350. mounted () {
  351. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  352. this.pageInit()
  353. this.resetSearchForm()
  354. }
  355. },
  356. activated () {
  357. // 如果是新页签打开,则重置当前页面
  358. if (this.$store.state.app.isNewTab) {
  359. this.pageInit()
  360. this.resetSearchForm()
  361. }
  362. },
  363. beforeRouteEnter (to, from, next) {
  364. next(vm => {})
  365. }
  366. }
  367. </script>