后台管理系统项目总结(下)

这是一个关于商品参数管理和订单管理的前端界面实现。组件包括级联选择器选择商品分类,动态参数和静态属性的添加、编辑、删除功能,以及属性值的tag展示。用户可以添加、编辑参数,通过表格展示属性详情,同时支持参数值的增删。订单列表展示包含搜索功能,可查看订单状态,修改地址及查看物流信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

分类参数

<template>
  <div>
    <!-- 卡片区域 -->
    <el-card>
      <el-alert title="注意:只允许为第三方分类设置相关参数!" type="warning" show-icon :closable="false"></el-alert>
      <!-- 选择商品分类 -->
      <el-row>
        <el-col>
          <span>选择商品分类:</span>
          <!-- 级联选择器鼠标滑过选中 -->
          <el-cascader
            expandTrigger="hover"
            v-model="selectedCateKeys"
            :options="cateList"
            :props="cateProps"
            @change="handleChange"
          ></el-cascader>
        </el-col>
        <el-col></el-col>
      </el-row>
      <!-- tabs标签页 -->
      <el-tabs v-model="activeName" @tab-click="handleTabClick">
        <!-- 添加动态参数的面板 -->
        <el-tab-pane label="动态参数" name="many">
          <el-button type="primary" :disabled="isBtnDisabled" @click="addDialogVisible = true">添加参数</el-button>
          <!-- 动态参数表格 -->
          <el-table :data="manyTableData" border stripe>
            <el-table-column type="expand">
              <template slot-scope="scope">
                <!-- 用tag循环渲染属性 -->
                <el-tag
                  v-for="(item, i) in scope.row.attr_vals"
                  :key="i"
                  closable
                  @close="handleClose(i, scope.row)"
                >{{ item }}</el-tag>
                <!-- 添加tag -->
                <el-input
                  class="input-new-tag"
                  v-if="scope.row.inputVisible"
                  v-model="scope.row.inputValue"
                  ref="saveTagInput"
                  size="small"
                  @keyup.enter.native="handleInputConfirm(scope.row)"
                  @blur="handleInputConfirm(scope.row)"
                ></el-input>
                <el-button
                  v-else
                  class="button-new-tag"
                  size="small"
                  @click="showInput(scope.row)"
                >+ New Tag</el-button>
              </template>
            </el-table-column>
            <el-table-column type="index" prop="#"></el-table-column>
            <el-table-column label="参数名称" prop="attr_name"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  icon="el-icon-edit"
                  @click="showEditDiialog(scope.row.attr_id)"
                >编辑</el-button>
                <el-button
                  type="danger"
                  size="mini"
                  icon="el-icon-delete"
                  @click="removeParams(scope.row.attr_id)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <!-- 添加静态属性的面板 -->
        <el-tab-pane label="静态属性" name="only">
          <el-button type="primary" :disabled="isBtnDisabled" @click="addDialogVisible = true">添加属性</el-button>
          <!-- 静态属性表格 -->
          <el-table :data="onlyTableData" border stripe>
            <el-table-column type="expand">
              <template slot-scope="scope">
                <!-- 用tag循环渲染属性 -->
                <el-tag
                  v-for="(item, i) in scope.row.attr_vals"
                  :key="i"
                  closable
                  @close="handleClose(i, scope.row)"
                >{{ item }}</el-tag>
                <!-- 添加tag -->
                <el-input
                  class="input-new-tag"
                  v-if="scope.row.inputVisible"
                  v-model="scope.row.inputValue"
                  ref="saveTagInput"
                  size="small"
                  @keyup.enter.native="handleInputConfirm(scope.row)"
                  @blur="handleInputConfirm(scope.row)"
                ></el-input>
                <el-button
                  v-else
                  class="button-new-tag"
                  size="small"
                  @click="showInput(scope.row)"
                >+ New Tag</el-button>
              </template>
            </el-table-column>
            <el-table-column type="index" prop="#"></el-table-column>
            <el-table-column label="属性名称" prop="attr_name"></el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  type="primary"
                  size="mini"
                  icon="el-icon-edit"
                  @click="showEditDiialog(scope.row.attr_id)"
                >编辑</el-button>
                <el-button
                  type="danger"
                  size="mini"
                  icon="el-icon-delete"
                  @click="removeParams(scope.row.attr_id)"
                >删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
    </el-card>
    <!-- 添加参数的对话框 -->
    <el-dialog
      :title="'添加' + titleText"
      :visible.sync="addDialogVisible"
      width="50%"
      @close="addDialogClosed"
    >
      <el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="100px">
        <el-form-item :label="titleText" prop="attr_name">
          <el-input v-model="addForm.attr_name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addParams">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 修改参数对话框 -->
    <el-dialog
      :title="'修改' + titleText"
      :visible.sync="editDialogVisible"
      width="50%"
      @close="editDialogClosed"
    >
      <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="100px">
        <el-form-item :label="titleText" prop="attr_name">
          <el-input v-model="editForm.attr_name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editParams">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import goodApi from './goodApi'
