华西海圻ELN前端工程
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
4.9 KiB

  1. <template>
  2. <div>
  3. <div >
  4. <el-form :inline="true" class="demo-form-inline" ref="SearchSjRef">
  5. <el-form-item v-for="(item,key) in searchForm" :key="key" :label="$t(item.label)">
  6. <el-select v-if="item.type === 'select'" v-model="listParams[key]" :placeholder="$t('form.placeholderSelect')">
  7. <el-option v-for="(opt) in item.options" :key="opt.value" :label="opt.label" :value="opt.value"></el-option>
  8. </el-select>
  9. <el-input v-else v-model="listParams[key]" :placeholder="$t('form.placeholderInput')"></el-input>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button type="primary" @click="onSearch">{{$t('form.search')}}</el-button>
  13. <el-button @click="reset">{{ $t('form.reset') }}</el-button>
  14. </el-form-item>
  15. </el-form>
  16. <el-table :data="dataSource" :row-key="(row) => row.id">
  17. <el-table-column width="80" align="center" v-if="showRadio">
  18. <template slot-scope="scope">
  19. <el-radio v-model="localSelectedId" :label="scope.row[selectedCode]" class="hide-label" @input.native.stop="handleRadioClick(scope.row)"></el-radio>
  20. </template>
  21. </el-table-column>
  22. <el-table-column v-for="(item) in columns" :prop="item.prop" :key="item.prop" :label="$t(item.label)">
  23. </el-table-column>
  24. </el-table>
  25. <div class="mt-10">
  26. <el-pagination
  27. :page-limit.sync="pagination.pageSize"
  28. :current-page.sync="pagination.pageNum"
  29. layout="total, sizes, prev, pager, next, jumper"
  30. :total="pagination.total"
  31. @size-change="handleSizeChange"
  32. @current-change="handleCurrentChange"
  33. />
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. props: {
  41. //[{label:"名称",prop:"name"}]
  42. searchForm: {
  43. type: Object,
  44. default: () => {},
  45. },
  46. showRadio: {//是否显示单选框
  47. type: Boolean,
  48. default: true,
  49. },
  50. columns: {
  51. type: Array,
  52. default: [],
  53. },
  54. selectedId: {
  55. type: String,
  56. default: "",
  57. },
  58. selectedCode: {
  59. type: String,
  60. default: "bh",//radio选中的值的字段
  61. },
  62. listApi:{
  63. type: Function,
  64. default: () => {},
  65. },
  66. studyFormId: {
  67. type: String,
  68. default: "",
  69. },
  70. },
  71. data() {
  72. return {
  73. localSelectedId: "",
  74. listParams: {
  75. pageNum: 1,
  76. pageSize: 10,
  77. },
  78. pagination: {
  79. pageNum: 1,
  80. pageSize: 10,
  81. total: 0,
  82. },
  83. dataSource: []
  84. }
  85. },
  86. watch: {
  87. selectedId: {
  88. immediate: true,
  89. handler(newVal, oldVal) {
  90. this.localSelectedId = newVal;
  91. },
  92. },
  93. },
  94. mounted() {
  95. },
  96. methods: {
  97. show(){
  98. this.localSelectedId = ''
  99. this.initSearchForm();
  100. this.getList();
  101. },
  102. //初始化查询表单
  103. initSearchForm() {
  104. for(let key in this.searchForm) {
  105. this.listParams[key] = "";
  106. }
  107. this.listParams = {...this.listParams}
  108. this.listParams.studyFormId = this.studyFormId || ''
  109. },
  110. async getList() {
  111. const res = await this.listApi(this.listParams);
  112. this.dataSource = res.rows;
  113. this.pagination = {
  114. pageNum: this.listParams.pageNum,
  115. pageSize: this.listParams.pageSize,
  116. total: res.total,
  117. };
  118. },
  119. //查询
  120. onSearch() {
  121. this.pagination.pageNum = 1;
  122. this.getList();
  123. },
  124. reset(){
  125. this.initSearchForm();
  126. this.getList();
  127. this.onSearch()
  128. },
  129. //分页大小切换
  130. handleSizeChange(e) {
  131. this.$emit("pagination", {pageSize: e});
  132. this.listParams.pageSize = e;
  133. this.getList();
  134. },
  135. //分页切换
  136. handleCurrentChange(e) {
  137. this.$emit("pagination", {pageNum: e});
  138. this.listParams.pageNum = e;
  139. this.getList();
  140. },
  141. //单选框点击
  142. handleRadioClick(row) {
  143. this.localSelectedId = row[this.selectedCode];
  144. this.$emit("radioSelect", row[this.selectedCode],row);
  145. },
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .mt-10 {
  151. margin-top: 10px;
  152. }
  153. </style>