index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="单位" prop="userUnit">
  5. <el-input
  6. v-model="queryParams.userUnit"
  7. placeholder="请输入单位"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="用户" prop="userIds">
  14. <el-input
  15. v-model="queryParams.userIds"
  16. placeholder="请输入用户"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  24. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  25. </el-form-item>
  26. </el-form>
  27. <el-row :gutter="10" class="mb8">
  28. <el-col :span="1.5">
  29. <el-button
  30. type="primary"
  31. icon="el-icon-plus"
  32. size="mini"
  33. @click="handleAdd"
  34. v-hasPermi="['invoice:unit:add']"
  35. >新增
  36. </el-button>
  37. </el-col>
  38. <el-col :span="1.5">
  39. <el-button
  40. type="success"
  41. icon="el-icon-edit"
  42. size="mini"
  43. :disabled="single"
  44. @click="handleUpdate"
  45. v-hasPermi="['invoice:unit:edit']"
  46. >修改
  47. </el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="danger"
  52. icon="el-icon-delete"
  53. size="mini"
  54. :disabled="multiple"
  55. @click="handleDelete"
  56. v-hasPermi="['invoice:unit:remove']"
  57. >删除
  58. </el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="info"
  63. icon="el-icon-upload2"
  64. size="mini"
  65. @click="handleImport"
  66. v-hasPermi="['invoice:unit:edit']"
  67. >导入
  68. </el-button>
  69. </el-col>
  70. <el-col :span="1.5">
  71. <el-button
  72. type="warning"
  73. icon="el-icon-download"
  74. size="mini"
  75. @click="handleExport"
  76. v-hasPermi="['invoice:unit:export']"
  77. >导出
  78. </el-button>
  79. </el-col>
  80. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  81. </el-row>
  82. <el-table v-loading="loading" ref="unitTable" :span-method="mergeMethod" :data="unitList" @selection-change="handleSelectionChange" :height="clientHeight"
  83. border >
  84. <el-table-column type="selection" width="55" align="center"/>
  85. <el-table-column label="单位" align="center" prop="userUnit" :show-overflow-tooltip="true"
  86. :formatter="unitFormat"/>
  87. <el-table-column label="用户" align="center" prop="nickName" :show-overflow-tooltip="true"/>
  88. <el-table-column label="备注" align="center" prop="remarks" :show-overflow-tooltip="true"/>
  89. <el-table-column label="操作" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
  90. <template slot-scope="scope">
  91. <el-button
  92. size="mini"
  93. type="text"
  94. icon="el-icon-edit"
  95. @click="handleUpdate(scope.row)"
  96. v-hasPermi="['invoice:unit:edit']"
  97. >修改
  98. </el-button>
  99. <el-button
  100. size="mini"
  101. type="text"
  102. icon="el-icon-delete"
  103. @click="handleDelete(scope.row)"
  104. v-hasPermi="['invoice:unit:remove']"
  105. >删除
  106. </el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <pagination
  111. v-show="total>0"
  112. :total="total"
  113. :page.sync="queryParams.pageNum"
  114. :limit.sync="queryParams.pageSize"
  115. @pagination="getList"
  116. />
  117. <!-- 添加或修改用户单位管理对话框 -->
  118. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  119. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  120. <el-form-item label="单位" prop="userUnit" >
  121. <el-select v-model="form.userUnit" :placeholder="$t('请选择') + $t('用户单位')" style="width: 100%">
  122. <el-option
  123. v-for="dict in unitOptions"
  124. :key="dict.dictValue"
  125. :label="dict.dictLabel"
  126. :value="dict.dictValue">
  127. </el-option>
  128. </el-select>
  129. </el-form-item>
  130. <el-form-item label="用户" prop="userIds">
  131. <el-select v-model="form.userIds" filterable :placeholder="$t('请选择') + $t('关联用户')" style="width: 100%">
  132. <el-option
  133. v-for="dict in userOptions"
  134. :key="dict.userId"
  135. :label="dict.nickName"
  136. :value="dict.userId">
  137. </el-option>
  138. </el-select>
  139. </el-form-item>
  140. <el-form-item label="归属部门" prop="deptId">
  141. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
  142. </el-form-item>
  143. <el-form-item label="备注" prop="remarks">
  144. <el-input v-model="form.remarks" placeholder="请输入备注"/>
  145. </el-form-item>
  146. </el-form>
  147. <div slot="footer" class="dialog-footer">
  148. <el-button type="primary" @click="submitForm">确 定</el-button>
  149. <el-button @click="cancel">取 消</el-button>
  150. </div>
  151. </el-dialog>
  152. <!-- 用户导入对话框 -->
  153. <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  154. <el-upload
  155. ref="upload"
  156. :limit="1"
  157. accept=".xlsx, .xls"
  158. :headers="upload.headers"
  159. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  160. :disabled="upload.isUploading"
  161. :on-progress="handleFileUploadProgress"
  162. :on-success="handleFileSuccess"
  163. :auto-upload="false"
  164. drag
  165. >
  166. <i class="el-icon-upload"></i>
  167. <div class="el-upload__text">
  168. 将文件拖到此处,或
  169. <em>点击上传</em>
  170. </div>
  171. <div class="el-upload__tip" slot="tip">
  172. <el-checkbox v-model="upload.updateSupport"/>
  173. 是否更新已经存在的用户数据
  174. <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
  175. </div>
  176. <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  177. </el-upload>
  178. <div slot="footer" class="dialog-footer">
  179. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  180. <el-button @click="upload.open = false">取 消</el-button>
  181. </div>
  182. </el-dialog>
  183. </div>
  184. </template>
  185. <script>
  186. import {listUnit, getUnit, delUnit, addUnit, updateUnit, exportUnit, importTemplate} from "@/api/invoice/unit";
  187. import {treeselect} from "@/api/system/dept";
  188. import {getToken} from "@/utils/auth";
  189. import Treeselect from "@riophae/vue-treeselect";
  190. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  191. import {listPostUser} from "@/api/system/user";
  192. export default {
  193. name: "Unit",
  194. components: {Treeselect},
  195. data() {
  196. return {
  197. unitOptions: [],
  198. userOptions: [],
  199. // 遮罩层
  200. loading: true,
  201. // 选中数组
  202. ids: [],
  203. // 非单个禁用
  204. single: true,
  205. // 非多个禁用
  206. multiple: true,
  207. // 显示搜索条件
  208. showSearch: false,
  209. // 总条数
  210. total: 0,
  211. // 用户单位管理表格数据
  212. unitList: [],
  213. // 弹出层标题
  214. title: "",
  215. // 部门树选项
  216. deptOptions: undefined,
  217. clientHeight: 300,
  218. // 是否显示弹出层
  219. open: false,
  220. // 用户导入参数
  221. upload: {
  222. // 是否显示弹出层(用户导入)
  223. open: false,
  224. // 弹出层标题(用户导入)
  225. title: "",
  226. // 是否禁用上传
  227. isUploading: false,
  228. // 是否更新已经存在的用户数据
  229. updateSupport: 0,
  230. // 设置上传的请求头部
  231. headers: {Authorization: "Bearer " + getToken()},
  232. // 上传的地址
  233. url: process.env.VUE_APP_BASE_API + "/invoice/unit/importData"
  234. },
  235. // 查询参数
  236. queryParams: {
  237. pageNum: 1,
  238. pageSize: 20,
  239. userUnit: null,
  240. userIds: null,
  241. createrCode: null,
  242. createdate: null,
  243. updaterCode: null,
  244. updatedate: null,
  245. deptId: null,
  246. remarks: null
  247. },
  248. // 表单参数
  249. form: {},
  250. // 表单校验
  251. rules: {
  252. userIds: [
  253. { required: true, message: "用户不能为空", trigger: "blur" }
  254. ],
  255. userUnit: [
  256. { required: true, message: "用户单位不能为空", trigger: "blur" }
  257. ],
  258. deptId: [
  259. { required: true, message: "归属部门不能为空", trigger: "blur" }
  260. ],
  261. }
  262. };
  263. },
  264. watch: {
  265. // 根据名称筛选部门树
  266. deptName(val) {
  267. this.$refs.tree.filter(val);
  268. }
  269. },
  270. created() {
  271. //设置表格高度对应屏幕高度
  272. this.$nextTick(() => {
  273. this.clientHeight = document.body.clientHeight - 250
  274. })
  275. this.getList();
  276. this.getTreeselect();
  277. this.getDicts("book_user_unit").then(response => {
  278. this.unitOptions = response.data;
  279. });
  280. listPostUser({}).then(response => {
  281. this.userOptions = response;
  282. });
  283. },
  284. methods: {
  285. // 状态字典翻译
  286. unitFormat(row, column) {
  287. return this.selectDictLabel(this.unitOptions, row.userUnit);
  288. },
  289. /** 查询用户单位管理列表 */
  290. getList() {
  291. let _this = this;
  292. this.loading = true;
  293. listUnit(this.queryParams).then(response => {
  294. this.unitList = response.rows;
  295. this.$nextTick(() => {
  296. this.$refs.unitTable.doLayout(); // 解决表格错位
  297. });
  298. this.total = response.total;
  299. this.loading = false;
  300. });
  301. },
  302. /** 查询部门下拉树结构 */
  303. getTreeselect() {
  304. treeselect().then(response => {
  305. this.deptOptions = response.data;
  306. });
  307. },
  308. // 取消按钮
  309. cancel() {
  310. this.open = false;
  311. this.reset();
  312. },
  313. // 表单重置
  314. reset() {
  315. this.form = {
  316. id: null,
  317. userUnit: null,
  318. userIds: null,
  319. delFlag: null,
  320. createrCode: null,
  321. createdate: null,
  322. updaterCode: null,
  323. updatedate: null,
  324. deptId: null,
  325. remarks: null
  326. };
  327. this.resetForm("form");
  328. },
  329. /** 搜索按钮操作 */
  330. handleQuery() {
  331. this.queryParams.pageNum = 1;
  332. this.getList();
  333. },
  334. /** 重置按钮操作 */
  335. resetQuery() {
  336. this.resetForm("queryForm");
  337. this.handleQuery();
  338. },
  339. // 多选框选中数据
  340. handleSelectionChange(selection) {
  341. this.ids = selection.map(item => item.id)
  342. this.single = selection.length !== 1
  343. this.multiple = !selection.length
  344. },
  345. /** 新增按钮操作 */
  346. handleAdd() {
  347. this.reset();
  348. this.open = true;
  349. this.title = "添加用户单位管理";
  350. },
  351. /** 修改按钮操作 */
  352. handleUpdate(row) {
  353. this.reset();
  354. const id = row.id || this.ids
  355. getUnit(id).then(response => {
  356. this.form = response.data;
  357. this.open = true;
  358. this.title = "修改用户单位管理";
  359. this.form.userIds = this.form.userIds - 0;
  360. });
  361. },
  362. /** 提交按钮 */
  363. submitForm() {
  364. this.$refs["form"].validate(valid => {
  365. if (valid) {
  366. if (this.form.id != null) {
  367. updateUnit(this.form).then(response => {
  368. this.msgSuccess("修改成功");
  369. this.open = false;
  370. this.getList();
  371. });
  372. } else {
  373. addUnit(this.form).then(response => {
  374. this.msgSuccess("新增成功");
  375. this.open = false;
  376. this.getList();
  377. });
  378. }
  379. }
  380. });
  381. },
  382. /** 删除按钮操作 */
  383. handleDelete(row) {
  384. const ids = row.id || this.ids;
  385. this.$confirm('是否确认删除?', "警告", {
  386. confirmButtonText: "确定",
  387. cancelButtonText: "取消",
  388. type: "warning"
  389. }).then(function () {
  390. return delUnit(ids);
  391. }).then(() => {
  392. this.getList();
  393. this.msgSuccess("删除成功");
  394. })
  395. },
  396. /** 导出按钮操作 */
  397. handleExport() {
  398. const queryParams = this.queryParams;
  399. this.$confirm('是否确认导出所有用户单位管理数据项?', "警告", {
  400. confirmButtonText: "确定",
  401. cancelButtonText: "取消",
  402. type: "warning"
  403. }).then(function () {
  404. return exportUnit(queryParams);
  405. }).then(response => {
  406. this.download(response.msg);
  407. })
  408. },
  409. /** 导入按钮操作 */
  410. handleImport() {
  411. this.upload.title = "用户导入";
  412. this.upload.open = true;
  413. },
  414. /** 下载模板操作 */
  415. importTemplate() {
  416. importTemplate().then(response => {
  417. this.download(response.msg);
  418. });
  419. },
  420. // 文件上传中处理
  421. handleFileUploadProgress(event, file, fileList) {
  422. this.upload.isUploading = true;
  423. },
  424. // 文件上传成功处理
  425. handleFileSuccess(response, file, fileList) {
  426. this.upload.open = false;
  427. this.upload.isUploading = false;
  428. this.$refs.upload.clearFiles();
  429. this.$alert(response.msg, "导入结果", {dangerouslyUseHTMLString: true});
  430. this.getList();
  431. },
  432. // 提交上传文件
  433. submitFileForm() {
  434. this.$refs.upload.submit();
  435. },
  436. //合并单元格
  437. mergeMethod({row, column, rowIndex, columnIndex}) {
  438. // if (columnIndex === 0) {
  439. // const _row = this.setTable(this.unitList).merge[rowIndex];
  440. // const _col = _row > 0 ? 1 : 0;
  441. // return {
  442. // rowspan: _row,
  443. // colspan: _col
  444. // };
  445. // }
  446. if (columnIndex === 1) {
  447. const _row = this.setTable(this.unitList).merge[rowIndex];
  448. const _col = _row > 0 ? 1 : 0;
  449. return {
  450. rowspan: _row,
  451. colspan: _col
  452. };
  453. }
  454. },
  455. //单元格整理
  456. setTable(tableData) {
  457. let spanArr = [],
  458. concat = 0;
  459. tableData.forEach((item, index) => {
  460. if (index === 0) {
  461. spanArr.push(1);
  462. } else {
  463. if (item.userUnit === tableData[index - 1].userUnit) {
  464. //第一列需合并相同内容的判断条件
  465. spanArr[concat] += 1;
  466. spanArr.push(0);
  467. } else {
  468. spanArr.push(1);
  469. concat = index;
  470. }
  471. }
  472. });
  473. return {
  474. merge: spanArr
  475. };
  476. }
  477. }
  478. };
  479. </script>