index.vue 19 KB

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