com-dialog-select.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <style>
  2. .com-dialog-dialog {
  3. min-width: 700px;
  4. }
  5. </style>
  6. <template id="com-dialog-select">
  7. <div class="com-dialog-select">
  8. <el-dialog append-to-body :title="title" :visible.sync="visible" :close-on-click-modal="false"
  9. custom-class="com-dialog-dialog" :before-close="close" @close="close">
  10. <div>
  11. <el-input v-model="search.keyword" placeholder="根据名称搜索" @keyup.enter.native="getDetail(1)">
  12. <el-button slot="append" @click="getDetail(1)">搜索</el-button>
  13. </el-input>
  14. <el-table border v-loading="listLoading" :data="list" style="margin-top: 24px;"
  15. @selection-change="handleSelectionChange">
  16. <el-table-column type="selection" width="60px" label="ID" props="id" v-if="multiple">
  17. </el-table-column>
  18. <el-table-column width="100px" label="ID" props="id" v-else>
  19. <template slot-scope="props">
  20. <el-radio-group v-model="radioSelection" @change="handleSelectionChange(props.row)">
  21. <el-radio :label="props.row.id"></el-radio>
  22. </el-radio-group>
  23. </template>
  24. </el-table-column>
  25. <el-table-column label="名称">
  26. <template slot-scope="props">
  27. <com-ellipsis :line="2">{{props.row[listKey]}}</com-ellipsis>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. </div>
  32. <div style="margin-top: 24px;">
  33. <el-row>
  34. <el-pagination
  35. v-if="pagination"
  36. style="display: inline-block;"
  37. background
  38. :page-size="pagination.pageSize"
  39. @current-change="getDetail"
  40. layout="prev, pager, next"
  41. :total="pagination.total_count">
  42. </el-pagination>
  43. <el-button type="primary" size="small" style="float: right" @click="confirm">选择</el-button>
  44. </el-row>
  45. </div>
  46. </el-dialog>
  47. <div @click="click" style="display: inline-block">
  48. <slot></slot>
  49. </div>
  50. </div>
  51. </template>
  52. <script>
  53. Vue.component('com-dialog-select', {
  54. template: '#com-dialog-select',
  55. props: {
  56. url: {
  57. type: String,
  58. default: 'plugin/o2o_store/mall/goods/select'
  59. },
  60. multiple: Boolean,
  61. title: {
  62. type: String,
  63. default: '商品选择'
  64. },
  65. listKey: {
  66. type: String,
  67. default: 'name'
  68. },
  69. params: Object,
  70. display: Boolean,
  71. extraSearch: Object,
  72. },
  73. data() {
  74. return {
  75. visible: false,
  76. listLoading: false,
  77. list: [],
  78. pagination: null,
  79. radioSelection: 0,
  80. search: {
  81. keyword: ''
  82. },
  83. multipleSelection: []
  84. }
  85. },
  86. methods: {
  87. close(){
  88. this.visible=false;
  89. this.$emit('close');
  90. },
  91. click() {
  92. this.getDetail(1);
  93. this.visible = !this.visible;
  94. },
  95. getDetail(page) {
  96. this.list = [];
  97. this.listLoading = true;
  98. let params = Object.assign({
  99. r: this.url,
  100. search: Object.assign(this.search, this.extraSearch),
  101. status: 1,
  102. page: page
  103. }, this.params);
  104. console.log(params);
  105. request({
  106. params: params
  107. }).then(e => {
  108. this.listLoading = false;
  109. if (e.data.code === 0) {
  110. this.list = e.data.data.list;
  111. this.pagination = e.data.data.pagination;
  112. } else {
  113. this.$message.error(e.data.msg);
  114. }
  115. }).catch(e => {
  116. this.listLoading = false;
  117. });
  118. },
  119. handleSelectionChange(val) {
  120. this.multipleSelection = val;
  121. },
  122. confirm() {
  123. this.visible = false;
  124. this.$emit('selected', this.multipleSelection);
  125. this.$emit('input', this.multipleSelection);
  126. }
  127. }
  128. });
  129. </script>