index.vue 14 KB

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