index.vue 12 KB

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