com-export-dialog.php 5.3 KB

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