index.vue 12 KB

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