list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <a-card size="small" :bordered="false" class="chainStockExpenditureReportList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div class="table-page-search-wrapper">
  6. <a-form-model
  7. id="chainStockExpenditureReportList-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="handelSearch" >
  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="chainStockExpenditureReportList-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-button type="primary" @click="handelSearch" id="chainStockExpenditureReportList-refresh">查询</a-button>
  38. <a-button style="margin-left: 8px" @click="resetSearchForm" id="chainStockExpenditureReportList-reset">重置</a-button>
  39. </a-col>
  40. </a-row>
  41. </a-form-model>
  42. </div>
  43. <!-- 列表 -->
  44. <a-row :gutter="15" style="margin-top: 50px;">
  45. <a-col :md="12" :sm="24">
  46. <div class="chart-box">
  47. <div class="chart-hj">
  48. 库存总出数量:{{ (totalData&&totalData.totalQty) ? totalData.totalQty : '--' }},
  49. 总成本:¥{{ (totalData&&totalData.totalCost) ? totalData.totalCost : '--' }}
  50. </div>
  51. <div id="con1" class="chart"></div>
  52. </div>
  53. </a-col>
  54. <a-col :md="12" :sm="24" style="margin-top: 30px;">
  55. <a-table
  56. class="sTable"
  57. ref="table"
  58. size="small"
  59. :rowKey="(record) => record.dataBizTypeDictValue"
  60. :columns="columns"
  61. :dataSource="tableData"
  62. :loading="listLoading"
  63. :pagination="false"
  64. bordered>
  65. </a-table>
  66. </a-col>
  67. </a-row>
  68. </a-spin>
  69. </a-card>
  70. </template>
  71. <script>
  72. import { commonMixin } from '@/utils/mixin'
  73. import rangeDate from '@/views/common/rangeDate.vue'
  74. import echarts from 'echarts'
  75. import { linkageGroupList } from '@/api/reportData'
  76. import { reportStockOutList } from '@/api/reportStock'
  77. import { on, off } from '@/libs/tools'
  78. export default {
  79. components: { rangeDate },
  80. mixins: [commonMixin],
  81. data () {
  82. return {
  83. spinning: false,
  84. queryParam: { // 查询条件
  85. time: [],
  86. beginDate: '',
  87. endDate: '',
  88. tenantId: undefined
  89. },
  90. labelCol: { span: 8 },
  91. wrapperCol: { span: 16 },
  92. rules: {
  93. 'tenantId': [{ required: true, message: '请选择连锁店', trigger: 'change' }],
  94. 'time': [{ required: true, message: '请选择出库完成时间', trigger: 'change' }]
  95. },
  96. disabled: false, // 查询、重置按钮是否可操作
  97. columns: [
  98. { title: '明细项', dataIndex: 'dataBizTypeDictValue', width: '30%', align: 'center', customRender: function (text) { return text || '--' } },
  99. { title: '数量(件)', dataIndex: 'productQty', width: '20%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  100. { title: '成本(元)', dataIndex: 'productCost', width: '20%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  101. { title: '售价(元)', dataIndex: 'productPrice', width: '20%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } }
  102. ],
  103. // 统计图
  104. pieData: [],
  105. pieColor: ['#00aaff', '#ffaa00', '#00aa00', '#ff55ff', '#1dc5d4', '#8465c7', '#00ffff'],
  106. tableData: [], // 含总计数据
  107. loadData: [], // 不含总计数据
  108. listLoading: false,
  109. chart1: null,
  110. totalData: null,
  111. linkageGroupData: []
  112. }
  113. },
  114. methods: {
  115. // 初始化饼图 title: 标题 data:数据 bit:单位
  116. initPie (chart, title, data, bit) {
  117. const legend = []
  118. if (bit) {
  119. data.map(item => {
  120. const p = `${item.name}: ${item.value}${bit}`
  121. legend.push(p)
  122. })
  123. }
  124. const option = {
  125. color: this.pieColor,
  126. title: {
  127. text: title,
  128. top: 20,
  129. left: 20,
  130. textStyle: {
  131. color: '#abd7ff'
  132. },
  133. textAlingn: 'left'
  134. },
  135. tooltip: {
  136. trigger: 'item',
  137. formatter: `{b} : {d}%`
  138. },
  139. legend: {
  140. orient: 'horizontal',
  141. left: 'center',
  142. bottom: '5',
  143. padding: 5,
  144. textStyle: {
  145. color: '#abd7ff',
  146. fontSize: 10
  147. },
  148. show: !!bit,
  149. formatter: function (name) {
  150. if (bit) {
  151. const p = data.find(item => item.name == name)
  152. return name + (p ? (':' + p.value + bit) : '')
  153. }
  154. }
  155. },
  156. series: [{
  157. type: 'pie',
  158. radius: ['50%', '70%'],
  159. startAngle: 75,
  160. top: 50,
  161. avoidLabelOverlap: true, // 在标签拥挤重叠的情况下会挪动各个标签的位置,防止标签间的重叠
  162. label: {
  163. normal: {
  164. formatter: params => {
  165. return (
  166. '{name|' + params.name + '}{value|' + params.percent + '%' + '}'
  167. )
  168. },
  169. padding: [0, -70, 25, -70],
  170. rich: {
  171. name: {
  172. fontSize: 12,
  173. padding: [0, 4, 0, 4],
  174. color: '#999'
  175. },
  176. value: {
  177. fontSize: 12,
  178. color: '#999'
  179. }
  180. }
  181. }
  182. },
  183. labelLine: {
  184. normal: {
  185. length: 20,
  186. length2: 70,
  187. lineStyle: {
  188. color: '#e6e6e6'
  189. }
  190. }
  191. },
  192. data: data,
  193. insideLabel: {
  194. show: true
  195. }
  196. }]
  197. }
  198. return option
  199. },
  200. // 时间 change
  201. dateChange (date) {
  202. this.queryParam.time = date
  203. this.queryParam.beginDate = date[0] || ''
  204. this.queryParam.endDate = date[1] || ''
  205. },
  206. handelSearch () {
  207. this.$refs.ruleForm.validate(valid => {
  208. if (valid) {
  209. this.getList()
  210. } else {
  211. console.log('error submit!!')
  212. return false
  213. }
  214. })
  215. },
  216. // 查询列表
  217. getList () {
  218. const params = {
  219. beginDate: this.queryParam.beginDate,
  220. endDate: this.queryParam.endDate,
  221. tenantId: this.queryParam.tenantId
  222. }
  223. // 开始查询
  224. this.listLoading = true
  225. this.spinning = true
  226. reportStockOutList(params).then(res => {
  227. this.listLoading = false
  228. if (res.status == 200 && res.data) {
  229. const reportStockOutVOList = (res.data && res.data.reportStockOutVOList) ? res.data.reportStockOutVOList : []
  230. const totalQty = (res.data && (res.data.totalQty || res.data.totalQty == 0)) ? res.data.totalQty : '--'
  231. const totalPrice = (res.data && (res.data.totalPrice || res.data.totalPrice == 0)) ? res.data.totalPrice : '--'
  232. const totalCost = (res.data && (res.data.totalCost || res.data.totalCost == 0)) ? res.data.totalCost : '--'
  233. this.totalData = {
  234. totalQty: totalQty,
  235. totalPrice: totalPrice,
  236. totalCost: totalCost
  237. }
  238. if (reportStockOutVOList) {
  239. this.loadData = res.data.reportStockOutVOList
  240. this.tableData = res.data.reportStockOutVOList
  241. const total = [{ dataBizTypeDictValue: '总出', productQty: totalQty, productCost: totalCost, productPrice: totalPrice }]
  242. this.tableData = [...this.tableData, ...total]
  243. } else {
  244. this.loadData = []
  245. this.tableData = []
  246. }
  247. this.chartInit()
  248. } else {
  249. this.loadData = []
  250. this.tableData = []
  251. this.totalData = null
  252. this.chartInit()
  253. }
  254. this.spinning = false
  255. })
  256. },
  257. chartInit () {
  258. this.pieData = []
  259. if (this.loadData.length < 1) {
  260. this.pieData = [{ name: '总成本', value: 0 }]
  261. } else {
  262. this.loadData.map((item, index) => {
  263. if (index != this.loadData.length) {
  264. this.pieData.push({
  265. name: item.dataBizTypeDictValue + '总成本',
  266. value: item.productCost
  267. })
  268. }
  269. })
  270. }
  271. const con1 = document.getElementById('con1')
  272. const chart1 = echarts.init(con1)
  273. const option = this.initPie(chart1, '', this.pieData)
  274. chart1.setOption(option)
  275. this.chart1 = chart1
  276. this.chart1.resize()
  277. },
  278. // 重置
  279. resetSearchForm () {
  280. this.$refs.rangeDate.resetDate()
  281. this.queryParam.time = []
  282. this.queryParam.beginDate = ''
  283. this.queryParam.endDate = ''
  284. this.queryParam.tenantId = undefined
  285. this.loadData = []
  286. this.tableData = []
  287. this.totalData = null
  288. this.chartInit()
  289. },
  290. filterOption (input, option) {
  291. return (
  292. option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
  293. )
  294. },
  295. // 连锁店
  296. getLinkageGroup () {
  297. linkageGroupList({}).then(res => {
  298. if (res.status == 200) {
  299. const data = res.data || []
  300. if (data.length > 0) {
  301. this.linkageGroupData = data
  302. } else {
  303. this.linkageGroupData = []
  304. }
  305. } else {
  306. this.linkageGroupData = []
  307. }
  308. })
  309. },
  310. chartResize () {
  311. this.chart1.resize()
  312. },
  313. pageInit () {
  314. this.getLinkageGroup()
  315. }
  316. },
  317. mounted () {
  318. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  319. this.pageInit()
  320. this.resetSearchForm()
  321. }
  322. },
  323. activated () {
  324. on(window, 'resize', this.chartResize)
  325. // 如果是新页签打开,则重置当前页面
  326. if (this.$store.state.app.isNewTab) {
  327. this.pageInit()
  328. this.resetSearchForm()
  329. }
  330. },
  331. deactivated () {
  332. off(window, 'resize', this.chartResize)
  333. },
  334. beforeDestroy () {
  335. off(window, 'resize', this.chartResize)
  336. },
  337. beforeRouteEnter (to, from, next) {
  338. next(vm => {})
  339. }
  340. }
  341. </script>
  342. <style lang="less">
  343. .chainStockExpenditureReportList-wrap{
  344. min-height: 700px;
  345. .chart-box{
  346. height: 400px;
  347. .chart-hj{
  348. font-size: 22px;
  349. text-align: center;
  350. }
  351. .chart{
  352. width: 100%;
  353. height: 450px;
  354. overflow: auto;
  355. }
  356. }
  357. }
  358. </style>