com-export-window.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template id="com-export-window">
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="dialogVisible"
  5. :width="width"
  6. @close="close"
  7. @open="open"
  8. >
  9. <el-checkbox :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
  10. <el-checkbox-group v-model="checkedFields" @change="handleCheckedCitiesChange">
  11. <el-checkbox v-for="(item, index) in exportList" :label="item[exportKey]" :key="index">
  12. {{ item[exportValue] }}
  13. </el-checkbox>
  14. </el-checkbox-group>
  15. <span slot="footer" class="dialog-footer">
  16. <el-button size="small" type="primary" v-loading="submitLoading" @click="submit">导 出</el-button>
  17. </span>
  18. </el-dialog>
  19. </template>
  20. <script>
  21. Vue.component('com-export-window', {
  22. template: '#com-export-window',
  23. props: {
  24. defaultCheck: {
  25. type: Boolean,
  26. default: () => {
  27. return false
  28. }
  29. },
  30. title: {
  31. type: String,
  32. default: () => {
  33. return '导出'
  34. }
  35. },
  36. width: {
  37. type: String,
  38. default: () => {
  39. return '50%'
  40. }
  41. },
  42. exportList: Array,
  43. params: Object,
  44. actionUrl: String,
  45. visible: {
  46. type: Boolean,
  47. default: false,
  48. },
  49. // 对象的key
  50. exportKey: {
  51. type: String,
  52. default: () => {
  53. return 'value'
  54. }
  55. },
  56. // 对象显示的值
  57. exportValue: {
  58. type: String,
  59. default: () => {
  60. return 'title'
  61. }
  62. },
  63. },
  64. data() {
  65. return {
  66. checkAll: false,
  67. checkedFields: [],
  68. isIndeterminate: true,
  69. submitLoading: false,
  70. }
  71. },
  72. computed: {
  73. dialogVisible: {
  74. get() {
  75. return this.visible
  76. },
  77. set() {},
  78. }
  79. },
  80. methods: {
  81. open() {
  82. // 默认全选
  83. if (this.defaultCheck) {
  84. this.checkAll = true
  85. this.checkedFields = this.exportList.map((item) => {
  86. return item[this.exportKey]
  87. })
  88. this.isIndeterminate = false
  89. }
  90. },
  91. close() {
  92. this.$emit('closed')
  93. },
  94. handleCheckAllChange(val) {
  95. let options = this.exportList.map((item) => {
  96. return item[this.exportKey]
  97. })
  98. this.checkedFields = val ? options : []
  99. this.isIndeterminate = false
  100. },
  101. handleCheckedCitiesChange(value) {
  102. let checkedCount = value.length
  103. this.checkAll = checkedCount === this.checkedFields.length
  104. this.isIndeterminate = checkedCount > 0 && checkedCount < this.cities.length
  105. },
  106. submit() {
  107. if (this.submitLoading) return
  108. this.submitLoading = true
  109. request({
  110. params: {
  111. r: this.actionUrl
  112. },
  113. data: {
  114. params: this.params,
  115. fields: this.checkedFields
  116. },
  117. method: 'post',
  118. }).then(res => {
  119. if (res.data.code == 0) {
  120. this.submitLoading = false
  121. this.$message.success(res.data.msg)
  122. this.close()
  123. } else {
  124. this.submitLoading = false
  125. this.$message.error(res.data.msg)
  126. }
  127. })
  128. },
  129. }
  130. })
  131. </script>