index.vue 6.4 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. :model="queryParams"
  19. @keyup.enter.native="getList()"
  20. @submit.native.prevent
  21. >
  22. <el-form-item prop="code">
  23. <el-input
  24. size="small"
  25. v-model="queryParams.userName"
  26. placeholder="员工编码"
  27. clearable
  28. ></el-input>
  29. </el-form-item>
  30. <el-form-item prop="name">
  31. <el-input
  32. size="small"
  33. v-model="queryParams.nickName"
  34. placeholder="员工名称"
  35. clearable
  36. ></el-input>
  37. </el-form-item>
  38. <el-form-item>
  39. <el-button
  40. type="primary"
  41. @click="getList()"
  42. size="small"
  43. icon="el-icon-search"
  44. >查询</el-button
  45. >
  46. <el-button
  47. @click="resetSearch()"
  48. size="small"
  49. icon="el-icon-refresh-right"
  50. >重置</el-button>
  51. </el-form-item>
  52. </el-form>
  53. </el-header>
  54. <el-main>
  55. <el-table
  56. :data="dataList"
  57. v-loading="loading"
  58. size="small"
  59. border
  60. ref="contractTable"
  61. @select="handleSelectionChange"
  62. height="calc(100% - 40px)"
  63. style="width: 100%"
  64. >
  65. <el-table-column
  66. type="selection"
  67. header-align="center"
  68. align="center"
  69. width="50"
  70. >
  71. </el-table-column>
  72. <el-table-column
  73. prop="userName"
  74. header-align="center"
  75. align="left"
  76. min-width="90"
  77. label="员工编码"
  78. >
  79. </el-table-column>
  80. <el-table-column
  81. prop="nickName"
  82. header-align="center"
  83. align="left"
  84. min-width="90"
  85. label="员工名称"
  86. >
  87. </el-table-column>
  88. </el-table>
  89. <el-pagination
  90. @size-change="sizeChangeHandle"
  91. @current-change="currentChangeHandle"
  92. :current-page="queryParams.pageNum"
  93. :page-sizes="[5, 10, 15, 20]"
  94. :page-size="queryParams.pageSize"
  95. :total="total"
  96. layout="total, sizes, prev, pager, next, jumper"
  97. >
  98. </el-pagination>
  99. </el-main>
  100. </el-container>
  101. </el-container>
  102. <span slot="footer" class="dialog-footer">
  103. <el-button
  104. size="small"
  105. @click="visible = false"
  106. icon="el-icon-circle-close"
  107. >关闭</el-button
  108. >
  109. <el-button
  110. size="small"
  111. type="primary"
  112. icon="el-icon-circle-check"
  113. @click="doSubmit()"
  114. >确定</el-button
  115. >
  116. </span>
  117. </el-dialog>
  118. </div>
  119. </template>
  120. <script>
  121. import { listUser } from "@/api/system/user";
  122. export default {
  123. data() {
  124. return {
  125. // 查询参数
  126. queryParams: {
  127. pageNum: 1,
  128. pageSize: 10,
  129. userName: undefined,
  130. nickName: undefined,
  131. },
  132. dataListAllSelections: [], // 所有选中的数据包含跨页数据
  133. idKey: "id", // 标识列表数据中每一行的唯一键的名称(需要按自己的数据改一下)
  134. dataList: [],
  135. pageNo: 1,
  136. pageSize: 10,
  137. total: 0,
  138. orders: [],
  139. loading: false,
  140. visible: false,
  141. };
  142. },
  143. props: {
  144. selectData: {
  145. type: Array,
  146. default: () => {
  147. return [];
  148. },
  149. },
  150. // 是否启用单选
  151. single: {
  152. type: Boolean,
  153. default: false
  154. }
  155. },
  156. methods: {
  157. init() {
  158. this.visible = true;
  159. this.$nextTick(() => {
  160. this.dataListAllSelections = JSON.parse(JSON.stringify(this.selectData));
  161. this.resetSearch();
  162. });
  163. },
  164. // 获取数据列表
  165. getList() {
  166. this.loading = true;
  167. listUser(this.addDateRange(this.queryParams)).then(response => {
  168. this.dataList = response.rows;
  169. this.total = response.total;
  170. this.loading = false;
  171. }
  172. );
  173. },
  174. // 每页数
  175. sizeChangeHandle(val) {
  176. this.queryParams.pageSize = val;
  177. this.queryParams.pageNum = 1;
  178. this.getList();
  179. },
  180. // 当前页
  181. currentChangeHandle(val) {
  182. this.queryParams.pageNum = val;
  183. this.getList();
  184. },
  185. // 重置
  186. resetSearch() {
  187. this.queryParams.userName = '';
  188. this.queryParams.nickName = '';
  189. this.getList();
  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>