475 lines
16 KiB
Vue
475 lines
16 KiB
Vue
<template>
|
||
<view class="container">
|
||
<view class="step_one">
|
||
<view class="input_content">
|
||
<view class="bar-code" v-if="bar_code_dis">
|
||
<view>商品条码</view>
|
||
<input type="number" placeholder="请手动添加条码" v-model="code" :disabled="bar_code_dis"
|
||
placeholder-class="inputPlaceHolder" />
|
||
</view>
|
||
<view class="input_content_textarea">
|
||
<textarea v-model="setFormData.store_name" placeholder="请输入商品名称" placeholder-class="placeholderStyle"
|
||
maxlength="60" />
|
||
<view class="flex" style="justify-content: space-between;color: #999999;">
|
||
<view>(品牌,名称,规格,口味)</view>
|
||
<view>
|
||
<text v-if="setFormData.store_name">{{ setFormData.store_name.length }}</text>
|
||
<text v-else>0</text>/60
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view class="photo_count">
|
||
<text class="photo_size" style="color: #e93323;">建议:图片尺寸为750*750px, 上传2张以上</text>
|
||
<view class="input_content_photo">
|
||
<view class="input_content_photo_adPh" v-for="(item, index) in setFormData.imageList" :key="index">
|
||
<image :src="item" class="myimg2 photos" @click="pop(item)"></image>
|
||
<view class="input_content_photo_adPh_jiao" @click="deleteImage(index)">
|
||
<image src="../static/images/close.png" mode=""></image>
|
||
</view>
|
||
</view>
|
||
<view v-if="setFormData.imageList.length < 9" class="input_content_photo_adPh addBtn" @click="clk">
|
||
<view>
|
||
<image src="../static/images/creamer.png" mode="widthFix"></image>
|
||
</view>
|
||
<view>添加图片</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<u-popup ref="select_popup" class="pop" :show="show" mode="center" closeOnClickOverlay bgColor='transparent'>
|
||
<image :src="image"></image>
|
||
<image src="@/static/images/guanbi.png" class="guanbi" @click="close"></image>
|
||
</u-popup>
|
||
</view>
|
||
|
||
<!-- 商品详情 -->
|
||
<commodityComponent v-if="showCommodity" :key="showCommodity" :showCommodity="showCommodity" :product_id="product_id" :merId="merId"
|
||
:code="code" @lastStep="lastStep">
|
||
</commodityComponent>
|
||
|
||
<view class="popup_group">
|
||
<view class="popup_group_item" @click="selectPlatform">
|
||
<view class="popup_group_item_label">平台分类</view>
|
||
<view class="popup_group_item_value">
|
||
<view class="popup_group_item_message">
|
||
<span v-if="setFormData.cate_name"
|
||
class="popup_group_item_message_value">{{ setFormData.cate_name }}</span>
|
||
<span v-else>请选择平台分类</span>
|
||
</view>
|
||
<view><span class="iconfont"></span></view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="popup_group_item">
|
||
<view class="popup_group_item_label">商品单位</view>
|
||
<view class="popup_group_item_value"><input v-model="setFormData.unit_name" type="text"
|
||
placeholder="请填写商品单位" /></view>
|
||
</view>
|
||
|
||
</view>
|
||
|
||
<!-- 选择平台分类弹框 -->
|
||
<uni-popup ref="select_platform" type="bottom">
|
||
<platfrom @close="closePlatfrom" :classifiedData="platformClassificationData" @getPlatData="getPlatData">
|
||
</platfrom>
|
||
</uni-popup>
|
||
|
||
<!-- 规格设置 -->
|
||
<priceComponent :product_id="product_id" :bar_code="code" @updateCode = "updateCode" v-if="showCommodity"></priceComponent>
|
||
|
||
<view class="popup_group">
|
||
<!-- <view class="popup_group_item" @click="showMoreInfo=!showMoreInfo">
|
||
<view class="popup_group_item_label">更多信息</view>
|
||
<view class="popup_group_item_value" :class="showMoreInfo?'icon_bottom':'icon_top'">
|
||
<view><span class="iconfont"></span></view>
|
||
</view>
|
||
</view> -->
|
||
<block >
|
||
<view class="input_content">
|
||
<!-- <view class="input_content_describe" style="border-top: none">
|
||
<view class="input_content_describe_title">
|
||
<view class="input_content_describe_title_msg">商品简介</view>
|
||
<view class="input_content_describe_title_num">
|
||
<text v-if="setFormData.store_info">{{ setFormData.store_info.length }}</text>
|
||
<text v-else>0</text>
|
||
/200
|
||
</view>
|
||
</view>
|
||
<view class="input_content_describe_textarea">
|
||
<textarea v-model="setFormData.store_info" value="" placeholder="请填写商品简介"
|
||
placeholderClass="placeholderClass" maxlength="200" />
|
||
</view>
|
||
</view> -->
|
||
|
||
<view class="input_content_keyword">
|
||
<view class="input_content_keyword_label">关键字</view>
|
||
<view class="input_content_keyword_value"><input v-model="setFormData.keyword" type="text" value=""
|
||
placeholder="填写关键字" /></view>
|
||
</view>
|
||
</view>
|
||
<view class="radio">
|
||
<view class="radio_label ">送货方式</view>
|
||
<checkbox-group class="select_group flex_start" @change="deliveryWayChange">
|
||
<label class="radio_select" v-for="(val, i) in deliveryFreeList" :key="val.value">
|
||
<view>
|
||
<checkbox :value="val.value" disabled :checked="val.value" />
|
||
</view>
|
||
<view>{{ val.name }}</view>
|
||
</label>
|
||
</checkbox-group>
|
||
</view>
|
||
</block>
|
||
|
||
</view>
|
||
|
||
</view>
|
||
|
||
<view class="handle">
|
||
<view class="handle_button" @click="submitCreatedGoods">提交</view>
|
||
</view>
|
||
|
||
<uni-popup ref="tempId" type="bottom">
|
||
<linkage-assembly selectProductTitle="选择运费模板" :form="setFormData" :classifiedData="classified['temp_id']"
|
||
:selectProductItem="productItem" :mer_id="merId" @getLinkageData="getTempIdData" @multipleList="multipleList"
|
||
@close="$refs.tempId.close()" @scrolltolower="scrolltolower"></linkage-assembly>
|
||
</uni-popup>
|
||
|
||
<!-- 图片选择器 -->
|
||
<avatar @upload="doUpload" @getName="getImgName" quality="1" ref="avatar" selWidth="250upx" selHeight="250upx">
|
||
</avatar>
|
||
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import {
|
||
TOKENNAME,
|
||
HTTP_REQUEST_URL
|
||
} from '@/config/app.js';
|
||
import {
|
||
categoryBrandlist,
|
||
categorySelect,
|
||
storeClassifyLst,
|
||
categoryList,
|
||
attrList,
|
||
templateList,
|
||
productDetail,
|
||
getDeliveryType
|
||
} from '@/api/product.js';
|
||
import avatar from "@/components/yq-avatar/yq-avatar.vue";
|
||
import platfrom from "./components/platform.vue";
|
||
import commodityComponent from "./components/commodity.vue";
|
||
import priceComponent from "./components/price.vue";
|
||
export default {
|
||
components:{
|
||
avatar,
|
||
platfrom,
|
||
commodityComponent,
|
||
priceComponent
|
||
},
|
||
data() {
|
||
return {
|
||
bar_code_dis: false,
|
||
merId: '', //商户id
|
||
product_id: '', //商品id
|
||
code: '', //商品条码
|
||
show: false, //是否预览图片
|
||
image: false, //预览的图
|
||
setFormData:{
|
||
store_name: '',
|
||
imageList: [],
|
||
cate_name: '', //平台分类
|
||
unit_name: '', //商品单位
|
||
},
|
||
platformClassificationData: [], // 平台分类数据
|
||
merchantClassification: [], // 店铺分类
|
||
brand: [], // 品牌
|
||
showCommodity: false, // 是否显示商品,售价
|
||
deliveryFreeList: [{
|
||
value: '1',
|
||
name: '到店核销'
|
||
},
|
||
{
|
||
value: '2',
|
||
name: '快递配送'
|
||
}
|
||
],
|
||
// 分类数据容器
|
||
classified: {
|
||
cate_id: [],
|
||
mer_cate_id: [],
|
||
brand_id: [],
|
||
attr: [],
|
||
temp_id: []
|
||
},
|
||
productItem: {} || [],
|
||
};
|
||
},
|
||
onLoad(opt) {
|
||
this.merId = Number(opt.mer_id);
|
||
this.product_id = opt.product_id;
|
||
if(!opt.product_id)this.showCommodity=true;
|
||
this.initData();
|
||
this.initClasiffy();
|
||
},
|
||
onBackPress() {
|
||
|
||
},
|
||
onShow() {
|
||
|
||
},
|
||
beforeDestroy() {
|
||
|
||
},
|
||
methods: {
|
||
// 查询详情数据
|
||
initDataEditData() {
|
||
this.setFormData = {
|
||
imageList: [],
|
||
specification: '',
|
||
image: '', //主图
|
||
slider_image: '', // 轮播图
|
||
store_name: '', // 商品名
|
||
store_info: '', // 简介
|
||
keyword: '', // 关键字
|
||
brand_id: '', // 品牌id
|
||
brand_name: '', // 品牌名称
|
||
cate_id: '', // 平台分类
|
||
cate_name: '', // 平台名称
|
||
mer_cate_id: '', // 店铺分类
|
||
mer_cate_name: '', // 店铺分类名称
|
||
unit_name: '', // 商品单位
|
||
spec_type: '0', // 0.单规格 1:多规格
|
||
attr: [], // 商品规格
|
||
specifica: '', // 商品规格名称
|
||
setSpecificaValue: '', // 价格设置提示
|
||
setSpecificaValue2: '', // 价格设置提示
|
||
delivery_way: [], // 配送方式 1 到店核销 2 快递配送
|
||
delivery_free: '0', // 是否包邮 0不包邮 1包邮
|
||
temp_id: '', // 运费模板ID
|
||
tempName: '' // 运费模板名称
|
||
};
|
||
if (getStorage('editGoodsDetils')) {
|
||
removeStorage('editGoodsDetils');
|
||
}
|
||
productDetail(this.merId, this.product_id).then(res => {
|
||
setStorage('editGoodsDetils', res.data);
|
||
if(res.data.content_arr.length>0) res.data.content = res.data.content_arr;
|
||
this.$store.commit('setStorage', res.data);
|
||
let editGoodsDetils = res.data;
|
||
Object.keys(this.setFormData).forEach(item => {
|
||
this.setFormData[item] = editGoodsDetils[item];
|
||
});
|
||
this.setFormData.product_id = this.product_id;
|
||
this.setFormData.imageList = [...(this.setFormData.image ? [this.setFormData.image] : []), ...
|
||
this
|
||
.setFormData.slider_image
|
||
];
|
||
this.setFormData.cate_name = editGoodsDetils?.storeCategory?.cate_name; // 平台分类回显
|
||
this.setFormData.mer_cate_name = editGoodsDetils.merCateId ? editGoodsDetils.merCateId.map(
|
||
item => item
|
||
.category && item.category.cate_name).join(',') : '';
|
||
this.setFormData.brand_name = editGoodsDetils.brand ? editGoodsDetils.brand.brand_name : '';
|
||
// 多规格
|
||
if (this.setFormData.spec_type == 1) {
|
||
if (editGoodsDetils.attr.length) {
|
||
this.setFormData.specifica = '点击修改规格'
|
||
}
|
||
if (editGoodsDetils.attrValue.length) {
|
||
this.setFormData.setSpecificaValue2 = '点击修改价格'
|
||
}
|
||
}
|
||
if (editGoodsDetils.spec_type == 0) {
|
||
setStorage('singleSpecification', editGoodsDetils.attrValue[0]);
|
||
if (editGoodsDetils.attrValue.length) {
|
||
this.setFormData.setSpecificaValue = '点击修改价格'
|
||
}
|
||
}
|
||
setStorage('attrValue', editGoodsDetils.attrValue);
|
||
editGoodsDetils.temp && (this.setFormData.tempName = editGoodsDetils.temp.name);
|
||
setStorage('canChange', true);
|
||
hideLoading();
|
||
this.showCommodity = true;
|
||
|
||
});
|
||
},
|
||
//获取商户分类
|
||
async initClasiffy() {
|
||
this.merchantClassification = (await storeClassifyLst(this.merId)).data;
|
||
},
|
||
async initData() {
|
||
// 获取品牌
|
||
this.brand = (await categoryBrandlist(this.merId)).data;
|
||
// 获取平台分类
|
||
let { data } = await categoryList(this.merId);
|
||
data.forEach((item1)=>{
|
||
item1.children.forEach((item2)=>{
|
||
item2.children = null;
|
||
})
|
||
})
|
||
this.platformClassificationData = data;
|
||
},
|
||
// 更新商品条码
|
||
updateCode(e){
|
||
this.code = e + '';
|
||
},
|
||
// 选择图片
|
||
handleChooseImage() {
|
||
let that = this;
|
||
that.$util.uploadImageOne('upload/image', function(res) {
|
||
that.setFormData.imageList.push(res.data.path);
|
||
});
|
||
},
|
||
clk() {
|
||
let avatar = this.$refs.avatar;
|
||
avatar.fChooseImg(1, {
|
||
selWidth: '350upx',
|
||
selHeight: '350upx',
|
||
inner: true
|
||
});
|
||
},
|
||
doUpload(rsp) {
|
||
let that = this
|
||
// console.log(rsp);
|
||
uni.uploadFile({
|
||
url: HTTP_REQUEST_URL + '/api/upload/image/field',
|
||
filePath: rsp.path,
|
||
name: 'field',
|
||
formData: {
|
||
'filename': rsp.path,
|
||
'name': that.imgName
|
||
},
|
||
header: {
|
||
// #ifdef MP
|
||
"Content-Type": "multipart/form-data",
|
||
// #endif
|
||
[TOKENNAME]: 'Bearer ' + this.$store.state.app.token
|
||
},
|
||
success: (uploadFileRes) => {
|
||
// console.log(uploadFileRes.data);
|
||
let imgData = JSON.parse(uploadFileRes.data)
|
||
that.setFormData.imageList.push(imgData.data.path)
|
||
},
|
||
complete(res) {
|
||
// console.log(res)
|
||
}
|
||
});
|
||
},
|
||
getImgName(name) {
|
||
this.imgName = name
|
||
},
|
||
//图片预览
|
||
pop(e) {
|
||
this.show = true
|
||
this.image = e
|
||
},
|
||
// 关闭弹框
|
||
close() {
|
||
this.$refs.select_popup.close();
|
||
this.show = false
|
||
},
|
||
// 删除图片
|
||
deleteImage(index) {
|
||
this.setFormData.imageList.splice(index, 1);
|
||
},
|
||
// 选择平台分类
|
||
selectPlatform() {
|
||
this.$refs.select_platform.open();
|
||
},
|
||
// 关闭频台分类
|
||
closePlatfrom() {
|
||
this.$refs.select_platform.close();
|
||
},
|
||
// 获取平台类数据
|
||
getPlatData(item, taplist) {
|
||
this.setFormData.cate_id = item.value;
|
||
this.setFormData.cate_name = item.label;
|
||
this.$refs.select_platform.close();
|
||
},
|
||
// 选择店铺分类
|
||
selectStoreClass() {
|
||
this.$refs.select_store.open();
|
||
},
|
||
// 关闭店铺分类
|
||
merchantClose() {
|
||
this.$refs.select_store.close();
|
||
},
|
||
|
||
// 获取已选择得店铺数据
|
||
handleGetSelectStore(item) {
|
||
this.setFormData.mer_cate_id = item.map(val => val.store_category_id);
|
||
this.setFormData.mer_cate_name = item.map(val => val.cate_name).join(',');
|
||
this.$refs.select_store.close();
|
||
},
|
||
|
||
// 获取品牌分类弹框
|
||
selectBrand() {
|
||
this.$refs.select_popup.open();
|
||
},
|
||
// 获取品牌分类数据
|
||
getLinkageData(item) {
|
||
this.setFormData.brand_id = item[0].value;
|
||
this.setFormData.brand_name = item[0].cate_name;
|
||
this.$refs.select_popup.close();
|
||
},
|
||
// 获取多选数据
|
||
multipleList(data, model) {
|
||
if (model == 'mer_cate_id') {
|
||
this.platformClassification[1].value = data.map(item => item.label).join(',');
|
||
this.platformClassification[1].allreadySelect = data;
|
||
this.setFormData.mer_cate_id = data.map(item => item.value);
|
||
}
|
||
},
|
||
// popup弹框中返回数据结束
|
||
// 关闭弹框
|
||
close() {
|
||
this.$refs.select_popup.close();
|
||
this.show = false
|
||
},
|
||
// 拼接字符串
|
||
getLinkDataOfRecursion(arr, child = 'children', key = 'value') {
|
||
let str = '';
|
||
let id = '';
|
||
arr.forEach(item => {
|
||
str = item.label;
|
||
id = item.value;
|
||
});
|
||
// str = str.slice(0, str.length - 1);
|
||
return {
|
||
str,
|
||
id
|
||
};
|
||
},
|
||
// 求运费模板列表
|
||
getTemplateList() {
|
||
templateList(this.merId, this.templateListPage).then(res => {
|
||
res.data.list.forEach(item => {
|
||
this.$set(item, 'value', item.shipping_template_id);
|
||
this.$set(item, 'label', item.name);
|
||
});
|
||
this.classified['temp_id'] = res.data.list;
|
||
this.$refs.tempId.open();
|
||
});
|
||
},
|
||
|
||
// 创建商品
|
||
submitCreatedGoods() {
|
||
console.log('创建商品');
|
||
console.log('商品数据', this.setFormData);
|
||
},
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
@import './scss/index.scss';
|
||
|
||
.pop {
|
||
z-index: 1;
|
||
}
|
||
|
||
.guanbi {
|
||
width: 20px;
|
||
height: 20px;
|
||
margin: 30px auto;
|
||
}
|
||
</style> |