Commit deabf2f5 by cwq0219

新增商品;表单

1 parent 80df3888
......@@ -46,7 +46,7 @@
</el-radio-group>
<el-date-picker v-else-if="item.type === 'datePicker'" v-model="formObj[item.name]" :type="item.dateType || 'daterange'" :clearable="item.isClear || false" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOption[item.pickerOptions]"></el-date-picker>
<!-- 图片上传 -->
<el-upload v-else-if="item.type === 'upload'" :auto-upload="false" action="#" list-type="picture-card" :limit="item.limitNum || 1" :fileList="formObj[item.name]" accept="image/jpeg,image/png,image/jpg" :on-change="(file, fileList) => handleChangeUpload(file, fileList, item)">
<!-- <el-upload v-else-if="item.type === 'upload'" :auto-upload="false" action="#" list-type="picture-card" :limit="item.limitNum || 1" :fileList="formObj[item.name]" accept="image/jpeg,image/png,image/jpg" :on-change="(file, fileList) => handleChangeUpload(file, fileList, item)">
<i slot="default" class="el-icon-plus"></i>
<div slot="file" slot-scope="{ file }">
<img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
......@@ -59,13 +59,45 @@
</span>
</span>
</div>
</el-upload>
</el-upload> -->
<template v-else-if="item.type === 'upload'">
<p class="photo-top-tips">{{ item.topTips }}</p>
<div v-if="Array.isArray(formObj[item.name]) ? (formObj[item.name].length < item.maxPhotoNum) : !formObj[item.name]" class="activity-img">
<div class="add">+</div>
<span class="number">{{ formObj[item.name].length }} / {{ item.maxPhotoNum }}</span>
<input type="file" style="opacity: 0;" :id="item.name + 'file'" ref="file" class="activity-img img-w-h" accept="image/png, image/jpeg, image/gif, image/jpg" @change="e => handleImgChange(e, item)">
</div>
<template>
<div v-if="Array.isArray(formObj[item.name]) ? formObj[item.name].length : formObj[item.name]">
<span v-if="Array.isArray(formObj[item.name])">
<span v-for="(subItem, subIndex) in formObj[item.name]" :key="subIndex" class="muti-imgs img-w-h">
<img class="img-w-h" :src="subItem.content" />
<span class="img-btns">
<span class="btn-item">
<i class="el-icon-delete" @click="handleImgDelete(item, subIndex)"></i>
<i class="el-icon-zoom-in" @click="handleImgLook(subItem.content)"></i>
</span>
</span>
</span>
</span>
<span v-else class="muti-imgs">
<img class="img-w-h" :src="formObj[item.name]" />
<span class="img-btns">
<span class="btn-item">
<i class="el-icon-delete" @click="handleImgDelete(item)"></i>
<i class="el-icon-zoom-in" @click="handleImgLook(formObj[item.name])"></i>
</span>
</span>
</span>
</div>
</template>
</template>
</el-form-item>
</template>
<slot name="footer"></slot>
</el-form>
<el-dialog :visible.sync="isImgVisible">
<img width="100%" :src="dialogImageUrl" alt="" />
<img class="dialog-img" width="100%" :src="dialogImageUrl" alt="" />
</el-dialog>
</div>
</template>
......@@ -133,37 +165,71 @@ export default {
item.keyFn()
}
},
// 图片上传
handleChangeUpload(file, fileList, targetItem) {
// 图片
handleImgChange(e, targetItem) {
var reader = new FileReader()
var file = e.srcElement.files[0]
const limitSize = targetItem.limitSize || 10
const isType = ['image/jpeg', 'image/png', 'image/jpg'].includes(file.raw.type)
const isLt10M = file.size / 1024 / 1024 < limitSize
const limitNum = targetItem.limitNum || 1
if (limitNum == this.formObj[targetItem.name].length) {
this.$message.error('只能上传' + limitNum + '张图片')
const isType = ['image/jpeg', 'image/png', 'image/jpg'].includes(file.type)
const isLt = file.size / 1024 / 1024 < limitSize
const maxPhotoNum = targetItem.maxPhotoNum || 1
if (maxPhotoNum == this.formObj[targetItem.name].length) {
this.$message.error('只能上传' + maxPhotoNum + '张图片')
return true
}
if (!isType) {
this.$message.error('上传图片不是jpg、jpeg或png的格式!')
this.formObj[targetItem.name] = this.formObj[targetItem.name].filter(item => item.uid != file.uid)
return true
}
if (!isLt10M) {
if (!isLt) {
this.$message.error('上传图片大小不能超过' + limitSize + 'MB!')
this.formObj[targetItem.name] = this.formObj[targetItem.name].filter(item => item.uid != file.uid)
return true
}
targetItem.handleUpload(file, fileList, targetItem)
reader.readAsDataURL(file)
reader.onload = e => {
targetItem.handleUpload(e, file, targetItem)
}
},
handleImgPreview(file) {
this.dialogImageUrl = file.url
this.isImgVisible = true
// 图片删除
handleImgDelete(targetItem, subIndex = -1) {
Array.isArray(this.formObj[targetItem.name]) ? this.formObj[targetItem.name].splice(subIndex, 1) : (this.formObj[targetItem.name] = '')
},
handleImgRemove(file, targetItem) {
this.formObj[targetItem.name] = this.formObj[targetItem.name].filter(item => item.uid != file.uid)
// 图片查看
handleImgLook(src) {
this.isImgVisible = true
this.dialogImageUrl = src
}
// 图片上传
// handleChangeUpload(file, fileList, targetItem) {
// const limitSize = targetItem.limitSize || 10
// const isType = ['image/jpeg', 'image/png', 'image/jpg'].includes(file.raw.type)
// const isLt10M = file.size / 1024 / 1024 < limitSize
// const limitNum = targetItem.limitNum || 1
// if (limitNum == this.formObj[targetItem.name].length) {
// this.$message.error('只能上传' + limitNum + '张图片')
// return true
// }
// if (!isType) {
// this.$message.error('上传图片不是jpg、jpeg或png的格式!')
// this.formObj[targetItem.name] = this.formObj[targetItem.name].filter(item => item.uid != file.uid)
// return true
// }
// if (!isLt10M) {
// this.$message.error('上传图片大小不能超过' + limitSize + 'MB!')
// this.formObj[targetItem.name] = this.formObj[targetItem.name].filter(item => item.uid != file.uid)
// return true
// }
// targetItem.handleUpload(file, fileList, targetItem)
// },
// handleImgPreview(file) {
// this.dialogImageUrl = file.url
// this.isImgVisible = true
// },
// handleImgRemove(file, targetItem) {
// this.formObj[targetItem.name] = this.formObj[targetItem.name].filter(item => item.uid != file.uid)
// }
}
}
</script>
......@@ -239,4 +305,85 @@ export default {
/* .glsx-combi-form .tips {
margin: 0;
} */
/* 图片上传 */
.glsx-combi-form .photo-top-tips {
/* height: 36px; */
margin: 0 0;
color: #999999;
}
.glsx-combi-form .img-w-h {
width: 88px;
height: 74px;
}
.glsx-combi-form .activity-img {
position: relative;
color: #999999;
border: 1px dashed #d9d9d9;
cursor: pointer;
}
.glsx-combi-form .activity-Input {
position: absolute;
top: 0;
left: 0;
}
.glsx-combi-form .muti-imgs {
display: inline-block;
position: relative;
}
.activity-img .add {
position: absolute;
top: 40%;
font-size: 40px;
left: 50%;
transform: translate3d(-50%, -50%, 0);
}
.activity-img .number {
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
}
.muti-imgs .img-btns {
display: none;
height: 100%;
position: absolute;
width: 88px;
height: 74px;
left: 0;
top: 0;
z-index: 2;
color: #fff;
background: rgba(0, 0, 0, 0.5);
}
.glsx-combi-form .el-icon-delete,
.glsx-combi-form .el-icon-zoom-in {
cursor: pointer;
}
.muti-imgs .img-btns .btn-item {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.muti-imgs .img-btns .btn-item {
display: flex;
width: 70%;
justify-content: space-around;
}
.muti-imgs:hover .img-btns {
display: block;
}
.glsx-combi-form .dialog-img {
width: 100%;
height: 100%;
}
/* 图片上传 */
</style>
......@@ -9,8 +9,8 @@
</div>
<div slot="proTable" class="select-pro">
<GLTable v-show="selectedProInfoList.length" ref="warehousListRef" :hasPage="hasPage" :searchForm="searchForm" :tableParams="tableParams" :tableData="selectedProInfoList">
<span slot="coverImgUrl" slot-scope="scope">
<img :src="scope.scope.goodsImage" />
<span slot="goodsImage" slot-scope="scope">
<img class="m-t-10" :src="scope.scope.goodsImage" />
</span>
<span slot="price">
<el-input placeholder="请输入" v-model="editForm.price"><template slot="append">元</template></el-input>
......@@ -67,7 +67,7 @@ export default {
editForm: {
name: '',
price: '',
coverImgUrl: []
coverImgUrl: ''
},
selectedProInfoList: [],
editRule: {
......@@ -83,22 +83,16 @@ export default {
label: '商品缩略图',
name: 'coverImgUrl',
type: 'upload',
limitSize: 1,
// limitSize: 1,
maxPhotoNum: 1,
tips: '建议尺寸:300像素 * 300像素,图片大小不得超过1M',
handleUpload: (file, fileList, targetItem) => {
// this.editForm[targetItem.name] = fileList
// this.editForm[targetItem.name].pop()
var reader = new FileReader()
var fileInfo = file.raw
reader.readAsDataURL(fileInfo)
reader.onload = e => {
const imgFile = e.target.result
const base64 = fileInfo.name.split('.')[1] + '@' + imgFile.split(',')[1]
uploadImg({ file: base64, fileType: 'image' }).then(res => {
this.editForm[targetItem.name] = [{ url: res, uid: file.uid }]
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
})
}
handleUpload: (e, file, targetItem) => {
const imgFile = e.target.result
const base64 = file.name.split('.')[1] + '@' + imgFile.split(',')[1]
uploadImg({ file: base64, fileType: 'image' }).then(res => {
this.editForm[targetItem.name] = res
this.$refs.editFormRef.$refs[this.editChildRef].validateField(targetItem.name)
})
}
},
{
......@@ -134,7 +128,7 @@ export default {
{
label: '商品图片',
prop: 'goodsImage',
addHtml: 'coverImgUrl'
addHtml: 'goodsImage'
},
{
label: '商品名称',
......@@ -175,9 +169,18 @@ export default {
getInfo() {
getGoodInfoApi({ id: this.routeInfo.id }).then(res => {
console.log(res)
this.editForm.id = res.id
this.editForm.name = res.name
this.editForm.price = res.price
this.editForm = res
this.editForm.price = res.price ? (res.price / 100).toFixed(2) : ''
if (res.goodsInfo) {
this.selectedProInfo = {
id: res.goodsInfo.goodsId,
goodsName: res.goodsInfo.name,
merchantId: res.goodsInfo.merchantId,
merchantName: res.goodsInfo.merchantName,
goodsImage: res.goodsInfo.selfGoodsImageUrl
}
this.selectedProInfoList = [this.selectedProInfo]
}
})
},
handleProDelete() {
......@@ -205,7 +208,6 @@ export default {
this.$refs.editFormRef.$refs[this.editChildRef].validate(valid => {
if (valid) {
var params = JSON.parse(JSON.stringify(this.editForm))
params.coverImgUrl = this.editForm.coverImgUrl[0].url
params.price = this.editForm.price * 100
params.shopMallGoodsInfo = {
goodsId: this.selectedProInfo.id,
......@@ -214,9 +216,7 @@ export default {
merchantName: this.selectedProInfo.merchantName,
selfGoodsImageUrl: this.selectedProInfo.goodsImage
}
console.log(params)
insertGoodApi(params).then(res => {
console.log(res)
this.$message({
message: res.code == '0' ? '操作成功' : '操作失败',
type: res.code == '0' ? 'success' : 'error'
......@@ -243,7 +243,7 @@ export default {
/* width: calc(98% - 140px); */
width: 98%;
}
.edit-pro img {
.edit-pro .m-t-10 {
margin-top: 10px;
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!