com-export-dialog.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. $url = Yii::$app->urlManager->createUrl(\Yii::$app->requestedRoute);
  3. ?>
  4. <style>
  5. .com-export-dialog .el-dialog__body .el-checkbox + .el-checkbox {
  6. margin-left: 0;
  7. }
  8. .com-export-dialog .el-date-editor .el-range-separator {
  9. padding: 0;
  10. }
  11. .com-export-dialog .modal-body {
  12. border: 1px solid #F0F2F7;
  13. }
  14. .com-export-dialog .all-choose {
  15. height: 50px;
  16. line-height: 50px;
  17. background-color: #F3F5F6;
  18. width: 100%;
  19. padding-left: 20px;
  20. }
  21. .com-export-dialog .choose-list {
  22. padding: 10px 25px 20px;
  23. }
  24. .com-export-dialog .choose-list .export-checkbox {
  25. width: 135px;
  26. height: 30px;
  27. line-height: 30px;
  28. }
  29. </style>
  30. <template id="com-export-dialog">
  31. <div class="com-export-dialog" style="display: inline-block">
  32. <el-button @click="confirm" type="primary" size="small">批量导出</el-button>
  33. <el-dialog
  34. title="选择导出信息"
  35. :close-on-click-modal="false"
  36. :visible.sync="dialogVisible"
  37. :modal-append-to-body='false'
  38. :append-to-body='true'
  39. width="50%">
  40. <form target="_blank" :action="action_url" method="post">
  41. <div class="modal-body">
  42. <input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
  43. <input name="flag" value="EXPORT" type="hidden">
  44. <input name="fields" :value="checkedFields" type="hidden">
  45. <input v-for="(value,key,index) in params" :name="key" :value="value" type="hidden">
  46. <el-checkbox class="all-choose" :indeterminate="isIndeterminate" v-model="checkAll"
  47. @change="exportCheckAll">全选
  48. </el-checkbox>
  49. <el-checkbox-group class="choose-list" v-model="checkedFields" @change="exportCheck">
  50. <el-checkbox class="export-checkbox" v-for="item in field_list" :key="item.key"
  51. :label="item.key">{{item.value}}
  52. </el-checkbox>
  53. </el-checkbox-group>
  54. </div>
  55. <div flex="dir:right" style="margin-top: 20px;">
  56. <button type="button" class="el-button el-button--primary el-button--small" @click="onsubmit">导出</button>
  57. </div>
  58. </form>
  59. </el-dialog>
  60. </div>
  61. </template>
  62. <script>
  63. Vue.component('com-export-dialog', {
  64. template: '#com-export-dialog',
  65. props: {
  66. field_list: Object,
  67. params: Object,
  68. action_url: {
  69. type: String,
  70. default:'<?= $url ?>'
  71. },//跳转路由
  72. },
  73. data() {
  74. return {
  75. dialogVisible: false,
  76. isIndeterminate: false,
  77. checkAll: false,
  78. checkedFields: [],
  79. }
  80. },
  81. computed: {},
  82. watch: {
  83. params: {
  84. deep: true,
  85. handler(newVal, oldVal) {
  86. this.data = newVal;
  87. if(newVal.exportUrl){
  88. this.action_url = newVal.exportUrl;
  89. console.log(this.action_url);
  90. }
  91. },
  92. },
  93. },
  94. methods: {
  95. exportCheckAll(val) {
  96. if (val) {
  97. let field_list = this.field_list;
  98. let array = [];
  99. field_list.forEach((item, index) => {
  100. array.push(item['key']);
  101. });
  102. this.checkedFields = array;
  103. } else {
  104. this.checkedFields = [];
  105. }
  106. this.isIndeterminate = false;
  107. },
  108. exportCheck(value) {
  109. let checkedCount = value.length;
  110. this.checkAll = checkedCount === this.field_list.length;
  111. this.isIndeterminate = checkedCount > 0 && checkedCount < this.field_list.length;
  112. },
  113. confirm() {
  114. this.dialogVisible = true;
  115. this.$emit('selected');
  116. },
  117. onsubmit(){
  118. this.params['fields'] = this.checkedFields;
  119. this.params['flag'] = 'EXPORT';
  120. // this.params['r'] = 'mall/order/index';
  121. request({
  122. params: this.params,
  123. method: 'get',
  124. }).then(e => {
  125. if (e.data.code == 0) {
  126. this.dialogVisible = false;
  127. this.$message({
  128. message: e.data.msg,
  129. type: 'success'
  130. });
  131. } else {
  132. this.$message.error(e.data.msg);
  133. }
  134. }).catch(e => {
  135. this.$message.error(e.data.msg);
  136. self.listLoading = false;
  137. });
  138. }
  139. },
  140. created() {
  141. // TODO 此处需获取网址上的所有参数、且需考虑参数名重复问题
  142. // TODO 已无作用
  143. this.params.status = getQuery('status');
  144. }
  145. });
  146. </script>