export default {
  // 组件名称
  name: "",
  // 组件参数 接收来自父组件的数据
  props: [],
  // 局部注册的组件
  components: {},
  // 组件状态值
  data() {
    return {
      // 分类列表
      cateList: [],
      //配置级联菜单中数据如何展示
      cateProps: {
        value: "cat_id",
        label: "cat_name",
        children: "children",
      },
      // 级联选择器的双向绑定
      selectedCateKeys: [],
      // 被激活的页签的名称
      activeName: "many",
      // 动态参数的数据
      manyTableData: [],
      // 静态属性的数据
      onlyTableData: [],
      //控制添加对话框的显示和隐藏
      addDialogVisible: false,
      // 添加参数的表单数据
      addForm: {
        attr_name: "",
      },
      // 添加表单的验证规则
      addFormRules: {
        attr_name: [
          { required: true, message: "请输入参数名称", trigger: "blur" },
        ],
      },
      // 修改对话框的显示隐藏
      editDialogVisible: false,
      // 修改的表单数据
      editForm: {
        attr_name: "",
      },
      // 修改的表单数据的验证规则
      editFormRules: {
        attr_name: [
          { required: true, message: "请输入参数名称", trigger: "blur" },
        ],
      },
      // 添加tag的切换
      inputVisible: false,
      // 添加tag的内容
      inputValue: "",
    };
  },
  // 计算属性
  computed: {
    // 按钮的禁用与启用
    isBtnDisabled() {
      if (this.selectedCateKeys.length !== 3) {
        return true;
      }
      return false;
    },
    // 当前选中的三级分类的id
    cateId() {
      if (this.selectedCateKeys.length === 3) {
        return this.selectedCateKeys[2];
      }
      return null;
    },
    // 动态计算标题的文本
    titleText() {
      if (this.activeName === "many") {
        return "动态参数";
      }
      return "静态属性";
    },
  },
  // 侦听器
  watch: {},
  // 组件方法
  methods: {
    async getCateList(id) {
      const { data: res } = await goodApi.getCateList(this.activeName);
      console.log(res);
      if (res.meta.status !== 200) {
        this.$message.error("获取商品分类失败");
      }
      // this.$message.success("获取商品分类成功");
      this.cateList = res.data;
      console.log(this.cateList);
    },
    // 级联选择器
    handleChange() {
      // console.log(this.selectedCateKeys)
      this.getParamsData();
    },
    // tab页签点击事件的处理函数
    handleTabClick() {
      console.log(this.activeName);
      this.getParamsData();
    },
    // 获取参数的列表数据
    async getParamsData() {
      if (this.selectedCateKeys.length !== 3) {
        this.selectedCateKeys = [];
        this.manyTableData = [];
        this.onlyTableData = [];
        return;
      }
      console.log(this.selectedCateKeys);
      // 根据id获取参数
      const { data: res } = await goodApi.getParams( this.cateId,this.activeName);
      console.log(res.data);
      /////////////////////////////
      // 获取属性attr_vals并循环
      res.data.forEach((item) => {
        item.attr_vals = item.attr_vals ? item.attr_vals.split(" ") : [];
        // 控制文本框的显示和隐藏
        item.inputVisible = false;
        // 文本框中输入的值
        item.inputValue = "";
      });
      console.log(res.data);

      /////////////////////////////
      if (res.meta.status !== 200) {
        return this.$message.error("获取参数列表失败");
      }
      // this.$message.success("获取参数列表成功");
      console.log(res.data);
      if (this.activeName === "many") {
        this.manyTableData = res.data;
      } else {
        this.onlyTableData = res.data;
      }
    },
    // 添加对话框的显示隐藏
    addDialogClosed() {
      this.$refs.addFormRef.resetFields();
    },
    // 进行添加参数
    addParams() {
      // 先进行表单验证
      this.$refs.addFormRef.validate(async (valid) => {
        if (!valid) return;
        const { data: res } = await goodApi.addParam(this.cateId,
          this.addForm.attr_name,
          this.activeName,
        );
        if (res.meta.status !== 201) {
          return this.$message.error("添加参数失败");
        }
        this.$message.success("添加参数成功");
        this.addDialogVisible = false;
        this.getParamsData();
      });
    },
    // 展示修改对话框
    async showEditDiialog(attr_id) {
      // 查询当前参数的信息
      const { data: res } = await goodApi.showEdit(this.cateId,attr_id, this.activeName);
      if (res.meta.status !== 200) {
        return this.$message.error("获取参数信息失败");
      }
      // 若获取数据成功将数据返回到编辑表单中
      this.editForm = res.data;
      this.editDialogVisible = true;
    },
    // 重置修改的表单
    editDialogClosed() {
      this.$refs.editFormRef.resetFields();
    },
    // 修改参数信息
    editParams() {
      this.$refs.editFormRef.validate(async (valid) => {
        if (!valid) return;
        const { data: res } = await goodApi.editParam(
        this.cateId,
        this.editForm.attr_id,
        this.editForm.attr_name,
        this.activeName,
        );
        if (res.meta.status !== 200) {
          return this.$message.error("修改参数失败");
        }
        this.$message.success("修改参数成功");
        this.getParamsData();
        this.editDialogVisible = false;
      });
    },
    // 根据id删除对应的参数项
    async removeParams(attr_id) {
      const confirmResult = await this.$confirm("确定删除这个属性吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).catch((err) => err);
      // 取消删除
      if (confirmResult !== "confirm") {
        return this.$message.info("已取消删除");
      }
      // 删除
      const { data: res } = await this.$http.delete(this.cateId,attr_id);
      if (res.meta.status !== 200) {
        return this.$message.error("删除失败");
      }
      this.$message.success("删除成功");
      this.getParamsData();
    },
    // 文本框失焦或回车都会触发
    async handleInputConfirm(row) {
      // 判断如果为空格则变回tag
      if (row.inputValue.trim().length === 0) {
        row.inputValue = "";
        row.inputVisible = false;
        return;
      }
      // 如果不为空格则追加tag
      row.attr_vals.push(row.inputValue.trim());
      row.inputValue = "";
      row.inputVisible = false;
      // 发起请求保存到数据库
      this.saveAttrVals(row);
    },
    // 将attr_vals的操作保存到数据库
    async saveAttrVals(row) {
      // 发起请求保存到数据库
      const { data: res } = await this.$http.put(
        `categories/${this.cateId}/attributes/${row.attr_id}`,
        {
         attr_name,
          attr_sel,attr_vals
        }
      );
      if (res.meta.status !== 200) {
        return this.$message.error("修改参数项失败");
      }
      this.$message.success("修改参数项成功");
    },
    // 添加tag
    showInput(row) {
      row.inputVisible = true;
      // 自动获取焦点
      this.$nextTick((_) => {
        this.$refs.saveTagInput.$refs.input.focus();
      });
    },
    // 删除对应的参数选项
    handleClose(i, row) {
      row.attr_vals.splice(i, 1);
      this.saveAttrVals(row);
    },
  },
  // 以下是生命周期钩子 注:没用到的钩子请自行删除
  beforeCreate() { },
  created() {
    this.getCateList();
  },
  beforeMount() { },
  mounted() { },
  beforeUpdate() { },
  updated() { },
  activated() { },
  deactivated() { },
  beforeDestroy() { },
  destroyed() { },
};
</script> 

订单列表

<template>
    <div>
        <!-- 面包屑 -->
        <Bread></Bread>
        <!-- 内容区域 -->
        <el-card>
            <el-row>
                <!-- 搜索 -->
                <el-col :span="8">
                    <el-input placeholder="请输入内容">
                        <el-button slot="append" icon="el-icon-search"></el-button>
                    </el-input>
                </el-col>
                <!-- 订单列表数据 -->
                <el-table :data="orderlist" stripe border>
                    <el-table-column type="index" label="#"></el-table-column>
                    <el-table-column prop="order_number" label="订单编号"></el-table-column>
                    <el-table-column prop="order_price" label="订单价格"></el-table-column>
                    <el-table-column label="是否付款">
                        <template slot-scope="scope">
                            <el-tag v-if="scope.row.pay_status === '1'" type="success">已付款</el-tag>
                            <el-tag v-else type="danger">未付款</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column prop="is_send" label="是否发货"></el-table-column>
                    <el-table-column prop="create_time" label="下单时间">
                        <template slot-scope="scope">{{ scope.row.create_time | dateFormat }}</template>
                    </el-table-column>
                    <el-table-column prop="address" label="操作">
                        <template>
                            <!-- 修改 -->
                            <el-button
                                type="primary"
                                icon="el-icon-edit"
                                size="mini"
                                @click="showBox"
                            ></el-button>
                            <!-- 物流 -->
                            <el-button
                                type="success"
                                icon="el-icon-location"
                                size="mini"
                                @click="showProgressBox"
                            ></el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <!-- 分页 -->
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="queryInfo.pagenum"
                    :page-sizes="[1, 3, 6, 9]"
                    :page-size="queryInfo.pagesize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                ></el-pagination>
            </el-row>
        </el-card>
        <!-- 修改对话框 -->
        <el-dialog title="修改地址" :visible.sync="addressVisible">
            <el-form
                :model="addressForm"
                :rules="addressFormRules"
                ref="addressFormRef"
                label-width="100px"
                class="demo-ruleForm"
                @close="addressDialogClosed"
            >
                <el-form-item label="省市区/县" prop="address1">
                    <el-cascader :options="cityData" v-model="addressForm.address1"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="addressForm.address2"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addressVisible = false">取 消</el-button>
                <el-button type="primary" @click="addressVisible = false">确 定</el-button>
            </span>
        </el-dialog>
        <!-- 物流信息 -->
        <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
            <!-- 时间线 -->
            <el-timeline>
                <el-timeline-item
                    v-for="(activity, index) in progressInfo"
                    :key="index"
                    :timestamp="activity.time"
                >{{ activity.context }}</el-timeline-item>
            </el-timeline>
        </el-dialog>
    </div>
</template>


<script>
import Bread from '../Bread.vue'
import cityData from './citydata.js'
import ordersApi from './ordersApi'
export default {
    components: { Bread },
    data() {
        return {
            //查询对象
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 3
            },
            total: 0,//总数据条数
            orderlist: [],
            addressVisible: false,
            addressForm: {
                address1: [],
                address2: ''
            },
            addressFormRules: {
                address1: [
                    { required: true, message: '请选择省市区县', trigger: 'blur' }
                ],
                address2: [
                    { required: true, message: '请填写详细地址', trigger: 'blur' }
                ]
            },
            cityData,
            progressVisible: false,
            progressInfo: []

        }
    },
    methods: {
        // 分页
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize
            this.getOrderList()
            console.log(`每页 ${newSize} 条`);
        },
        handleCurrentChange(newNum) {
            this.queryInfo.pagenum = newNum
            this.getOrderList()
            console.log(`当前页: ${newNum}`);
        },
        //获取所有数据
        async getOrderList() {
            const { data: res } = await ordersApi.OrderList( this.queryInfo )
            console.log(res);
            if (res.meta.status !== 200) { return this.$message.error(res.meta.msg) }
            this.total = res.data.total
            this.orderlist = res.data.goods
        },
        //修改
        showBox() {
            this.addressVisible = true
        },
        // 清空
        addressDialogClosed() {
            this.$refs.addressFormRef.refetFields()

        },
        //物流
        async showProgressBox() {
            const { data: res } = await ordersApi.showProgress('/kuaidi/804909574412544580')
            if (res.meta.status !== 200) {
                return this.$message.error(res.meta.msg)
            }
            this.progressInfo = res.data
            this.progressVisible = true
        }
    },
    mounted() {
        this.getOrderList()
    }
}
</script>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值