index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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" plain @click="addClassify">新增</el-button>
  7. <el-button type="primary" size="mini" plain @click="editClassify">修改</el-button>
  8. <el-button type="primary" size="mini" plain @click="refreshData">{{refreshName ? '全部分类': '过滤停用'}}</el-button>
  9. <el-button type="primary" size="mini" plain @click="deleteClassify">删除</el-button>
  10. </div>
  11. </el-row>
  12. <el-row :gutter="10" class="content">
  13. <el-col :span="6">
  14. <el-input
  15. placeholder="输入关键字/编码进行过滤"
  16. size="mini"
  17. v-model="filterText"
  18. >
  19. </el-input>
  20. <el-tree
  21. class="filter-tree"
  22. :data="data"
  23. :props="defaultProps"
  24. node-key="id"
  25. @node-click="clickTree"
  26. highlight-current
  27. :default-expanded-keys="defaultExpanded"
  28. :filter-node-method="filterNode"
  29. ref="tree"
  30. >
  31. <span slot-scope="{ node, data }">
  32. {{ data.code }}{{ data.materialType }}
  33. </span>
  34. </el-tree>
  35. </el-col>
  36. <el-col :span="18">
  37. <span class="title">基本信息</span>
  38. <el-form
  39. :model="ruleForm"
  40. :rules="rules"
  41. ref="ruleForm"
  42. label-width="140px"
  43. class="demo-ruleForm"
  44. >
  45. <el-row :gutter="20">
  46. <el-col :span="12">
  47. <el-form-item label="物料基本分类编码" prop="code">
  48. <el-input
  49. :disabled="disable"
  50. v-model="ruleForm.code"
  51. size="mini"
  52. ></el-input>
  53. <span>编码规则x-xxx-xxx-xxx</span>
  54. </el-form-item>
  55. </el-col>
  56. <el-col :span="12">
  57. <el-form-item label="物料基本分类名称" prop="materialType">
  58. <el-input
  59. :disabled="disable"
  60. v-model="ruleForm.materialType"
  61. size="mini"
  62. ></el-input>
  63. </el-form-item>
  64. </el-col>
  65. </el-row>
  66. <el-row :gutter="20">
  67. <el-col :span="12">
  68. <el-form-item label="启用状态" prop="isEnable">
  69. <el-select
  70. v-model="ruleForm.isEnable"
  71. placeholder="启用状态"
  72. clearable
  73. size="mini"
  74. :disabled="disable"
  75. style="width: 230px"
  76. >
  77. <el-option
  78. v-for="dict in dict.type.material_enable"
  79. :key="dict.value"
  80. :label="dict.label"
  81. :value="dict.value"
  82. />
  83. </el-select>
  84. </el-form-item>
  85. </el-col>
  86. </el-row>
  87. <span class="title">辅助属性</span>
  88. <el-row :gutter="20">
  89. <el-col :span="12">
  90. <el-form-item label="辅助属性结构" prop="marasstframe">
  91. <el-select
  92. v-model="ruleForm.marasstframe"
  93. placeholder="属性结构"
  94. clearable
  95. :disabled="disable"
  96. size="mini"
  97. style="width: 230px"
  98. >
  99. <el-option
  100. v-for="dict in dict.type.sys_assist_condtion"
  101. :key="dict.value"
  102. :label="dict.label"
  103. :value="dict.value"
  104. />
  105. </el-select>
  106. </el-form-item>
  107. </el-col>
  108. </el-row>
  109. <el-row :gutter="20">
  110. <el-col :span="24">
  111. <el-form-item label="" prop="name">
  112. <!-- <el-checkbox-group :disabled="disable" v-model="checkList"> -->
  113. <el-checkbox
  114. :disabled="disable"
  115. v-model="ruleForm.isInventory"
  116. label="isInventory"
  117. >库存状态</el-checkbox
  118. >
  119. <!-- <el-checkbox label="项目"></el-checkbox>
  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
  125. :disabled="disable"
  126. v-model="ruleForm.isProductBatch"
  127. label="isProductBatch"
  128. >产品批号</el-checkbox
  129. >
  130. <!-- </el-checkbox-group> -->
  131. </el-form-item>
  132. </el-col>
  133. </el-row>
  134. <el-row :gutter="20">
  135. <el-col :span="24">
  136. <el-form-item v-if="!disable">
  137. <el-button type="primary" @click="submitForm('ruleForm')"
  138. >保存</el-button
  139. >
  140. <el-button @click="resetForm('ruleForm')">取消</el-button>
  141. </el-form-item>
  142. </el-col>
  143. </el-row>
  144. </el-form>
  145. </el-col>
  146. </el-row>
  147. </el-card>
  148. </div>
  149. </template>
  150. <script>
  151. import {
  152. getTree,
  153. getDetail,
  154. add,
  155. delClassify,
  156. edit,
  157. } from "@/api/classify/basic";
  158. export default {
  159. name: "classify",
  160. dicts: ["material_enable", "sys_assist_condtion"],
  161. data() {
  162. return {
  163. loading: false,
  164. filterText: "",
  165. data: [],
  166. defaultProps: {
  167. children: "childrens",
  168. label: "materialType",
  169. },
  170. ruleForm: {
  171. code: "",
  172. materialType: "",
  173. isEnable: "0",
  174. delFlag: "",
  175. marasstframe: "",
  176. isInventory: "",
  177. isProductBatch: "",
  178. },
  179. rules: {
  180. code: [
  181. {
  182. required: true,
  183. message: "请输入物料基本分类编码",
  184. trigger: "blur",
  185. },
  186. ],
  187. materialType: [
  188. {
  189. required: true,
  190. message: "请输入物料基本分类名称",
  191. trigger: "blur",
  192. },
  193. ],
  194. },
  195. checkList: [],
  196. disable: true,
  197. biao: { parentId: 0 },
  198. // 删除节点id
  199. delId: "",
  200. // 判断是新增还是修改
  201. isAdd: true,
  202. defaultExpanded: [],
  203. // 是否过滤停用
  204. refreshName: false
  205. };
  206. },
  207. watch: {
  208. filterText(val) {
  209. this.$refs.tree.filter(val);
  210. },
  211. },
  212. created() {
  213. this.getTreeData();
  214. //
  215. },
  216. mounted() {},
  217. methods: {
  218. // 获取树形结构
  219. getTreeData(isEnable) {
  220. this.loading = true;
  221. getTree({}).then((res) => {
  222. let { code, rows } = res;
  223. if (code === 200) {
  224. this.data = rows;
  225. }
  226. })
  227. .finally(() => {
  228. this.loading = false;
  229. });
  230. },
  231. // 获取物料基本分类详情
  232. getDetailData(id) {
  233. getDetail(id).then((res) => {
  234. let { code, data } = res;
  235. if (code === 200) {
  236. console.log("data", data);
  237. this.ruleForm = data;
  238. this.ruleForm.isInventory = data.isInventory === "0" ? true : false;
  239. this.ruleForm.isProductBatch =
  240. data.isProductBatch === "0" ? true : false;
  241. }
  242. });
  243. },
  244. filterNode(value, data) {
  245. if (!value) return true;
  246. return data.materialType.indexOf(value) !== -1 || data.code.indexOf(value) !== -1;
  247. },
  248. clickTree(data, node) {
  249. console.log("data", data, node);
  250. // 如果点击新增时选择了树形节点,则不回显数据,且需要清空ruleForm内的数据
  251. if (this.disable) {
  252. this.getDetailData(data.id);
  253. } else {
  254. this.$refs["ruleForm"].resetFields();
  255. }
  256. // 标记是否为树形结构最外层
  257. this.biao.parentId = data.id;
  258. // 将节点id用作删除id
  259. this.delId = data.id;
  260. let { id } = data;
  261. if (this.defaultExpanded.findIndex((item) => item === id) === -1) {
  262. this.defaultExpanded.push(id);
  263. this.defaultExpanded = [...new Set(this.defaultExpanded)];
  264. } else {
  265. this.defaultExpanded = this.defaultExpanded.filter(
  266. (item) => item !== id
  267. );
  268. }
  269. },
  270. submitForm(formName) {
  271. let isInventory = this.ruleForm.isInventory ? "0" : "2";
  272. let isProductBatch = this.ruleForm.isProductBatch ? "0" : "2";
  273. this.$refs[formName].validate((valid) => {
  274. if (valid) {
  275. if (this.isAdd) {
  276. //判断是走新增还是修改
  277. console.log("add!");
  278. console.log(this.biao.parentId);
  279. console.log(this.ruleForm);
  280. let params = {
  281. ...this.ruleForm,
  282. ...this.biao,
  283. isInventory,
  284. isProductBatch,
  285. };
  286. console.log("params", params);
  287. add(params).then((res) => {
  288. if (res.code === 200) {
  289. this.$message({
  290. message: res.msg,
  291. type: "success",
  292. });
  293. this.getTreeData();
  294. // this.$refs['ruleForm'].resetFields();
  295. this.disable = true;
  296. }
  297. });
  298. } else {
  299. //修改
  300. console.log("edit");
  301. let ids = { id: this.biao.parentId };
  302. console.log("ids", ids);
  303. let params = {
  304. ...this.ruleForm,
  305. ...ids,
  306. isInventory,
  307. isProductBatch,
  308. };
  309. console.log("params", params);
  310. edit(params).then((res) => {
  311. if (res.code === 200) {
  312. this.$message({
  313. message: res.msg,
  314. type: "success",
  315. });
  316. this.getTreeData();
  317. // this.currentNode = params;
  318. console.log("this.data", this.defaultExpanded);
  319. this.disable = true;
  320. }
  321. });
  322. }
  323. } else {
  324. console.log("error submit!!");
  325. return false;
  326. }
  327. });
  328. },
  329. resetForm(formName) {
  330. console.log(formName);
  331. if (this.isAdd) {
  332. this.$refs[formName].resetFields();
  333. this.disable = true;
  334. } else {
  335. this.disable = true;
  336. }
  337. },
  338. // 点击新增按钮
  339. addClassify() {
  340. // console.log('值呢:', this.ruleForm)
  341. // 如果点击了树形节点后再点击新增,则清空数据再填写
  342. if (this.biao.parentId !== 0) {
  343. this.$refs["ruleForm"].resetFields();
  344. }
  345. this.disable = false;
  346. this.isAdd = true;
  347. },
  348. // 删除按钮
  349. deleteClassify() {
  350. if (this.biao.parentId == 0) {
  351. this.$message({
  352. message: "请选择删除节点",
  353. type: "warning",
  354. });
  355. } else {
  356. console.log("删除", this.delId);
  357. delClassify({ id: this.delId }).then((res) => {
  358. if (res.code === 200) {
  359. this.getTreeData();
  360. this.$message({
  361. message: "删除成功",
  362. type: "success",
  363. });
  364. }
  365. });
  366. }
  367. },
  368. // 修改按钮
  369. editClassify() {
  370. if (this.biao.parentId == 0) {
  371. this.$message({
  372. message: "请选择修改节点",
  373. type: "warning",
  374. });
  375. } else {
  376. console.log("修改");
  377. this.disable = false;
  378. this.isAdd = false;
  379. }
  380. },
  381. // 启用停用
  382. refreshData() {
  383. if(this.refreshName == false) {
  384. this.refreshName = true
  385. this.loading = true;
  386. getTree({isEnable: '0'}).then((res) => {
  387. let { code, rows } = res;
  388. if (code === 200) {
  389. this.data = rows;
  390. }
  391. })
  392. .finally(() => {
  393. this.loading = false;
  394. });
  395. } else {
  396. this.refreshName = false
  397. this.getTreeData();
  398. }
  399. },
  400. },
  401. };
  402. </script>
  403. <style scoped lang="scss">
  404. .classify {
  405. height: calc(100vh - 84px);
  406. padding: 12px;
  407. box-sizing: border-box;
  408. overflow-y: auto;
  409. }
  410. .title {
  411. font-weight: bold;
  412. }
  413. .mb10 {
  414. display: flex;
  415. flex-direction: row-reverse;
  416. }
  417. </style>