list.vue 9.5 KB

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