123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- <template>
- <div class="category-box" v-loading="loading > 0">
- <Header :title="title"></Header>
- <div class="container">
- <div class="content">
- <!-- 表格 -->
- <div class="btn" @click="categoryModal('add')">+ 添加{{name}}分类</div>
- <el-table
- :data="categoryList"
- class="table no-border-table"
- ref="newsTable"
- :header-cell-style="{
- border: 'none',
- color: '#333',
- background: '#f6f6f6',
- borderBottom: '1px solid #E8E8E8',
- height: '54px',
- }"
- :row-style="{
- height: '54px',
- }"
- >
- <el-table-column
- prop="name"
- align="center"
- label="名称"
- width="120"
- ></el-table-column>
- <el-table-column
- prop="sort"
- align="left"
- label="排序"
- ></el-table-column>
- <el-table-column
- prop="created"
- align="left"
- label="编辑日期"
- ></el-table-column>
- <el-table-column prop="created" align="left" label="是否显示">
- <div slot-scope="scope">
- <i
- v-if="scope.row.status === 1"
- class="iconfont icon-checkbox checked-icon"
- ></i>
- <i v-else class="iconfont icon-checkbox no-checked-icon"></i>
- </div>
- </el-table-column>
- <el-table-column label="操作" align="left" width="240">
- <div slot-scope="scope">
- <div>
- <button
- size="mini"
- class="table-btn"
- @click="categoryModal('edit', scope.row)"
- >
- 编辑
- </button>
- <button
- size="mini"
- class="table-btn"
- @click="deleteCategory(scope.row.id)"
- >
- 删除
- </button>
- </div>
- </div>
- </el-table-column>
- </el-table>
- </div>
- <!-- 分页按钮 -->
- <div class="footer">
- <el-pagination
- @current-change="handleCurrentChange"
- :current-page.sync="currentPage"
- background
- layout="total, prev, pager, next, jumper"
- :page-size="size"
- :total="total"
- ></el-pagination>
- </div>
- </div>
- <!-- 发布分类弹窗 -->
- <el-dialog width="456px" :visible.sync="categoryShow">
- <div slot="title">
- <p class="dialog-title">
- {{ type === "add" ? "添加" : "编辑" }}{{name}}分类
- </p>
- </div>
- <div class="dialog-content">
- <el-form
- :rules="rules"
- :model="form"
- ref="categoryForm"
- class="form"
- label-width="180px"
- >
- <el-form-item label="分类名称:" prop="name">
- <el-input
- class="category-input"
- size="small"
- style="width: 150px"
- v-model="form.name"
- placeholder="请输入分类名称"
- ></el-input>
- </el-form-item>
- <el-form-item label="输入排序:">
- <el-input
- class="category-input"
- size="small"
- style="width: 60px"
- type="number"
- onkeypress="return( /[\d]/.test(String.fromCharCode(event.keyCode)))"
- v-model.number="form.sort"
- placeholder=""
- ></el-input>
- </el-form-item>
- <el-form-item label="展示:">
- <el-checkbox v-model="form.status">是否展示该分类</el-checkbox>
- </el-form-item>
- </el-form>
- </div>
- <div slot="footer" class="dialog-footer">
- <button
- class="btn cancel-btn"
- size="small"
- @click="categoryShow = false"
- >
- 取 消
- </button>
- <button class="btn confirm-btn" size="small" @click="handleCategory">
- 确 定
- </button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script type="text/ecmascript-6">
- import dayjs from 'dayjs';
- import Header from '../../components/common/header';
- export default {
- components: {
- Header
- },
- name: 'category',
- data() {
- return {
- currentPage: 1, // 当前页码
- size: 20, // 每页条数
- total: 0, // 总页数
- loading: 0, // 加载中
- type: '', // edit:修改 add:添加
- categoryInfo: {}, // 分类信息
- categoryList: [], // 分类列表
- categoryShow: false, // 分类弹窗
- form: {
- // 表单数据
- name: '',
- class: null,
- label: 0,
- sort: 0,
- status: false
- },
- rules: {
- // 表单验证规则
- name: [{ required: true, message: '请输入内容', trigger: 'blur' }]
- }
- };
- },
- props: {
- name: {
- type: String,
- value: ''
- },
- classNum: {
- type: Number
- },
- title: {
- type: Object,
- value: {
- // 页面标题
- firstTitile: '',
- secondTitle: ''
- }
- }
- },
- mounted() {
- // 获取列表
- this.getCategoryList();
- },
- filters: {
- // 时间格式化
- dateFormat(date) {
- if (!date) return '请选择时间';
- let day = dayjs(date);
- return day.format('YYYY-MM-DD HH:mm:ss');
- }
- },
- computed: {},
- methods: {
- // 切换页码
- handleCurrentChange(page) {
- this.currentPage = page;
- this.getCategoryList();
- },
- // 获取分类列表
- getCategoryList() {
- this.loading++;
- this.httpGet(this.$root.getCategoryList, {
- page: this.currentPage,
- page_size: this.size,
- class: this.classNum
- }).then(
- (res) => {
- this.loading--;
- this.categoryList = res.list;
- this.total = res.total;
- },
- (res) => {
- this.loading--;
- this.$message.error(res);
- }
- );
- },
- // 分类弹窗
- categoryModal(type, rowData) {
- this.$refs.categoryForm && this.$refs.categoryForm.clearValidate();
- this.type = type;
- if (type === 'edit') {
- this.categoryInfo = rowData;
- this.form = {
- name: rowData.name,
- class: this.classNum,
- sort: rowData.sort,
- status: rowData.status === 1,
- label: 0
- };
- } else if (type === 'add') {
- this.form = {
- name: '',
- class: this.classNum,
- label: 0,
- sort: 0,
- status: false
- };
- }
- this.categoryShow = true;
- },
- // 确认添加/修改分类
- handleCategory() {
- this.$refs.categoryForm.validate((valid) => {
- if (valid) {
- this.loading++;
- let inputData = {};
- let url = '';
- if (this.type === 'add') {
- url = this.$root.addCategory;
- inputData = { ...this.form };
- } else if (this.type === 'edit') {
- url = this.$root.updateCategory;
- inputData = {
- id: this.categoryInfo.id,
- ...this.form
- };
- }
- this.httpPost(url, {
- ...inputData,
- status: inputData.status ? 1 : 2
- }).then(
- (res) => {
- this.$message({
- message: '操作成功',
- type: 'success'
- });
- this.loading--;
- this.categoryShow = false;
- this.getCategoryList();
- },
- (res) => {
- this.loading--;
- this.$message.error(res);
- }
- );
- } else {
- return false;
- }
- });
- },
- // 删除分类
- deleteCategory(id) {
- this.$confirm(
- `<p class='title'><i class='icon el-icon-question'></i>确认要删除这条${this.name}分类吗?</p><p class='text'>此操作将永久删除该条信息,要继续完成该删除动作吗?</p>`,
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- cancelButtonClass: 'cancel-btn',
- confirmButtonClass: 'confirm-btn',
- customClass: 'confirm-box',
- dangerouslyUseHTMLString: true,
- showClose: false,
- type: 'none'
- }
- ).then(() => {
- this.loading++;
- this.httpPost(this.$root.deleteCategory, {
- class: 1,
- id
- }).then(
- (res) => {
- this.$message({
- message: '操作成功',
- type: 'success'
- });
- this.loading--;
- this.getCategoryList();
- },
- (res) => {
- this.loading--;
- this.$message.error(res);
- }
- );
- });
- }
- }
- };
- </script>
- <style lang="stylus" rel="stylesheet/stylus">
- @import '~assets/public.styl';
- </style>
- <style lang="stylus" rel="stylesheet/stylus" scoped>
- @import '~assets/main.styl';
- .category-box {
- height: 100%;
- width: 100%;
- flex-y(flex-start, flex-start);
- overflow-y: hidden;
- background: bg-color;
- .container {
- box-sizing: border-box;
- height: 100%;
- width: 100%;
- overflow-y: auto;
- flex-y(flex-start, flex-start);
- padding: 24px;
- // content 表格
- .content {
- flex: 1;
- width: 100%;
- font-size: 14px;
- background: white;
- box-sizing: border-box;
- padding: 24px 32px;
- border-radius: 2px;
- .checked-icon {
- color: btn-color;
- font-size: 16px;
- }
- .no-checked-icon {
- color: #aaa;
- }
- // 按钮
- .btn {
- // width: 100px;
- display: inline-block;
- padding: 0 10px;
- height: 32px;
- line-height: 32px;
- confirm-btn();
- font-size: 14px;
- margin-bottom: 16px;
- }
- // 表格按钮
- .table-btn {
- width: 65px;
- height: 24px;
- line-height: 24px;
- color: gray3;
- font-size: 12px;
- margin-right: 8px;
- cancel-btn();
- }
- }
- }
- .footer {
- width: 100%;
- padding: 24px;
- box-sizing: border-box;
- flex-x(flex-end);
- background: white;
- }
- .dialog-content {
- flex-y();
- .form {
- width: 100%;
- // flex-y();
- }
- }
- }
- </style>
|