| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <com-list-page :crumbs="crumbs" id="application">
- <com-list-table
- ref="table"
- :api="'bargain/default/cate-index'"
- >
- <el-table-column prop="id" label="编号" width="150" align="center"></el-table-column>
- <el-table-column prop="name" label="名称" align="center"></el-table-column>
- <el-table-column prop="status" label="状态" width="150">
- <template slot-scope="scope">
- <el-tag v-if="scope.row.status == 0" size="small" type="danger" @click="updateStatus(scope.row.id,1)">禁用</el-tag>
- <el-tag v-if="scope.row.status == 1" size="small" type="success" @click="updateStatus(scope.row.id,0)">启用</el-tag>
- </template>
- </el-table-column>
- <el-table-column label="添加时间" width="300" align="center">
- <template slot-scope="scope">
- <span> {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="300" align="right">
- <template slot-scope="scope">
- <el-button @click="handleEdit(scope.row.id)" type="text" :loading="btnLoad" size="small">编辑</el-button>
- <el-button @click="updateStatus(scope.row.id,-1)" type="text" size="small">删除</el-button>
- </template>
- </el-table-column>
- <template slot="header-left">
- <el-button
- type="primary"
- size="mini"
- icon="el-icon-plus"
- @click="handleEdit(0)">新增分类</el-button>
- </template>
- </com-list-table>
- <el-dialog :title="form.id==0 ? '新增' : '修改'" :visible.sync="dialogFormVisible" @close="handleClose()" width="20%">
- <el-form :model="form" :rules="rules" ref="form">
- <el-form-item label="名称" :label-width="formLabelWidth" prop="name">
- <el-input v-model="form.name" autocomplete="off"></el-input>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="dialogFormVisible = false">取 消</el-button>
- <el-button type="primary" @click="postEdit('form')">确 定</el-button>
- </div>
- </el-dialog>
- </com-list-page>
- <script>
- const application = new Vue({
- el: '#application',
- data: {
- crumbs: [{
- title: '砍价',
- },
- {
- title: '砍价分类',
- }
- ],
- dialogFormVisible: false,
- btnLoad: false,
- form: {
- id: 0,
- name: '',
- },
- formLabelWidth: '80px',
- rules: {
- name: [
- {
- required: true,
- message: '请输入名称',
- trigger: 'blur'
- },
- ],
- },
- },
- methods: {
- handleEdit(id) {
- if (id != 0) {
- this.btnLoad = true
- this.$request({
- params: {
- r: 'bargain/default/cate-edit',
- id: id,
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.form.id = e.data.data.id;
- this.form.name = e.data.data.name;
- this.btnLoad = false
- this.dialogFormVisible = true;
- }
- }).catch(e => {});
- } else {
- this.dialogFormVisible = true;
- }
- },
- postEdit(formName) {
- this.$refs[formName].validate((valid) => {
- if (valid) {
- this.$request({
- method: "post",
- params: {
- r: 'bargain/default/cate-edit',
- },
- data: this.form
- }).then(e => {
- if (e.data.code == 0) {
- this.dialogFormVisible = false;
- this.$message({
- message: e.data.msg,
- type: 'success'
- });
- this.$nextTick(function() {
- this.$refs.table.handleSearch();
- })
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {});
- }
- });
- },
- updateStatus(id, status) {
- this.$request({
- method: "post",
- params: {
- r: 'bargain/default/cate-edit',
- },
- data: {
- id: id,
- status: status
- }
- }).then(e => {
- if (e.data.code == 0) {
- this.$message({
- message: e.data.msg,
- type: 'success'
- });
- this.$nextTick(function() {
- this.$refs.table.handleSearch();
- })
- } else {
- this.$message.error(e.data.msg);
- }
- }).catch(e => {});
- },
- handleClose() {
- this.form = {
- id: 0,
- name: '',
- };
- },
- }
- })
- </script>
- <style lang="scss" scoped>
- .el-form-item {
- margin-bottom: 0;
- }
- </style>
|