index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  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. console.log(this.checkedList, 'this.checkedList');
  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.$message({
  207. message: `${this.checkedList.length > 1 ? '修改只能选择单个数据!' : '请选择需要修改的信息!'}`,
  208. type: 'warning'
  209. });
  210. }
  211. },
  212. // 删除
  213. handleDel() {
  214. console.log('删除', this.checkedList);
  215. // delMaterial
  216. if (this.checkedList.length) {
  217. let ids = this.checkedList.map(i => i.id);
  218. materialApi.delMaterial(ids).then(res => {
  219. if (res.code == 200) {
  220. this.handleRefresh();
  221. // 清空选中数据
  222. this.checkedList = [];
  223. this.$refs.materialTable.clearSelection();
  224. }
  225. })
  226. } else {
  227. this.$message({
  228. message: '请选择需要删除的数据!',
  229. type: 'warning'
  230. });
  231. }
  232. },
  233. // 复制
  234. handleCopy() {
  235. console.log('复制');
  236. },
  237. //查询
  238. handleQuery() {
  239. console.log('查询');
  240. this.getMaterialList('material');
  241. },
  242. // 重置查询条件
  243. handleResetQuery() {
  244. for (const key in this.queryForm) {
  245. this.queryForm[key] = '';
  246. }
  247. },
  248. // 刷新
  249. handleRefresh() {
  250. console.log('刷新');
  251. this.getMaterialList('material');
  252. for (const key in this.queryForm) {
  253. this.queryForm[key] = '';
  254. }
  255. },
  256. // 过滤
  257. handleFilter(e) {
  258. console.log(e, '过滤');
  259. },
  260. filterCondition(type) {
  261. return {
  262. type
  263. }
  264. },
  265. // 启用/停用
  266. handleIsInvoke() {
  267. // true 当前状态为启用,需要改为停用
  268. // 0:启用 2:停用
  269. let param = {
  270. isEnable: this.handleJudgeIsUsing() ? '2' : '0',
  271. id: this.checkedList[0].id
  272. };
  273. materialApi.updateEnableMaterial(param).then(res => {
  274. console.log(res, '启用/停用');
  275. if (res.code == 200) {
  276. this.handleRefresh();
  277. // 清空选中数据
  278. this.checkedList = [];
  279. this.$refs.materialTable.clearSelection();
  280. }
  281. })
  282. },
  283. isInvoke(val) {
  284. return val;
  285. },
  286. // 申请单查询
  287. handleQueryForm() {
  288. console.log('申请单查询');
  289. },
  290. // 批量导入
  291. handleImport() {
  292. console.log('批量导入');
  293. this.importData.show = true
  294. },
  295. // 导入弹窗关闭前
  296. handlefileDialogColse(done) {
  297. this.importData.list = [];
  298. done();
  299. },
  300. // 导入弹窗操作
  301. handleImportData(type) {
  302. console.log('导入弹窗操作');
  303. switch (type) {
  304. // 取消
  305. case 'cancal':
  306. this.importData.list = [];
  307. this.importData.show = false;
  308. break;
  309. // 确认
  310. case 'confirm':
  311. console.log(this.importData.list, 'this.fileList');
  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. }
  320. this.$message({
  321. message: res.msg,
  322. type: res.code == 200 ? 'success' : 'warning'
  323. });
  324. })
  325. } else {
  326. this.$message({
  327. message: '请上传文件之后在确认!',
  328. type: 'warning'
  329. });
  330. }
  331. break;
  332. }
  333. },
  334. // 删除文件
  335. handleFileRemove(file, fileList) {
  336. console.log('删除文件', file, 'file', fileList, 'fileList');
  337. this.importData.list = fileList;
  338. },
  339. // 文件发生改变
  340. handleChangeFile(file, fileList) {
  341. this.importData.list = fileList;
  342. console.log(this.importData.list, '文件发生改变');
  343. },
  344. // 批量导出
  345. handleExport() {
  346. console.log('批量导出', this.checkedList);
  347. let ids = this.checkedList.length ? this.checkedList.map(i => i.id) : [];
  348. if (ids.length) {
  349. let params = {
  350. // orgId: '1',
  351. ids,
  352. }
  353. this.download('/system/material/export', params, `物料基本信息${new Date().getTime()}.xlsx`);
  354. } else {
  355. this.$message({
  356. message: '请选择需要导出的数据!',
  357. type: 'warning'
  358. });
  359. }
  360. },
  361. // 下载模板
  362. handleDownTemplate() {
  363. console.log('下载模板');
  364. this.download('/system/material/download', {}, `物料基本信息模板.xlsx`)
  365. },
  366. // 操作弹窗显隐
  367. handleOptionShow(type, val) {
  368. switch (type) {
  369. case 'option':
  370. this.optionDialog.show = val;
  371. break;
  372. }
  373. },
  374. // 操作弹窗确认按钮
  375. handleComfirmOption(op) {
  376. switch (op) {
  377. case 'cancal':
  378. this.handleOptionShow('option', false);
  379. break;
  380. }
  381. },
  382. // 双击行
  383. handledbClick(e) {
  384. console.log(e, '双击行');
  385. this.$router.push({
  386. path: `/material/basicFile/detail/${e.id}`,
  387. });
  388. },
  389. // 绑定row-key
  390. getRowKey(row) {
  391. return row.id;
  392. },
  393. // 对象数组去重
  394. handleUnique(arr, key) {
  395. // arr 需要去重的数组 type:作为去重依据的key
  396. const res = new Map();
  397. return arr.filter((arr) => !res.has(arr[key]) && res.set(arr[key], 1))
  398. },
  399. // 选中数据改变
  400. handleSelectionChange(list) {
  401. // this.checkedList = this.handleUnique([...this.checkedList, ...list], 'id');
  402. // console.log(this.checkedList, '选中数据改变');
  403. // this.$emit('headerOption', JSON.stringify({ checkedList: [... this.checkedList] }))
  404. },
  405. // 行数据勾选操作
  406. handleSelect(selection, row) {
  407. this.checkedList = selection;
  408. // // true就是选中,0或者false是取消选中
  409. // let selected = selection.length && selection.indexOf(row) !== -1
  410. },
  411. //手动勾选全选
  412. handleSelectAll(selection) {
  413. // console.log(selection, '手动勾选全选--------------');
  414. this.checkedList = selection;
  415. },
  416. // 获取物料列表信息
  417. getMaterialList(templateCode, query) {
  418. let _this = this;
  419. this.loading = true;
  420. let page = {
  421. pageNum: this.queryParams.pageNum,
  422. pageSize: this.queryParams.pageSize,
  423. }
  424. let param = {
  425. templateCode,
  426. ...this.queryForm
  427. }
  428. // console.log(param, 'param');
  429. materialApi.materialList(param, page).then((res) => {
  430. _this.loading = false;
  431. console.log(res, '获取物料列表信息以及表头字段');
  432. let { code, data } = res;
  433. if (code == 200) {
  434. _this.taskList = data.tableBody.rows;
  435. _this.total = data.tableBody.total;
  436. }
  437. })
  438. },
  439. // 获取物料列表表头
  440. getTagList(templateCode) {
  441. materialApi.tagList({ templateCode }).then(res => {
  442. console.log(res, '获取物料列表表头');
  443. if (res.code == 200) {
  444. this.tableHeader = res.data;
  445. }
  446. })
  447. },
  448. },
  449. created() {
  450. // this.getMaterialList('material');
  451. // this.getTagList('material');
  452. },
  453. beforeRouteEnter(to, from, next) {
  454. console.log(to, 'to', from, 'beforeRouteEnter');
  455. next((vm) => {
  456. if (from.name == 'materialDetail') {
  457. // this.$store.getQuery(this.queryForm);
  458. console.log(vm, 'queryValue', vm.$store);
  459. vm.queryForm = vm.$store.state.query.queryVlue;
  460. // 清空选中数据
  461. vm.checkedList = [];
  462. vm.$refs.materialTable.clearSelection();
  463. }
  464. vm.getTagList('material');
  465. vm.getMaterialList('material');
  466. });
  467. },
  468. // 进入详情,保留查询条件
  469. beforeRouteLeave(to, from, next) {
  470. console.log(to, 'to', from, 'beforeRouteLeave');
  471. if (to.name == 'materialDetail') {
  472. this.$store.commit('SET_QUERY', this.queryForm);
  473. } else {
  474. this.$store.commit('SET_QUERY', { name: '', code: '' });
  475. }
  476. next();
  477. }
  478. };
  479. </script>
  480. <style lang="scss">
  481. .material-list {
  482. // height: calc(100% - 100px);
  483. height: calc(100% - 70px);
  484. .el-card__body {
  485. height: 100%;
  486. box-sizing: border-box;
  487. .el-table {
  488. height: calc(100% - 35px);
  489. overflow: auto;
  490. .el-table__body-wrapper {
  491. // height: calc(100% - 150px);
  492. height: calc(100% - 70px);
  493. overflow-y: auto !important;
  494. overflow-x: auto !important;
  495. // .el-table__body {
  496. // height: 100%;
  497. // }
  498. }
  499. }
  500. }
  501. .el-pagination {
  502. margin-top: 8px;
  503. text-align: right;
  504. }
  505. }
  506. .mb-import {
  507. padding: 0 20%;
  508. text-align: center;
  509. display: flex;
  510. align-items: flex-start;
  511. justify-content: space-around;
  512. }
  513. </style>
  514. <style scoped>
  515. .el-dialog__header {
  516. background-color: rgb(244, 244, 244);
  517. }
  518. .mb-query>>>.el-form-item__label {
  519. font-weight: normal;
  520. font-size: 12px;
  521. }
  522. .mb-query>>>.el-form-item {
  523. margin-bottom: 8px;
  524. }
  525. .mb-query>>>.el-select {
  526. width: 90px;
  527. }
  528. .mb-query>>>.el-scrollbar__wrap {
  529. margin-bottom: -18px;
  530. }
  531. </style>