index.vue 16 KB

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