更改图库功能

This commit is contained in:
duan 2024-08-07 15:51:33 +08:00
parent 7f54c59092
commit 3b12a2ba06
3 changed files with 212 additions and 59 deletions

View File

@ -45,9 +45,19 @@
<addClassify ref="addClassifyRef" @success="tbShopCategoryGet" /> <addClassify ref="addClassifyRef" @success="tbShopCategoryGet" />
</el-form-item> </el-form-item>
<el-form-item label="商品图片"> <el-form-item label="商品图片">
<uploadImg ref="uploadImg" :limit="9" @success="uploadSuccess" @remove="uploadRemove" /> <div style="display: flex;flex-wrap: wrap; ">
<div v-for="item in imgList" style="position: relative;" class="showStyle">
<i class="el-icon-error buttonstyle" @click="deleteEvent(item)"></i>
<img style="width: 148px;height: 148px;margin-right: 6px;" class="imgStyle" :key="item.id" :src="item.url"
alt="">
</div>
<div class="upImgStyle" @click="$refs.addImg.show()">
+
</div>
</div>
<!-- <uploadImg ref="uploadImg" :limit="9" @success="uploadSuccess" @remove="uploadRemove" /> -->
<div class="tips">第一张图为商品封面图图片尺寸为750×750</div> <div class="tips">第一张图为商品封面图图片尺寸为750×750</div>
<el-button type="primary" plain icon="el-icon-plus" @click="$refs.addImg.show()">选择图片</el-button> <!-- <el-button type="primary" plain icon="el-icon-plus" @click="$refs.addImg.show()">选择图片</el-button> -->
</el-form-item> </el-form-item>
<el-form-item label="套餐商品" v-if="shopTypes[shopTypesActive].typeEnum == 'group'"> <el-form-item label="套餐商品" v-if="shopTypes[shopTypesActive].typeEnum == 'group'">
<el-table :data="form.groupSnap" border v-if="form.groupSnap.length"> <el-table :data="form.groupSnap" border v-if="form.groupSnap.length">
@ -470,6 +480,7 @@ export default {
usageRules: "" usageRules: ""
} }
}, },
imgList: [],
rules: { rules: {
typeEnum: [ typeEnum: [
{ {
@ -552,20 +563,22 @@ export default {
}, },
methods: { methods: {
successEvent(d) { successEvent(d) {
if (this.$refs.uploadImg.fileList.length < 9) { this.form.images.push(d[0].url);
d.forEach(item => { this.imgList.push(d[0])
item.uid = item.id // if (this.$refs.uploadImg.fileList.length < 9) {
item.url = item.url // d.forEach(item => {
this.form.images.push(item.url); // item.uid = item.id
}) // item.url = item.url
this.$refs.uploadImg.fileList.push(...d) // this.form.images.push(item.url);
console.log(this.$refs.uploadImg.fileList, '调试1') // })
} else { // this.$refs.uploadImg.fileList.push(...d)
this.$notify.error({ // console.log(this.$refs.uploadImg.fileList, '1')
title: '错误', // } else {
message: '最多选择9张图片' // this.$notify.error({
}); // title: '',
} // message: '9'
// });
// }
}, },
priceFormat(item, key) { priceFormat(item, key) {
const messageheight = 48; const messageheight = 48;
@ -587,6 +600,10 @@ export default {
} }
}) })
}, },
deleteEvent(d) {
let index = this.imgList.findIndex(ele => ele.url == d.url)
this.imgList.splice(index, 1);
},
// //
delGoods(goods, index, $index) { delGoods(goods, index, $index) {
goods.splice(index, 1); goods.splice(index, 1);
@ -635,14 +652,18 @@ export default {
); );
this.specTableHeaders = JSON.parse(res.specTableHeaders); this.specTableHeaders = JSON.parse(res.specTableHeaders);
this.selectSpec = JSON.parse(res.selectSpec); this.selectSpec = JSON.parse(res.selectSpec);
console.log(res, '调试11111')
// //
this.$refs.uploadImg.fileList = res.images.map(item => { // this.$refs.uploadImg.fileList = res.images.map(item => {
// return {
// url: item
// };
// });
this.imgList = res.images.map(item => {
return { return {
url: item url: item
}; };
}); });
this.form = res; this.form = res;
if (res.typeEnum == "sku") { if (res.typeEnum == "sku") {
let skuList = [...res.skuList]; let skuList = [...res.skuList];
@ -939,6 +960,18 @@ export default {
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.upImgStyle {
cursor: pointer;
width: 148px;
height: 148px;
line-height: 148px;
text-align: center;
border: 1px dashed #ccc;
border-radius: 1%;
font-size: 30px;
color: #ccc;
}
.shop_list { .shop_list {
.item { .item {
display: flex; display: flex;
@ -994,4 +1027,20 @@ export default {
cursor: pointer; cursor: pointer;
} }
} }
.buttonstyle {
border-radius: 50%;
color: #db1616;
background-color: #fff;
font-size: 20px;
display: none;
position: absolute;
right: -10px;
top: -10px;
z-index: 10;
}
.showStyle:hover>.buttonstyle {
display: block;
}
</style> </style>

View File

@ -1,7 +1,32 @@
<template> <template>
<div v-if="dialogVisible"> <div v-if="dialogVisible">
<el-dialog title="请选择" :visible.sync="dialogVisible" width=""> <el-dialog title="请选择" :visible.sync="dialogVisible" width="1000px">
<el-select v-model="value" placeholder="请选择" @change="changeEvent"> <el-container>
<el-aside style="background-color: #fff;" width="150px">
<ul style="padding-left: 0;">
<li style="cursor: pointer;" v-for="item in options" :key="item.id"
:class="[activedata == item.id ? 'activedata' : '']" @click="changeEvent(item.id)">{{
item.name }}</li>
</ul>
<div class="uplocation" :class="[activedata == -1 ? 'activedata' : '']" @click="uplocation">本地上传
</div>
</el-aside>
<el-main>
<imageComponent @onSelectImage="onSelectImage" @getList="getList" :activedata="activedata"
:list='dataImages'>
</imageComponent>
<el-pagination layout="prev, pager, next" :total="total" :page-size="20"
@current-change="handleCurrentChange">
</el-pagination>
</el-main>
</el-container>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="sumbit"> </el-button>
</span>
</el-dialog>
<!-- <el-select v-model="value" placeholder="请选择" @change="changeEvent">
<el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id"> <el-option v-for="item in options" :key="item.id" :label="item.name" :value="item.id">
<span style="float: left">{{ item.name }}</span> <span style="float: left">{{ item.name }}</span>
<template v-if="item.id != '681'"> <template v-if="item.id != '681'">
@ -10,32 +35,23 @@
<span style="float: right; color: #8492a6; font-size: 13px"><i class="el-icon-error " <span style="float: right; color: #8492a6; font-size: 13px"><i class="el-icon-error "
@click="deleteType(item.id)"></i></span> @click="deleteType(item.id)"></i></span>
</template> </template>
</template> </template>
</template> </template>
</el-option> </el-option>
</el-select> </el-select> -->
<el-button type="primary" @click="dialogTableVisibles = true">新增类型</el-button> <!-- <el-button type="primary" @click="dialogTableVisibles = true">新增类型</el-button> -->
<el-button type="primary" @click="showUpload = true">新增图片</el-button> <!-- <el-button type="primary" @click="showUpload = true">新增图片</el-button> -->
<imageComponent @onSelectImage="onSelectImage" @getList="getList" :list='dataImages'>
</imageComponent>
<el-pagination layout="prev, pager, next" :total="total" :page-size="20"
@current-change="handleCurrentChange">
</el-pagination>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false"> </el-button>
<el-button type="primary" @click="sumbit"> </el-button>
</span>
</el-dialog>
<!-- 新增类型 --> <!-- 新增类型 -->
<el-dialog title="新增类型" :visible.sync="dialogTableVisibles"> <!-- <el-dialog title="新增类型" :visible.sync="dialogTableVisibles">
<el-input v-model="typedata" placeholder="请输入类型" autocomplete="off"></el-input> <el-input v-model="typedata" placeholder="请输入类型" autocomplete="off"></el-input>
<span slot="footer" class="dialog-footer"> <span slot="footer" class="dialog-footer">
<el-button @click="dialogTableVisibles = false"> </el-button> <el-button @click="dialogTableVisibles = false"> </el-button>
<el-button type="primary" @click="addtype"> </el-button> <el-button type="primary" @click="addtype"> </el-button>
</span> </span>
</el-dialog> </el-dialog> -->
<!-- 新增图片 --> <!-- 新增图片 -->
<template v-if="showUpload"> <!-- <template v-if="showUpload">
<el-dialog :visible.sync="showUpload" :close-on-click-modal="false" append-to-body width="1000px" <el-dialog :visible.sync="showUpload" :close-on-click-modal="false" append-to-body width="1000px"
@close="showUpload = false"> @close="showUpload = false">
<el-upload :before-remove="handleBeforeRemove" list-type="picture-card" :on-success="handleSuccess" <el-upload :before-remove="handleBeforeRemove" list-type="picture-card" :on-success="handleSuccess"
@ -46,7 +62,7 @@
<el-button type="primary" @click="doSubmit">确认</el-button> <el-button type="primary" @click="doSubmit">确认</el-button>
</div> </div>
</el-dialog> </el-dialog>
</template> </template> -->
</div> </div>
</template> </template>
@ -78,15 +94,24 @@ export default {
typedata: '', typedata: '',
showUpload: false, showUpload: false,
page: 1, page: 1,
total: 0 total: 0,
activedata: '681'
} }
}, },
mounted() { mounted() {
this.getType() this.getType()
}, },
methods: { methods: {
changeEvent() { uplocation() {
this.activedata = -1
this.page = 1 this.page = 1
this.dataImages = []
this.total = 0
this.getList()
},
changeEvent(id) {
this.page = 1
this.activedata = id
this.getList() this.getList()
}, },
handleCurrentChange(i) { handleCurrentChange(i) {
@ -167,11 +192,10 @@ export default {
}, },
async getList() { async getList() {
let obj = { let obj = {
category: this.value, category: this.activedata == -1 ? '' : this.activedata,
page: this.page, page: this.page,
size: 20, size: this.activedata == -1 ? 17:18,
store_id: localStorage.getItem("shopId"), store_id: localStorage.getItem("shopId"),
} }
const res = await getcommonpicture(obj); const res = await getcommonpicture(obj);
this.dataImages = res.data this.dataImages = res.data
@ -191,3 +215,14 @@ export default {
} }
} }
</script> </script>
<style scoped>
.activedata {
color: #1890ff;
}
.uplocation {
cursor: pointer;
position: absolute;
bottom: 20px;
}
</style>

View File

@ -1,37 +1,96 @@
<template> <template>
<div> <div>
<ul class="ulStyle" > <ul class="ulStyle">
<li class="upImgStyles" @click="showUpload = true" v-if="activedata == -1">
+
</li>
<li v-for="item in list" :key="item.id" class="listyle" :class="[selectList.id == item.id ? 'actives' : '']" <li v-for="item in list" :key="item.id" class="listyle" :class="[selectList.id == item.id ? 'actives' : '']"
@click="clickEvent(item)"> @click="clickEvent(item)">
<img :src="item.url" style="width: 100px;height: 100px;" alt=""> <img :src="item.url" style="width: 100px;height: 100px;" alt="">
<el-popconfirm title="确定删除吗?" class="show" @confirm="deleteEvent(item.id)"> <!-- <el-popconfirm title="确定删除吗?" class="show" @confirm="deleteEvent(item.id)">
<template v-if="item.pid != '681'"> <template v-if="item.pid != '681'">
<template v-if="item.pid != '682'"> <template v-if="item.pid != '682'">
<template v-if="item.pid != '699'"> <template v-if="item.pid != '699'">
<i class="el-icon-error buttonstyle" slot="reference"></i> <i class="el-icon-error buttonstyle" slot="reference"></i>
</template> </template>
</template> </template>
</template> </template>
</el-popconfirm> </el-popconfirm> -->
</li> </li>
</ul> </ul>
<template v-if="showUpload">
<el-dialog :visible.sync="showUpload" :close-on-click-modal="false" append-to-body width="1000px"
@close="showUpload = false">
<el-upload :before-remove="handleBeforeRemove" list-type="picture-card" :on-success="handleSuccess"
:file-list="fileList" :headers="headers" :action="qiNiuUploadApi" class="upload-demo" multiple>
<i class="el-icon-plus"></i>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="doSubmit">确认</el-button>
</div>
</el-dialog>
</template>
</div> </div>
</template> </template>
<script> <script>
import { delimg } from "@/api/imagesPhp"; import { delimg } from "@/api/imagesPhp";
import { getToken } from "@/utils/auth";
import { mapGetters } from "vuex";
import { getcommonCategor, getcommonpicture, storeAddcategory, addImg, delcate } from "@/api/imagesPhp";
export default { export default {
props: ['list'], computed: {
...mapGetters(["qiNiuUploadApi"])
},
props: ['list', 'activedata'],
data() { data() {
return { return {
showUpload: false,
selectList: [], selectList: [],
files: [],
fileList: [],
headers: {
Authorization: getToken()
},
} }
}, },
mounted() { mounted() {
}, },
methods: { methods: {
async doSubmit() {
this.showUpload = false;
let arr = []
if (this.files.length) {
this.files.forEach(ele => {
arr.push({
url: ele.response.data[0],
name: ele.name
})
})
const res = await addImg({
category: '',
store_id: localStorage.getItem("shopId"),
url: arr
})
if (res.code == 1) {
// this.getType(this.value)
this.$emit('getList')
this.$message.success(res.msg);
} else {
this.$message.error(res.msg);
}
this.files = [];
}
},
handleSuccess(response, file, fileList) {
this.files.push(file)
},
handleBeforeRemove(file, fileList) {
let index = this.files.findIndex(ele => ele.name == file.name)
this.files.splice(index, 1);
},
clickEvent(d) { clickEvent(d) {
this.selectList = d this.selectList = d
this.$emit('onSelectImage', d) this.$emit('onSelectImage', d)
@ -90,9 +149,19 @@ li {
position: relative; position: relative;
} }
.upImgStyles {
cursor: pointer;
width: 110px;
height: 110px;
line-height: 110px;
text-align: center;
border: 1px dashed #ccc;
border-radius: 1%;
font-size: 30px;
color: #ccc;
margin-right: 10px;
margin-top: 10px;
}
.actives { .actives {