| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <template>
- <div class="m-container">
- <h2>
- <div class="squrt"></div>
- 商品分类管理
- </h2>
- <div class="m-core">
- <el-button
- v-permission="'category/upset'"
- @click="openTypes('create')"
- type="primary"
- style="margin-bottom:20px"
- >
- 添加
- </el-button>
- <!-- 列表 -->
- <div class="tableWrap">
- <el-table
- :data="tableList"
- :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
- >
- <el-table-column align="center" prop="name" label="分类名称">
- </el-table-column>
- <el-table-column align="center" label="声部属性">
- <template slot-scope="scope">
- <overflow-text
- width="100%"
- :text="scope.row.subjectName | joinArray(',')"
- ></overflow-text>
- </template>
- </el-table-column>
- <el-table-column align="center" label="操作">
- <template slot-scope="scope">
- <el-button
- @click="openTypes('update', scope.row)"
- v-permission="'category/upset'"
- type="text"
- >修改</el-button
- >
- <el-button
- @click="onTypesDelOpeation(scope.row)"
- v-permission="'category/del'"
- type="text"
- >删除</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- <pagination
- sync
- :total.sync="pageInfo.total"
- :page.sync="pageInfo.page"
- :limit.sync="pageInfo.limit"
- :page-sizes="pageInfo.page_size"
- @pagination="getList"
- />
- </div>
- </div>
- <el-dialog
- :title="formTitle[formActionTitle]"
- :visible.sync="typeStatus"
- @close="onFormClose('ruleForm')"
- width="500px"
- >
- <el-form :model="form" :rules="rules" ref="ruleForm">
- <el-form-item
- label="商品分类名称"
- prop="name"
- :label-width="formLabelWidth"
- >
- <el-input v-model.trim="form.name" autocomplete="off"></el-input>
- </el-form-item>
- <el-form-item
- label="声部属性"
- v-if="form.classGroupType != 'MIX'"
- prop="subjectIds"
- :label-width="formLabelWidth"
- >
- <select-all
- v-model.trim="form.subjectIds"
- clearable
- filterable
- multiple
- >
- <!-- <el-select > -->
- <el-option-group
- v-for="group in subjectList"
- :key="group.id"
- :label="group.label"
- >
- <el-option
- v-for="item in group.options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-option-group>
- </select-all>
- <!-- </el-select> -->
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="typeStatus = false">取 消</el-button>
- <el-button type="primary" @click="onTypesSubmit('ruleForm')"
- >确 定</el-button
- >
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- import pagination from "@/components/Pagination/index";
- import store from "@/store";
- import { subjectListTree } from "@/api/specialSetting";
- import {
- categoryListTree,
- categoryUpSet,
- categoryUpSetDel
- } from "@/api/businessManager";
- export default {
- components: { pagination },
- name: "shopCategory",
- data() {
- return {
- tableList: [],
- subjectList: [], // 声部列表
- formActionTitle: "create",
- formTitle: {
- create: "添加商品分类",
- update: "修改商品分类"
- },
- typeStatus: false, // 添加教学点
- formLabelWidth: "120px",
- form: {
- name: null, // 训练模块名称
- subjectIds: []
- },
- rules: {
- name: [{ required: true, message: "请输入类型名称", trigger: "blur" }],
- subjectIds: [
- { required: true, message: "请选择声部组合", trigger: "change" }
- ]
- },
- pageInfo: {
- // 分页规则
- limit: 10, // 限制显示条数
- page: 1, // 当前页
- total: 0, // 总条数
- page_size: [10, 20, 40, 50] // 选择限制显示条数
- }
- };
- },
- mounted() {
- this.getList();
- this.getSubjectTree();
- },
- methods: {
- onTypesDelOpeation(row) {
- this.$confirm("您确定删除该分类?", "提示", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(() => {
- categoryUpSetDel({ id: row.id }).then(res => {
- this.messageTips("删除", res);
- });
- });
- },
- onTypesSubmit(formName) {
- // 添加数据
- this.$refs[formName].validate(valid => {
- if (valid) {
- if (this.formActionTitle == "create") {
- if (this.form.id) {
- // 判断有没有Id,如果有则删除
- delete this.form.id;
- }
- categoryUpSet(this.form).then(res => {
- this.messageTips("添加", res);
- });
- } else if (this.formActionTitle == "update") {
- categoryUpSet(this.form).then(res => {
- this.messageTips("修改", res);
- });
- }
- } else {
- return false;
- }
- });
- },
- messageTips(title, res) {
- if (res.code == 200) {
- this.$message.success(title + "成功");
- this.typeStatus = false;
- this.getList();
- } else {
- this.$message.error(res.msg);
- }
- },
- getList() {
- categoryListTree({
- delFlag: 0,
- rows: this.pageInfo.limit,
- page: this.pageInfo.page
- }).then(res => {
- let result = res.data;
- if (res.code == 200) {
- result.rows.forEach(row => {
- let subjectname = [],
- subjectIds = [];
- (row.subjects || []).forEach(item => {
- subjectname.push(item.name);
- subjectIds.push(item.id);
- });
- row.subjectName = subjectname;
- row.subjectIds = subjectIds;
- });
- this.tableList = result.rows;
- this.pageInfo.total = result.total;
- }
- });
- },
- openTypes(type, row) {
- this.typeStatus = true;
- this.formActionTitle = type;
- // 修改的时候赋值
- if (type == "update") {
- this.form = {
- id: row.id,
- name: row.name,
- subjectIds: row.subjectIds
- };
- }
- },
- onFormClose(formName) {
- // 关闭弹窗重置验证
- this.form = {
- name: null, // 训练模块名称
- subjectIds: []
- };
- this.$refs[formName].resetFields();
- },
- getSubjectTree() {
- // 获取声部列表
- subjectListTree({
- delFlag: 0,
- rows: 9999
- }).then(res => {
- let result = res.data;
- if (res.code == 200) {
- let tempArray = [];
- result.rows.forEach((item, index) => {
- let subject = [];
- (item.subjects || []).forEach(s => {
- subject.push({
- value: s.id,
- label: s.name
- });
- });
- tempArray[index] = {
- label: item.name,
- options: subject
- };
- });
- this.subjectList = tempArray;
- }
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- ::v-deep .el-date-editor.el-input {
- width: 100% !important;
- }
- ::v-deep .el-select {
- width: 100% !important;
- }
- </style>
|