list.vue 9.9 KB

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