index.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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="handleExport" 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. // 重新查询后需要清空列表选中的数据
  300. this.checkedList = [];
  301. this.$refs.materialTable.clearSelection();
  302. this.getMaterialList('material');
  303. },
  304. // 重置查询条件
  305. handleResetQuery() {
  306. // for (const key in this.queryForm) {
  307. // this.queryForm[key] = '';
  308. // }
  309. this.queryParams.pageNum = 1;
  310. this.queryParams.pageSize = 10;
  311. this.params = this.$init.params(SearchColumns);
  312. this.handleQuery();
  313. },
  314. // 刷新
  315. handleRefresh() {
  316. this.getMaterialList('material');
  317. // for (const key in this.queryForm) {
  318. // this.queryForm[key] = '';
  319. // }
  320. },
  321. // 过滤
  322. handleFilter(e) {
  323. console.log(e, '过滤');
  324. },
  325. filterCondition(type) {
  326. return {
  327. type
  328. }
  329. },
  330. // 启用/停用
  331. handleIsInvoke() {
  332. // true 当前状态为启用,需要改为停用
  333. // 0:启用 2:停用
  334. let param = {
  335. isEnable: this.handleJudgeIsUsing() ? '2' : '0',
  336. id: this.checkedList[0].id
  337. };
  338. materialApi.updateEnableMaterial(param).then(res => {
  339. if (res.code == 200) {
  340. this.handleRefresh();
  341. // 清空选中数据
  342. this.checkedList = [];
  343. this.$refs.materialTable.clearSelection();
  344. }
  345. })
  346. },
  347. isInvoke(val) {
  348. return val;
  349. },
  350. // 申请单查询
  351. handleQueryForm() {
  352. console.log('申请单查询');
  353. },
  354. // 批量导入
  355. handleImport() {
  356. this.importData.show = true
  357. },
  358. // 导入弹窗关闭前
  359. handlefileDialogColse(done) {
  360. this.importData.list = [];
  361. done();
  362. },
  363. // 导入弹窗操作
  364. handleImportData(type) {
  365. switch (type) {
  366. // 取消
  367. case 'cancal':
  368. this.importData.list = [];
  369. this.importData.show = false;
  370. break;
  371. // 确认
  372. case 'confirm':
  373. if (this.importData.list.length) {
  374. let formData = new FormData();
  375. formData.append('file', this.importData.list[0].raw);
  376. materialApi.fileImport(formData).then(res => {
  377. if (res.code == 200) {
  378. this.importData.show = false;
  379. this.importData.list = [];
  380. if (res.data.flag) {
  381. this.failLoad = true;
  382. console.log(res.data.datas)
  383. let param = {failDatas: res.data.datas}
  384. if (null != param) {
  385. materialApi.exportMartial(param).then(res => {
  386. const blob = new Blob([res], {
  387. type: "application/vnd.ms-excel;charset=UTF-8",
  388. });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
  389. const downloadElement = document.createElement("a"); //创建a标签
  390. const href = window.URL.createObjectURL(blob); // 创建下载的链接
  391. downloadElement.href = href; //下载地址
  392. downloadElement.download = '导入失败的物料基础档案数据.xlsx'; // 下载后文件名
  393. document.body.appendChild(downloadElement);
  394. downloadElement.click(); // 点击下载
  395. document.body.removeChild(downloadElement); // 下载完成移除元素
  396. window.URL.revokeObjectURL(href); // 释放blob对象
  397. this.failLoad = false;
  398. })
  399. }
  400. }
  401. this.$notify({
  402. message: res.data.msg,
  403. type: res.data.flag ? 'warning' : 'success'
  404. });
  405. } else {
  406. this.$notify({
  407. message: res.msg,
  408. type: res.code == 200 ? 'success' : 'warning'
  409. });
  410. }
  411. })
  412. } else {
  413. this.$notify({
  414. title:'警告',
  415. message: '请上传文件之后在确认!',
  416. type: 'warning',
  417. });
  418. }
  419. break;
  420. }
  421. },
  422. // 删除文件
  423. handleFileRemove(file, fileList) {
  424. console.log('删除文件', file, 'file', fileList, 'fileList');
  425. this.importData.list = fileList;
  426. },
  427. // 文件发生改变
  428. handleChangeFile(file, fileList) {
  429. this.importData.list = fileList;
  430. },
  431. // 批量导出
  432. handleExport() {
  433. let ids = this.checkedList.length ? this.checkedList.map(i => i.id) : [];
  434. if (ids.length) {
  435. let params = {
  436. // orgId: '1',
  437. ids,
  438. }
  439. this.download('/system/material/export', params, `物料基本信息${new Date().getTime()}.xlsx`);
  440. } else {
  441. let params = {
  442. templateCode:'material',
  443. ...this.params,
  444. createTimeBegin: (this.params.createTimeQueue && this.params.createTimeQueue[0]) || '',
  445. createTimeEnd:(this.params.createTimeQueue && this.params.createTimeQueue[1]) || '',
  446. updateTimeBegin:(this.params.updateTimeQueue && this.params.updateTimeQueue[0]) || '',
  447. updateTimeEnd:(this.params.updateTimeQueue && this.params.updateTimeQueue[1]) || ''
  448. }
  449. this.download('/system/material/export', params, `物料基本信息${new Date().getTime()}.xlsx`);
  450. }
  451. },
  452. // 下载模板
  453. handleDownTemplate() {
  454. this.download('/system/material/download', {}, `物料基本信息模板.xlsx`)
  455. },
  456. // 操作弹窗显隐
  457. handleOptionShow(type, val) {
  458. switch (type) {
  459. case 'option':
  460. this.optionDialog.show = val;
  461. break;
  462. }
  463. },
  464. // 操作弹窗确认按钮
  465. handleComfirmOption(op) {
  466. switch (op) {
  467. case 'cancal':
  468. this.handleOptionShow('option', false);
  469. break;
  470. }
  471. },
  472. // 双击行
  473. handledbClick(e) {
  474. this.$router.push({
  475. path: `/material/basicFile/detail/${e.id}`,
  476. });
  477. },
  478. // 绑定row-key
  479. getRowKey(row) {
  480. return row.id;
  481. },
  482. // 对象数组去重
  483. handleUnique(arr, key) {
  484. // arr 需要去重的数组 type:作为去重依据的key
  485. const res = new Map();
  486. return arr.filter((arr) => !res.has(arr[key]) && res.set(arr[key], 1))
  487. },
  488. // 选中数据改变
  489. handleSelectionChange(list) {
  490. // this.checkedList = this.handleUnique([...this.checkedList, ...list], 'id');
  491. // this.$emit('headerOption', JSON.stringify({ checkedList: [... this.checkedList] }))
  492. },
  493. // 行数据勾选操作
  494. handleSelect(selection, row) {
  495. this.checkedList = selection;
  496. // // true就是选中,0或者false是取消选中
  497. // let selected = selection.length && selection.indexOf(row) !== -1
  498. },
  499. //手动勾选全选
  500. handleSelectAll(selection) {
  501. this.checkedList = selection;
  502. },
  503. // 获取物料列表信息
  504. async getMaterialList(templateCode, query) {
  505. try {
  506. this.loading = true;
  507. let page = {
  508. pageNum: this.queryParams.pageNum,
  509. pageSize: this.queryParams.pageSize,
  510. }
  511. let param = {
  512. templateCode,
  513. ...this.params,
  514. createTimeBegin: (this.params.createTimeQueue && this.params.createTimeQueue[0]) || '',
  515. createTimeEnd:(this.params.createTimeQueue && this.params.createTimeQueue[1]) || '',
  516. updateTimeBegin:(this.params.updateTimeQueue && this.params.updateTimeQueue[0]) || '',
  517. updateTimeEnd:(this.params.updateTimeQueue && this.params.updateTimeQueue[1]) || ''
  518. }
  519. console.log(param,'param--------------');
  520. let {code,data} = await materialApi.materialList(param, page);
  521. if (code == 200) {
  522. this.taskList = data.tableBody.rows;
  523. this.total = data.tableBody.total;
  524. }
  525. } catch (error) {
  526. }finally{
  527. this.loading = false;
  528. }
  529. // materialApi.materialList(param, page).then((res) => {
  530. // _this.loading = false;
  531. // console.log(res, '获取物料列表信息以及表头字段');
  532. // let {code, data} = res;
  533. // if (code == 200) {
  534. // _this.taskList = data.tableBody.rows;
  535. // _this.total = data.tableBody.total;
  536. // }
  537. // })
  538. },
  539. // 获取物料列表表头
  540. getTagList(templateCode) {
  541. materialApi.tagList({templateCode}).then(res => {
  542. console.log(res, '获取物料列表表头');
  543. if (res.code == 200) {
  544. // let dictList = []
  545. // res.data.forEach(item =>{
  546. // if(item.dictId){
  547. // // 字典
  548. // dictList.push({
  549. // item:{...item},
  550. // attr:{
  551. // dictName:item.dictId
  552. // }
  553. // });
  554. // }
  555. // })
  556. // console.log(dictList,'dictList');
  557. // console.log(this,'this');
  558. // this.dict =[...initDicts([...SearchColumns,...dictList])]
  559. this.tableHeader = res.data;
  560. }
  561. })
  562. },
  563. },
  564. created() {
  565. // this.getMaterialList('material');
  566. // this.getTagList('material');
  567. },
  568. beforeRouteEnter(to, from, next) {
  569. next((vm) => {
  570. if (from.name == 'materialDetail') {
  571. // this.$store.getQuery(this.queryForm);
  572. console.log(vm, 'queryValue', vm.$store);
  573. vm.queryForm = vm.$store.state.query.queryVlue;
  574. // 清空选中数据
  575. vm.checkedList = [];
  576. vm.$refs.materialTable &&vm.$refs.materialTable.clearSelection();
  577. }
  578. vm.getTagList('material');
  579. vm.getMaterialList('material');
  580. });
  581. },
  582. // 进入详情,保留查询条件
  583. beforeRouteLeave(to, from, next) {
  584. if (to.name == 'materialDetail') {
  585. this.$store.commit('SET_QUERY', this.queryForm);
  586. } else {
  587. this.$store.commit('SET_QUERY', {name: '', code: ''});
  588. }
  589. next();
  590. }
  591. };
  592. </script>
  593. <style lang="scss">
  594. .material-list {
  595. // height: calc(100vh - 70px);
  596. .el-card__body {
  597. height: 100%;
  598. box-sizing: border-box;
  599. padding: 10px;
  600. .el-table {
  601. overflow: auto;
  602. .el-table__body-wrapper {
  603. overflow-y: auto !important;
  604. overflow-x: auto !important;
  605. }
  606. }
  607. }
  608. .el-pagination {
  609. margin-top: 8px;
  610. text-align: right;
  611. }
  612. }
  613. .mb-import {
  614. padding: 0 20%;
  615. text-align: center;
  616. display: flex;
  617. align-items: flex-start;
  618. justify-content: space-around;
  619. }
  620. </style>
  621. <style scoped>
  622. .el-dialog__header {
  623. background-color: rgb(244, 244, 244);
  624. }
  625. .mb-query >>> .el-form-item__label {
  626. font-weight: normal;
  627. font-size: 12px;
  628. }
  629. .mb-query >>> .el-form-item {
  630. margin-bottom: 8px;
  631. }
  632. .mb-query >>> .el-select {
  633. width: 90px;
  634. }
  635. .mb-query >>> .el-scrollbar__wrap {
  636. margin-bottom: -18px;
  637. }
  638. </style>