index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <!-- 物料信息基础档案 -->
  2. <script src="../../../main.js"></script>
  3. <template>
  4. <div class="material-basic" v-loading="failLoad">
  5. <!-- 操作栏 -->
  6. <div>
  7. <!-- 查询条件 -->
  8. <el-row :gutter="10">
  9. <el-col :span="1.5">
  10. <el-form :inline="true" :model="queryForm" class="mb-query" @submit.native.prevent>
  11. <el-form-item label="物料编码">
  12. <el-input size="small" v-model="queryForm.code" placeholder="物料编码" clearable></el-input>
  13. </el-form-item>
  14. <el-form-item label="物料名称">
  15. <el-input size="small" v-model="queryForm.name" placeholder="物料名称" clearable></el-input>
  16. </el-form-item>
  17. <el-form-item label="启用状态">
  18. <!-- 0=已启用,2=已停用 -->
  19. <el-select size="small" v-model="queryForm.isEnable" placeholder="请选择" clearable>
  20. <el-option key="0" label="已启用" value="0"></el-option>
  21. <el-option key="2" label="已停用" value="2"></el-option>
  22. </el-select>
  23. </el-form-item>
  24. <el-form-item label="是否同步NC">
  25. <!-- 是否同步;2=否,0=是 -->
  26. <el-select size="small" v-model="queryForm.isSync" placeholder="请选择" clearable>
  27. <el-option key="0" label="是" value="0"></el-option>
  28. <el-option key="2" label="否" value="2"></el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button size="small" type="primary" @click="handleQuery">搜索</el-button>
  33. <el-button size="small" @click="handleResetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. </el-col>
  37. </el-row>
  38. <el-row
  39. :gutter="10"
  40. class="mb10"
  41. type="flex"
  42. justify="end"
  43. >
  44. <!-- 新增、修改、删除、复制 -->
  45. <el-col :span="1.5">
  46. <el-button-group>
  47. <!-- <el-button size="small" @click="handleInster">新增</el-button> -->
  48. <el-button size="small" @click="handleEdit">修改</el-button>
  49. <!-- <el-button size="small" @click="handleDel">删除</el-button> -->
  50. <!-- <el-button size="small" @click="handleCopy">复制</el-button> -->
  51. </el-button-group>
  52. </el-col>
  53. <!-- 查询、刷新、过滤 -->
  54. <el-col :span="1.5">
  55. <el-button-group>
  56. <!-- <el-dropdown size="small" @command="handleFilter">
  57. <el-button size="small">
  58. 过滤<i class="el-icon-arrow-down el-icon--right"></i>
  59. </el-button>
  60. <el-dropdown-menu slot="dropdown">
  61. <el-dropdown-item :command="filterCondition('stop')">显示停用</el-dropdown-item>
  62. <el-dropdown-item :command="filterCondition('allot')">显示已分配</el-dropdown-item>
  63. </el-dropdown-menu>
  64. </el-dropdown> -->
  65. <!-- <el-button size="small" @click="handleQuery">查询</el-button> -->
  66. <el-button size="small" @click="handleRefresh">刷新</el-button>
  67. </el-button-group>
  68. </el-col>
  69. <!-- 启用 -->
  70. <el-col :span="1.5">
  71. <el-button-group>
  72. <el-button size="small" @click="handleIsInvoke" :disabled="checkedList.length != 1"
  73. v-hasPermi="['system:material:add']">
  74. <!-- 0:启用 2:停用 -->
  75. {{ handleJudgeIsUsing() ? '停用' : '启用' }}
  76. </el-button>
  77. </el-button-group>
  78. </el-col>
  79. <!-- 导入导出 -->
  80. <el-col :span="1.5">
  81. <el-button-group>
  82. <el-button size="small" @click="handleImport" v-hasPermi="['system:material:import']">批量导入</el-button>
  83. <el-button size="small" @click="handleExport" v-hasPermi="['system:material:export']">批量导出</el-button>
  84. </el-button-group>
  85. </el-col>
  86. </el-row>
  87. </div>
  88. <!-- 主体列表 -->
  89. <el-card class="material-list" v-loading="loading">
  90. <el-table :data="taskList" ref="materialTable" @cell-dblclick="handledbClick" :row-key="getRowKey"
  91. @selection-change="handleSelectionChange" @select="handleSelect" @select-all="handleSelectAll">
  92. <!-- -->
  93. <el-table-column type="selection" width="30" :reserve-selection="true"/>
  94. <el-table-column type="index" label="序号" width="55" align="center"/>
  95. <el-table-column width="150" v-for="h in tableHeader" v-if="h.show" :label="h.name" align="center"
  96. show-overflow-tooltip>
  97. <!-- :prop="h.attribute == 'select' ? `${h.prop}Name` : h.prop" -->
  98. <template slot-scope="scope">
  99. {{ h.attribute == 'select' ? scope.row[`${h.prop}Name`] :
  100. (h.attribute == 'checkbox' ?
  101. (scope.row[h.prop] == '0' ? '√' : '')
  102. : scope.row[h.prop])
  103. }}
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
  108. :current-page="queryParams.pageNum" :page-sizes="[10, 20, 50, 100]"
  109. layout="total, sizes, prev, pager, next, jumper" :total="total">
  110. </el-pagination>
  111. </el-card>
  112. <!-- 操作提示 -->
  113. <el-dialog title="操作提示" :visible.sync="optionDialog.show" width="30%" center>
  114. <span>是否确认{{ optionDialog.op }}?</span>
  115. <span slot="footer">
  116. <el-button @click="handleOptionShow('option', false)">取 消</el-button>
  117. <el-button type="primary" @click="handleComfirmOption('cancal')">确 定</el-button>
  118. </span>
  119. </el-dialog>
  120. <!-- 导入弹窗 -->
  121. <el-dialog title="批量导入" :visible.sync="importData.show" width="35%" center :before-close="handlefileDialogColse">
  122. <div class="mb-import">
  123. <el-upload class="upload-demo" accept=".xls, .xlsx" ref="upload" action="#" :on-remove="handleFileRemove"
  124. :file-list="importData.list" :auto-upload="false" :on-change="handleChangeFile" :limit="1">
  125. <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
  126. <el-button style="margin-left: 10px;" size="small" type="success" @click="handleDownTemplate">下载模板</el-button>
  127. <div slot="tip" class="el-upload__tip">只能上传Excel文件</div>
  128. </el-upload>
  129. </div>
  130. <span slot="footer">
  131. <el-button @click="handleImportData('cancal')">取 消</el-button>
  132. <el-button type="primary" @click="handleImportData('confirm')">确 定</el-button>
  133. </span>
  134. </el-dialog>
  135. </div>
  136. </template>
  137. <script>
  138. import './style/index.scss';
  139. import materialApi from '@/api/material/basic';
  140. export default {
  141. name: "material-basic",
  142. data() {
  143. return {
  144. failLoad: false,
  145. // 物料基本信息数据
  146. taskList: [],
  147. // 查询表单字段
  148. queryForm: {
  149. name: '',
  150. code: '',
  151. isEnable: '',
  152. },
  153. // 总条数
  154. total: 1,
  155. loading: false,
  156. importData: {
  157. show: false,
  158. list: []
  159. },
  160. // 查询参数
  161. queryParams: {
  162. pageNum: 1,
  163. pageSize: 10,
  164. code: null,
  165. name: null
  166. },
  167. // 表头
  168. tableHeader: [],
  169. // 多选数组
  170. checkedList: [],
  171. // 列表选中数据
  172. // checkedList: [],
  173. // 操作弹窗
  174. optionDialog: {
  175. show: false,
  176. op: ''
  177. },
  178. }
  179. },
  180. methods: {
  181. // 判读是否启用
  182. handleJudgeIsUsing() {
  183. return this.checkedList.length == 1 && this.checkedList[0].isEnable == '已启用';
  184. },
  185. // 改变分页大小
  186. handleSizeChange(e) {
  187. this.queryParams.pageSize = e;
  188. this.handleQuery();
  189. },
  190. // 改变当前页
  191. handleCurrentChange(e) {
  192. this.queryParams.pageNum = e;
  193. this.handleQuery();
  194. },
  195. // 新增
  196. handleInster() {
  197. this.$message({
  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.$message({
  213. message: `${this.checkedList.length > 1 ? '修改只能选择单个数据!' : '请选择需要修改的信息!'}`,
  214. type: 'warning'
  215. });
  216. }
  217. },
  218. // 删除
  219. handleDel() {
  220. console.log('删除', this.checkedList);
  221. // delMaterial
  222. if (this.checkedList.length) {
  223. let ids = this.checkedList.map(i => i.id);
  224. materialApi.delMaterial(ids).then(res => {
  225. if (res.code == 200) {
  226. this.handleRefresh();
  227. // 清空选中数据
  228. this.checkedList = [];
  229. this.$refs.materialTable.clearSelection();
  230. }
  231. })
  232. } else {
  233. this.$message({
  234. message: '请选择需要删除的数据!',
  235. type: 'warning'
  236. });
  237. }
  238. },
  239. // 复制
  240. handleCopy() {
  241. console.log('复制');
  242. },
  243. //查询
  244. handleQuery() {
  245. this.getMaterialList('material');
  246. },
  247. // 重置查询条件
  248. handleResetQuery() {
  249. for (const key in this.queryForm) {
  250. this.queryForm[key] = '';
  251. }
  252. },
  253. // 刷新
  254. handleRefresh() {
  255. this.getMaterialList('material');
  256. for (const key in this.queryForm) {
  257. this.queryForm[key] = '';
  258. }
  259. },
  260. // 过滤
  261. handleFilter(e) {
  262. console.log(e, '过滤');
  263. },
  264. filterCondition(type) {
  265. return {
  266. type
  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.$message({
  341. message: res.data.msg,
  342. type: res.data.flag ? 'warning' : 'success'
  343. });
  344. } else {
  345. this.$message({
  346. message: res.msg,
  347. type: res.code == 200 ? 'success' : 'warning'
  348. });
  349. }
  350. })
  351. } else {
  352. this.$message({
  353. message: '请上传文件之后在确认!',
  354. type: 'warning'
  355. });
  356. }
  357. break;
  358. }
  359. },
  360. // 删除文件
  361. handleFileRemove(file, fileList) {
  362. console.log('删除文件', file, 'file', fileList, 'fileList');
  363. this.importData.list = fileList;
  364. },
  365. // 文件发生改变
  366. handleChangeFile(file, fileList) {
  367. this.importData.list = fileList;
  368. },
  369. // 批量导出
  370. handleExport() {
  371. let ids = this.checkedList.length ? this.checkedList.map(i => i.id) : [];
  372. if (ids.length) {
  373. let params = {
  374. // orgId: '1',
  375. ids,
  376. }
  377. this.download('/system/material/export', params, `物料基本信息${new Date().getTime()}.xlsx`);
  378. } else {
  379. this.$message({
  380. message: '请选择需要导出的数据!',
  381. type: 'warning'
  382. });
  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. getMaterialList(templateCode, query) {
  438. let _this = this;
  439. this.loading = true;
  440. let page = {
  441. pageNum: this.queryParams.pageNum,
  442. pageSize: this.queryParams.pageSize,
  443. }
  444. let param = {
  445. templateCode,
  446. ...this.queryForm
  447. }
  448. // console.log(param, 'param');
  449. materialApi.materialList(param, page).then((res) => {
  450. _this.loading = false;
  451. console.log(res, '获取物料列表信息以及表头字段');
  452. let {code, data} = res;
  453. if (code == 200) {
  454. _this.taskList = data.tableBody.rows;
  455. _this.total = data.tableBody.total;
  456. }
  457. })
  458. },
  459. // 获取物料列表表头
  460. getTagList(templateCode) {
  461. materialApi.tagList({templateCode}).then(res => {
  462. console.log(res, '获取物料列表表头');
  463. if (res.code == 200) {
  464. this.tableHeader = res.data;
  465. }
  466. })
  467. },
  468. },
  469. created() {
  470. // this.getMaterialList('material');
  471. // this.getTagList('material');
  472. },
  473. beforeRouteEnter(to, from, next) {
  474. next((vm) => {
  475. if (from.name == 'materialDetail') {
  476. // this.$store.getQuery(this.queryForm);
  477. console.log(vm, 'queryValue', vm.$store);
  478. vm.queryForm = vm.$store.state.query.queryVlue;
  479. // 清空选中数据
  480. vm.checkedList = [];
  481. vm.$refs.materialTable.clearSelection();
  482. }
  483. vm.getTagList('material');
  484. vm.getMaterialList('material');
  485. });
  486. },
  487. // 进入详情,保留查询条件
  488. beforeRouteLeave(to, from, next) {
  489. if (to.name == 'materialDetail') {
  490. this.$store.commit('SET_QUERY', this.queryForm);
  491. } else {
  492. this.$store.commit('SET_QUERY', {name: '', code: ''});
  493. }
  494. next();
  495. }
  496. };
  497. </script>
  498. <style lang="scss">
  499. .material-list {
  500. // height: calc(100% - 100px);
  501. height: calc(100% - 70px);
  502. .el-card__body {
  503. height: 100%;
  504. box-sizing: border-box;
  505. .el-table {
  506. height: calc(100% - 35px);
  507. overflow: auto;
  508. .el-table__body-wrapper {
  509. // height: calc(100% - 150px);
  510. height: calc(100% - 70px);
  511. overflow-y: auto !important;
  512. overflow-x: auto !important;
  513. // .el-table__body {
  514. // height: 100%;
  515. // }
  516. }
  517. }
  518. }
  519. .el-pagination {
  520. margin-top: 8px;
  521. text-align: right;
  522. }
  523. }
  524. .mb-import {
  525. padding: 0 20%;
  526. text-align: center;
  527. display: flex;
  528. align-items: flex-start;
  529. justify-content: space-around;
  530. }
  531. </style>
  532. <style scoped>
  533. .el-dialog__header {
  534. background-color: rgb(244, 244, 244);
  535. }
  536. .mb-query >>> .el-form-item__label {
  537. font-weight: normal;
  538. font-size: 12px;
  539. }
  540. .mb-query >>> .el-form-item {
  541. margin-bottom: 8px;
  542. }
  543. .mb-query >>> .el-select {
  544. width: 90px;
  545. }
  546. .mb-query >>> .el-scrollbar__wrap {
  547. margin-bottom: -18px;
  548. }
  549. </style>