classify_list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div class="app-container">
  3. <div class="main-content">
  4. <div class="main-left">
  5. <el-button icon="el-icon-plus" type="primary" plain style="width: 100%" v-if="$checkBtnRole('add', $route.meta.roles)" @click="openAddGroupForm('add')">新建分组</el-button>
  6. <div class="list">
  7. <div class="item">
  8. <strong class="title">所有分组</strong>
  9. </div>
  10. <div class="item" :class="activeGroup === v.productCategoryId ? 'active' : ''" v-for="v in categoryList" :key="v.productCategoryId" @click="changeGroup(v.productCategoryId, v)">
  11. <div class="title">{{ v.productCategoryName }}</div>
  12. <el-dropdown trigger="click" @command="handleCommand">
  13. <span class="el-dropdown-link">
  14. <i class="el-icon-more icon-more"></i>
  15. </span>
  16. <el-dropdown-menu slot="dropdown">
  17. <el-dropdown-item :command="['edit', v]" v-if="$checkBtnRole('edit', $route.meta.roles)">修改名称</el-dropdown-item>
  18. <el-dropdown-item :command="['del', v]" v-if="$checkBtnRole('del', $route.meta.roles)">删除分组</el-dropdown-item>
  19. </el-dropdown-menu>
  20. </el-dropdown>
  21. </div>
  22. </div>
  23. </div>
  24. <div class="main-right">
  25. <!-- 筛选条件 -->
  26. <div>
  27. <el-form ref="searchForm" :model="searchForm" label-width="70px" size="mini" label-position="left">
  28. <el-row :gutter="20">
  29. <el-col :xs="24" :sm="12" :lg="6">
  30. <el-form-item label="编码" prop="productCategoryNumber">
  31. <el-input v-model="searchForm.productCategoryNumber" placeholder="请输入"></el-input>
  32. </el-form-item>
  33. </el-col>
  34. <el-col :xs="24" :sm="12" :lg="6">
  35. <el-form-item label="名称" prop="productCategoryName">
  36. <el-input v-model="searchForm.productCategoryName" placeholder="请输入"></el-input>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :xs="24" :sm="24" :lg="12" class="tr">
  40. <el-form-item label="">
  41. <el-button size="mini" @click="clearFn">清空</el-button>
  42. <el-button size="mini" type="primary" @click="searchFn">搜索</el-button>
  43. </el-form-item>
  44. </el-col>
  45. </el-row>
  46. </el-form>
  47. </div>
  48. <!-- 按钮 -->
  49. <div class="btn-group clearfix">
  50. <div class="fl">
  51. <el-button v-if="$checkBtnRole('add', $route.meta.roles)" type="primary" size="mini" @click="addCategoryFn">添加类别</el-button>
  52. </div>
  53. </div>
  54. <div class="mymain-container">
  55. <!-- 列表 -->
  56. <div class="table">
  57. <el-table v-loading="listLoading" :data="dataList" element-loading-text="Loading" border fit highlight-current-row stripe>
  58. <el-table-column align="left" label="编码" prop="kingDeeCategoryNumber" min-width="160" show-overflow-tooltip></el-table-column>
  59. <el-table-column align="left" label="品类" prop="kingDeeCategoryName" min-width="160" show-overflow-tooltip></el-table-column>
  60. <el-table-column align="center" label="操作" min-width="160" show-overflow-tooltip>
  61. <template slot-scope="scope">
  62. <el-popconfirm confirm-button-text="好的" cancel-button-text="不用了" icon="el-icon-info" icon-color="red" title="内容确定删除吗?" @onConfirm="hanleDelete(scope.row.id)">
  63. <el-button slot="reference" type="text" class="textColor el-popover-left" v-if="$checkBtnRole('del', $route.meta.roles)">删除</el-button>
  64. </el-popconfirm>
  65. </template>
  66. </el-table-column>
  67. </el-table>
  68. </div>
  69. <!-- 分页
  70. <div class="fr">
  71. <el-pagination
  72. :current-page="currentPage"
  73. :page-sizes="[10, 20, 30, 50]"
  74. :page-size="10"
  75. layout="total, sizes, prev, pager, next, jumper"
  76. :total="listTotal"
  77. >
  78. </el-pagination>
  79. </div> -->
  80. </div>
  81. </div>
  82. </div>
  83. <!-- 新增编辑分组 -->
  84. <el-dialog :title="addGroupFormType == 'add' ? '新建分组' : '编辑分组'" :visible.sync="addGroupFormVisible" :show-close="false" width="40%" :close-on-click-modal="false">
  85. <el-form ref="addGroupForm" :model="addGroupForm" label-position="left" label-width="80px">
  86. <el-form-item label="分组名称" prop="">
  87. <el-input autocomplete="off" v-model="addGroupForm.productCategoryName" placeholder="请输入分组名称"></el-input>
  88. </el-form-item>
  89. <el-form-item label="编码" prop="">
  90. <el-input autocomplete="off" v-model="addGroupForm.productCategoryNumber" placeholder="请输入" v-if="addGroupFormType == 'add'"></el-input>
  91. <el-input v-else autocomplete="off" v-model="addGroupForm.productCategoryNumber" placeholder="请输入" disabled="disabled"></el-input>
  92. </el-form-item>
  93. </el-form>
  94. <div slot="footer" class="dialog-footer">
  95. <el-button @click="cancelFn">取 消</el-button>
  96. <el-button type="primary" @click="btnOK">确 定</el-button>
  97. </div>
  98. </el-dialog>
  99. <!-- 添加类别弹窗 -->
  100. <ClassifyListSmall :dataCategory="dataCategory" :showAddSelect.sync="showAddSelect" :data="dataList" @updateList="updateListFn" ref="updateDate" />
  101. </div>
  102. </template>
  103. <script>
  104. import ClassifyListSmall from "./components/classify_list-small";
  105. import {
  106. getProductCategoryList,
  107. getProductCategorySubList,
  108. getProductCategoryAdd,
  109. getProductCategoryEdit,
  110. getProductCategoryDelSub,
  111. getProductCategoryDel,
  112. } from "@/api/basic_data/material";
  113. export default {
  114. data() {
  115. return {
  116. searchForm: {
  117. productCategoryNumber: "",
  118. productCategoryName: "",
  119. },
  120. addGroupFormVisible: false,
  121. activeGroup: "",
  122. dataList: null, // 列表数据
  123. listLoading: false, // 列表加载loading
  124. // currentPage: 1, // 当前页码
  125. // pageSize: 10, // 每页数量
  126. // listTotal: 0, // 列表总数
  127. categoryList: [], //品类列表
  128. addGroupForm: {
  129. productCategoryName: "",
  130. productCategoryNumber: "",
  131. },
  132. addGroupFormType: "add",
  133. showAddSelect: false, //添加分类弹窗
  134. dataCategory: null, //当前选中的品类
  135. };
  136. },
  137. components: {
  138. ClassifyListSmall,
  139. },
  140. created() {
  141. this.getDataList();
  142. },
  143. methods: {
  144. //清空
  145. clearFn() {
  146. this.$refs.searchForm.resetFields();
  147. },
  148. //搜索
  149. searchFn() {
  150. this.getDataList({ ...this.searchForm });
  151. },
  152. //删除
  153. async hanleDelete(id) {
  154. console.log(this.dataCategory);
  155. let arr = [id];
  156. let res = arr.toString();
  157. await getProductCategoryDelSub({ ids: res });
  158. const res2 = await getProductCategorySubList({
  159. id: this.dataCategory.productCategoryId,
  160. });
  161. this.dataList = res2.data;
  162. this.$message.success("删除成功");
  163. },
  164. //更新列表
  165. async updateListFn(id) {
  166. const res = await getProductCategorySubList({ id });
  167. this.dataList = res.data;
  168. },
  169. //添加类别
  170. async addCategoryFn() {
  171. await this.$refs.updateDate.getDataList();
  172. this.showAddSelect = true;
  173. },
  174. //取消
  175. cancelFn() {
  176. this.addGroupForm = {
  177. productCategoryName: "",
  178. productCategoryNumber: "",
  179. };
  180. this.addGroupFormVisible = false;
  181. },
  182. //确定
  183. async btnOK() {
  184. if (this.addGroupFormType == "edit") {
  185. await getProductCategoryEdit({ ...this.addGroupForm });
  186. this.$message.success("编辑成功");
  187. } else {
  188. await getProductCategoryAdd({ ...this.addGroupForm });
  189. this.$message.success("新建成功");
  190. }
  191. this.addGroupForm = {
  192. productCategoryName: "",
  193. productCategoryNumber: "",
  194. };
  195. this.getDataList();
  196. this.addGroupFormVisible = false;
  197. },
  198. //切换分组
  199. async changeGroup(id, v) {
  200. console.log(v);
  201. this.dataCategory = v;
  202. this.activeGroup = id;
  203. const res = await getProductCategorySubList({ id });
  204. this.dataList = res.data;
  205. },
  206. //获取产品类别列表
  207. async getDataList(data) {
  208. const res = await getProductCategoryList(data);
  209. this.categoryList = res.data;
  210. },
  211. //新建分组弹窗
  212. openAddGroupForm(type, item) {
  213. this.addGroupFormType = type;
  214. if (type == "edit") {
  215. this.addGroupForm.productCategoryNumber = item.productCategoryNumber;
  216. this.addGroupForm.productCategoryName = item.productCategoryName;
  217. this.addGroupForm.productCategoryId = item.productCategoryId;
  218. }
  219. this.addGroupFormVisible = true;
  220. },
  221. // 操作分组
  222. handleCommand(command) {
  223. let type = command[0],
  224. v = command[1];
  225. if (type == "del") {
  226. this.$confirm("此操作将删除该分组, 是否继续?", "删除分组", {
  227. confirmButtonText: "确定",
  228. cancelButtonText: "取消",
  229. type: "warning",
  230. })
  231. .then(() => {
  232. console.log(v, 111);
  233. getProductCategoryDel({ ids: v.productCategoryId }).then((res) => {
  234. this.getDataList();
  235. this.$successMsg("删除成功");
  236. });
  237. })
  238. .catch(() => {});
  239. }
  240. if (type == "edit") {
  241. //修改
  242. console.log(1111);
  243. this.openAddGroupForm("edit", v);
  244. }
  245. },
  246. },
  247. };
  248. </script>
  249. <style lang="scss" scoped>
  250. .main-content {
  251. display: flex;
  252. height: auto;
  253. .main-left {
  254. margin-right: 20px;
  255. padding: 10px;
  256. width: 210px;
  257. overflow-y: auto;
  258. // border: 1px solid #eaeaea;
  259. border-radius: 5px;
  260. .list {
  261. margin-top: 10px;
  262. .item {
  263. display: flex;
  264. padding: 10px;
  265. cursor: pointer;
  266. color: #333;
  267. &.active {
  268. color: #377cfd;
  269. font-weight: 600;
  270. background-color: #f5f7fa;
  271. }
  272. .title {
  273. flex: 1;
  274. min-width: 0;
  275. padding-right: 10px;
  276. font-size: 14px;
  277. }
  278. .icon-more {
  279. transform: rotate(90deg);
  280. }
  281. }
  282. }
  283. }
  284. .main-right {
  285. flex: 1;
  286. height: auto;
  287. ::v-deep .el-divider--horizontal {
  288. margin: 10px 0;
  289. }
  290. .btn-group {
  291. display: flex;
  292. justify-content: space-between;
  293. .left {
  294. display: flex;
  295. align-items: center;
  296. .tips {
  297. font-size: 14px;
  298. margin-left: 10px;
  299. }
  300. }
  301. }
  302. .list-container {
  303. margin-top: 20px;
  304. .box-card {
  305. ::v-deep .el-card__header {
  306. padding: 10px 10px 10px 20px;
  307. }
  308. .header {
  309. display: flex;
  310. justify-content: space-between;
  311. align-items: center;
  312. }
  313. .body {
  314. .info {
  315. display: flex;
  316. justify-content: space-between;
  317. align-items: center;
  318. font-size: 14px;
  319. color: #666;
  320. margin: 10px 0;
  321. }
  322. .content {
  323. max-width: 100%;
  324. height: 168px;
  325. overflow-y: hidden;
  326. background-color: #fafafa;
  327. word-break: break-all;
  328. border-radius: 2px;
  329. padding: 8px;
  330. font-size: 14px;
  331. line-height: 19px;
  332. .text {
  333. overflow: hidden;
  334. text-overflow: ellipsis;
  335. display: -webkit-box;
  336. -webkit-line-clamp: 8;
  337. -webkit-box-orient: vertical;
  338. }
  339. }
  340. .img {
  341. width: 100%;
  342. height: 168px;
  343. display: block;
  344. }
  345. .video {
  346. width: 100%;
  347. height: 168px;
  348. display: block;
  349. }
  350. .file {
  351. display: flex;
  352. justify-content: space-between;
  353. align-items: center;
  354. img {
  355. width: 40px;
  356. height: 40px;
  357. display: block;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. .empty {
  364. display: flex;
  365. flex-direction: column;
  366. align-items: center;
  367. justify-content: center;
  368. padding: 20px 0;
  369. img {
  370. width: 280px;
  371. }
  372. div {
  373. font-size: 14px;
  374. color: #666;
  375. }
  376. }
  377. }
  378. }
  379. </style>