You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1068 lines
31 KiB

2 months ago
<style lang="less">
@import "@/styles/tree&table-common.less";
@import "./dictManage.less";
.btn{
width: 80px;
height: 30px;
text-align: center;
line-height: 30px;
background: #008ba0;
color:#fff;
border-right:1px solid #fff;
}
.content-left {
width: 80px;
background: #eee;
height: 475px;
overflow: scroll;
scrollbar-width: none;
}
.left-box {
width: 100%;
height: 50px;
font-size: 14px;
text-align: center;
line-height: 50px;
border-bottom: 1px solid #fff;
}
.left-box-hover {
width: 100%;
height: 50px;
font-size: 14px;
text-align: center;
line-height: 50px;
border-bottom: 1px solid #fff;
background-color: #fff;
}
.red {
border-right: 3px solid red;
}
.content-low{
height: 50px;
padding: 3px 5px;
border:1px solid #eee;
display: inline;
margin-right: 5px;
font-weight: bold;
}
.checked{
background: #60F3FF;
color: #fff !important;
}
2 months ago
</style>
<template>
<div class="search">
<Card>
<Row type="flex" justify="space-between">
<Col v-show="expand" span="5">
<Row class="operation">
<Button @click="handleAddDict" type="primary" icon="md-add">添加分类</Button>
<Dropdown @on-click="handleDropdown">
<Button>
更多操作
<Icon type="md-arrow-dropdown" />
</Button>
<DropdownMenu slot="list">
<DropdownItem name="editDict">编辑分类</DropdownItem>
<DropdownItem name="delDict">删除分类</DropdownItem>
<DropdownItem name="refreshDict">刷新</DropdownItem>
</DropdownMenu>
</Dropdown>
</Row>
<Alert show-icon>
当前选择
<span class="select-title">{{ editTitle }}</span>
<a class="select-clear" v-if="editTitle" @click="cancelEdit">取消选择</a>
</Alert>
<Input v-model="searchKey" suffix="ios-search" @on-change="search" placeholder="输入搜索分类" clearable />
<div style="position: relative">
<div class="tree-bar" :style="{ maxHeight: maxHeight }">
<Tree ref="tree" :data="treeData" @on-select-change="selectTree"></Tree>
</div>
<Spin size="large" fix v-if="treeLoading"></Spin>
</div>
</Col>
<div class="expand">
<Icon :type="expandIcon" size="16" class="icon" @click="changeExpand" />
</div>
<Col :span="span">
<Row v-show="openSearch" @keydown.enter.native="handleSearch">
<Form ref="searchForm" :model="searchForm" inline :label-width="70">
<FormItem label="数据名称" prop="title">
<Input type="text" v-model="searchForm.title" placeholder="请输入" clearable
style="width: 200px" />
</FormItem>
<FormItem label="状态" prop="status">
<Select v-model="searchForm.status" placeholder="请选择" clearable style="width: 200px">
<Option value="0">正常</Option>
<Option value="-1">禁用</Option>
</Select>
</FormItem>
<FormItem style="margin-left: -35px" class="br">
<Button @click="handleSearch" type="primary" icon="ios-search">搜索</Button>
<Button @click="handleReset">重置</Button>
</FormItem>
</Form>
</Row>
<Row align="middle" justify="space-between" class="operation">
<div>
<Button @click="add" type="primary" icon="md-add">新增商品</Button>
2 months ago
<Button @click="delAll" icon="md-trash">批量删除</Button>
</div>
<div class="icons">
<Tooltip content="刷新" placement="top" transfer>
<Icon type="md-refresh" size="18" class="item" @click="getDataList" />
</Tooltip>
<Tooltip :content="openSearch ? '关闭搜索' : '开启搜索'" placement="top" transfer>
<Icon type="ios-search" size="18" class="item tip" @click="openSearch = !openSearch" />
</Tooltip>
<Tooltip :content="openTip ? '关闭提示' : '开启提示'" placement="top" transfer>
<Icon type="md-bulb" size="18" class="item tip" @click="openTip = !openTip" />
</Tooltip>
<Tooltip content="表格密度" placement="top" transfer>
<Dropdown @on-click="changeTableSize" trigger="click">
<Icon type="md-list" size="18" class="item" />
<DropdownMenu slot="list">
<DropdownItem :selected="tableSize == 'default'" name="default">默认</DropdownItem>
<DropdownItem :selected="tableSize == 'large'" name="large">宽松</DropdownItem>
<DropdownItem :selected="tableSize == 'small'" name="small">紧密</DropdownItem>
</DropdownMenu>
</Dropdown>
</Tooltip>
<Tooltip content="导出数据" placement="top" transfer>
<Icon type="md-download" size="18" class="item" @click="exportData" />
</Tooltip>
</div>
</Row>
<Alert show-icon v-show="openTip">
已选择
<span class="select-count">{{ selectList.length }}</span>
<a class="select-clear" @click="clearSelectAll">清空</a>
</Alert>
<Table :loading="loading" border :columns="columns" :data="data" :size="tableSize" sortable="custom"
@on-sort-change="changeSort" @on-selection-change="showSelect" ref="table"></Table>
<Row type="flex" justify="end" class="page">
<Page :current="searchForm.pageNum" :total="total" :page-size="searchForm.pageSize"
2 months ago
@on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10, 20, 50]"
size="small" show-total show-elevator show-sizer></Page>
</Row>
</Col>
</Row>
</Card>
<addType ref="addTypePage" :dataLength="dataLength" v-model="showAddDict" @on-submit="getGoodsType" />
2 months ago
<editDictType ref="editTypePage" :data="dictForm" v-model="showEditDict" @on-submit="editDictSuccess" />
2 months ago
<Modal :title="modalTitle" v-model="modalVisible" :mask-closable="false" :width="screenWidth *0.9">
2 months ago
<Form ref="form" :model="form" :label-width="80" :rules="formValidate">
<Col span="6">
<FormItem label="商品图标" class="form-noheight">
<upload-pic-input v-model="addGoodsForm.productPicture"></upload-pic-input>
</FormItem>
</Col>
<Col span="6">
<FormItem label="名称" prop="title">
<Input v-model="addGoodsForm.productName" />
</FormItem>
</Col>
<Col span="6">
<FormItem label="店铺分类" class="form-noheight">
<Input v-model="editTitle" disabled />
</FormItem>
</Col>
<Col span="6">
<FormItem label="商品规格" class="form-noheight">
<div>
<div v-for="(item,index) in addGoodsForm.attributeListPrice" style="display: flex;margin-top:5px;">
<Input v-model="item.specName" v-if="item.specName != ''&& addGoodsForm.attributeListPrice.length != 1" style="padding-right: 10px;" disabled />
<Input v-model="item.specPrice" style="padding-right: 10px;" placeholder="商品价格" />
<Input v-model="item.specNum" style="padding-right: 10px;" placeholder="商品库存"/>
<button @click="deldantiaoguige(index)" v-if="addGoodsForm.attributeListPrice.length>1" style="width: 120px;height: 30px;line-height: 30px;color: red;border:none;background: #fff;">删除</button>
</div>
<div @click="checkSpec('guige')" style="margin-top:5px;width: 80px;height: 30px;text-align: center;line-height: 30px;background: #008ba0;color:#fff;">
选择规格
</div>
</div>
</FormItem>
</Col>
<Col span="6">
<FormItem label="拼团信息" class="form-noheight">
<div>
<div v-for="(item,index) in addGoodsForm.productGroupBuyPrices" style="display: flex;margin-top:5px;">
<Input v-model="item.groupCount" style="padding-right: 10px;" placeholder="成团人数" />
<Input v-model="item.groupPrice" style="padding-right: 10px;" placeholder="成团价格"/>
<button @click="delGroup(index)" v-if="addGoodsForm.productGroupBuyPrices.length>1" style="width: 120px;height: 30px;line-height: 30px;color: red;border:none;background: #fff;">删除</button>
</div>
<div @click="addGroup()" style="margin-top:5px;width: 80px;height: 30px;text-align: center;line-height: 30px;background: #008ba0;color:#fff;">
新增拼团
</div>
</div>
</FormItem>
</Col>
<Col span="6">
<FormItem label="餐盒费" class="form-noheight">
<Input v-model="addGoodsForm.lunchBox" />
</FormItem>
</Col>
<Col span="6">
<FormItem label="商品属性" class="form-noheight">
<div style="display: flex;flex-direction: column;">
<div v-for="(value,key) in Array.from(addGoodsForm.attributeList1)" style="display: flex;">
{{value[0]}}:
<div v-for="(item,index) in value[1].title">
{{item}}
</div>
</div>
<div @click="checkSpec('shuxing')" style="width: 80px;height: 30px;text-align: center;line-height: 30px;background: #008ba0;color:#fff;">
选择属性
</div>
</div>
</FormItem>
</Col>
<Col span="6">
<FormItem label="起售数量" class="form-noheight">
<Input v-model="addGoodsForm.startPayNum" type="number" placeholder="每笔订单起购数量" />
</FormItem>
</Col>
<Col span="8">
<FormItem label="可售时间" class="form-noheight">
<div>
<div style="line-height: 37px;">
<input type="radio" :checked="addGoodsForm.sellTime==0" name="sellTime" @click="checkSellTime('0')" />全时段售卖
<input type="radio" :checked="addGoodsForm.sellTime==1" name="sellTime" @click="checkSellTime('1')" />自定义时段
</div>
</div>
<div style="display: flex;" v-if="addGoodsForm.sellTime == 1">
<TimePicker format="HH:mm" v-model="addGoodsForm.sellBeginTime" @on-change="selectDateRange" placeholder="选择起始时间"/>
<div style="width: 10px;height: 10px;"></div>
<TimePicker format="HH:mm" v-model="addGoodsForm.sellEndTime" @on-change="selectDateRange" placeholder="选择结束时间"/>
</div>
</FormItem>
</Col>
<Col span="8">
<FormItem label="详细图文" class="form-noheight">
<div style="width:500px;height:400px;">
<editor v-model="addGoodsForm.productIntro" height="250"></editor>
</div>
</FormItem>
</Col>
2 months ago
</Form>
<div slot="footer">
<Button type="text" @click="modalVisible = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="handelSubmit">提交</Button>
</div>
</Modal>
<Modal :title="modalTitle" v-model="modalclass" :mask-closable="false" :width="700">
<div style="height:500px;">
<div class="content-left" style="float: left;">
<div class="left-box" v-for="(item,index) in categoryData" :key="index"
:class="item.parentId ? 'left-box-hover':''" @click="clickLeftBtn(index)">
<span style="width: 100%;height: 50px;line-height: 50px;display: inline-block;overflow: hidden;"
:class="item.parentId ? 'red' :''">{{item.title}}</span>
</div>
</div>
<div v-for="(item,index) in categorySonData" :key="index" @click="checkSpecValue(index)" class="content-low" :class="item.checked?'checked':''">
{{item.title}}
</div>
</div>
<div slot="footer">
<Button type="text" @click="modalclass = false">取消</Button>
<Button type="primary" :loading="submitLoading" @click="guigeSubmit">提交</Button>
</div>
</Modal>
2 months ago
</div>
</template>
<script>
import {
searchDict,
getAllDictDataList,
addDictData,
editDictData,
deleteData,
} from "@/api/index";
import {
goodsType,
deleteType,
categoryList,
categorySonList,
productSave,
getShareList,
productEdit
} from "@/api/app";
2 months ago
import addType from "./addType.vue";
import editDictType from "./editDictType.vue";
import uploadPicInput from "@/views/my-components/hiver/upload-pic-input";
import editor from "@/views/my-components/hiver/editor";
import dict from "@/views/my-components/hiver/dict";
2 months ago
export default {
name: "dic-manage",
components: {
addType,
editDictType,
uploadPicInput,
dict,
editor
2 months ago
},
data() {
return {
Visiable: false,
specValueArr:[],
attrValueArr:[],
modalclassType:'',
shopId: '',
2 months ago
tableSize: "default",
dataLength: 0,
showAddDict: false,
dictForm: {},
showEditDict: false,
openSearch: true,
categoryIndex: 0,
2 months ago
openTip: true,
treeLoading: false, // 树加载状态
maxHeight: "500px",
loading: false, // 表格加载状态
editTitle: "", // 编辑节点名称
searchKey: "", // 搜索树
expand: true,
span: 18,
expandIcon: "ios-arrow-back",
selectNode: {},
categoryData:[],
categorySonData:[],
2 months ago
treeData: [], // 树数据
selectList: [], // 多选数据
searchForm: {
// 搜索框对应data对象
categoryId: "",
shopId:'',
order: "",
pageNum: 1,
pageSize: "10",
searchStr: "",
sort: ""
// name: "",
// status: "",
// pageSize: 10, // 页面大小
// sort: "sort", // 默认排序字段
// order: "asc", // 默认排序方式
2 months ago
},
modalType: 0, // 添加或编辑标识
modalVisible: false, // 添加或编辑显示
modalclass:false,
2 months ago
modalTitle: "", // 添加或编辑标题
form: {
// 添加或编辑表单对象初始化数据
title: "",
value: "",
status: 0,
description: "",
sort: 0,
},
addGoodsForm:{
id:'',
shopId:'',
categoryId:'', //商品分类id
categoryName:'', //商品分类名称
productPicture:'', //商品图标
productName:'', //商品名称
lunchBox:0, //餐盒
startPayNum:'', //起售数量
attributeListPrice:[{ //商品规格
specPrice:"",
specNum:9999
}],
sellTime:0, //可售时间
sellBeginTime:'', //可售时段自定义---开始时间
sellEndTime:'', //可售时段自定义---结束时间
attributeList:'',
productGroupBuyPrices:[],
attributeList1:new Map(), //商品属性
productIntro:"" //详细图文
2 months ago
},
formValidate: {
// 表单验证规则
productName: [{
2 months ago
required: true,
message: "请输入",
trigger: "blur"
}]
2 months ago
},
columns: [
// 表头
{
type: "selection",
width: 60,
align: "center",
},
{
type: "index",
width: 60,
align: "center",
},
{
title: "图片",
key: "productPicture",
2 months ago
minWidth: 160,
render: (h, params) => {
return h("img", {
attrs: {
src: params.row.productPicture,
},
style: {
cursor: "zoom-in",
width: "80px",
height: "60px",
margin: "10px 0",
"object-fit": "contain",
},
on: {
click: () => {
this.showPic(params.row);
},
},
});
},
2 months ago
},
{
title: "名称",
key: "productName",
2 months ago
minWidth: 160,
},
{
title: "起售数量",
key: "startPayNum",
2 months ago
width: 150,
},
// {
// title: "状态",
// key: "status",
// align: "center",
// width: 120,
// render: (h, params) => {
// let re = "";
// if (params.row.status == 0) {
// return h("div", [
// h("Badge", {
// props: {
// status: "success",
// text: "启用",
// },
// }),
// ]);
// } else if (params.row.status == -1) {
// return h("div", [
// h("Badge", {
// props: {
// status: "error",
// text: "禁用",
// },
// }),
// ]);
// }
// },
// },
2 months ago
{
title: "操作",
key: "action",
width: 150,
align: "center",
fixed: "right",
render: (h, params) => {
return h("div", [
h(
"a", {
on: {
click: () => {
this.edit(params.row);
},
},
},
"编辑"
),
h("Divider", {
props: {
type: "vertical",
},
}),
h(
"a", {
on: {
click: () => {
this.remove(params.row);
},
},
},
"删除"
),
]);
},
},
],
submitLoading: false, // 添加或编辑提交状态
data: [], //表单数据
total: 0, // 表单数据总数
screenWidth: 0,
2 months ago
};
},
methods: {
init(v) {
this.shopId = v.id
this.searchForm.shopId = v.id
this.addGoodsForm.shopId = v.id
this.screenWidth = window.screen.width;
2 months ago
// 获取树数据
this.getGoodsType();
// 获取表单数据
// this.getDataList();
2 months ago
},
getGoodsType() {
this.treeLoading = true;
goodsType({
shopId: this.shopId
}).then((res) => {
2 months ago
this.treeLoading = false;
if (res.success) {
this.treeData = res.result;
for (let i = 0; i < this.treeData.length; i++) {
2 months ago
this.treeData[i].title = this.treeData[i].categoryName
}
}
});
},
search() {
// 搜索树
if (this.searchKey) {
this.treeLoading = true;
searchDict({
key: this.searchKey
}).then((res) => {
this.treeLoading = false;
if (res.success) {
this.treeData = res.result;
}
});
} else {
// 为空重新加载
this.getGoodsType();
}
},
checkSpec(type){
this.modalclass = true;
this.modalclassType = type
if(type == 'shuxing'){
this.modalTitle = "选择属性";
}else{
this.modalTitle = "选择规格";
}
getAllDictDataList({
name: "",
status: "",
pageNumber: 1,
pageSize: 100000,
sort: 'sortOrder',
order: 'asc',
dictId: '2026945661353725952'
}).then((res) => {
if(res.code == 200){
this.categoryData = res.result.content
for (var i = 0; i < this.categoryData.length; i++) {
if (i == this.categoryIndex) {
this.categoryData[i].parentId = true
} else {
this.categoryData[i].parentId = false
}
}
//如果是选择属性,需要拿一个分类名,保存成parent
this.typeToAttrName = res.result.content[this.categoryIndex].title
this.getCateGorySon(res.result.content[this.categoryIndex].id)
}
});
},
deldantiaoguige(index){
for (var m = 0; m < this.specValueArr.length; m++) {
if(this.specValueArr[m].title == this.addGoodsForm.attributeListPrice[index].specName){
this.specValueArr.splice(m,1)
this.addGoodsForm.attributeListPrice.splice(index,1)
if(this.addGoodsForm.attributeListPrice.length == 1){
this.addGoodsForm.attributeListPrice = {
specName:"",
specPrice:'',
specNum:9999
}
this.specValueArr = []
}
this.$forceUpdate()
return
}
}
},
delGroup(index){
this.addGoodsForm.productGroupBuyPrices.splice(index,1)
},
addGroup(){
let data = {
groupCount:'',
groupPrice:0
}
this.addGoodsForm.productGroupBuyPrices.push(data)
},
showPic(v) {
let image = new Image();
image.src = v.productPicture;
let viewer = new Viewer(image, {
hidden: function() {
viewer.destroy();
},
});
viewer.show();
},
getCateGorySon(id){
getAllDictDataList({
name: "",
status: "",
pageNumber: 1,
pageSize: 100000,
sort: 'sortOrder',
order: 'asc',
dictId: id
}).then((res) => {
if(res.code == 200){
this.categorySonData = res.result.content
if(this.modalclassType == 'shuxing'){
console.log('属性',this.attrValueArr)
if(this.attrValueArr == ""){
this.attrValueArr = this.addGoodsForm.attributeListPrice
}
for (var i = 0; i < this.categorySonData.length; i++) {
if(this.attrValueArr.length>0){
for (var m = 0; m < this.attrValueArr.length; m++) {
if(this.attrValueArr[m].id == this.categorySonData[i].id){
this.categorySonData[i].checked = true
}else{
this.categorySonData[i].checked = false
}
}
}else{
this.categorySonData[i].checked = false
}
}
}else{
//guige
for (var i = 0; i < this.categorySonData.length; i++) {
if(this.specValueArr.length>0){
for (var m = 0; m < this.specValueArr.length; m++) {
if(this.specValueArr[m].id == this.categorySonData[i].id){
this.categorySonData[i].checked = true
}
}
}else{
this.categorySonData[i].checked = false
}
}
}
}
});
},
//点击左侧菜单切换
clickLeftBtn(index) {
for (var i = 0; i < this.categoryData.length; i++) {
if (i == index) {
this.categoryData[i].parentId = true
} else {
this.categoryData[i].parentId = false
}
}
this.categoryIndex = index
this.typeToAttrName = this.categoryData[this.categoryIndex].title
this.getCateGorySon(this.categoryData[this.categoryIndex].id)
},
checkSellTime(type){
this.addGoodsForm.sellTime = type;
},
checkSpecValue(index){
//this.typeToAttrName = res.result.content[this.categoryIndex].title
this.categorySonData[index].checked = !this.categorySonData[index].checked
if(this.modalclassType == 'shuxing'){
if(this.categorySonData[index].checked == true){
this.categorySonData[index].parentName = this.typeToAttrName
this.attrValueArr.push(this.categorySonData[index])
}else{
for(let i=0;i<this.attrValueArr.length;i++){
if(this.categorySonData[index].id == this.attrValueArr[i].id){
this.attrValueArr.splice(i,1)
}
}
}
}else{
//guige
if(this.categorySonData[index].checked == true){
this.specValueArr.push(this.categorySonData[index])
}else{
for(let i=0;i<this.specValueArr.length;i++){
if(this.categorySonData[index].id == this.specValueArr[i].id){
this.specValueArr.splice(i,1)
}
}
}
2 months ago
}
this.$forceUpdate()
},
guigeSubmit(){
if(this.modalclassType == 'shuxing'){
for(let i=0;i<this.attrValueArr.length;i++){
if(this.addGoodsForm.attributeList1.size == 0){
//set has get
let data = {
title:[]
}
data.title.push(this.attrValueArr[i].title)
this.addGoodsForm.attributeList1.set(this.attrValueArr[i].parentName,data)
}else{
if(this.addGoodsForm.attributeList1.has(this.attrValueArr[i].parentName)){
this.addGoodsForm.attributeList1.get(this.attrValueArr[i].parentName).title.push(this.attrValueArr[i].title)
}else{
let data = {
title:[]
}
data.title.push(this.attrValueArr[i].title)
this.addGoodsForm.attributeList1.set(this.attrValueArr[i].parentName,data)
}
}
}
}else{
//guige
this.addGoodsForm.attributeListPrice = []
for(let i=0;i<this.specValueArr.length;i++){
this.addGoodsForm.attributeListPrice.push({
specName:this.specValueArr[i].title,
specPrice:'',
specNum:9999
})
}
}
this.modalclass = false;
2 months ago
},
selectTree(v) {
if (v.length > 0) {
// 转换null为""
for (let attr in v[0]) {
if (v[0][attr] == null) {
v[0][attr] = "";
}
}
let str = JSON.stringify(v[0]);
let data = JSON.parse(str);
this.selectNode = data;
this.dictForm = data;
this.editTitle = data.title;
2 months ago
// 重新加载表
this.searchForm.pageNum = 1;
2 months ago
this.searchForm.pageSize = 10;
this.getDataList();
} else {
this.cancelEdit();
}
},
cancelEdit() {
let data = this.$refs.tree.getSelectedNodes()[0];
if (data) {
data.selected = false;
}
// 取消选择后获取全部数据
this.selectNode = {};
this.editTitle = "";
// this.getDataList();
2 months ago
},
changeTableSize(v) {
this.tableSize = v;
},
exportData() {
this.$refs.table.exportCsv({
filename: "数据",
});
},
changeSelect(v) {
this.selectList = v;
},
changeExpand() {
this.expand = !this.expand;
if (this.expand) {
this.expandIcon = "ios-arrow-back";
this.span = 18;
} else {
this.expandIcon = "ios-arrow-forward";
this.span = 23;
}
},
changePage(v) {
this.searchForm.pageNum = v;
// this.getDataList();
2 months ago
this.clearSelectAll();
},
changePageSize(v) {
this.searchForm.pageSize = v;
// this.getDataList();
2 months ago
},
getDataList() {
this.loading = true;
// if (this.selectNode.id) {
this.searchForm.categoryId = this.selectNode.id;
// } else {
// delete this.searchForm.dictId;
// }
2 months ago
if (!this.searchForm.status) {
this.searchForm.status = "";
}
getShareList(this.searchForm).then((res) => {
2 months ago
this.loading = false;
if (res.success) {
this.data = res.result.records;
this.total = res.result.total;
if (this.data.length == 0 && this.searchForm.pageNum > 1) {
this.searchForm.pageNum -= 1;
2 months ago
this.getDataList();
}
}
});
},
handleSearch() {
this.searchForm.pageNum = 1;
2 months ago
this.searchForm.pageSize = 10;
// this.getDataList();
2 months ago
},
handleReset() {
this.$refs.searchForm.resetFields();
this.searchForm.pageNum = 1;
2 months ago
this.searchForm.pageSize = 10;
// 重新加载数据
// this.getDataList();
2 months ago
},
changeSort(e) {
this.searchForm.sort = e.key;
this.searchForm.order = e.order;
if (e.order == "normal") {
this.searchForm.order = "";
}
// this.getDataList();
2 months ago
},
showSelect(e) {
this.selectList = e;
},
clearSelectAll() {
this.$refs.table.selectAll(false);
},
refreshDict() {
this.getGoodsType();
2 months ago
this.selectNode = {};
this.editTitle = "";
// this.getDataList();
2 months ago
},
handleDropdown(name) {
if (name == "editDict") {
if (!this.selectNode.id) {
this.$Message.warning("您还未选择要编辑的分类");
2 months ago
return;
}
this.handleEditDict();
} else if (name == "delDict") {
this.delDict();
} else if (name == "refreshDict") {
this.refreshDict();
}
},
handleAddDict() {
this.dataLength = this.treeData.length + 1;
this.showAddDict = true;
this.$refs.addTypePage.init(this.shopId)
2 months ago
},
handleEditDict() {
this.showEditDict = true;
this.$refs.editTypePage.init(this.shopId)
2 months ago
},
editDictSuccess(v) {
for (let attr in v) {
if (v[attr] == null) {
v[attr] = "";
}
}
let str = JSON.stringify(v);
let data = JSON.parse(str);
this.dictForm = data;
this.editTitle = v.title + "(" + v.type + ")";
this.getGoodsType();
2 months ago
},
delDict() {
if (!this.selectNode.id) {
this.$Message.warning("您还未选择要删除的分类");
2 months ago
return;
}
this.$Modal.confirm({
title: "确认删除",
loading: true,
content: "您确认要删除分类 " + this.selectNode.title + " 及其所有数据?",
2 months ago
onOk: () => {
// 删除
deleteType({
id: this.selectNode.id,
shopId: this.shopId
2 months ago
}).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("操作成功");
this.refreshDict();
}
});
},
});
},
getChildren(v) {
2 months ago
this.Visiable = true;
this.$nextTick(() => {
this.$refs.dialog.initRecharge(v);
});
},
add() {
if (!this.selectNode.id) {
this.$Message.warning("请先选择一个分类");
2 months ago
return;
}
this.modalType = 0;
this.modalTitle = "添加分类 " + this.editTitle + " 的数据";
2 months ago
this.$refs.form.resetFields();
this.form.sort = this.data.length + 1;
this.addGoodsForm.categoryId = this.selectNode.id
this.addGoodsForm.categoryName = this.selectNode.categoryName
2 months ago
this.modalVisible = true;
},
edit(v) {
this.modalType = 1;
if (this.editTitle) {
this.modalTitle = "编辑分类 " + this.editTitle + " 的数据";
2 months ago
} else {
this.modalTitle = "编辑分类数据";
2 months ago
}
// 转换null为""
for (let attr in v) {
if (v[attr] == null) {
v[attr] = "";
}
}
let str = JSON.stringify(v);
let data = JSON.parse(str);
console.log('111111',data)
this.addGoodsForm = data;
this.addGoodsForm.attributeList1 = JSON.parse(this.addGoodsForm.attributeList)
this.addGoodsForm.attributeList1 = new Map(Object.entries(this.addGoodsForm.attributeList1));
this.addGoodsForm.attributeListPrice = JSON.parse(this.addGoodsForm.attributeListPrice)
this.addGoodsForm.sellTime = this.addGoodsForm.sellBeginTime != '' ? 1 : 0
2 months ago
this.modalVisible = true;
},
handelSubmit() {
this.$refs.form.validate((valid) => {
if (valid) {
2 months ago
this.submitLoading = true;
if (this.modalType == 0) {
// 添加 避免编辑后传入id等数据 记得删除
delete this.addGoodsForm.id;
this.addGoodsForm.attributeListPrice = JSON.stringify(this.addGoodsForm.attributeListPrice)
this.addGoodsForm.attributeList = Object.fromEntries(this.addGoodsForm.attributeList1)
this.addGoodsForm.attributeList = JSON.stringify(this.addGoodsForm.attributeList)
productSave(this.addGoodsForm).then((res) => {
2 months ago
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
this.modalVisible = false;
}
});
} else if (this.modalType == 1) {
// 编辑
this.addGoodsForm.attributeListPrice = JSON.stringify(this.addGoodsForm.attributeListPrice)
this.addGoodsForm.attributeList = Object.fromEntries(this.addGoodsForm.attributeList1)
this.addGoodsForm.attributeList = JSON.stringify(this.addGoodsForm.attributeList)
this.addGoodsForm.productPictures = []
productEdit(this.addGoodsForm).then((res) => {
2 months ago
this.submitLoading = false;
if (res.success) {
this.$Message.success("操作成功");
// this.getDataList();
2 months ago
this.modalVisible = false;
}
});
}
}
});
},
remove(v) {
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除 " + v.title + " ?",
loading: true,
onOk: () => {
// 删除
deleteData({
ids: v.id
}).then((res) => {
this.$Modal.remove();
if (res.success) {
this.clearSelectAll();
this.$Message.success("操作成功");
// this.getDataList();
2 months ago
}
});
},
});
},
delAll() {
if (this.selectList.length <= 0) {
this.$Message.warning("您还未选择要删除的数据");
return;
}
this.$Modal.confirm({
title: "确认删除",
content: "您确认要删除所选的 " + this.selectList.length + " 条数据?",
loading: true,
onOk: () => {
let ids = "";
this.selectList.forEach(function(e) {
ids += e.id + ",";
});
ids = ids.substring(0, ids.length - 1);
// 批量删除
deleteData({
ids: ids
}).then((res) => {
this.$Modal.remove();
if (res.success) {
this.$Message.success("操作成功");
this.clearSelectAll();
// this.getDataList();
2 months ago
}
});
},
});
},
},
mounted() {
// 计算高度
let height = document.documentElement.clientHeight;
this.maxHeight = Number(height - 287) + "px";
this.init();
},
};
</script>