index.vue 18 KB

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