place.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="产地选择"
  5. width="1000px"
  6. :close-on-click-modal="false"
  7. :append-to-body="true"
  8. v-dialogDrag
  9. class="userDialog"
  10. :visible.sync="visible"
  11. >
  12. <el-container style="height: 500px">
  13. <el-container>
  14. <el-header style="text-align: left; font-size: 12px; height: 30px">
  15. <el-form
  16. size="small"
  17. :inline="true"
  18. ref="searchForm"
  19. :model="searchForm"
  20. @keyup.enter.native="refreshList()"
  21. @submit.native.prevent
  22. >
  23. <el-form-item prop="param" label="名称/编号" >
  24. <el-input
  25. size="small"
  26. v-model="searchForm.param"
  27. placeholder="输入名称/编号查询"
  28. clearable
  29. ></el-input>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button
  33. type="primary"
  34. @click="refreshList()"
  35. size="small"
  36. icon="el-icon-search"
  37. >查询</el-button
  38. >
  39. <el-button
  40. @click="resetSearch()"
  41. size="small"
  42. icon="el-icon-refresh-right"
  43. >重置</el-button>
  44. </el-form-item>
  45. </el-form>
  46. </el-header>
  47. <el-main>
  48. <el-table
  49. :data="dataList"
  50. v-loading="loading"
  51. size="small"
  52. border
  53. ref="contractTable"
  54. @select="handleSelectionChange"
  55. @row-click="rowSelect"
  56. height="calc(100% - 40px)"
  57. style="width: 100%"
  58. >
  59. <el-table-column
  60. type="selection"
  61. header-align="center"
  62. align="center"
  63. width="50"
  64. >
  65. </el-table-column>
  66. <el-table-column
  67. prop="id"
  68. header-align="center"
  69. align="center"
  70. sortable="custom"
  71. min-width="90"
  72. label="id"
  73. >
  74. </el-table-column>
  75. <el-table-column
  76. prop="name"
  77. header-align="center"
  78. align="center"
  79. sortable="custom"
  80. min-width="90"
  81. label="名称"
  82. >
  83. </el-table-column>
  84. </el-table>
  85. <el-pagination
  86. @size-change="sizeChangeHandle"
  87. @current-change="currentChangeHandle"
  88. :current-page="searchForm.pageNo"
  89. :page-sizes="[5, 10, 15, 20]"
  90. :page-size="searchForm.pageSize"
  91. :total="total"
  92. layout="total, sizes, prev, pager, next, jumper"
  93. >
  94. </el-pagination>
  95. </el-main>
  96. </el-container>
  97. </el-container>
  98. <span slot="footer" class="dialog-footer">
  99. <el-button
  100. size="small"
  101. @click="visible = false"
  102. icon="el-icon-circle-close"
  103. >关闭</el-button
  104. >
  105. <el-button
  106. size="small"
  107. type="primary"
  108. icon="el-icon-circle-check"
  109. @click="doSubmit()"
  110. >确定</el-button
  111. >
  112. </span>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script>
  117. import { getPlace } from '@/api/requisition/basic'
  118. export default {
  119. data() {
  120. return {
  121. searchForm: {
  122. param: '',
  123. pageNo: 1,
  124. pageSize: 10,
  125. },
  126. dataListAllSelections: [], // 所有选中的数据包含跨页数据
  127. idKey: "id", // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
  128. dataList: [],
  129. total: 0,
  130. orders: [],
  131. loading: false,
  132. visible: false,
  133. };
  134. },
  135. props: {
  136. selectData: {
  137. type: Array,
  138. default: () => {
  139. return [];
  140. },
  141. },
  142. // 是否启用单选
  143. single: {
  144. type: Boolean,
  145. default: false
  146. }
  147. },
  148. methods: {
  149. init() {
  150. this.visible = true;
  151. this.$nextTick(() => {
  152. this.dataListAllSelections = JSON.parse(JSON.stringify(this.selectData));
  153. this.resetSearch();
  154. });
  155. },
  156. // 获取数据列表
  157. refreshList() {
  158. this.loading = true;
  159. getPlace(this.searchForm).then(({ data }) => {
  160. console.log('data',data)
  161. this.dataList = data.tableBody;
  162. this.total = data.total
  163. this.loading = false;
  164. this.$nextTick(() => {
  165. this.setSelectRow();
  166. });
  167. });
  168. },
  169. // 每页数
  170. sizeChangeHandle(val) {
  171. this.searchForm.pageSize = val;
  172. this.refreshList();
  173. },
  174. // 当前页
  175. currentChangeHandle(val) {
  176. this.searchForm.pageNo = val;
  177. this.refreshList();
  178. },
  179. // 排序
  180. resetSearch() {
  181. this.$refs['searchForm'].resetFields();
  182. this.searchForm.pageNo = 1;
  183. this.refreshList();
  184. },
  185. // 表格选中数据
  186. rowSelect(row, column, event) {
  187. this.$refs.contractTable.clearSelection();
  188. this.$refs.contractTable.toggleRowSelection(row);
  189. this.dataListAllSelections = this.single ? [row] : selection
  190. },
  191. // 选中数据
  192. handleSelectionChange(selection, row) {
  193. if (this.single && selection.length > 1) {
  194. this.$refs.contractTable.clearSelection();
  195. this.$refs.contractTable.toggleRowSelection(row);
  196. }
  197. this.dataListAllSelections = this.single ? [row] : selection
  198. },
  199. // 设置选中的方法
  200. setSelectRow() {
  201. this.$refs.contractTable.clearSelection();
  202. if (!this.dataListAllSelections || this.dataListAllSelections.length <= 0) {
  203. return;
  204. }
  205. for (let i = 0; i < this.dataList.length; i++) {
  206. if (this.dataListAllSelections.some(item => item[this.idKey] == this.dataList[i][this.idKey])) {
  207. // 设置选中,记住table组件需要使用ref="table"
  208. this.$refs.contractTable.toggleRowSelection(this.dataList[i], true);
  209. }
  210. }
  211. },
  212. doSubmit() {
  213. this.visible = false;
  214. console.log('选择的数据?',this.dataListAllSelections)
  215. this.$emit("doSubmit", this.dataListAllSelections);
  216. },
  217. },
  218. };
  219. </script>
  220. <style lang="scss">
  221. .userDialog {
  222. .el-dialog__body {
  223. padding: 10px 0px 0px 10px;
  224. color: #606266;
  225. font-size: 14px;
  226. word-break: break-all;
  227. }
  228. .el-main {
  229. padding: 20px 20px 5px 20px;
  230. .el-pagination {
  231. margin-top: 5px;
  232. }
  233. }
  234. }
  235. </style>