index-copy.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. <!-- 物料信息基础档案 -->
  2. <script src="../../../main.js"></script>
  3. <template>
  4. <div class="material-basic" v-loading="failLoad">
  5. <!-- 主体列表 -->
  6. <el-card
  7. class="material-list"
  8. v-loading="loading"
  9. :body-style="{
  10. height: '100%',
  11. padding: '10px ',
  12. display: 'flex',
  13. 'flex-direction': 'column',
  14. }"
  15. >
  16. <!-- 查询条件 -->
  17. <el-super-search
  18. v-model="params"
  19. :size="size"
  20. :dict="dict"
  21. :columns="SearchColumns"
  22. @reset="handleResetQuery"
  23. @submit="handleQuery"
  24. ></el-super-search>
  25. <!-- 操作栏 -->
  26. <el-row
  27. :gutter="10"
  28. class="mb10"
  29. type="flex"
  30. justify="end"
  31. style="margin: 10px 0"
  32. >
  33. <!-- 新增、修改、删除、复制 -->
  34. <el-col :span="1.5">
  35. <el-button-group>
  36. <el-button :size="size" @click="handleEdit">修改</el-button>
  37. <el-button :size="size" @click="handleRefresh">刷新</el-button>
  38. </el-button-group>
  39. </el-col>
  40. <!-- 启用 -->
  41. <el-col :span="1.5">
  42. <is-using
  43. :size="size"
  44. :select-data="checkedList"
  45. @success="handleQuery"
  46. ></is-using>
  47. </el-col>
  48. <!-- 导入导出 -->
  49. <el-col :span="1.5">
  50. <el-button-group>
  51. <el-button
  52. :size="size"
  53. @click="handleImport"
  54. v-hasPermi="['system:material:import']"
  55. >批量导入</el-button
  56. >
  57. <el-button
  58. :size="size"
  59. @click="handleExport"
  60. v-hasPermi="['system:material:export']"
  61. >批量导出</el-button
  62. >
  63. </el-button-group>
  64. </el-col>
  65. <!-- <el-col :span="1.5">
  66. <whlbButton :data="checkedList" :size="size"></whlbButton>
  67. </el-col> -->
  68. </el-row>
  69. <div
  70. class="el-super-ux-table"
  71. v-resize="resize"
  72. style="
  73. position: relative;
  74. display: flex;
  75. flex: 1;
  76. flex-direction: column;
  77. overflow: auto;
  78. "
  79. >
  80. <ux-grid
  81. v-if="tableHeader.length"
  82. border
  83. use-virtual
  84. keep-source
  85. beautify-table
  86. :size="size"
  87. :data="taskList"
  88. :height="tableHeight"
  89. ref="materialTable"
  90. @cell-dblclick="handledbClick"
  91. @select="handleSelect"
  92. @select-all="handleSelectAll"
  93. :header-row-style="{
  94. color: '#515a6e',
  95. }"
  96. style="flex: 1"
  97. >
  98. <
  99. <!-- 多选 -->
  100. <ux-table-column
  101. fixed="left"
  102. width="60"
  103. align="center"
  104. type="checkbox"
  105. resizable
  106. reserve-selection
  107. :column-key="rowKey"
  108. ></ux-table-column>
  109. <!-- 序号 -->
  110. <ux-table-column
  111. fixed="left"
  112. width="50"
  113. title="序号"
  114. type="index"
  115. align="center"
  116. class="is-index"
  117. resizable
  118. ></ux-table-column>
  119. <!-- <ux-table-column type="selection" width="45" :reserve-selection="true" fixed/>
  120. <ux-table-column type="index" title="序号" width="55" align="center"/> -->
  121. <ux-table-column
  122. width="150"
  123. v-for="h in tableHeader"
  124. v-if="h.show"
  125. :title="h.name"
  126. align="center"
  127. resizable
  128. show-overflow-tooltip
  129. >
  130. <template slot-scope="scope">
  131. <span v-if="h.apiUrl">{{ scope.row[`${h.prop}Name`] }}</span>
  132. <el-checkbox
  133. v-else-if="h.attribute == 'checkbox'"
  134. v-model="scope.row[h.prop]"
  135. disabled
  136. true-label="0"
  137. false-label="2"
  138. ></el-checkbox>
  139. <el-dict-tag
  140. v-else-if="h.dictId"
  141. :value="scope.row[h.prop]"
  142. :options="dict.type[h.dictId]"
  143. ></el-dict-tag>
  144. <span v-else>{{ scope.row[h.prop] || "--" }}</span>
  145. <!-- {{ h.attribute == 'select' ? scope.row[`${h.prop}Name`] :
  146. (h.attribute == 'checkbox' ?
  147. (scope.row[h.prop] == '0' ? '√' : '')
  148. : scope.row[h.prop])
  149. }} -->
  150. </template>
  151. </ux-table-column>
  152. </ux-grid>
  153. <div
  154. style="
  155. height: 50px;
  156. display: flex;
  157. justify-content: space-between;
  158. align-items: center;
  159. "
  160. :style="{
  161. height: '50px',
  162. }"
  163. >
  164. <pagination
  165. :total="total"
  166. :page.sync="queryParams.pageNum"
  167. :limit.sync="queryParams.pageSize"
  168. @pagination="handleQuery"
  169. style="
  170. height: 32px;
  171. padding: 0 !important;
  172. flex: 1;
  173. overflow-x: auto;
  174. "
  175. />
  176. </div>
  177. </div>
  178. </el-card>
  179. <!-- 操作提示 -->
  180. <el-dialog
  181. title="操作提示"
  182. :visible.sync="optionDialog.show"
  183. width="30%"
  184. center
  185. >
  186. <span>是否确认{{ optionDialog.op }}?</span>
  187. <span slot="footer">
  188. <el-button @click="handleOptionShow('option', false)">取 消</el-button>
  189. <el-button type="primary" @click="handleComfirmOption('cancal')"
  190. >确 定</el-button
  191. >
  192. </span>
  193. </el-dialog>
  194. <!-- 导入弹窗 -->
  195. <el-dialog
  196. title="批量导入"
  197. :visible.sync="importData.show"
  198. width="35%"
  199. center
  200. :before-close="handlefileDialogColse"
  201. >
  202. <div class="mb-import">
  203. <el-upload
  204. class="upload-demo"
  205. accept=".xls, .xlsx"
  206. ref="upload"
  207. action="#"
  208. :on-remove="handleFileRemove"
  209. :file-list="importData.list"
  210. :auto-upload="false"
  211. :on-change="handleChangeFile"
  212. :limit="1"
  213. >
  214. <el-button slot="trigger" :size="size" type="primary"
  215. >选取文件</el-button
  216. >
  217. <el-button
  218. style="margin-left: 10px"
  219. :size="size"
  220. type="success"
  221. @click="handleDownTemplate"
  222. >下载模板</el-button
  223. >
  224. <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
  225. </el-upload>
  226. </div>
  227. <span slot="footer">
  228. <el-button @click="handleImportData('cancal')">取 消</el-button>
  229. <el-button type="primary" @click="handleImportData('confirm')"
  230. >确 定</el-button
  231. >
  232. </span>
  233. </el-dialog>
  234. </div>
  235. </template>
  236. <script>
  237. import "./style/index.scss";
  238. import materialApi from "@/api/material/basic";
  239. import { SearchColumns, OtherDictColumns } from "./columns";
  240. import { initDicts } from "@/utils/init.js";
  241. export default {
  242. name: "material-basic",
  243. dicts: [...initDicts([...SearchColumns, ...OtherDictColumns])],
  244. components: {
  245. ElSuperSearch: () => import("@/components/super-search/index.vue"),
  246. ElDictTag: () => import("@/components/DictTag/index.vue"),
  247. IsUsing: () => import("./isUsing/index.vue"),
  248. whlbButton: () => import("./wei-hu-lei-bie/index.vue"),
  249. },
  250. data() {
  251. const params = this.$init.params(SearchColumns);
  252. return {
  253. failLoad: false,
  254. params: params,
  255. SearchColumns: SearchColumns,
  256. rowKey: "id",
  257. size: "mini",
  258. // 物料基本信息数据
  259. taskList: [],
  260. // 查询表单字段
  261. queryForm: {
  262. name: "",
  263. code: "",
  264. isEnable: "",
  265. },
  266. // 总条数
  267. total: 1,
  268. loading: false,
  269. importData: {
  270. show: false,
  271. list: [],
  272. },
  273. // 查询参数
  274. queryParams: {
  275. pageNum: 1,
  276. pageSize: 50,
  277. code: null,
  278. name: null,
  279. },
  280. // 表头
  281. tableHeader: [],
  282. // 多选数组
  283. checkedList: [],
  284. // 列表选中数据
  285. // checkedList: [],
  286. // 操作弹窗
  287. optionDialog: {
  288. show: false,
  289. op: "",
  290. },
  291. resizeHeight: 0,
  292. };
  293. },
  294. computed: {
  295. tableHeight: {
  296. get() {
  297. return this.resizeHeight;
  298. },
  299. set() {},
  300. },
  301. },
  302. directives: {
  303. // 使用局部注册指令的方式
  304. resize: {
  305. // 指令的名称
  306. bind(el, binding) {
  307. // el为绑定的元素,binding为绑定给指令的对象
  308. let width = "",
  309. height = "";
  310. function isReize() {
  311. const style = document.defaultView.getComputedStyle(el);
  312. if (width !== style.width || height !== style.height) {
  313. binding.value(); // 关键
  314. }
  315. width = style.width;
  316. height = style.height;
  317. }
  318. el.__vueSetInterval__ = setInterval(isReize, 300);
  319. },
  320. unbind(el) {
  321. clearInterval(el.__vueSetInterval__);
  322. },
  323. },
  324. },
  325. methods: {
  326. resize() {
  327. this.resizeHeight =
  328. document.getElementsByClassName("el-super-ux-table")[0].offsetHeight -
  329. 55;
  330. },
  331. // 判读是否启用
  332. handleJudgeIsUsing() {
  333. return (
  334. this.checkedList.length == 1 && this.checkedList[0].isEnable == "已启用"
  335. );
  336. },
  337. // 修改
  338. handleEdit() {
  339. if (this.checkedList.length == 1) {
  340. this.$router.push({
  341. path: `/material/basicFile/detail/${this.checkedList[0].id}`,
  342. query: {
  343. isEdit: true,
  344. },
  345. });
  346. } else {
  347. this.$notify.warning({
  348. message: `${
  349. this.checkedList.length > 1
  350. ? "修改只能选择单个数据!"
  351. : "请选择需要修改的信息!"
  352. }`,
  353. });
  354. }
  355. },
  356. // 删除
  357. handleDel() {
  358. console.log("删除", this.checkedList);
  359. // delMaterial
  360. if (this.checkedList.length) {
  361. let ids = this.checkedList.map((i) => i.id);
  362. materialApi.delMaterial(ids).then((res) => {
  363. if (res.code == 200) {
  364. this.handleRefresh();
  365. // 清空选中数据
  366. this.checkedList = [];
  367. this.$refs.materialTable.clearSelection();
  368. }
  369. });
  370. } else {
  371. this.$notify.warning({
  372. message: `请选择需要删除的数据!`,
  373. });
  374. }
  375. },
  376. //查询
  377. handleQuery() {
  378. // 重新查询后需要清空列表选中的数据
  379. this.checkedList = [];
  380. this.$refs.materialTable.clearSelection();
  381. this.getMaterialList();
  382. },
  383. // 重置查询条件
  384. handleResetQuery() {
  385. this.queryParams.pageNum = 1;
  386. this.queryParams.pageSize = 100;
  387. this.params = this.$init.params(SearchColumns);
  388. this.handleQuery();
  389. },
  390. // 刷新
  391. handleRefresh() {
  392. this.getMaterialList();
  393. // for (const key in this.queryForm) {
  394. // this.queryForm[key] = '';
  395. // }
  396. },
  397. // 批量导入
  398. handleImport() {
  399. this.importData.show = true;
  400. },
  401. // 导入弹窗关闭前
  402. handlefileDialogColse(done) {
  403. this.importData.list = [];
  404. done();
  405. },
  406. // 导入弹窗操作
  407. handleImportData(type) {
  408. switch (type) {
  409. // 取消
  410. case "cancal":
  411. this.importData.list = [];
  412. this.importData.show = false;
  413. break;
  414. // 确认
  415. case "confirm":
  416. if (this.importData.list.length) {
  417. let formData = new FormData();
  418. formData.append("file", this.importData.list[0].raw);
  419. materialApi.fileImport(formData).then((res) => {
  420. if (res.code == 200) {
  421. this.importData.show = false;
  422. this.importData.list = [];
  423. if (res.data.flag) {
  424. this.failLoad = true;
  425. console.log(res.data.datas);
  426. let param = { failDatas: res.data.datas };
  427. if (null != param) {
  428. materialApi.exportMartial(param).then((res) => {
  429. const blob = new Blob([res], {
  430. type: "application/vnd.ms-excel;charset=UTF-8",
  431. }); // 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
  432. const downloadElement = document.createElement("a"); //创建a标签
  433. const href = window.URL.createObjectURL(blob); // 创建下载的链接
  434. downloadElement.href = href; //下载地址
  435. downloadElement.download =
  436. "导入失败的物料基础档案数据.xlsx"; // 下载后文件名
  437. document.body.appendChild(downloadElement);
  438. downloadElement.click(); // 点击下载
  439. document.body.removeChild(downloadElement); // 下载完成移除元素
  440. window.URL.revokeObjectURL(href); // 释放blob对象
  441. this.failLoad = false;
  442. });
  443. }
  444. }
  445. this.$notify({
  446. message: res.data.msg,
  447. type: res.data.flag ? "warning" : "success",
  448. });
  449. } else {
  450. this.$notify({
  451. message: res.msg,
  452. type: res.code == 200 ? "success" : "warning",
  453. });
  454. }
  455. });
  456. } else {
  457. this.$notify({
  458. title: "警告",
  459. message: "请上传文件之后在确认!",
  460. type: "warning",
  461. });
  462. }
  463. break;
  464. }
  465. },
  466. // 删除文件
  467. handleFileRemove(file, fileList) {
  468. // console.log('删除文件', file, 'file', fileList, 'fileList');
  469. this.importData.list = fileList;
  470. },
  471. // 文件发生改变
  472. handleChangeFile(file, fileList) {
  473. this.importData.list = fileList;
  474. },
  475. // 批量导出
  476. handleExport() {
  477. let ids = this.checkedList.length
  478. ? this.checkedList.map((i) => i.id)
  479. : [];
  480. if (ids.length) {
  481. let params = {
  482. // orgId: '1',
  483. ids,
  484. };
  485. this.download(
  486. "/system/material/export",
  487. params,
  488. `物料基本信息${new Date().getTime()}.xlsx`
  489. );
  490. } else {
  491. let params = {
  492. templateCode: "material",
  493. ...this.params,
  494. createTimeBegin:
  495. (this.params.createTimeQueue && this.params.createTimeQueue[0]) ||
  496. "",
  497. createTimeEnd:
  498. (this.params.createTimeQueue && this.params.createTimeQueue[1]) ||
  499. "",
  500. updateTimeBegin:
  501. (this.params.updateTimeQueue && this.params.updateTimeQueue[0]) ||
  502. "",
  503. updateTimeEnd:
  504. (this.params.updateTimeQueue && this.params.updateTimeQueue[1]) ||
  505. "",
  506. };
  507. this.download(
  508. "/system/material/export",
  509. params,
  510. `物料基本信息${new Date().getTime()}.xlsx`
  511. );
  512. }
  513. },
  514. // 下载模板
  515. handleDownTemplate() {
  516. this.download("/system/material/download", {}, `物料基本信息模板.xlsx`);
  517. },
  518. // 操作弹窗显隐
  519. handleOptionShow(type, val) {
  520. switch (type) {
  521. case "option":
  522. this.optionDialog.show = val;
  523. break;
  524. }
  525. },
  526. // 操作弹窗确认按钮
  527. handleComfirmOption(op) {
  528. switch (op) {
  529. case "cancal":
  530. this.handleOptionShow("option", false);
  531. break;
  532. }
  533. },
  534. // 双击行
  535. handledbClick(e) {
  536. this.$router.push({
  537. path: `/material/basicFile/detail/${e.id}`,
  538. });
  539. },
  540. // 绑定row-key
  541. getRowKey(row) {
  542. return row.id;
  543. },
  544. // 对象数组去重
  545. handleUnique(arr, key) {
  546. // arr 需要去重的数组 type:作为去重依据的key
  547. const res = new Map();
  548. return arr.filter((arr) => !res.has(arr[key]) && res.set(arr[key], 1));
  549. },
  550. // 行数据勾选操作
  551. handleSelect(selection, row) {
  552. this.checkedList = selection;
  553. // // true就是选中,0或者false是取消选中
  554. // let selected = selection.length && selection.indexOf(row) !== -1
  555. },
  556. //手动勾选全选
  557. handleSelectAll(selection) {
  558. this.checkedList = selection;
  559. },
  560. // 获取物料列表信息
  561. async getMaterialList() {
  562. try {
  563. this.loading = true;
  564. let page = {
  565. pageNum: this.queryParams.pageNum,
  566. pageSize: this.queryParams.pageSize,
  567. };
  568. let param = {
  569. templateCode: "material",
  570. ...this.params,
  571. createTimeBegin:
  572. (this.params.createTimeQueue && this.params.createTimeQueue[0]) ||
  573. "",
  574. createTimeEnd:
  575. (this.params.createTimeQueue && this.params.createTimeQueue[1]) ||
  576. "",
  577. updateTimeBegin:
  578. (this.params.updateTimeQueue && this.params.updateTimeQueue[0]) ||
  579. "",
  580. updateTimeEnd:
  581. (this.params.updateTimeQueue && this.params.updateTimeQueue[1]) ||
  582. "",
  583. };
  584. let { code, data } = await materialApi.materialList(param, page);
  585. if (code == 200) {
  586. this.taskList = data.tableBody.rows;
  587. this.total = data.tableBody.total;
  588. }
  589. } catch (error) {
  590. } finally {
  591. this.loading = false;
  592. }
  593. // materialApi.materialList(param, page).then((res) => {
  594. // _this.loading = false;
  595. // console.log(res, '获取物料列表信息以及表头字段');
  596. // let {code, data} = res;
  597. // if (code == 200) {
  598. // _this.taskList = data.tableBody.rows;
  599. // _this.total = data.tableBody.total;
  600. // }
  601. // })
  602. },
  603. // 获取物料列表表头
  604. getTagList(templateCode) {
  605. materialApi.tagList({ templateCode }).then((res) => {
  606. console.log(res, "获取物料列表表头");
  607. if (res.code == 200) {
  608. this.tableHeader = res.data;
  609. }
  610. });
  611. },
  612. },
  613. created() {},
  614. beforeRouteEnter(to, from, next) {
  615. next((vm) => {
  616. if (from.name == "materialDetail") {
  617. // this.$store.getQuery(this.queryForm);
  618. console.log(vm, "queryValue", vm.$store);
  619. vm.queryForm = vm.$store.state.query.queryVlue;
  620. // 清空选中数据
  621. vm.checkedList = [];
  622. vm.$refs.materialTable && vm.$refs.materialTable.clearSelection();
  623. }
  624. vm.getTagList("material_list");
  625. vm.getMaterialList();
  626. });
  627. },
  628. // 进入详情,保留查询条件
  629. beforeRouteLeave(to, from, next) {
  630. if (to.name == "materialDetail") {
  631. this.$store.commit("SET_QUERY", this.queryForm);
  632. } else {
  633. this.$store.commit("SET_QUERY", { name: "", code: "" });
  634. }
  635. next();
  636. },
  637. };
  638. </script>
  639. <style lang="scss">
  640. .material-basic {
  641. height: calc(100vh);
  642. }
  643. .material-list {
  644. // height: calc(100vh - 70px);
  645. height: 100%;
  646. .el-card__body {
  647. height: 100%;
  648. box-sizing: border-box;
  649. padding: 10px;
  650. .el-table {
  651. // overflow: auto;
  652. .el-table__body-wrapper {
  653. overflow-y: auto !important;
  654. overflow-x: auto !important;
  655. }
  656. }
  657. }
  658. .el-pagination {
  659. // margin-top: 8px;
  660. text-align: right;
  661. }
  662. }
  663. .mb-import {
  664. padding: 0 20%;
  665. text-align: center;
  666. display: flex;
  667. align-items: flex-start;
  668. justify-content: space-around;
  669. }
  670. </style>
  671. <style scoped>
  672. .el-dialog__header {
  673. background-color: rgb(244, 244, 244);
  674. }
  675. .mb-query >>> .el-form-item__label {
  676. font-weight: normal;
  677. font-size: 12px;
  678. }
  679. .mb-query >>> .el-form-item {
  680. margin-bottom: 8px;
  681. }
  682. .mb-query >>> .el-select {
  683. width: 90px;
  684. }
  685. .mb-query >>> .el-scrollbar__wrap {
  686. margin-bottom: -18px;
  687. }
  688. ::v-deep.uxbeautifyTableClass
  689. .elx-header--column
  690. .elx-resizable.is--line:before {
  691. height: 100%;
  692. background-color: #dfe6ec;
  693. }
  694. </style>