dingdong-master/pages/my/new-serv.vue

481 lines
17 KiB
Vue
Raw Normal View History

2022-05-15 01:46:26 +08:00
<template>
<view>
<!-- 顶部操作条 -->
<cu-custom :bgColor="'bg-main-color'" :isBack="true">
<block slot="backText">返回</block>
<block slot="content">服务上架</block>
</cu-custom>
<!-- 表单内容 -->
<form @submit="submit">
<view class="cu-form-group">
<view class="title">服务名称</view>
2022-06-01 00:37:46 +08:00
<input name="servName" v-model="formData.servName" placeholder="请编辑上架标题(供客户搜索)"></input>
2022-05-15 01:46:26 +08:00
</view>
<view class="cu-form-group">
<view class="title">服务描述</view>
2022-06-01 00:37:46 +08:00
<input name="servDesc" v-model="formData.servDesc" placeholder="让客户更清晰的上架内容描述"></input>
2022-05-15 01:46:26 +08:00
</view>
<view class="solid-top">
<view class="cu-form-group">
<view class="title">选择类目</view>
<picker :mode="'multiSelector'" @change="categoryChange" @columnchange="categoryColChange" :value="categoryMultiIndex" :range-key="'goodsCategoryName'" :range="categoryList">
2022-05-24 18:03:36 +08:00
<input disabled class="line-input radius-input" :value="formData.category && formData.category.length ? formData.category[0].goodsCategoryName + '-' + formData.category[1].goodsCategoryName + '-' + formData.category[2].goodsCategoryName : ''"
2022-05-15 01:46:26 +08:00
placeholder="请选择类目"></input>
</picker>
</view>
2022-05-16 00:38:19 +08:00
<view v-if="formData.specsList && formData.specsList.length > 0">
<checkbox-group class="padding-lr bg-white" @change="checkSpecs" :class="isShowAllSpecs ? '' : 'certern-height'">
<view v-for="(item, index) in formData.specsList" class="padding-tb-sm">
<view class="flex">
<view class="flex-sub">
<checkbox style="transform:scale(1)" class="main-color margin-right-xs" :value="index" :checked="item.checked"></checkbox>
2022-06-01 00:37:46 +08:00
<text>{{item.goodsCategoryName}}</text>
2022-05-16 00:38:19 +08:00
</view>
<view class="flex-sub">
2022-06-01 00:37:46 +08:00
<input class="radius-input" @input="inputSpecs($event, index, 'goodsStandardName')" :value="item.goodsStandardName" placeholder="自编辑购买标题"></input>
2022-05-16 00:38:19 +08:00
</view>
</view>
<view class="flex margin-top-xs">
<view class="flex-sub">
2022-06-01 00:37:46 +08:00
<input class="radius-input" @input="inputSpecs($event, index, 'goodsPrice')" :value="item.goodsPrice" placeholder="价格(平6%+¥5销10%+¥18)"></input>
2022-05-16 00:38:19 +08:00
</view>
</view>
<view class="flex margin-top-xs">
<view class="flex-sub">
<input class="radius-input" @input="inputSpecs($event, index, 'deduct')" :value="item.deduct" placeholder="追加提成额"></input>
</view>
<view class="flex-sub flex margin-left-xs">
<view class="flex-sub">
<input class="radius-input" @input="inputSpecs($event, index, 'groupPrice')" :value="item.groupPrice" placeholder="团购价"></input>
</view>
<view class="flex-sub margin-left-xs">
<input class="radius-input" @input="inputSpecs($event, index, 'unit')" :value="item.unit" placeholder="单位"></input>
</view>
</view>
</view>
</view>
</checkbox-group>
<view class="text-bold text-gray text-lg text-center bg-white padding-tb-sm" @click="showAllSpecs()"><text
:class="'cuIcon-' + (isShowAllSpecs ? 'fold' : 'unfold')"></text></view>
2022-05-15 01:46:26 +08:00
</view>
2022-05-16 00:38:19 +08:00
<view class="bg-white">
<view class="padding-lr flex align-center">
<view class="flex-twice flex justify-start align-center">
<view style="width: 20%;">单位</view>
<my-uni-combox :candidates="productUnits" placeholder="请选择" v-model="formData.productUnit"></my-uni-combox>
</view>
<view class="flex-sub margin-left">
优惠券+
</view>
</view>
<view class="padding-lr flex align-center padding-tb-xs">
<view class="flex-sub">
<checkbox style="transform:scale(1)" class="main-color margin-right-xs" :value="true" :v-model="formData.isGoldenServ" :checked="formData.isGoldenServ"></checkbox>
<text>金牌服务</text>
</view>
<view class="flex-twice flex justify-start align-center">
<view style="width: 25%;">质保期</view>
<my-uni-combox :candidates="productProtectTimes" placeholder="请选择" v-model="formData.productProtectTime"></my-uni-combox>
</view>
</view>
</view>
</view>
<view class="solid-top">
<view class="cu-form-group">
<view class="title">上架区域</view>
<picker :mode="'multiSelector'" @change="regionChange" @columnchange="regionColChange" :value="regionMultiIndex" :range-key="'areaName'" :range="regionList">
2022-05-24 18:03:36 +08:00
<input disabled class="line-input radius-input" :value="formData.region && formData.region.length ? formData.region[0].areaName + '-' + formData.region[1].areaName : ''"
2022-05-16 00:38:19 +08:00
placeholder="请选择区域"></input>
</picker>
</view>
<view class="padding-lr bg-white">
<checkbox-group @change="checkDistirct" class="grid col-3">
<view v-for="(item, index) in formData.districtList" class="margin-tb-xs">
<checkbox style="transform:scale(1)" class="main-color margin-right-xs" :value="index" :checked="item.checked"></checkbox>
<text>{{item.areaName}}</text>
2022-05-16 00:38:19 +08:00
</view>
</checkbox-group>
</view>
</view>
<view class="cu-form-group">
<view class="title">区域描述</view>
<input name="areaDesc" :value="formData.areaDesc" :v-model="formData.areaDesc" placeholder="请输入区域描述"></input>
</view>
<view class="cu-form-group">
<view class="title">上门费</view>
2022-05-24 18:03:36 +08:00
<input type="digit" name="doorPrice" :value="formData.doorPrice" :v-model="formData.doorPrice" placeholder="单位:元/次"></input>
</view>
2022-06-01 00:37:46 +08:00
<view class="cu-bar bg-white solid-top">
<view class="action text-black">
商品封面图上传
</view>
</view>
<view class="cu-form-group">
<view class="grid col-4 grid-square flex-sub">
<view class="bg-img" v-for="(item,index) in formData.coverImgList" :key="index" @tap="viewImage($event, formData.coverImgList)"
:data-url="item">
<image :src="item" mode="aspectFill"></image>
<view class="cu-tag bg-red" @tap.stop="delImg($event, formData.coverImgList)" :data-index="index">
<text class='cuIcon-close'></text>
</view>
</view>
<view class="solids" @tap="chooseImgList($event, 'coverImgList')" v-if="formData.coverImgList.length === 0">
<text class='cuIcon-cameraadd'></text>
</view>
</view>
</view>
2022-05-24 18:03:36 +08:00
<view class="cu-bar bg-white solid-top">
<view class="action text-black">
详情图上传
</view>
</view>
<view class="cu-form-group">
<view class="grid col-4 grid-square flex-sub">
<view class="bg-img" v-for="(item,index) in formData.descImgList" :key="index" @tap="viewImage($event, formData.descImgList)"
:data-url="item">
<image :src="item" mode="aspectFill"></image>
<view class="cu-tag bg-red" @tap.stop="delImg($event, formData.descImgList)" :data-index="index">
<text class='cuIcon-close'></text>
</view>
</view>
<view class="solids" @tap="chooseImgList($event, 'descImgList')" v-if="formData.descImgList.length<9">
<text class='cuIcon-cameraadd'></text>
</view>
</view>
2022-05-16 00:38:19 +08:00
</view>
<view class="cu-bar bg-white solid-top">
<view class="action text-black">
轮播图上传
</view>
</view>
<view class="cu-form-group">
<view class="grid col-4 grid-square flex-sub">
<view class="bg-img" v-for="(item,index) in formData.imgList" :key="index" @tap="viewImage($event, formData.imgList)"
:data-url="item">
<image :src="item" mode="aspectFill"></image>
<view class="cu-tag bg-red" @tap.stop="delImg($event, formData.imgList)" :data-index="index">
<text class='cuIcon-close'></text>
</view>
</view>
2022-05-24 18:03:36 +08:00
<view class="solids" @tap="chooseImgList($event, 'imgList')" v-if="formData.imgList.length<9">
2022-05-16 00:38:19 +08:00
<text class='cuIcon-cameraadd'></text>
</view>
</view>
</view>
<view class="cu-bar bg-white solid-top">
<view class="action text-black">
视频上传
</view>
</view>
<view class="bg-white padding-lr padding-bottom-sm">
<uni-file-picker limit="1" file-mediatype="video" return-type="object" @select="selectVideo">
<button class="cu-btn bg-main-color shadow-blur">选择文件</button>
</uni-file-picker>
</view>
<view class="padding-sm bg-white solid-top">
<textarea style="width: 100%;" class="solid radius text-left padding-sm" v-model="formData.detailDesc" maxlength="-1" placeholder="请输入详情介绍"></textarea>
</view>
<view class="padding-bottom-lg padding-top bg-white text-center">
<button class="cu-btn bg-main-color shadow-blur long-btn" @click="submit">确定</button>
2022-05-15 01:46:26 +08:00
</view>
</form>
</view>
</template>
<script>
2022-05-16 00:38:19 +08:00
import myUniCombox from '@/components/uni-combox/my-uni-combox.vue';
2022-05-15 01:46:26 +08:00
export default {
2022-05-16 00:38:19 +08:00
components: {
myUniCombox
},
2022-05-15 01:46:26 +08:00
data() {
return {
2022-05-16 00:38:19 +08:00
formData: {
servName: '',
servDesc: '',
specsList: [],
category: [],
productUnit: '',
isGoldenServ: false,
region: [],
districtList: [],
areaDesc: '',
doorPrice: '',
imgList: [],
detailDesc: '',
2022-05-24 18:03:36 +08:00
descImgList: [],
2022-06-01 00:37:46 +08:00
coverImgList: [],
video: ''
2022-05-16 00:38:19 +08:00
},
2022-05-15 01:46:26 +08:00
categoryList: [],
categoryMultiIndex: [0, 0, 0],
2022-05-16 00:38:19 +08:00
regionList: [],
regionMultiIndex: [0, 0],
isShowAllSpecs: false,
productUnits: [{
code: 1,
name: '台'
}, {
code: 2,
name: '件'
}, {
code: 3,
name: '套'
}, {
code: 4,
name: '个'
}, {
code: 5,
name: '平方'
}],
productProtectTimes: [{
code: 1,
name: '15天'
}, {
code: 2,
name: '30天'
}, {
code: 3,
name: '45天'
}]
2022-05-15 01:46:26 +08:00
}
},
onLoad(options) {
let goodId = null;
if (options && options.goodId) {
goodId = options.goodId;
}
this.loadData(goodId);
2022-05-15 01:46:26 +08:00
},
methods: {
async loadData(goodId) {
this.loadCategoryList();
this.loadRegionList();
// TODO 如果存在goodId说明是修改需要查询good信息进行回显
// this.categoryList = await this.$api.data('categoryList');
// this.regionList = await this.$api.data('regionList');
2022-05-15 01:46:26 +08:00
},
async loadCategoryList(idArr) {
let typeList = await this.$request.listByStep();
typeList = typeList.data;
let col1Id = idArr ? idArr[0] : typeList[0].goodsCategoryId;
let subTypeList = await this.$request.listByStep({ goodsCategoryId: col1Id });
subTypeList = subTypeList.data;
let col2Id = idArr ? idArr[1] : subTypeList[0].goodsCategoryId;
let subSubTypeList = await this.$request.listByStep({ goodsCategoryId: col2Id });
subSubTypeList = subSubTypeList.data;
this.categoryList.push(typeList);
this.categoryList.push(subTypeList);
this.categoryList.push(subSubTypeList);
},
async loadRegionList() {
let regionList = await this.$request.areaListByStep();
regionList = regionList.data;
let subRegionList = [];
if (regionList && regionList.length > 0) {
subRegionList = await this.$request.areaListByStep({ parentCode: regionList[0].areaCode });
subRegionList = subRegionList.data;
}
this.regionList.push(regionList);
this.regionList.push(subRegionList);
},
2022-05-15 01:46:26 +08:00
async categoryChange(e) {
this.categoryMultiIndex = e.detail.value;
let chosenCategory = [];
for(let i = 0; i < this.categoryList.length; i++) {
chosenCategory.push(this.categoryList[i][this.categoryMultiIndex[i]]);
}
this.formData.category = chosenCategory;
2022-06-01 00:37:46 +08:00
// 查询最后一级品类
let res = await this.$request.listByStep({goodsCategoryId: chosenCategory[2].goodsCategoryId});
this.formData.specsList = res.data;
2022-05-16 00:38:19 +08:00
},
async categoryColChange(e) {
let colObj = e.detail;
if (colObj.column == 0) {
// 通过一级查询二级,通过二级查三级
let subTypeList = await this.$request.listByStep({goodsCategoryId: this.categoryList[0][colObj.value].goodsCategoryId});
subTypeList = subTypeList.data;
let subSubTypeList = await this.$request.listByStep({ goodsCategoryId: subTypeList[0].goodsCategoryId });
subSubTypeList = subSubTypeList.data;
this.categoryList.pop();
this.categoryList.pop();
this.categoryList.push(subTypeList);
this.categoryList.push(subSubTypeList);
this.categoryMultiIndex = [colObj.value, 0, 0];
} else if (colObj.column == 1) {
// 通过二级查三级
let subSubTypeList = await this.$request.listByStep({ goodsCategoryId: this.categoryList[1][colObj.value].goodsCategoryId });
subSubTypeList = subSubTypeList.data;
this.categoryList.pop();
this.categoryList.push(subSubTypeList);
this.categoryMultiIndex = [this.categoryMultiIndex[0], colObj.value, 0];
}
},
2022-05-16 00:38:19 +08:00
async regionChange(e) {
this.regionMultiIndex = e.detail.value;
let chosenRegion = [];
for(let i = 0; i < this.regionList.length; i++) {
chosenRegion.push(this.regionList[i][this.regionMultiIndex[i]]);
}
this.formData.region = chosenRegion;
// 查询最后一级区域
let areaList = await this.$request.areaListByStep({parentCode: chosenRegion[1].areaCode});
this.formData.districtList = areaList.data;
},
async regionColChange(e) {
let colObj = e.detail;
if (colObj.column == 0) {
2022-06-01 00:37:46 +08:00
// 通过一级查二级
let subAreaList = await this.$request.areaListByStep({parentCode: this.regionList[0][colObj.value].areaCode});
subAreaList = subAreaList.data;
this.regionList.pop();
this.regionList.push(subAreaList);
this.regionMultiIndex = [colObj.value, 0];
}
2022-05-15 01:46:26 +08:00
},
2022-05-16 00:38:19 +08:00
checkSpecs(e) {
let checkedIndexArr = e.detail.value;
for(let i = 0; i < this.formData.specsList.length; i++) {
if (checkedIndexArr.indexOf(String(i)) !== -1) {
this.formData.specsList[i].checked = true;
} else {
this.formData.specsList[i].checked = false;
}
}
},
inputSpecs(e, index, field) {
this.formData.specsList[index][field] = e.detail.value;
},
showAllSpecs() {
this.isShowAllSpecs = !this.isShowAllSpecs;
},
checkDistirct(e) {
let checkedIndexArr = e.detail.value;
for(let i = 0; i < this.formData.districtList.length; i++) {
if (checkedIndexArr.indexOf(String(i)) !== -1) {
this.formData.districtList[i].checked = true;
} else {
this.formData.districtList[i].checked = false;
}
}
},
2022-05-24 18:03:36 +08:00
chooseImgList(e, imgListField) {
2022-05-16 00:38:19 +08:00
uni.chooseImage({
count: 9, //默认9
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
sourceType: ['album'], //从相册选择
success: (res) => {
2022-06-01 00:37:46 +08:00
uni.showLoading({
title: '上传中',
mask:true
});
res.tempFilePaths.forEach((tmpUrl, index) => {
this.$request.uploadFile(tmpUrl).then((url) => {
this.formData[imgListField].push(url);
if (index === res.tempFilePaths.length - 1) {
uni.hideLoading();
}
});
});
2022-05-16 00:38:19 +08:00
}
});
},
viewImage(e, imgList) {
uni.previewImage({
urls: imgList,
current: e.currentTarget.dataset.url
});
},
delImg(e, imgList) {
uni.showModal({
title: '',
content: '确定要删除这张图片吗?',
cancelText: '取消',
confirmText: '确定',
success: res => {
if (res.confirm) {
imgList.splice(e.currentTarget.dataset.index, 1)
}
}
})
},
async selectVideo(e) {
2022-06-01 00:37:46 +08:00
uni.showLoading({
title: '上传中',
mask:true
});
this.formData.video = await this.$request.uploadFile(e.tempFilePaths[0]);
uni.hideLoading();
2022-05-16 00:38:19 +08:00
},
2022-06-01 00:37:46 +08:00
async submit() {
2022-05-16 00:38:19 +08:00
console.log(this.formData)
2022-06-01 00:37:46 +08:00
let goodsStandardList = this.formData.specsList.filter((item) => {
if (item.checked) {
return item;
}
});
let goodsAreaList = this.formData.districtList.filter((item) => {
if (item.checked) {
item.countryAreaId = item.areaId;
return item;
}
});
// 0是轮播图1是详情图
let goodsImgsList = [];
this.formData.imgList.forEach((url) => {
goodsImgsList.push({
imgUrl: url,
imgType: 0
});
});
this.formData.descImgList.forEach((url) => {
goodsImgsList.push({
imgUrl: url,
imgType: 1
});
});
let params = {
goodsName: this.formData.servName,
deptGoodsCategoryId: this.formData.category[2].goodsCategoryId,
goodsStandardList: goodsStandardList,
goodsAreaList: goodsAreaList,
goodsImgUrl: this.formData.coverImgList[0],
goodsImgsList: goodsImgsList,
goodsVideoUrl: this.formData.video,
status: 0,
remark: this.formData.detailDesc
}
console.log("格式化后的请求参数:" + params)
let res = await this.$request.addGoods(params);
if (res.code === 0) {
uni.showToast({
icon: 'success'
})
uni.navigateBack({
delta: -1
})
}
2022-05-16 00:38:19 +08:00
}
2022-05-15 01:46:26 +08:00
},
}
</script>
<style scoped>
.cu-form-group picker::after {
display: none;
}
2022-05-16 00:38:19 +08:00
.certern-height {
2022-06-01 00:37:46 +08:00
max-height: 520rpx;
2022-05-16 00:38:19 +08:00
overflow: hidden;
}
.long-btn{
width: 95%;
}
2022-05-15 01:46:26 +08:00
</style>