ba-order-list.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div v-loading="loading">
  3. <div class="white-box">
  4. <div class="filter-box">
  5. <filter-user :filter-types="filterTypes" @select-value="handleFilterUser"></filter-user>
  6. </div>
  7. <el-table class="table-box" ref="multipleTable" :data="tableData" stripe style="width: 100%;" @selection-change="handleSelectionChange" :height="tool.getTableHeight()">
  8. <el-table-column type="selection" width="70" v-if="tableHeaders"></el-table-column>
  9. <el-table-column v-for="(tableHeader, key) in tableHeaders" :key="key" :label="tableHeader.header" :width="tableHeader.other.width ? tableHeader.other.width : ''" :prop="tableHeader.other.prop ? tableHeader.other.prop : null">
  10. <template slot-scope="scope">
  11. <template v-if="scope.row[tableHeader.index].other.tag" >
  12. <el-tag :type="scope.row[tableHeader.index].other.tag.type ? scope.row[tableHeader.index].other.tag.type : null" :size="scope.row[tableHeader.index].other.tag.size ? scope.row[tableHeader.index].other.tag.size : null" :class="scope.row[tableHeader.index].other.tag.class ? scope.row[tableHeader.index].other.tag.class : null" >{{scope.row[tableHeader.index].value}}</el-tag>
  13. </template>
  14. <template v-else>
  15. <div v-html="scope.row[tableHeader.index].value"></div>
  16. </template>
  17. </template>
  18. </el-table-column>
  19. </el-table>
  20. <div class="white-box-footer">
  21. <el-button type="success" size="small" @click="handleExport" v-show="permission.hasPermission(`shop/ba-order-list-export`)">Export Excel</el-button>
  22. <el-button type="primary" size="small" @click="handleExportPDF" v-show="permission.hasPermission(`shop/ba-order-list-export`)">Export PDF</el-button>
  23. <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
  24. </div>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import network from '@/utils/network'
  30. import tool from '@/utils/tool'
  31. import baseInfo from '@/utils/baseInfo'
  32. import FilterUser from '@/components/FilterUser'
  33. import permission from '@/utils/permission'
  34. import Pagination from '@/components/Pagination'
  35. import filterHelper from '@/utils/filterHelper'
  36. export default {
  37. name: 'ba-order-list',
  38. components: {FilterUser, Pagination},
  39. mounted () {
  40. this.getData()
  41. },
  42. data () {
  43. return {
  44. tableHeaders: null,
  45. tableData: null,
  46. tableHeight: window.innerHeight - 310,
  47. loading: true,
  48. multipleSelection: [],
  49. currentPage: 1,
  50. totalPages: 1,
  51. totalCount: 1,
  52. pageSize: 20,
  53. tool: tool,
  54. permission: permission,
  55. filterTypes: null,
  56. filterModel: {},
  57. }
  58. },
  59. methods: {
  60. handleSelectionChange (val) {
  61. this.multipleSelection = val
  62. },
  63. handleCurrentChange (page) {
  64. this.getData(page, this.pageSize)
  65. },
  66. handleSizeChange (pageSize) {
  67. this.getData(this.currentPage, pageSize)
  68. },
  69. handleFilterUser (filterData) {
  70. filterHelper.handleFilterUser(this, filterData)
  71. },
  72. getData (page, pageSize) {
  73. let filterData = this.filterModel
  74. network.getPageData(this, 'shop/ba-order-list', page, pageSize, filterData, response => {
  75. this.filterTypes = response.filterTypes
  76. this.allData = response
  77. })
  78. },
  79. handleExport () {
  80. this.$confirm(`Are you sure you want to export the current data?`, 'Hint', { // `确定要导出当前数据吗?`, '提示'
  81. confirmButtonText: 'Confirm', // 确定
  82. cancelButtonText: 'Cancel', // 取消
  83. type: 'warning'
  84. }).then(() => {
  85. return network.getData(`shop/ba-order-list-export`, this.filterModel)
  86. }).then(response => {
  87. this.$message({
  88. message: response,
  89. type: 'success'
  90. })
  91. }).catch(response => {
  92. })
  93. },
  94. handleExportPDF () {
  95. if (this.multipleSelection.length === 0) {
  96. this.$message({
  97. message: 'Please select an order to export', // 请选择一条订单导出
  98. type: 'error'
  99. })
  100. return false
  101. }
  102. // 提取订单ID
  103. let orderSnList = this.multipleSelection.map((item) => item.SN.value || '')
  104. // 去重
  105. let orderSnSet = Array.from(new Set(orderSnList))
  106. if (orderSnSet.length !== 1) {
  107. this.$message({
  108. message: 'Only one order can be exported at a time', // 每次只能导出一条订单
  109. type: 'error'
  110. })
  111. return false
  112. }
  113. this.$confirm(`Are you sure you want to export the current data?`, 'Hint', { // `确定要导出当前数据吗?`, '提示'
  114. confirmButtonText: 'Confirm', // 确定
  115. cancelButtonText: 'Cancel', // 取消
  116. type: 'info'
  117. }).then(() => {
  118. // 导出时只需要订单ID即可
  119. let orderSn = orderSnSet[0]
  120. network.getData(`shop/ba-order-list-export-pdf/${orderSn}`).then(response => {
  121. this.$message({
  122. message: response,
  123. type: 'success'
  124. })
  125. })
  126. }).catch(response => {
  127. this.$message({
  128. message: response,
  129. type: 'error'
  130. })
  131. })
  132. },
  133. }
  134. }
  135. </script>
  136. <style scoped>
  137. </style>