Commit b7b4c95c by cwq0219

接口联调

1 parent 9e023b16
......@@ -6,3 +6,15 @@ export function getList(data) {
data.method = `${path}goodsinfo.page`
return request(data)
}
// 添加产品
export function addGoods(data) {
data.method = `${path}goodsinfo.add`
return request(data, 'post')
}
// 编辑产品
export function editGoods(data) {
data.method = `${path}goodsinfo.update`
return request(data, 'post')
}
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-08-26 18:02:55
* @Last Modified by: chenwq
* @Last Modified time: 2020-11-05 17:39:39
* @Last Modified time: 2020-11-12 19:02:01
*/
import request from './request'
......@@ -32,8 +32,8 @@ export function AccountLogin(data) {
// loginName: 'foutouren',
// authes: []
// // authes: [{
// // authId: '101',
// // parentId: '0'
// // authId: '10101',
// // parentId: '101'
// // }, {
// // authId: '102',
// // parentId: '0'
......
......@@ -2,11 +2,11 @@
* @Author: limin
* @Date: 2019-08-26 18:02:55
* @Last Modified by: chenwq
* @Last Modified time: 2020-11-11 17:42:10
* @Last Modified time: 2020-11-12 14:56:05
*/
import request from './request'
// import RequestMethods from './request.methods'
import RequestMethods from './request.methods'
export const BASE_DATA_URL = 'fims.configuration.from.conftype'
......@@ -23,3 +23,9 @@ export function getChannelType(data) {
data.method = `${path}channel.type.list`
return request(data)
}
// 图片上传
export function uploadImg(data) {
data.method = `${path}common.uploadImg`
return request(data, RequestMethods.POST, ['file'])
}
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-09-01 19:06:01
* @Last Modified by: chenwq
* @Last Modified time: 2020-11-11 17:38:18
* @Last Modified time: 2020-11-12 19:10:13
*/
// import { LOGIN_URL, REG_URL, ROLE_LIST_URL } from '@/api/sys.account'
......@@ -73,3 +73,36 @@ export const ghUserType = {
5: '总部',
6: '供应商'
}
// 品牌商
export const brandMerchantList = [{
confId: 1,
confValue: '3M/福膜'
}, {
confId: 2,
confValue: '强生/福膜'
}, {
confId: 3,
confValue: '强生/斯帝飞'
}, {
confId: 4,
confValue: '3M/斯帝飞'
}, {
confId: 5,
confValue: '3M/今蓝'
}, {
confId: 6,
confValue: '量子/今蓝'
}, {
confId: 7,
confValue: '强生'
}, {
confId: 8,
confValue: '今蓝'
}, {
confId: 9,
confValue: '琥珀'
}, {
confId: 10,
confValue: '嘀嘀虎'
}]
......@@ -153,6 +153,93 @@
</div>
<el-button @click="handleAddPro">新增关联商品</el-button>
</template>
<template v-else-if="item.type === 'photo'">
<p class="photo-top-tips">{{item.topTips}}</p>
<div
class="activity-img"
:class="[disabled ? 'input-bg':'']"
>
<div
class="add"
v-show="!formData[item.name] || (item.maxPhotoNum > 1 && (formData[item.name].length < item.maxPhotoNum))"
>+</div>
<span
class="number"
v-if="!formData[item.name] && item.maxPhotoNum === 1"
>0/{{item.maxPhotoNum}}</span>
<span
class="number"
v-else-if="item.maxPhotoNum > 1 && (formData[item.name].length < item.maxPhotoNum)"
>{{formData[item.name].length}}/{{item.maxPhotoNum}}</span>
<template>
<img
v-if="formData[item.name] && item.maxPhotoNum === 1"
:src="formData[item.name]"
alt=""
>
</template>
<input
type="file"
name='thumbUrl'
:id="item.name + 'file'"
ref="file"
class="activity-img"
accept="image/png, image/jpeg, image/gif, image/jpg"
@click="handleAddClick(item)"
@change="e => handleImgChange(e, item)"
style="opacity: 0;"
>
</div>
<template>
<div v-if="item.maxPhotoNum > 1 && formData[item.name].length">
<img
class="muti-imgs"
v-for="(subItem, subIndex) in formData[item.name]"
:key="subIndex"
:src="subItem.content"
/>
<div
class="close"
@click='delBgimg($index)'
>
<i class="el-icon-delete"></i>
</div>
</div>
</template>
</template>
<template v-else-if="item.type === 'descList'">
<el-row>
<el-button @click="handleAddDesc(2, item)">添加文字</el-button>
<el-button @click="handleAddDesc(1, item)">添加图片</el-button>
</el-row>
<el-row
v-for="(subItem, subIndex) in formData[item.name]"
:key="subIndex"
>
<el-input
v-if="subItem.resType === 2"
type="textarea"
v-model="subItem.content"
:rows="4"
placeholder="请输入详情内容"
></el-input>
<div
class="descList-img"
v-else-if="subItem.resType === 1"
>
<img :src="subItem.content" />
<input
type="file"
class="activity-img"
accept="image/png, image/jpeg, image/gif, image/jpg"
@click="handleAddClick(item)"
@change="e => handleImgChange(e, item, subIndex)"
style="opacity: 0;"
>
</div>
<i class="el-icon-delete"></i>
</el-row>
</template>
<span v-else>{{item.name ? formData[item.name] : item.value}}</span>
</el-form-item>
<span
......@@ -196,6 +283,7 @@ import _ from 'lodash'
import relateProDialog from './relateProDialog'
import relateStoreDialog from './relateStoreDialog'
import { getGoodsList } from '@/api/commodity'
import { uploadImg } from '@/api/sys.base'
export default {
name: 'd2-form',
data() {
......@@ -319,19 +407,62 @@ export default {
var filterArr = this.formData[formDataName].filter(i => i[formItem.optionValue] !== item[formItem.optionValue])
this.formData[formDataName] = filterArr
},
// 图片
handleAddClick(targetItem) {
// console.log(this.$refs.file)
// this.$refs.file.value = null
// document.getElementsByClassName(targetItem.name + 'file')[0].value = null
},
handleImgChange(e, targetItem, subIndex = 0) {
var reader = new FileReader()
var fileInfo = e.srcElement.files[0]
reader.readAsDataURL(fileInfo)
reader.onload = e => {
const imgFile = e.target.result
const base64 = fileInfo.name.split('.')[1] + '@' + imgFile.split(',')[1]
// console.log(base64)
uploadImg({ file: base64 }).then(res => {
console.log(res)
// this.formData[targetItem.name].push()
if (!Array.isArray(this.formData[targetItem.name])) {
console.log(targetItem)
this.formData[targetItem.name] = res
} else {
if (targetItem.name === 'goodsImgList') {
this.formData[targetItem.name].push({ content: res })
} else {
this.formData[targetItem.name][subIndex].content = res
}
}
console.log(this.formData[targetItem.name])
})
}
},
// 描述 1-图片;2-文字
handleAddDesc(resType, targetItem) {
// console.log(this.formData[targetItem.name])
const orderNo = this.formData[targetItem.name].length
this.formData[targetItem.name].push({
resType: resType,
orderNo: orderNo,
content: ''
})
},
handleClose() {
this.$emit('handleClose')
},
handleUp() {
// console.log(this.formData)
let flag = true
this.formData.upgradeGoods.forEach(item => {
if (!item.profitValue) {
if (this.formData.hasOwnProperty('upgradeGoods')) {
this.formData.upgradeGoods.forEach(item => {
if (!item.profitValue) {
flag = false
}
})
if (!this.formData.linkMerchantIds.length) {
flag = false
}
})
if (!this.formData.linkMerchantIds.length) {
flag = false
}
if (flag) {
this.$refs.d2FormRuleForm.validate(valid => {
......@@ -352,9 +483,6 @@ export default {
padding-left: 20px;
background-color: #e1e0e0;
}
.d2-form .el-form-item {
/* margin-bottom: 5px; */
}
.d2-form .dis-in-block {
display: inline-block;
}
......@@ -374,6 +502,74 @@ export default {
width: 50px;
display: inline-block;
}
.d2-form .photo-top-tips {
height: 36px;
margin: 0 0;
color: #999999;
}
.d2-form .activity-img,
.d2-form .descList-img {
position: relative;
width: 88px;
height: 74px;
color: #999999;
border: 1px dashed #d9d9d9;
cursor: pointer;
margin-right: 10px;
}
.d2-form .muti-imgs {
width: 88px;
height: 74px;
}
.activity-img img {
width: 100%;
height: 100%;
}
.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%);
}
.activity-img .close {
display: none;
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
z-index: 2;
background: rgba(0, 0, 0, 0.5);
opacity: 1;
}
.activity-img .close i {
width: 18px;
height: 18px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.activity-img:hover .close {
display: block;
}
.d2-form .input-bg {
background-color: #eee;
}
.d2-form .pro-item.el-input--medium .el-input__inner,
.d2-form .pro-item .el-input--medium .el-input__inner {
padding: 0 2px;
......
......@@ -189,7 +189,6 @@ export default {
mounted() {
this.getBaseData()
console.log(this.$route.params)
// var allOpt = { confId: '', confKey: '全部' }
// this.baseData.goodsType.unshift(allOpt)
// this.baseData.brandList.unshift(allOpt)
......
......@@ -140,7 +140,6 @@ export default {
} else {
this.editForm[0].formBlock[0].isDisabled = false
this.getGoodsList()
this.$nextTick(() => {
this.show = true
})
......@@ -157,7 +156,8 @@ export default {
})
},
handleAddClose(isRefresh = false) {
this.$router.push({ name: 'commodity', params: isRefresh })
this.close({ tagName: '/commodity' })
this.$router.push({ name: 'commodity' })
this.close({ tagName: '/editCommodity' })
},
handleAddConfirm(data) {
......
......@@ -2,10 +2,11 @@
<template>
<div class="edit-product">
<d2-form
v-if="show"
ref="d2ProductForm"
:formItemWidth="formItemWidth"
:rules="rules"
:addOrEdit="addOrEdit"
addOrEdit="add"
:originData="editData"
:formList="editForm"
@handleAddConfirm="handleAddConfirm"
......@@ -15,8 +16,10 @@
</template>
<script>
import _ from 'lodash'
import { mapActions } from 'vuex'
import { BaseData } from '@/common/constants.js'
import { BaseData, brandMerchantList } from '@/common/constants.js'
import { addGoods, editGoods } from '@/api/product'
export default {
name: 'editProduct',
data() {
......@@ -25,7 +28,9 @@ export default {
addOrEdit: 'add',
rules: {
goodsName: [{ required: true, message: '请输入产品名称', trigger: 'blur' }],
goodsType: [{ required: true, message: '请选择分类', trigger: 'change' }]
goodsType: [{ required: true, message: '请选择分类', trigger: 'blur' }],
thumbUrl: [{ required: true, message: '请选择缩略图', trigger: 'change' }],
goodsImgList: [{ required: true, message: '请选择产品主图', trigger: 'change' }]
},
editData: {
goodsName: '',
......@@ -36,7 +41,11 @@ export default {
brandMerchantName: '',
thumbUrl: '',
goodsImgList: [],
goodsDescList: []
goodsDescList: [{
resType: 2,
orderNo: 0,
content: ''
}]
},
editForm: [{
title: '产品基本信息',
......@@ -66,8 +75,24 @@ export default {
tips: '选择品牌商',
isClear: true,
optionList: [],
optionId: 'goodsType',
optionLabel: 'goodsTypeName'
optionId: 'confId',
optionLabel: 'confValue'
}, {
name: 'thumbUrl',
label: '缩略图',
type: 'photo',
topTips: '用于在小程序主页的商品列表展示',
maxPhotoNum: 1
}, {
name: 'goodsImgList',
label: '产品主图',
type: 'photo',
topTips: '用于在小程序商品详情页的顶部展示',
maxPhotoNum: 10
}, {
name: 'goodsDescList',
label: '产品描述',
type: 'descList'
}]
}],
baseData: {
......@@ -77,18 +102,74 @@ export default {
},
mounted() {
this.addOrEdit = this.$route.params.addOrEdit
if (this.addOrEdit === 'edit') {
this.show = false
this.editData = _.cloneDeep(this.$route.params.form)
console.log(this.editData)
this.$nextTick(() => {
this.show = true
})
} else {
this.show = true
}
this.getBaseData()
this.editForm[0].formBlock[3].optionList = brandMerchantList
},
methods: {
...mapActions({
get: 'd2admin/base/get'
get: 'd2admin/base/get',
close: 'd2admin/page/close'
}),
async getBaseData() {
const temp = await this.get(BaseData.productType)
this.baseData.productType = temp
this.editForm[0].formBlock[1].optionList = temp
console.log(this.baseData.productType)
},
handleAddClose(isRefresh = false) {
this.close({ tagName: '/product' })
this.$router.push({ name: 'product' })
this.close({ tagName: '/editProduct' })
},
handleAddConfirm(data) {
data.goodsDescList = data.goodsDescList.filter(item => item.content)
data.goodsTypeName = this.baseData.productType.find(item => item.goodsType === data.goodsType).goodsTypeName
console.log(data)
data.brandMerchantCode && (data.brandMerchantName = brandMerchantList.find(item => item.confId === data.brandMerchantCode).confValue)
if (this.addOrEdit === 'edit') {
var params = {
id: data.id,
goodsName: data.goodsName,
goodsType: data.goodsType,
goodsTypeName: data.goodsTypeName,
brandMerchantCode: data.brandMerchantCode,
brandMerchantName: data.brandMerchantName,
sapCode: data.sapCode,
thumbUrl: data.thumbUrl,
goodsImgList: data.goodsImgList,
goodsDescList: data.goodsDescList
}
params.goodsImgList.forEach(i => {
delete i.createdDate
delete i.updatedDate
})
params.goodsDescList.forEach(i => {
delete i.createdDate
delete i.updatedDate
})
editGoods(params).then(res => {
console.log(res)
this.notice.okTips()
this.handleAddClose(true)
})
} else {
addGoods(data).then(res => {
this.notice.okTips()
this.handleAddClose(true)
})
}
}
}
}
......
......@@ -45,7 +45,7 @@
<el-option
v-for="item in baseData.brandList"
:key="item.confId"
:label="item.confKey"
:label="item.confValue"
:value="item.confId"
></el-option>
</el-select>
......@@ -89,6 +89,7 @@
<script>
import { getList } from '@api/product'
import { brandMerchantList } from '@/common/constants'
export default {
name: 'product',
data() {
......@@ -159,6 +160,7 @@ export default {
// var allOpt = { confId: '', confKey: '全部' }
// this.baseData.product.unshift(allOpt)
// this.baseData.brandList.unshift(allOpt)
this.baseData.brandList = brandMerchantList
},
methods: {
......@@ -175,12 +177,25 @@ export default {
this.$refs.productTable.refreshTable()
},
handleAdd(form) {
console.log(form)
this.$router.push({ name: 'editProduct' })
// console.log(form)
this.$router.push({
name: 'editProduct',
params: {
addOrEdit: 'add',
form: form
}
})
},
handleExport() { },
handleEdit(row) {
console.log(row)
// console.log(row)
this.$router.push({
name: 'editProduct',
params: {
addOrEdit: 'edit',
form: row
}
})
},
handleDetail(row) {
this.detailData = row
......
......@@ -121,8 +121,8 @@ export default {
time: dayjs().format('HH:mm:ss'),
// 表单
formLogin: {
userName: 'dongdao',
// userName: 'houlai',
// userName: 'dongdao',
userName: 'houlai',
password: '123456'
},
// 表单校验
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!