staffSelection.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <div class="container">
  3. <!-- 单据弹窗 -->
  4. <ele-modal
  5. title="选择设备"
  6. :before-close="handleClose"
  7. :visible.sync="dialogVisible"
  8. :close-on-click-modal="false"
  9. :append-to-body="true"
  10. width="80%" :maxable="true"
  11. >
  12. <el-row class="zw-page">
  13. <el-col :span="6" class="zw-page-left">
  14. <el-card>
  15. <div class="zw-card-header" slot="header">
  16. <span class="zw-header-title details-title">分类</span>
  17. </div>
  18. <div class="zw-page-left-tree">
  19. <el-container class="zw-container">
  20. <el-tree
  21. ref="tree"
  22. :data="treeList"
  23. highlight-current
  24. node-key="id"
  25. :props="{ label: 'name' }"
  26. :expand-on-click-node="false"
  27. :default-expand-all="true"
  28. @node-click="handleNodeClick"
  29. >
  30. </el-tree>
  31. </el-container>
  32. </div>
  33. </el-card>
  34. </el-col>
  35. <el-col :span="9" class="zw-page-main">
  36. <el-card>
  37. <div class="zw-card-header" slot="header">
  38. <span class="zw-header-title details-title">设备列表</span>
  39. </div>
  40. <div class="zw-page-main-list">
  41. <el-container class="zw-container">
  42. <el-table
  43. :data="staffList"
  44. tooltip-effect="dark"
  45. style="width: 100%"
  46. :header-cell-style="{
  47. background: '#F0F3F3',
  48. border: 'none'
  49. }"
  50. >
  51. <el-table-column prop="code" label="设备编码">
  52. <template slot-scope="{ row }">
  53. <div>{{ row.code }}</div>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="设备名称">
  57. <template slot-scope="{ row }">
  58. <div>{{ row.name }}</div>
  59. </template>
  60. </el-table-column>
  61. <el-table-column width="80" label="操作">
  62. <template slot-scope="{ row }">
  63. <el-button
  64. size="mini"
  65. type="primary"
  66. @click="choiceAsset(row)"
  67. :disabled="row.disabled"
  68. icon="el-icon-arrow-right"
  69. circle
  70. >
  71. </el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <div
  76. v-if="staffList.length !== 0 && isMore"
  77. class="zw-page-list-more"
  78. >
  79. <el-link @click="getMore(page)" type="primary"
  80. >更多<i class="el-icon-caret-bottom"></i>
  81. </el-link>
  82. </div>
  83. </el-container>
  84. </div>
  85. </el-card>
  86. </el-col>
  87. <el-col :span="9" class="zw-page-right">
  88. <el-card>
  89. <div class="zw-card-header" slot="header">
  90. <span class="zw-header-title">已选设备</span>
  91. </div>
  92. <div class="zw-page-right-list">
  93. <el-container class="zw-container">
  94. <el-table
  95. :data="selectStafflist"
  96. tooltip-effect="dark"
  97. style="width: 100%"
  98. :header-cell-style="{
  99. background: '#F0F3F3',
  100. border: 'none'
  101. }"
  102. >
  103. <el-table-column prop="code" label="设备编码">
  104. <template slot-scope="{ row }">
  105. <div>{{ row.code }}</div>
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="设备名称">
  109. <template slot-scope="{ row }">
  110. <div>{{ row.name }}</div>
  111. </template>
  112. </el-table-column>
  113. <el-table-column width="80" label="操作">
  114. <template slot-scope="scope">
  115. <el-button
  116. @click="deleteSelectStaff(scope.row, scope.$index)"
  117. size="mini"
  118. type="danger"
  119. >删除
  120. </el-button>
  121. </template>
  122. </el-table-column>
  123. </el-table>
  124. </el-container>
  125. </div>
  126. </el-card>
  127. </el-col>
  128. </el-row>
  129. <div slot="footer" class="dialog-footer">
  130. <el-button size="small" @click="handleClose">关 闭</el-button>
  131. <el-button size="small" @click="sumbit" type="primary">确 认</el-button>
  132. </div>
  133. </ele-modal>
  134. </div>
  135. </template>
  136. <script>
  137. import { listOrganizations, getUserPage } from '@/api/system/organization';
  138. import { getAssetList } from '@/api/ledgerAssets';
  139. import { getTreeByType } from '@/api/classifyManage';
  140. export default {
  141. data() {
  142. return {
  143. form: {
  144. groupId: null
  145. },
  146. treeList: [],
  147. // 选择的分类
  148. currentTree: '',
  149. staffList: [],
  150. selectStafflist: [], //已选员工
  151. defaultProps: {
  152. children: 'children',
  153. label: 'name',
  154. value: 'code'
  155. },
  156. pageNum: 1, //设备当前页数
  157. size: 10,
  158. isMore: false,
  159. dialogVisible: false
  160. };
  161. },
  162. created() {},
  163. methods: {
  164. open(selectedList) {
  165. this.dialogVisible = true;
  166. this.selectStafflist = selectedList;
  167. this.getInfo();
  168. },
  169. //初始数据
  170. async getInfo() {
  171. let res = await getTreeByType(1);
  172. this.treeList = this.$util.toTreeData({
  173. data: res.data,
  174. idField: 'id',
  175. parentIdField: 'parentId'
  176. });
  177. //this.treeList = res.data;
  178. },
  179. //选择分类
  180. handleNodeClick(data) {
  181. this.currentTree = data;
  182. this.pageNum = 1;
  183. let params = {
  184. pageNum: 1,
  185. size: this.size,
  186. categoryLevelId: this.currentTree.id,
  187. rootCategoryLevelId: this.treeList[0].id
  188. };
  189. this.staffList = [];
  190. this.getStaffList(params);
  191. },
  192. //获取设备列表
  193. async getStaffList(params) {
  194. let res = await getAssetList(params);
  195. let list = res.list;
  196. list.forEach((el) => {
  197. let _index = this.selectStafflist.findIndex((n) => n.id == el.id);
  198. if (_index !== -1) {
  199. el.disabled = true;
  200. } else {
  201. el.disabled = false;
  202. }
  203. });
  204. this.staffList = [...this.staffList, ...list];
  205. if (this.staffList.length < res.count) {
  206. this.isMore = true;
  207. } else {
  208. this.isMore = false;
  209. }
  210. // this.pageNum = res.pageNum;
  211. },
  212. //查询更多设备
  213. async getMore() {
  214. this.pageNum += 1;
  215. let params = {
  216. pageNum: 1,
  217. size: this.size,
  218. categoryLevelId: this.currentTree.id,
  219. rootCategoryLevelId: this.treeList[0].id
  220. };
  221. this.getStaffList(params);
  222. },
  223. //选择员工
  224. choiceAsset(info) {
  225. let data = JSON.parse(JSON.stringify(info));
  226. this.selectStafflist.push(data);
  227. info.disabled = true;
  228. },
  229. //删除已选员工
  230. deleteSelectStaff(info, index) {
  231. this.staffList.forEach((el) => {
  232. if (el.id == info.id) {
  233. el.disabled = false;
  234. }
  235. });
  236. this.selectStafflist.splice(index, 1);
  237. },
  238. //保存
  239. sumbit() {
  240. if (this.selectStafflist.length === 0) {
  241. this.$message.warning('请选择设备');
  242. } else {
  243. this.$emit('confirm', JSON.parse(JSON.stringify(this.selectStafflist)));
  244. this.handleClose();
  245. }
  246. },
  247. handleClose() {
  248. this.staffList = [];
  249. this.selectStafflist = [];
  250. this.dialogVisible = false;
  251. }
  252. }
  253. };
  254. </script>
  255. <style lang='scss' scoped>
  256. .container {
  257. padding: 10px 0;
  258. }
  259. .zw-container {
  260. height: 500px;
  261. }
  262. .zw-header-title {
  263. display: inline-block;
  264. margin-right: 10px;
  265. font-weight: 600;
  266. }
  267. .details-title {
  268. line-height: 32px;
  269. height: 32px;
  270. }
  271. .zw-page-list-p {
  272. font-size: 14px;
  273. margin-bottom: 18px;
  274. display: flex;
  275. justify-content: space-between;
  276. // align-items: center;
  277. .zw-page-list-right {
  278. display: flex;
  279. }
  280. }
  281. .zw-page {
  282. background: #fff;
  283. // padding: 20px 0;
  284. .zw-page-left {
  285. padding: 0 10px;
  286. }
  287. .zw-page-main {
  288. padding: 0 10px;
  289. .zw-page-main-list {
  290. span {
  291. margin-right: 10px;
  292. }
  293. .zw-page-span-num {
  294. font-size: 12px;
  295. color: #157a2c;
  296. }
  297. .zw-page-p-operation {
  298. text-align: right;
  299. // width: 200px;
  300. }
  301. .zw-page-operation-num {
  302. width: 100px;
  303. margin: 0 10px;
  304. }
  305. }
  306. .zw-page-list-more {
  307. text-align: center;
  308. }
  309. }
  310. .zw-page-right {
  311. .zw-card-header {
  312. display: flex;
  313. justify-content: space-between;
  314. align-items: center;
  315. height: 32px;
  316. }
  317. span {
  318. margin-right: 10px;
  319. }
  320. .zw-page-span-num {
  321. font-size: 12px;
  322. color: #157a2c;
  323. }
  324. }
  325. }
  326. .notes {
  327. font-size: 12px;
  328. color: #909090;
  329. }
  330. </style>