index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div class="classify">
  3. <el-card v-loading="loading">
  4. <el-row :gutter="10" class="mb10">
  5. <div>
  6. <el-button type="primary" size="mini" @click="mbDownload">模板下载</el-button>
  7. <el-button type="primary" size="mini" @click="importMb">导入</el-button>
  8. <el-button type="primary" size="mini" plain @click="addClassify">新增</el-button>
  9. <el-button type="primary" size="mini" plain @click="editClassify">修改</el-button>
  10. <el-button type="primary" size="mini" plain @click="refreshData">{{refreshName ? '全部分类': '过滤停用'}}</el-button>
  11. <!-- <el-button type="primary" size="mini" plain @click="deleteClassify">删除</el-button> -->
  12. </div>
  13. </el-row>
  14. <el-row :gutter="10" class="content">
  15. <el-col :span="6">
  16. <el-input
  17. placeholder="输入关键字/编码进行过滤"
  18. size="mini"
  19. v-model="filterText"
  20. >
  21. </el-input>
  22. <el-tree
  23. class="filter-tree"
  24. :data="data"
  25. :props="defaultProps"
  26. node-key="id"
  27. @node-click="clickTree"
  28. highlight-current
  29. :default-expanded-keys="defaultExpanded"
  30. :filter-node-method="filterNode"
  31. ref="tree"
  32. >
  33. <span slot-scope="{ node, data }">
  34. {{ data.code }}{{ data.materialType }}
  35. </span>
  36. </el-tree>
  37. </el-col>
  38. <el-col :span="18">
  39. <span class="title">基本信息</span>
  40. <el-form
  41. :model="ruleForm"
  42. :rules="rules"
  43. ref="ruleForm"
  44. label-width="140px"
  45. class="demo-ruleForm"
  46. >
  47. <el-row :gutter="20">
  48. <el-col :span="12">
  49. <el-form-item label="物料基本分类编码" prop="code">
  50. <el-input
  51. :disabled="disable"
  52. v-model="ruleForm.code"
  53. size="mini"
  54. ></el-input>
  55. <span>编码规则x-xxx-xxx-xxx</span>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item label="物料基本分类名称" prop="materialType">
  60. <el-input
  61. :disabled="disable"
  62. v-model="ruleForm.materialType"
  63. size="mini"
  64. ></el-input>
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. <el-row :gutter="20">
  69. <el-col :span="12">
  70. <el-form-item label="启用状态" prop="isEnable">
  71. <el-select
  72. v-model="ruleForm.isEnable"
  73. placeholder="启用状态"
  74. size="mini"
  75. :disabled="disable"
  76. style="width: 230px"
  77. >
  78. <el-option
  79. v-for="dict in dict.type.material_enable"
  80. :key="dict.value"
  81. :label="dict.label"
  82. :value="dict.value"
  83. />
  84. </el-select>
  85. </el-form-item>
  86. </el-col>
  87. </el-row>
  88. <span class="title">辅助属性</span>
  89. <el-row :gutter="20">
  90. <el-col :span="12">
  91. <el-form-item label="辅助属性结构" prop="marasstframe">
  92. <el-select
  93. v-model="ruleForm.marasstframe"
  94. placeholder="属性结构"
  95. clearable
  96. :disabled="disable"
  97. size="mini"
  98. style="width: 230px"
  99. >
  100. <el-option
  101. v-for="dict in dict.type.sys_assist_condtion"
  102. :key="dict.value"
  103. :label="dict.label"
  104. :value="dict.value"
  105. />
  106. </el-select>
  107. </el-form-item>
  108. </el-col>
  109. </el-row>
  110. <el-row :gutter="20">
  111. <el-col :span="24">
  112. <el-form-item label="" prop="name">
  113. <!-- <el-checkbox-group :disabled="disable" v-model="checkList"> -->
  114. <el-checkbox
  115. :disabled="disable"
  116. v-model="ruleForm.isInventory"
  117. label="isInventory"
  118. >库存状态</el-checkbox
  119. >
  120. <!-- <el-checkbox label="项目"></el-checkbox>
  121. <el-checkbox label="供应商"></el-checkbox>
  122. <el-checkbox label="生产厂商"></el-checkbox>
  123. <el-checkbox label="客户"></el-checkbox>
  124. <el-checkbox label="特征码"></el-checkbox> -->
  125. <el-checkbox
  126. :disabled="disable"
  127. v-model="ruleForm.isProductBatch"
  128. label="isProductBatch"
  129. >产品批号</el-checkbox
  130. >
  131. <!-- </el-checkbox-group> -->
  132. </el-form-item>
  133. </el-col>
  134. </el-row>
  135. <el-row :gutter="20">
  136. <el-col :span="24">
  137. <el-form-item v-if="!disable">
  138. <el-button size="mini" type="primary" @click="submitForm('ruleForm')"
  139. >保存</el-button
  140. >
  141. <el-button size="mini" @click="resetForm('ruleForm')">取消</el-button>
  142. </el-form-item>
  143. </el-col>
  144. </el-row>
  145. </el-form>
  146. </el-col>
  147. </el-row>
  148. </el-card>
  149. <!-- 导入对话框 -->
  150. <el-dialog title="数据导入" :visible.sync="upload.open" width="400px">
  151. <el-upload
  152. ref="upload"
  153. :limit="1"
  154. accept=".xlsx, .xls"
  155. :headers="upload.headers"
  156. :action="upload.url + '?updateSupport=' + upload.updateSupport"
  157. :disabled="upload.isUploading"
  158. :on-progress="handleFileUploadProgress"
  159. :on-success="handleFileSuccess"
  160. :on-error="errorFile"
  161. :auto-upload="false"
  162. drag
  163. >
  164. <i class="el-icon-upload"></i>
  165. <div class="el-upload__text">
  166. 将文件拖到此处,或
  167. <em>点击上传</em>
  168. </div>
  169. <!-- <div class="el-upload__tip" slot="tip">
  170. <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据
  171. </div> -->
  172. <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  173. </el-upload>
  174. <div slot="footer">
  175. <el-button size="mini" type="primary" @click="submitFile">确 定</el-button>
  176. <el-button size="mini" @click="upload.open = false">取 消</el-button>
  177. </div>
  178. </el-dialog>
  179. </div>
  180. </template>
  181. <script>
  182. // 导入的token
  183. import { getToken } from "@/utils/auth";
  184. import {
  185. getTree,
  186. getDetail,
  187. add,
  188. delClassify,
  189. edit,
  190. downLoadClassify,
  191. } from "@/api/classify/basic";
  192. export default {
  193. name: "classify",
  194. dicts: ["material_enable", "sys_assist_condtion"],
  195. data() {
  196. return {
  197. // 导入参数
  198. upload: {
  199. // 是否显示弹出层(导入)
  200. open: false,
  201. // 弹出层标题(导入)
  202. title: "数据导入",
  203. // 是否禁用上传
  204. isUploading: false,
  205. // 是否更新已经存在的用户数据
  206. updateSupport: 1,
  207. // 设置上传的请求头部
  208. headers: { Authorization: "Bearer " + getToken() },
  209. // 上传的地址
  210. url: process.env.VUE_APP_BASE_API + "/system/classify/import"
  211. },
  212. loading: false,
  213. filterText: "",
  214. data: [],
  215. defaultProps: {
  216. children: "childrens",
  217. label: "materialType",
  218. },
  219. ruleForm: {
  220. code: "",
  221. materialType: "",
  222. isEnable: "0",
  223. delFlag: "",
  224. marasstframe: "",
  225. isInventory: "",
  226. isProductBatch: "",
  227. },
  228. rules: {
  229. code: [
  230. {
  231. required: true,
  232. message: "请输入物料基本分类编码",
  233. trigger: "blur",
  234. },
  235. ],
  236. materialType: [
  237. {
  238. required: true,
  239. message: "请输入物料基本分类名称",
  240. trigger: "blur",
  241. },
  242. ],
  243. },
  244. checkList: [],
  245. disable: true,
  246. biao: { parentId: 0 },
  247. // 删除节点id
  248. delId: "",
  249. // 判断是新增还是修改
  250. isAdd: true,
  251. defaultExpanded: [],
  252. // 是否过滤停用
  253. refreshName: false
  254. };
  255. },
  256. watch: {
  257. filterText(val) {
  258. this.$refs.tree.filter(val);
  259. },
  260. },
  261. created() {
  262. this.getTreeData();
  263. //
  264. },
  265. mounted() {},
  266. methods: {
  267. // 获取树形结构
  268. getTreeData(isEnable) {
  269. this.loading = true;
  270. getTree({}).then((res) => {
  271. let { code, rows } = res;
  272. if (code === 200) {
  273. this.data = rows;
  274. }
  275. })
  276. .finally(() => {
  277. this.loading = false;
  278. });
  279. },
  280. // 获取物料基本分类详情
  281. getDetailData(id) {
  282. getDetail(id).then((res) => {
  283. let { code, data } = res;
  284. if (code === 200) {
  285. console.log("data", data);
  286. this.ruleForm = data;
  287. this.ruleForm.isInventory = data.isInventory === "0" ? true : false;
  288. this.ruleForm.isProductBatch =
  289. data.isProductBatch === "0" ? true : false;
  290. }
  291. });
  292. },
  293. filterNode(value, data) {
  294. if (!value) return true;
  295. return data.materialType.indexOf(value) !== -1 || data.code.indexOf(value) !== -1;
  296. },
  297. clickTree(data, node) {
  298. console.log("data", data, node);
  299. // 如果点击新增时选择了树形节点,则不回显数据,且需要清空ruleForm内的数据
  300. if (this.disable) {
  301. this.getDetailData(data.id);
  302. } else {
  303. this.$refs["ruleForm"].resetFields();
  304. }
  305. // 标记是否为树形结构最外层
  306. this.biao.parentId = data.id;
  307. // 将节点id用作删除id
  308. this.delId = data.id;
  309. let { id } = data;
  310. if (this.defaultExpanded.findIndex((item) => item === id) === -1) {
  311. this.defaultExpanded.push(id);
  312. this.defaultExpanded = [...new Set(this.defaultExpanded)];
  313. } else {
  314. this.defaultExpanded = this.defaultExpanded.filter(
  315. (item) => item !== id
  316. );
  317. }
  318. },
  319. submitForm(formName) {
  320. let isInventory = this.ruleForm.isInventory ? "0" : "2";
  321. let isProductBatch = this.ruleForm.isProductBatch ? "0" : "2";
  322. this.$refs[formName].validate((valid) => {
  323. if (valid) {
  324. if (this.isAdd) {
  325. //判断是走新增还是修改
  326. console.log("add!");
  327. console.log(this.biao.parentId);
  328. console.log(this.ruleForm);
  329. let params = {
  330. ...this.ruleForm,
  331. ...this.biao,
  332. isInventory,
  333. isProductBatch,
  334. };
  335. console.log("params", params);
  336. add(params).then((res) => {
  337. if (res.code === 200) {
  338. this.$message({
  339. message: res.msg,
  340. type: "success",
  341. });
  342. this.getTreeData();
  343. // this.$refs['ruleForm'].resetFields();
  344. this.disable = true;
  345. }
  346. });
  347. } else {
  348. //修改
  349. console.log("edit");
  350. let ids = { id: this.biao.parentId };
  351. console.log("ids", ids);
  352. let params = {
  353. ...this.ruleForm,
  354. ...ids,
  355. isInventory,
  356. isProductBatch,
  357. };
  358. console.log("params", params);
  359. edit(params).then((res) => {
  360. if (res.code === 200) {
  361. this.$message({
  362. message: res.msg,
  363. type: "success",
  364. });
  365. this.getTreeData();
  366. // this.currentNode = params;
  367. console.log("this.data", this.defaultExpanded);
  368. this.disable = true;
  369. }
  370. });
  371. }
  372. } else {
  373. console.log("error submit!!");
  374. return false;
  375. }
  376. });
  377. },
  378. resetForm(formName) {
  379. console.log(formName);
  380. if (this.isAdd) {
  381. this.$refs[formName].resetFields();
  382. this.disable = true;
  383. } else {
  384. this.disable = true;
  385. }
  386. },
  387. // 点击新增按钮
  388. addClassify() {
  389. // console.log('值呢:', this.ruleForm)
  390. // 如果点击了树形节点后再点击新增,则清空数据再填写
  391. if (this.biao.parentId !== 0) {
  392. this.$refs["ruleForm"].resetFields();
  393. }
  394. this.disable = false;
  395. this.isAdd = true;
  396. },
  397. // 删除按钮
  398. deleteClassify() {
  399. if (this.biao.parentId == 0) {
  400. this.$message({
  401. message: "请选择删除节点",
  402. type: "warning",
  403. });
  404. } else {
  405. console.log("删除", this.delId);
  406. delClassify({ id: this.delId }).then((res) => {
  407. if (res.code === 200) {
  408. this.getTreeData();
  409. this.$message({
  410. message: "删除成功",
  411. type: "success",
  412. });
  413. }
  414. });
  415. }
  416. },
  417. // 修改按钮
  418. editClassify() {
  419. if (this.biao.parentId == 0) {
  420. this.$message({
  421. message: "请选择修改节点",
  422. type: "warning",
  423. });
  424. } else {
  425. console.log("修改");
  426. this.disable = false;
  427. this.isAdd = false;
  428. }
  429. },
  430. // 启用停用
  431. refreshData() {
  432. if(this.refreshName == false) {
  433. this.refreshName = true
  434. this.loading = true;
  435. getTree({isEnable: '0'}).then((res) => {
  436. let { code, rows } = res;
  437. if (code === 200) {
  438. this.data = rows;
  439. }
  440. })
  441. .finally(() => {
  442. this.loading = false;
  443. });
  444. } else {
  445. this.refreshName = false
  446. this.getTreeData();
  447. }
  448. },
  449. // 模板下载
  450. mbDownload() {
  451. this.$modal.loading("正在下载模板,请稍后...");
  452. downLoadClassify({}).then(res => {
  453. this.$modal.closeLoading();
  454. const blob = new Blob([res], {
  455. type: "application/vnd.ms-excel;charset=UTF-8",
  456. });// 创建一个类文件对象:Blob对象表示一个不可变的、原始数据的类文件对象
  457. const downloadElement = document.createElement("a"); //创建a标签
  458. const href = window.URL.createObjectURL(blob); // 创建下载的链接
  459. // var temp = res.headers["content-disposition"];
  460. // var fileName = decodeURIComponent(temp.split("filename=")[1]); // 中文需要转码 (前端乱码)
  461. // var name = fileName.split(";")[0]; //切割成文件名
  462. downloadElement.href = href; //下载地址
  463. downloadElement.download = '物料基本分类模板'+ this.parseTime(new Date().getTime()) + ".xlsx"; // 下载后文件名
  464. document.body.appendChild(downloadElement);
  465. downloadElement.click(); // 点击下载
  466. document.body.removeChild(downloadElement); // 下载完成移除元素
  467. window.URL.revokeObjectURL(href); // 释放blob对象
  468. this.download.open = false
  469. }).catch(err => {
  470. this.$modal.closeLoading();
  471. })
  472. },
  473. // 文件导入
  474. importMb() {
  475. this.upload.open = true
  476. },
  477. // 文件上传中处理
  478. handleFileUploadProgress(event, file, fileList) {
  479. this.upload.isUploading = true;
  480. this.$modal.loading("正在导入数据,请稍后...");
  481. },
  482. // 文件上传成功处理
  483. handleFileSuccess(response, file, fileList) {
  484. this.$modal.closeLoading();
  485. this.upload.open = false;
  486. this.upload.isUploading = false;
  487. this.$refs.upload.clearFiles();
  488. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  489. this.getTreeData();
  490. },
  491. errorFile(err) {
  492. this.$modal.closeLoading();
  493. this.$modal.notifyError("文件已变动,请重新上传");
  494. },
  495. // 提交上传文件
  496. submitFile() {
  497. this.$refs.upload.submit();
  498. },
  499. },
  500. };
  501. </script>
  502. <style scoped lang="scss">
  503. .classify {
  504. height: calc(100vh - 84px);
  505. padding: 12px;
  506. box-sizing: border-box;
  507. overflow-y: auto;
  508. }
  509. .title {
  510. font-weight: bold;
  511. }
  512. .mb10 {
  513. display: flex;
  514. flex-direction: row-reverse;
  515. }
  516. </style>