com-export-dialog.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.com/
  4. * @copyright: Copyright (c) 2020 广东七件事集团
  5. * Created by PhpStorm
  6. * Author: ganxiaohao
  7. * Date: 2020-04-24
  8. * Time: 16:21
  9. */
  10. //$url = Yii::$app->urlManager->createUrl(Yii::$app->controller->route);
  11. $url = Yii::$app->urlManager->createUrl(\Yii::$app->requestedRoute);
  12. ?>
  13. <style>
  14. .com-export-dialog .el-dialog__body .el-checkbox + .el-checkbox {
  15. margin-left: 0;
  16. }
  17. .com-export-dialog .el-date-editor .el-range-separator {
  18. padding: 0;
  19. }
  20. .com-export-dialog .modal-body {
  21. border: 1px solid #F0F2F7;
  22. }
  23. .com-export-dialog .all-choose {
  24. height: 50px;
  25. line-height: 50px;
  26. background-color: #F3F5F6;
  27. width: 100%;
  28. padding-left: 20px;
  29. }
  30. .com-export-dialog .choose-list {
  31. padding: 10px 25px 20px;
  32. }
  33. .com-export-dialog .choose-list .export-checkbox {
  34. width: 135px;
  35. height: 30px;
  36. line-height: 30px;
  37. }
  38. </style>
  39. <template id="com-export-dialog">
  40. <div class="com-export-dialog" style="display: inline-block">
  41. <el-button @click="confirm" :type="btn.type" size="small">{{btn.title}}</el-button>
  42. <el-dialog
  43. title="选择导出信息"
  44. :visible.sync="dialogVisible"
  45. :modal-append-to-body='false'
  46. :append-to-body='true'
  47. width="50%">
  48. <el-form :model="exportForm" method="post" ref="export_form">
  49. <div class="modal-body">
  50. <input v-model="exportForm._csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
  51. <input v-model="exportForm.flag" value="EXPORT" type="hidden">
  52. <input v-model="exportForm.fields" type="hidden">
  53. <input v-for="(value,key,index) in params" :name="key" :value="value" type="hidden">
  54. <el-checkbox class="all-choose" :indeterminate="isIndeterminate" v-model="checkAll"
  55. @change="exportCheckAll">全选
  56. </el-checkbox>
  57. <el-checkbox-group class="choose-list" v-model="checkedFields" @change="exportCheck">
  58. <el-checkbox class="export-checkbox" v-for="(item,index) in field_list" :key="index"
  59. :label="index">{{item}}
  60. </el-checkbox>
  61. </el-checkbox-group>
  62. </div>
  63. <div flex="dir:right" style="margin-top: 20px;">
  64. <button @click="submitForm" class="el-button el-button--primary el-button--small">导出</button>
  65. </div>
  66. </el-form>
  67. </el-dialog>
  68. </div>
  69. </template>
  70. <script>
  71. Vue.component('com-export-dialog', {
  72. template: '#com-export-dialog',
  73. props: {
  74. field_list: Object,
  75. params: Object,
  76. action_url: {
  77. type: String,
  78. default:'<?= $url ?>'
  79. },//跳转路由
  80. btn: {
  81. type: Object,
  82. default: function () {
  83. return {
  84. title: '批量导出',
  85. type: 'primary'
  86. }
  87. }
  88. },
  89. export_type: {
  90. type: String,
  91. default: ''
  92. },
  93. },
  94. data() {
  95. return {
  96. dialogVisible: false,
  97. isIndeterminate: false,
  98. checkAll: false,
  99. checkedFields: [],
  100. exportForm:{
  101. _csrf:'<?= Yii::$app->request->csrfToken ?>',
  102. flag:'EXPORT',
  103. fields:[]
  104. }
  105. }
  106. },
  107. computed: {},
  108. watch: {
  109. params: {
  110. deep: true,
  111. handler(newVal, oldVal) {
  112. this.data = newVal;
  113. if(newVal.exportUrl){
  114. this.action_url = newVal.exportUrl;
  115. console.log(this.action_url);
  116. }
  117. if(newVal.fields){
  118. this.exportForm.fields = newVal.fields;
  119. this.checkedFields = newVal.fields;
  120. }
  121. },
  122. },
  123. checkedFields:{
  124. handler(newVal, oldVal) {
  125. this.exportForm.fields = newVal;
  126. }
  127. }
  128. },
  129. methods: {
  130. submitForm(){
  131. event.preventDefault();
  132. self = this;
  133. delete self.params.fields;
  134. let data = Object.assign({},self.exportForm,self.params);
  135. request({
  136. params: {
  137. r: this.action_url,
  138. type: this.export_type
  139. },
  140. method: 'post',
  141. data:data
  142. }).then(e => {
  143. if (e.data.code == 0) {
  144. this.$message.success(e.data.msg);
  145. } else {
  146. this.$message.error(e.data.msg);
  147. }
  148. this.dialogVisible = false;
  149. }).catch(e => {
  150. this.remarksLoading = false;
  151. this.$message.error('未知错误');
  152. });
  153. },
  154. exportCheckAll(val) {
  155. if (val) {
  156. this.checkedFields = objectKeys(this.field_list);
  157. } else {
  158. this.checkedFields = [];
  159. }
  160. this.isIndeterminate = false;
  161. },
  162. exportCheck(value) {
  163. let checkedCount = value.length;
  164. this.checkAll = checkedCount === this.field_list.length;
  165. this.isIndeterminate = checkedCount > 0 && checkedCount < this.field_list.length;
  166. },
  167. confirm() {
  168. this.dialogVisible = true;
  169. this.$emit('selected');
  170. }
  171. },
  172. created() {
  173. // TODO 此处需获取网址上的所有参数、且需考虑参数名重复问题
  174. // TODO 已无作用
  175. if (this.params.status === undefined) {
  176. this.params.status = getQuery('status');
  177. }
  178. }
  179. });
  180. </script>