com-dialog-template.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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: 19:54
  9. */
  10. ?>
  11. <style>
  12. .com-dialog-dialog {
  13. min-width: 700px;
  14. }
  15. .input-item {
  16. display: inline-block;
  17. width: 250px;
  18. }
  19. .input-item .el-input__inner {
  20. border-right: 0;
  21. }
  22. .input-item .el-input__inner:hover {
  23. border: 1px solid #dcdfe6;
  24. border-right: 0;
  25. outline: 0;
  26. }
  27. .input-item .el-input__inner:focus {
  28. border: 1px solid #dcdfe6;
  29. border-right: 0;
  30. outline: 0;
  31. }
  32. .input-item .el-input-group__append {
  33. background-color: #fff;
  34. border-left: 0;
  35. width: 10%;
  36. padding: 0;
  37. }
  38. .input-item .el-input-group__append .el-button {
  39. padding: 0;
  40. }
  41. .input-item .el-input-group__append .el-button {
  42. margin: 0;
  43. }
  44. </style>
  45. <template id="com-dialog-template">
  46. <div class="com-dialog-template">
  47. <el-dialog append-to-body title="选择模板" :visible.sync="show" :close-on-click-modal="false"
  48. custom-class="com-dialog-dialog" :before-close="close">
  49. <el-form size="small" :inline="true" v-if="status == 1">
  50. <el-form-item>
  51. <el-select @change="onSubmit" style="width: 150px" v-model="is_buy">
  52. <el-option value="" label="全部模板"></el-option>
  53. <el-option :value="1" label="已购买"></el-option>
  54. <el-option :value="0" label="未购买"></el-option>
  55. </el-select>
  56. </el-form-item>
  57. <el-form-item style="display: none">
  58. <div class="search-input-item">
  59. <el-input @keyup.enter.native="onSubmit" size="small" placeholder="请输入模板名称"
  60. v-model="keyword" clearable @clear="onSubmit">
  61. <el-button slot="append" icon="el-icon-search" @click="onSubmit"></el-button>
  62. </el-input>
  63. </div>
  64. </el-form-item>
  65. <el-form-item>
  66. <el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">批量选择</el-checkbox>
  67. </el-form-item>
  68. </el-form>
  69. <div v-loading="listLoading">
  70. <el-checkbox-group v-model="selected_list">
  71. <el-checkbox v-for="(item, index) in list" style="width: 145px;margin-right: 5px;margin-top: 10px;"
  72. :label="item.id" :key="index">{{item.name}}</el-checkbox>
  73. </el-checkbox-group>
  74. <div style="text-align: center;margin-top: 20px;color: #999999;">
  75. <template v-if="no_more">
  76. <span>没有更多数据</span>
  77. </template>
  78. <el-button type="text" :loading="loading" @click="more" v-else>加载更多</el-button>
  79. </div>
  80. </div>
  81. <div style="margin-top: 24px;" slot="footer">
  82. <el-button size="small" @click="cancel">取消</el-button>
  83. <el-button type="primary" size="small" @click="confirm">确定</el-button>
  84. </div>
  85. </el-dialog>
  86. </div>
  87. </template>
  88. <script>
  89. Vue.component('com-dialog-template', {
  90. template: '#com-dialog-template',
  91. props: {
  92. show: Boolean,
  93. selected: Array,
  94. status: Number,
  95. },
  96. data() {
  97. return {
  98. listLoading: false,
  99. list: [],
  100. keyword: '',
  101. selected_list: [],
  102. page: 1,
  103. type: '',
  104. loading: false,
  105. no_more: false,
  106. is_buy: '',
  107. checkAll: false,
  108. };
  109. },
  110. watch: {
  111. show() {
  112. if (this.show) {
  113. this.reset();
  114. this.loadData();
  115. this.selected_list = this.selected;
  116. }
  117. },
  118. selected_list: {
  119. handler() {
  120. this.checkAll = this.list.length > 0 && this.list.length === this.selected_list.length;
  121. },
  122. immediate: true,
  123. deep: true,
  124. }
  125. },
  126. computed: {
  127. isIndeterminate() {
  128. return this.selected_list.length > 0 && this.selected_list.length < this.list.length
  129. }
  130. },
  131. methods: {
  132. loadData() {
  133. this.listLoading = true;
  134. request({
  135. params: {
  136. r: 'admin/template/list',
  137. page: this.page,
  138. is_buy: this.is_buy,
  139. status: this.status
  140. }
  141. }).then(response => {
  142. this.listLoading = false;
  143. if (response.data.code == 0) {
  144. this.list = [...this.list, ...response.data.data.list];
  145. if (response.data.data.list.length == 20) {
  146. this.page++;
  147. } else {
  148. this.no_more = true;
  149. }
  150. } else {
  151. this.$message.error(response.data.msg);
  152. }
  153. }).catch(response => {
  154. this.listLoading = false;
  155. });
  156. },
  157. reset() {
  158. this.page = 1;
  159. this.list = [];
  160. this.type = '';
  161. this.keyword = '';
  162. this.is_buy = '';
  163. },
  164. close(done) {
  165. this.reset();
  166. this.$emit('selected');
  167. done();
  168. },
  169. cancel() {
  170. this.reset();
  171. this.$emit('selected');
  172. },
  173. confirm() {
  174. let list = [];
  175. for (let i in this.selected_list) {
  176. this.list.forEach(item => {
  177. if (item.id == this.selected_list[i]) {
  178. list.push(item);
  179. }
  180. });
  181. }
  182. this.$emit('selected', list);
  183. this.reset();
  184. },
  185. onSubmit() {
  186. this.page = 1;
  187. this.list = [];
  188. this.loadData();
  189. },
  190. more() {
  191. if (!this.no_more) {
  192. this.loadData();
  193. }
  194. },
  195. handleCheckAllChange(val) {
  196. if (val) {
  197. let list = [];
  198. for (let i in this.list) {
  199. list.push(this.list[i].id);
  200. }
  201. this.selected_list = list;
  202. } else {
  203. this.selected_list = [];
  204. }
  205. }
  206. }
  207. });
  208. </script>