2个文件已修改
4个文件已添加
988 ■■■■■ 已修改文件
manager/src/api/order.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/api/tag-type.js 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/api/tag.js 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/views/order/order/orderDetail.vue 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/views/tag/tag-type/index.vue 311 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/views/tag/tag/index.vue 403 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manager/src/api/order.js
@@ -130,6 +130,10 @@
export const getLogisticsChecked = () => {
  return getRequest(`/other/logistics/getChecked`)
}
//查询包裹列表
export const getPackage = (orderSn) => {
  return getRequest(`/order/order/getPackage/${orderSn}`);
}
//查询物流
export const getTraces = (sn, params) => {
manager/src/api/tag-type.js
New file
@@ -0,0 +1,48 @@
import service from "@/libs/axios";
// 获取标签分类列表
export const getTagTypeList = (params) => {
    return service({
        url: "/lmk/tag-type/list",
        method: "GET",
        params: params
    })
}
export const getTagKeyTypeList = () => {
    return service({
        url: "/lmk/tag-type/key/list",
        method: "GET"
    })
}
// 通过id删除标签分类
export const deleteTagTypeById = (params) => {
    return service({
        url: "/lmk/tag-type/" + params,
        method: "DELETE"
    })
}
// 修改标签分类
export const updateTagType = (params) => {
    return service({
        url: "/lmk/tag-type/",
        method: "PUT",
        data: params
    })
}
// 添加标签分类
export const saveTagType = (params) => {
    return service({
        url: "/lmk/tag-type/",
        method: "POST",
        data: params
    })
}
manager/src/api/tag.js
New file
@@ -0,0 +1,47 @@
import service from "@/libs/axios";
// 获取标签分页
export const getTags = (data) => {
    return service({
        url: "/lmk/tag/page",
        method: "GET",
        params: data
    })
}
// 获取标签列表
export const getTagList = () => {
    return service({
        url: "/lmk/tag/list",
        method: "GET"
    })
}
// 通过id删除标签
export const deleteTagById = (params) => {
    return service({
        url: "/lmk/tag/" + params,
        method: "DELETE"
    })
}
// 修改标签
export const editTag = (params) => {
    return service({
        url: "/lmk/tag/",
        method: "PUT",
        data: params
    })
}
// 添加标签
export const addTag = (params) => {
    return service({
        url: "/lmk/tag/",
        method: "POST",
        data: params
    })
}
manager/src/views/order/order/orderDetail.vue
@@ -7,6 +7,7 @@
          <Button v-if="allowOperation.editConsignee" @click="editAddress" type="primary" ghost>修改收货地址</Button>
          <Button v-if="allowOperation.cancel" @click="orderCancel" type="warning" ghost>订单取消</Button>
          <Button v-if="orderInfo.order.orderStatus === 'UNPAID'" @click="confirmPrice" type="primary">收款</Button>
          <Button v-if="allowOperation.showLogistics || orderPackage.length > 0" @click="checkLogistics" type="primary">查看物流</Button>
          <Button @click="orderLog" type="info" ghost>订单日志</Button>
          <Button @click="printOrder" type="primary" ghost style="float:right;"
            v-if="$route.query.orderType != 'VIRTUAL'">打印发货单</Button>
@@ -310,6 +311,74 @@
        <Button type="primary" @click="modifyPriceSubmit">调整</Button>
      </div>
    </Modal>
    <!-- 查询物流 -->
    <Modal v-model="logisticsModal" width="40">
      <p slot="header">
        <span>查询物流</span>
      </p>
      <div class="layui-layer-wrap">
        <dl>
          <dt>订单号:</dt>
          <dd>
            <div class="text-box">{{ sn }}</div>
          </dd>
        </dl>
      </div>
      <div v-if="packageTraceList.length > 0" v-for="(packageItem, packageIndex) in packageTraceList" :key="packageIndex">
        <div class="layui-layer-wrap">
          <dl>
            <dt>物流公司:</dt>
            <dd><div class="text-box">{{ packageItem.logisticsName }}</div></dd>
          </dl>
          <dl>
            <dt>快递单号:</dt>
            <dd><div nctype="ordersSn" class="text-box">{{ packageItem.logisticsNo }}</div></dd>
          </dl>
          <div class="div-express-log">
            <ul class="express-log express-log-name">
              <li v-for="(item, index) in packageItem.orderPackageItemList" :key="index">
                <span class="time" style="width: 50%;"><span>商品名称:</span><span>{{ item.goodsName }}</span></span>
                <span class="time" style="width: 30%;"><span>发货时间:</span><span>{{ item.logisticsTime }}</span></span>
                <span class="time" style="width: 20%;"><span>发货数量:</span><span>{{ item.deliverNumber }}</span></span>
              </li>
            </ul>
          </div>
          <div class="div-express-log">
            <ul class="express-log" v-if="packageItem.traces && packageItem.traces.traces">
              <li v-for="(item, index) in packageItem.traces.traces" :key="index">
                <span class="time">{{ item.AcceptTime || item.acceptTime }}</span>
                <span class="detail">{{ item.AcceptStation || item.remark }}</span>
              </li>
            </ul>
            <ul class="express-log" v-else><li>暂无物流信息</li></ul>
          </div>
        </div>
      </div>
      <div v-if = "packageTraceList.length == 0 && logisticsInfo">
        <div class="layui-layer-wrap">
          <dl>
            <dt>物流公司:</dt>
            <dd><div class="text-box">{{ logisticsInfo.shipper }}</div></dd>
          </dl>
          <dl>
            <dt>快递单号:</dt>
            <dd><div nctype="ordersSn" class="text-box">{{ logisticsInfo.logisticCode }}</div></dd>
          </dl>
          <div class="div-express-log">
            <ul class="express-log" v-if="logisticsInfo && logisticsInfo.traces">
              <li v-for="(item, index) in logisticsInfo.traces" :key="index">
                <span class="time">{{ item.AcceptTime }}</span>
                <span class="detail">{{ item.AcceptStation }}</span>
              </li>
            </ul>
            <ul class="express-log" v-else><li>暂无物流信息</li></ul>
          </div>
        </div>
      </div>
      <div slot="footer" style="text-align: right">
        <Button @click="logisticsModal = false">取消</Button>
      </div>
    </Modal>
    <!-- 订单取消模态框 -->
    <Modal v-model="orderCancelModal" width="530">
      <p slot="header">
@@ -468,6 +537,12 @@
      orderLogModal: false, //弹出调整价格框
      checkedLogistics: [], //选中的物流公司集合
      allowOperation: {}, //订单可才做选项
      logisticsModal: false, //弹出查询物流框
      packageTraceList: [],
      orderPackage: [],
      logisticsInfo: {
        shipper: "",
      }, //物流信息
      sn: "", //订单编号
      orderInfo: {
        order: {
@@ -645,7 +720,39 @@
    gotoHomes () {
      return false
    },
    getOrderPackage() {
      API_Order.getPackage(this.sn).then(res => {
        if (res.success) {
          this.orderPackage = res.result;
          console.log('this.orderPackage',this.orderPackage);
        }
      })
    },
    //查询物流
    checkLogistics () {
      this.logisticsModal = true;
      if (this.orderPackage.length > 0) {
        this.logisticsList();
      } else {
        this.logistics();
      }
    },
    logisticsList () {
      this.logisticsModal = true;
      API_Order.getPackage(this.sn).then((res) => {
        if (res.success && res.result != null) {
          this.packageTraceList = res.result;
        }
      });
    },
    logistics () {
      this.logisticsModal = true;
      API_Order.getTraces(this.sn).then((res) => {
        if (res.success && res.result != null) {
          this.logisticsInfo = res.result;
        }
      });
    },
    //确认收款
    confirmPrice () {
      this.$Modal.confirm({
@@ -805,6 +912,7 @@
  mounted () {
    this.sn = this.$route.query.sn;
    this.getDataList();
    this.getOrderPackage();
  },
};
</script>
@@ -910,7 +1018,72 @@
    }
  }
}
.div-express-log {
  max-height: 300px;
  border: solid 1px #e7e7e7;
  background: #fafafa;
  overflow-y: auto;
  overflow-x: auto;
}
.layui-layer-wrap {
  dl {
    border-top: solid 1px #f5f5f5;
    margin-top: -1px;
    overflow: hidden;
    dt {
      font-size: 14px;
      line-height: 28px;
      display: inline-block;
      padding: 8px 1% 8px 0;
      color: #999;
    }
    dd {
      font-size: 14px;
      line-height: 28px;
      display: inline-block;
      padding: 8px 0 8px 8px;
      border-left: solid 1px #f5f5f5;
      .text-box {
        line-height: 40px;
        color: #333;
        word-break: break-all;
      }
    }
  }
}
.express-log {
  /*margin: 5px -10px 5px 5px;*/
  padding: 10px;
  list-style-type: none;
  .time {
    width: 30%;
    display: inline-block;
    float: left;
  }
  .detail {
    width: 60%;
    margin-left: 30px;
    display: inline-block;
  }
  li {
    line-height: 30px;
  }
}
.express-log-name {
  li {
    display: flex;
    span  {
      display: flex;
    }
  }
}
.f14 {
  font-size: 14px;
  color: #333;
manager/src/views/tag/tag-type/index.vue
New file
@@ -0,0 +1,311 @@
<template>
    <div>
        <Card>
            <div class="operation mb_10">
                <Button @click="addParent" type="primary" icon="md-add">添加一级分类</Button>
            </div>
            <tree-table ref="treeTable" size="default" :loading="loading" :data="tableData" :columns="columns"
                :border="true" :show-index="false" :is-fold="true" :expand-type="false" primary-key="id">
                <template slot="action" slot-scope="scope">
                    <Button type="info" @click="edit(scope.row)" size="small" style="margin-right: 5px">编辑
                    </Button>
                    <Button type="error" @click="remove(scope.row)" size="small" style="margin-right: 5px">删除
                    </Button>
                    <Button v-show="scope.row.level != 1" type="success" @click="addChildren(scope.row)" size="small"
                        style="margin-right: 5px">添加子分类
                    </Button>
                </template>
            </tree-table>
        </Card>
        <Modal :title="modalTitle" v-model="modalVisible" :mask-closable="false" :width="500">
            <Form ref="formAdd" :model="formAdd" :label-width="100" :rules="formValidate">
                <div v-if="showParent">
                    <FormItem label="上级分类" prop="parentId">
                        {{ parentTitle }}
                        <Input v-model="formAdd.parentId" clearable style="width: 100%; display: none" />
                    </FormItem>
                </div>
                <FormItem label="分类名称" prop="tagTypeName">
                    <Input v-model="formAdd.tagTypeName" clearable style="width: 100%" />
                </FormItem>
                <FormItem label="分类标识" prop="typeKey">
                    <Select v-model="formAdd.typeKey" :disabled="formAdd.parentId!==0" placeholder="请选择分类标识" filterable :popper-append-to-body="false"
                        popper-class="spec-values-popper" style="width: 100%; text-align: left; margin-right: 10px">
                        <Option v-for="item in typeKeyList" :value="item.value" :label="item.value" :key="item.value">
                        </Option>
                    </Select>
                </FormItem>
                <FormItem label="排序值" prop="sortNum">
                    <InputNumber v-model="formAdd.sortNum"></InputNumber>
                </FormItem>
            </Form>
            <div slot="footer">
                <Button type="text" @click="modalVisible = false">取消</Button>
                <Button type="primary" :loading="submitLoading" @click="Submit">提交</Button>
            </div>
        </Modal>
    </div>
</template>
<script>
import {
    saveTagType,
    getTagTypeList ,
    deleteTagTypeById,
    updateTagType,getTagKeyTypeList
} from "@/api/tag-type";
import TreeTable from "@/components/tree-table/Table/Table";
import uploadPicInput from "@/components/lili/upload-pic-input";
import { regular } from "@/utils";
export default {
    name: "lili-components",
    components: {
        TreeTable,
        uploadPicInput,
    },
    data() {
        return {
            submitLoading: false,
            loading: false, // 加载状态
            expandLevel: 1, // 展开的层级
            modalType: 0, // 添加或编辑标识
            modalVisible: false, // 添加或编辑显示
            modalTitle: "", // 添加或编辑标题
            showParent: false, // 是否展示上级菜单
            parentTitle: "", // 父级菜单名称
            formAdd: {
                // 添加或编辑表单对象初始化数据
                parentId: "",
                sortNum: 1,
                level: 0,
                tagTypeName: "",
                typeKey:''
            },
            // 表单验证规则
            formValidate: {
                tagTypeName: [regular.REQUIRED],
                typeKey: [regular.REQUIRED],
                sortNum: [regular.REQUIRED, regular.INTEGER],
            },
            columns: [
                {
                    title: "分类名称",
                    key: "tagTypeName",
                    witt: "100px",
                },
                {
                    title: "分类标识",
                    key: "typeKey",
                    witt: "100px",
                },
                {
                    title: "排序",
                    key: "sortNum",
                    width: "100px",
                },
                {
                    title: "操作",
                    key: "action",
                    align: "center",
                    headerAlign: "center",
                    width: "400px",
                    type: "template",
                    template: "action",
                },
            ],
            typeKeyList: [],
            tableData: [], // 表格数据
        };
    },
    methods: {
        // 初始化数据
        init() {
            this.getAllList();
            this.getKeyTypeList();
        },
        getKeyTypeList() {
            getTagKeyTypeList().then((res) => {
                this.typeKeyList = res.data
            })
        },
        // 添加子分类
        addChildren(v) {
            this.modalType = 0;
            this.modalTitle = "添加子分类";
            this.formAdd.tagTypeName = "";
            this.parentTitle = v.tagTypeName;
            this.formAdd.typeKey = v.typeKey;
            this.typeKeyEdit = false
            this.formAdd.level = eval(v.level + "+1");
            this.showParent = true;
            delete this.formAdd.id;
            this.formAdd.parentId = v.id;
            this.modalVisible = true;
        },
        // 编辑分类
        edit(v) {
            this.modalType = 1;
            this.modalTitle = "编辑";
            this.formAdd.id = v.id;
            this.formAdd.tagTypeName = v.tagTypeName;
            this.formAdd.level = v.level;
            this.formAdd.parentId = v.parentId;
            this.formAdd.sortNum = v.sortNum;
            this.showParent = false;
            this.modalVisible = true;
        },
        // 添加一级分类
        addParent() {
            this.modalType = 0;
            this.modalTitle = "添加一级分类";
            this.parentTitle = "顶级分类";
            this.showParent = true;
            this.$refs.formAdd.resetFields();
            delete this.formAdd.id;
            this.formAdd.parentId = 0;
            this.modalVisible = true;
        },
        // 提交
        Submit() {
            this.$refs.formAdd.validate((valid) => {
                if (valid) {
                    this.submitLoading = true;
                    if (this.modalType === 0) {
                        // 添加 避免编辑后传入id等数据 记得删除
                        delete this.formAdd.id;
                        saveTagType(this.formAdd).then((res) => {
                            this.submitLoading = false;
                            if (res.success) {
                                this.$Message.success("添加成功");
                                this.formAdd = {
                                    // 添加或编辑表单对象初始化数据
                                    parentId: "",
                                    sortNum: 1,
                                    level: 0,
                                    tagTypeName: "",
                                };
                            } else {
                                // this.$Message.error(res.message);
                            }
                            this.getAllList();
                            this.modalVisible = false;
                        });
                    } else {
                        // 编辑
                        updateTagType(this.formAdd, this.formAdd.id).then((res) => {
                            this.submitLoading = false;
                            if (res.success) {
                                this.$Message.success("修改成功");
                            } else {
                                // this.$Message.error(res.message);
                            }
                            this.getAllList();
                            this.modalVisible = false;
                            this.$refs.formAdd.resetFields();
                        });
                    }
                }
            });
        },
        // 删除分类
        remove(v) {
            this.$Modal.confirm({
                title: "确认删除",
                content: "您确认要删除 " + v.tagTypeName + " ?",
                loading: true,
                onOk: () => {
                    // 删除
                    deleteTagTypeById(v.id).then((res) => {
                        this.$Modal.remove();
                        if (res.code===200) {
                            this.$Message.success("操作成功");
                            this.getAllList();
                        }
                    });
                },
            });
        },
        // 获取分类数据
        getAllList(newval) {
            this.loading = true;
            getTagTypeList().then((res) => {
                this.loading = false;
                if (res.code===200) {
                    // 仅展开指定级数 默认后台已展开所有
                    let expandLevel = this.expandLevel;
                    res.data.forEach(function (e) {
                        if (expandLevel == 1) {
                            if (e.level == 0) {
                                e.expand = false;
                            }
                            if (e.children && e.children.length > 0) {
                                e.children.forEach(function (c) {
                                    if (c.level == 1) {
                                        c.expand = false;
                                    }
                                    if (c.children && c.children.length > 0) {
                                        c.children.forEach(function (b) {
                                            if (b.level == 2) {
                                                b.expand = false;
                                            }
                                        });
                                    }
                                });
                            }
                        } else if (expandLevel == 2) {
                            if (e.level == 0) {
                                e.expand = true;
                            }
                            if (e.children && e.children.length > 0) {
                                e.children.forEach(function (c) {
                                    if (c.level == 1) {
                                        c.expand = false;
                                    }
                                    if (c.children && c.children.length > 0) {
                                        c.children.forEach(function (b) {
                                            if (b.level == 2) {
                                                b.expand = false;
                                            }
                                        });
                                    }
                                });
                            }
                        } else if (expandLevel == 3) {
                            if (e.level == 0) {
                                e.expand = true;
                            }
                            if (e.children && e.children.length > 0) {
                                e.children.forEach(function (c) {
                                    if (c.level == 1) {
                                        c.expand = true;
                                    }
                                    if (c.children && c.children.length > 0) {
                                        c.children.forEach(function (b) {
                                            if (b.level == 2) {
                                                b.expand = false;
                                            }
                                        });
                                    }
                                });
                            }
                        }
                    });
                    this.tableData = res.data;
                }
            });
        },
    },
    mounted() {
        this.init();
    },
};
</script>
<style lang="scss" scoped>
.article {
    font-size: 16px;
    font-weight: 400;
    margin: 12px 0;
}
</style>
manager/src/views/tag/tag/index.vue
New file
@@ -0,0 +1,403 @@
<template>
  <div class="wrapper">
    <Row>
      <Col span="4">
      <Card style="height: 100%;" class="article-category mr_10">
        <Tree :data="treeData" @on-select-change="handleCateChange"></Tree>
      </Card>
      </Col>
      <Col span="20">
      <Card class="article-detail">
        <Row @keydown.enter.native="handleSearch">
          <Form ref="searchForm" :model="searchForm" inline :label-width="70" style="width: 100%" class="search-form">
            <Form-item label="标签名称" prop="tagName">
              <Input type="text" v-model="searchForm.tagName" placeholder="请输入标签名称" clearable style="width: 200px" />
            </Form-item>
            <Button @click="handleSearch" type="primary" icon="ios-search" class="search-btn">搜索</Button>
          </Form>
        </Row>
        <Row class="operation padding-row">
          <Button @click="add" v-if="!selected" type="primary">添加</Button>
        </Row>
        <Table :loading="loading" border :columns="columns" :data="data" style="height: calc(100vh - 328px);"
          ref="table">
          <!-- 页面展示 -->
          <template slot="openStatusSlot" slot-scope="scope">
            <div></div>
            <i-switch size="large" v-model="scope.row.openStatus" @on-change="changeSwitch(scope.row)">
              <span slot="open">展示</span>
              <span slot="close">隐藏</span>
            </i-switch>
          </template>
        </Table>
        <Row type="flex" justify="end" class="mt_10">
          <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage"
            @on-page-size-change="changePageSize" :page-size-opts="[10, 20, 50]" size="small" show-total show-elevator>
          </Page>
        </Row>
      </Card>
      </Col>
    </Row>
    <template v-if="!selected">
      <Modal :tagName="modalTitle" v-model="modalVisible" :mask-closable="false" :width="1100">
        <Form ref="form" :model="form" :label-width="100">
          <FormItem label="标签名称" prop="tagName">
            <Input v-model="form.tagName" clearable style="width: 40%" />
          </FormItem>
          <FormItem label="标签分类" prop="tagTypeId">
            <Select v-model="treeValue" placeholder="请选择" clearable style="width: 180px">
              <Option v-if="treeValue" :value="treeValue" style="display: none">{{ treeValue }}
              </Option>
              <Tree :data="treeDataDefault" @on-select-change="handleCheckChange"></Tree>
            </Select>
          </FormItem>
          <FormItem label="排序" prop="sortNum">
            <Input type="number" v-model="form.sortNum" clearable style="width: 10%" />
          </FormItem>
        </Form>
        <div slot="footer">
          <Button type="text" @click="modalVisible = false">取消</Button>
          <Button type="primary" :loading="submitLoading" @click="handleSubmit">提交</Button>
        </div>
      </Modal>
    </template>
  </div>
</template>
<script>
import { getTagTypeList } from "@/api/tag-type";
import { getTags, deleteTagById, editTag, addTag } from "@/api/tag";
import tinymec from "@/components/editor/index.vue";
export default {
  components: {
    tinymec: tinymec,
  },
  props: {
    selected: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      selectedIndex: 99999, // 已选下标
      loading: true, // 表单加载状态
      modalType: 0, // 添加或编辑标识
      modalVisible: false, // 添加或编辑显示
      modalTitle: "", // 添加或编辑标题
      treeDataDefault: [],
      searchForm: {
        // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sortNum: "createTime", // 默认排序字段
        order: "desc", // 默认排序方式
        tagTypeId: "",
      },
      searchTreeValue: "", // 切换
      form: {
        // 添加或编辑表单对象初始化数据
        tagName: "",
        tagTypeId: "",
        sortNum: 1,
        id: "",
      },
      list: [], // 列表
      treeValue: "", // 选择的分类
      //树结构
      treeData: [],
      submitLoading: false, // 添加或编辑提交状态
      columns: [
        // 表头
        {
          title: "分类名称",
          key: "tagTypeName",
          width: 150,
        },
        {
          title: "标签名称",
          key: "tagName",
          minWidth: 200,
          tooltip: true,
        },
        {
          title: "排序",
          key: "sortNum",
          width: 100,
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          width: 230,
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    size: "small",
                    type:
                      this.selectedIndex == params.index
                        ? "primary"
                        : "default",
                  },
                  style: {
                    marginRight: "5px",
                    display: this.selected ? "" : "none",
                  },
                  on: {
                    click: () => {
                      this.selectedIndex = params.index;
                      this.$emit("callbacked", params.row);
                    },
                  },
                },
                this.selectedIndex == params.index ? "已选" : "选择"
              ),
              h(
                "Button",
                {
                  props: {
                    size: "small",
                    type: "info",
                  },
                  style: {
                    marginRight: "5px",
                  },
                  on: {
                    click: () => {
                      this.edit(params.row);
                    },
                  },
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small",
                  },
                  on: {
                    click: () => {
                      this.remove(params.row);
                    },
                  },
                },
                "删除"
              ),
            ]);
          },
        },
      ],
      data: [], // 表单数据
      total: 0, // 表单数据总数
    };
  },
  watch: {
    "searchForm.tagTypeId": {
      handler() {
        this.handleSearch();
      },
      deep: true,
    },
    "searchForm.tagName": {
      handler() {
        this.handleSearch();
      },
      deep: true,
    },
  },
  methods: {
    // 初始化数据
    init() {
      this.getDataList();
      this.getAllList(0);
    },
    // 选择分类回调
    handleCateChange(data) {
      let { value, title } = data[0];
      this.list.push({
        value,
        title,
      });
      this.searchForm.tagTypeId = value;
      this.searchTreeValue = title;
      this.getDataList()
    },
    // 标签分类的选择事件
    handleCheckChange(data) {
      let value = "";
      let title = "";
      this.list = [];
      data.forEach((item, index) => {
        value += `${item.value},`;
        title += `${item.title},`;
      });
      value = value.substring(0, value.length - 1);
      title = title.substring(0, title.length - 1);
      this.list.push({
        value,
        title,
      });
      this.form.tagTypeId = value;
      this.treeValue = title;
    },
    // 改变页数
    changePage(v) {
      this.searchForm.pageNumber = v;
      this.getDataList();
    },
    // 改变页码
    changePageSize(v) {
      this.selected.pageNumber = 1;
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    // 搜索列表
    handleSearch() {
      this.searchForm.pageNumber = 1;
      this.searchForm.pageSize = 10;
      this.getDataList();
    },
    // 获取全部标签分类
    getAllList(parent_id) {
      this.loading = true;
      getTagTypeList(parent_id).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.treeData = this.getTree(res.data);
          this.treeDataDefault = this.getTree(res.data);
          this.treeData.unshift({
            title: "全部",
            level: 0,
            children: [],
            id: "0",
            tagTypeId: 0,
          });
        }
      });
    },
    // 标签分类格式化方法
    getTree(tree = []) {
      let arr = [];
      if (!!tree && tree.length !== 0) {
        tree.forEach((item) => {
          let obj = {};
          obj.title = item.tagTypeName;
          obj.value = item.id;
          obj.attr = item.tagTypeName; // 其他你想要添加的属性
          obj.expand = false;
          obj.selected = false;
          obj.children = this.getTree(item.children); // 递归调用
          arr.push(obj);
        });
      }
      return arr;
    },
    // 获取标签列表
    getDataList(val) {
      if (val) this.form = {};
      this.loading = true;
      getTags(this.searchForm).then((res) => {
        this.loading = false;
        if (res.code === 200) {
          this.total = res.total;
          //为了在是否展示一列展示开关 需要改一下数据类型,最终提交再次更改
          this.data = [];
          if (res.data.length > 0) {
            this.data = res.data;
          }
        }
      });
      this.total = this.data?.length;
      this.loading = false;
    },
    // 添加标签
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.submitLoading = true;
          if (this.modalType === 0) {
            // 添加 避免编辑后传入id等数据 记得删除
            delete this.form.id;
            addTag(this.form).then((res) => {
              this.submitLoading = false;
              if (res.code === 200) {
                this.$Message.success("操作成功");
                this.getDataList();
                this.modalVisible = false;
              }
            });
          } else {
            // 编辑
            editTag(this.form).then((res) => {
              this.submitLoading = false;
              if (res.code === 200) {
                this.$Message.success("操作成功");
                this.getDataList();
                this.modalVisible = false;
              }
            });
          }
        }
      });
    },
    // 添加标签modal
    add() {
      this.modalType = 0;
      this.modalTitle = "添加标签";
      this.treeValue = "";
      this.form = {
        sortNum: 1,
        tagName: "",
      };
      this.$refs.form.resetFields();
      delete this.form.id;
      this.modalVisible = true;
    },
    // 编辑标签modal
    edit(data) {
      this.modalType = 1;
      this.modalTitle = "编辑标签";
      this.treeValue = "";
      this.form = {
        tagName: "",
      };
      this.$refs.form.resetFields();
      this.modalVisible = true;
      this.form.tagTypeId = data.tagTypeId;
      this.treeValue = data.tagTypeName;
      this.form.id = data.id;
      this.form.tagName = data.tagName;
      this.form.sortNum = data.sortNum;
    },
    // 删除标签
    remove(v) {
      this.$Modal.confirm({
        tagName: "确认删除",
        content: "您确认要删除么?",
        loading: true,
        onOk: () => {
          // 删除
          deleteTagById(v.id).then((res) => {
            this.$Modal.remove();
            if (res.code === 200) {
              this.$Message.success("操作成功");
              this.getDataList();
            }
          });
        },
      });
    },
  },
  mounted() {
    this.init();
  },
};
</script>