index.vue 21 KB

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