| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513 |
- <template>
- <div>
- <save-form
- :inline="true"
- class="searchForm"
- save-key="memberSet"
- @submit="search"
- @reset="onReSet"
- :model.sync="searchForm"
- >
- <!-- 状态 指导老师 活动方案-->
- <el-form-item>
- <el-input
- v-model.trim="searchForm.search"
- clearable
- placeholder="会员名称"
- ></el-input>
- </el-form-item>
- <el-form-item>
- <el-button native-type="submit" type="danger">搜索</el-button>
- <!-- <el-button native-type="reset" type="primary">重置</el-button> -->
- </el-form-item>
- </save-form>
- <el-button
- type="primary"
- style="margin-bottom: 20px"
- v-permission="'memberRankSetting/add'"
- @click="addLeave"
- >新增会员等级</el-button
- >
- <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" prop="type" label="会员标识">
- <template slot-scope="scope">
- <el-image
- style="width: 100px; height: 100px"
- :src="scope.row.icon"
- :preview-src-list="[scope.row.icon]"
- >
- </el-image>
- </template>
- </el-table-column>
- <!-- <el-table-column
- align="center"
- prop="type"
- label="是否新用户试用"
- ></el-table-column> -->
- <el-table-column
- align="center"
- prop="updateTime"
- width="100px"
- label="修改时间"
- ></el-table-column>
- <el-table-column
- align="center"
- prop="type"
- label="修改人"
- ></el-table-column>
- <el-table-column align="center" label="操作">
- <template slot-scope="scope">
- <div>
- <!-- memberRankSetting/add -->
- <auth auths="memberRankSetting/get">
- <el-button type="text" @click="resetMember(scope.row)"
- >详情</el-button
- >
- </auth>
- <auth
- :auths="['memberRankSetting/get', 'memberRankSetting/update']"
- mulit
- >
- <el-button type="text" @click="resetMember(scope.row, 'update')"
- >修改</el-button
- >
- </auth>
- </div>
- </template>
- </el-table-column>
- </el-table>
- <el-dialog
- :title="title"
- :close-on-click-modal="false"
- :visible.sync="branchStatus"
- v-if="branchStatus"
- default-expand-all
- @close="onFormClose('ruleForm')"
- width="800px"
- >
- <el-form :model="form" :inline="true" ref="ruleForm">
- <el-alert
- title="会员信息"
- type="info"
- :closable="false"
- style="margin-bottom: 20px"
- >
- </el-alert>
- <el-form-item
- label="会员名称"
- prop="name"
- :label-width="formLabelWidth"
- :rules="[{ required: true, message: '请输入会员名称' }]"
- >
- <el-input
- :disabled="addDisabled"
- v-model.trim="form.name"
- autocomplete="off"
- style="width: 620px"
- maxlength="10"
- show-word-limit
- ></el-input>
- </el-form-item>
- <el-form-item
- label="会员介绍"
- prop="intro"
- :label-width="formLabelWidth"
- :rules="[{ required: true, message: '请输入会员介绍' }]"
- >
- <el-input
- maxlength="50"
- show-word-limit
- :disabled="addDisabled"
- v-model.trim="form.intro"
- autocomplete="off"
- type="textarea"
- :rows="3"
- style="width: 620px"
- ></el-input>
- </el-form-item>
- <el-form-item
- label="会员标识"
- prop="icon"
- :label-width="formLabelWidth"
- :rules="[{ required: true, message: '请上传会员标识' }]"
- >
- <upload
- v-if="!addDisabled"
- v-model="form.icon"
- :imageWidthM="200"
- :disabled="addDisabled"
- :imageHeightM="200"
- ></upload>
- <img v-else :src="form.icon" alt="" width="120px" height="120px" />
- <p style="color: red" v-if="!addDisabled">
- 请上传200*200像素,大小2M以内,格式为jpg、png、gif图片
- </p>
- </el-form-item>
- <!-- <br />
- <el-form-item
- label="是否新用户试用"
- prop="name"
- :label-width="formLabelWidth"
- >
- <el-select
- v-model.trim="form.isProbationPeriod"
- clearable
- filterable
- placeholder="请选择是否试用"
- >
- <el-option label="是" :value="true"></el-option>
- <el-option label="否" :value="false"></el-option>
- </el-select>
- </el-form-item>
- <el-form-item
- label="试用期限"
- prop="name"
- :label-width="formLabelWidth"
- >
- <el-input
- style="width: 200px"
- v-model.trim="form.name"
- autocomplete="off"
- >
- <template slot="append">天</template>
- </el-input>
- </el-form-item> -->
- <el-alert
- title="会员权益"
- type="info"
- :closable="false"
- style="margin-bottom: 20px"
- >
- </el-alert>
- <el-form-item :label="searchName" :label-width="formLabelWidth">
- <el-input
- style="width: 210px"
- v-model.trim="seachRoleValue"
- ></el-input>
- <el-button style="margin-left: 10px" type="danger" @click="seachRoles"
- >搜索</el-button
- >
- <el-button type="primary" @click="onReSetRole">重置</el-button>
- </el-form-item>
- <br />
- <el-form-item label="会员功能" :label-width="formLabelWidth">
- <el-checkbox
- :disabled="addDisabled"
- :indeterminate="isIndeterminate"
- @change="onCheckAll"
- v-model.trim="checkAll"
- >全选</el-checkbox
- >
- <div>
- <el-tree
- class="tree"
- :data="treeData"
- show-checkbox
- node-key="id"
- @check="onTreeCheck"
- :filter-node-method="filterNode"
- ref="trees"
- highlight-current
- :default-checked-keys="checkList"
- :props="defaultProps"
- >
- <div slot-scope="{ node, data }">
- {{ node.label }}
- </div>
- </el-tree>
- </div>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button v-if="!addDisabled" @click="branchStatus = false"
- >取 消</el-button
- >
- <el-button @click="onSubmit" type="primary">确 定</el-button>
- </span>
- </el-dialog>
- <pagination
- save-key="memberSet"
- :total.sync="rules.total"
- sync
- :page.sync="rules.page"
- :limit.sync="rules.limit"
- :page-sizes="rules.page_size"
- @pagination="getList"
- />
- </div>
- </template>
- <script>
- import pagination from "@/components/Pagination/index";
- import Upload from "@/components/Upload/index";
- import {
- addMemberRank,
- getmemberRankList,
- getmemberRankDetail,
- resetMemberRank,
- } from "./api";
- import { getMemberPrivilegesItem } from "@/views/dictionaryManager/api";
- export default {
- components: { pagination, Upload },
- name: "memberSet",
- data() {
- return {
- formLabelWidth: "120px",
- searchForm: {
- search: null,
- },
- rules: {
- // 分页规则
- limit: 10, // 限制显示条数
- page: 1, // 当前页
- total: 0, // 总条数
- page_size: [10, 20, 40, 50], // 选择限制显示条数
- },
- tableList: [],
- title: "新增会员等级",
- branchStatus: false,
- form: {
- name: "",
- icon: "",
- into: "",
- },
- addDisabled: false,
- checkAll: false,
- isIndeterminate: false,
- treeData: [],
- defaultProps: {
- children: "children",
- label: "label",
- disabled: this.addDisabled,
- },
- result: {
- roleName: null,
- roleDesc: null,
- },
- seachRoleValue: "",
- silderList: [],
- slideCount: 0,
- pageType: "",
- allChildIds: [],
- checkList: [],
- searchName: "搜索\xa0\xa0\xa0\xa0\xa0\xa0\xa0",
- };
- },
- async mounted() {
- this.getList();
- },
- methods: {
- onFormClose(ruleForm) {
- (this.form = {
- name: "",
- icon: "",
- into: "",
- }),
- this.$refs.trees.setCheckedNodes([]);
- this.onTreeCheck();
- this.$refs[ruleForm].resetFields();
- },
- search() {
- this.rules.page = 1;
- this.getList();
- },
- onReSet() {},
- async getList() {
- try {
- const res = await getmemberRankList({
- search: this.searchForm.search,
- rows: this.rules.limit,
- page: this.rules.page,
- });
- this.tableList = res.data.rows;
- this.rules.total = res.data.total;
- } catch {}
- },
- async addLeave() {
- this.checkList = [];
- this.title = "新增会员等级";
- this.addDisabled = false;
- this.pageType = "create";
- await this.getNewTree();
- this.slideCount = 0;
- this.treeData = await this.setTableData(this.silderList, this.addDisabled);
- this.branchStatus = true;
- },
- onSubmit() {
- this.$refs.ruleForm.validate(async (flag) => {
- if (flag) {
- let tempIds = this.$refs.trees.getCheckedKeys();
- let halfIds = this.$refs.trees.getHalfCheckedKeys();
- let allIds = [...tempIds, ...halfIds];
- if (this.pageType == "update") {
- try {
- const res = await resetMemberRank({
- ...this.form,
- memberPrivilegesItemIdList: allIds,
- });
- this.$message.success("修改成功");
- this.branchStatus = false;
- this.getList();
- } catch {}
- } else if (this.pageType == "create") {
- try {
- const res = await addMemberRank({
- ...this.form,
- memberPrivilegesItemIdList: allIds,
- });
- this.$message.success("新建会员成功");
- this.branchStatus = false;
- this.getList();
- } catch {}
- } else {
- this.branchStatus = false;
- }
- }
- });
- },
- onCheckAll(val) {
- if (val) {
- // 先去掉半选
- this.isIndeterminate = false;
- this.$refs.trees.setCheckedNodes(this.treeData);
- } else {
- this.$refs.trees.setCheckedNodes([]);
- }
- },
- onTreeCheck() {
- let checkTree = this.$refs.trees.getCheckedKeys();
- this.checkAll = checkTree.length >= this.slideCount;
- this.isIndeterminate =
- checkTree.length > 0 && checkTree.length < this.slideCount;
- },
- filterNode(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- seachRoles() {
- this.$refs.trees.filter(this.seachRoleValue);
- },
- onReSetRole() {
- this.seachRoleValue = "";
- // this.data = this.setTableData(this.silderList);
- this.$refs.trees.filter(this.seachRoleValue);
- // console.log(this.data);
- },
- setTableData(result, disabled) {
- let list = [];
- list = result.map((res) => {
- let tempList = {};
- tempList = {
- id: res.id,
- name: res.name,
- label: res.name,
- disabled: disabled ? disabled : false,
- };
- this.slideCount++;
- if (res.memberPrivilegesItems && res.memberPrivilegesItems.length > 0) {
- tempList.children = this.setTableData(
- res.memberPrivilegesItems,
- disabled
- );
- }
- return tempList;
- });
- return list;
- },
- async resetMember(row, type) {
- this.branchStatus = true;
- await this.resetTree(row);
- if (type) {
- this.title = "修改会员等级";
- this.pageType = "update";
- this.addDisabled = false;
- this.slideCount = 0;
- this.treeData = await this.setTableData(this.silderList, this.addDisabled);
- } else {
- this.addDisabled = true;
- this.title = "查看会员等级";
- this.pageType = "";
- this.slideCount = 0;
- this.treeData = await this.setTableData(this.silderList, this.addDisabled);
- }
- },
- //递归获取到所有的为子级的ID
- getParent(checkIds, data) {
- let removeIds = JSON.parse(JSON.stringify(checkIds));
- this.getAllChildIds(data);
- let tempAllChildIds = this.allChildIds;
- for (let i = checkIds.length; i > 0; i--) {
- if (!tempAllChildIds.includes(checkIds[i - 1])) {
- removeIds.splice(i - 1, 1);
- }
- }
- return removeIds;
- },
- getAllChildIds(data) {
- // 获取所有最子集编号
- let child = this.allChildIds;
- let tempList = [];
- data.forEach((item, index) => {
- let temp = [];
- if (item.children && item.children.length > 0) {
- temp = this.getAllChildIds(item.children);
- } else {
- child.push(item.id);
- }
- });
- },
- async resetTree(row) {
- try {
- this.treeData = await this.getNewTree()
- const res = await getmemberRankDetail({ memberRankSettingId: row.id });
- this.form = { ...res.data };
- this.checkAll =
- res.data.memberPrivilegesItemIdList?.length >= this.slideCount || false;
- // 反写树的值
- this.isIndeterminate =
- res.data.memberPrivilegesItemIdList?.length > 0 &&
- res.data.memberPrivilegesItemIdList?.length < this.slideCount;
- this.checkList = res.data.memberPrivilegesItemIdList;
- let tSplice = this.getParent(
- res.data.memberPrivilegesItemIdList||[],
- this.treeData
- );
- this.checkList = tSplice;
- this.$nextTick(() => {
- this.$refs.trees.setCheckedKeys(this.checkList);
- });
- } catch (e) {
- console.log(e);
- }
- },
- async getNewTree() {
- try {
- const resTree = await getMemberPrivilegesItem();
- this.silderList = resTree.data;
- this.slideCount = 0;
- return this.setTableData(resTree.data)
- } catch {}
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .tree {
- min-width: 630px;
- }
- </style>
|