index.vue 19 KB

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