tianyi 1 month ago
parent
commit
8d017ba703
  1. 933
      pages/goods/addGoods.vue
  2. 2
      pages/login/login.vue
  3. 268
      pages/shop/addGoods.vue
  4. 19
      pages/shop/goodsList.vue

933
pages/goods/addGoods.vue

@ -1,39 +1,155 @@
<!-- 底部菜单--库存--新增商品 -->
<template>
<view class="page1">
<view class="title">
<view class="title-sreach">
<view class="back-btn" @tap="back">
<uni-icons type="left" size="28"></uni-icons>
</view>
<view class="title-name">
新增商品
</view>
</view>
</view>
<view class="formBox">
<uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="170rpx">
<uni-forms-item label="商品名称" name="productName" required>
<uni-easyinput type="text" v-model="formData.productName" placeholder="请输入商品名称" trim="all" />
</uni-forms-item>
<uni-forms-item label="商品主图" name="productPicture">
<view v-if="formData.productPicture !=''">
<img :src="formData.productPicture" alt="" class="upload-img">
<view class="upload-img" @tap="pictureAdd"
style="background: #eee;text-align: center;line-height: 160rpx;">
<uni-icons type="camera" size="28" color="#777"></uni-icons>
</view>
<view style="overflow-x: scroll;display: flex;width: 350rpx;">
<view v-if="formData.productPicture !=''" style="width: 160rpx;height: 160rpx;margin-left: 20rpx;">
<img :src="formData.productPicture" alt="" class="upload-img">
</view>
</view>
</uni-forms-item>
<uni-forms-item label="排名" name="orderFiled">
<input type="digit" class="content-input" v-model="formData.orderFiled" placeholder="请输入排名">
</uni-forms-item>
<uni-forms-item label="商品分类" name="editTitle">
<view style="border: 4rpx solid #eee;display: flex;flex: 1;border-radius: 10rpx;">
<input type="text" placeholder="请选择商品分类" disabled v-model="typeItem.categoryName"
class="content-input" @tap="goGategoryLow" style="border: 0;">
<uni-icons type="right" size="16"
style="margin-left: 40rpx;line-height: 70rpx;"></uni-icons>
</view>
</uni-forms-item>
<uni-forms-item label="商品规格" name="attributeListPrice">
<view>
<view v-for="(item,index) in formData.attributeListPrice" :key="index" style="display: flex;margin-top:10rpx;">
<input class="content-input" v-model="item.specName" v-if="item.specName != ''&& formData.attributeListPrice.length != 1" style="padding-right: 20rpx;" disabled />
<input class="content-input" v-model="item.specPrice" style="padding-right: 20rpx;margin-right: 20rpx;" @click="changePrice(index)" placeholder="商品价格" />
<input class="content-input" v-model="item.specNum" style="padding-right: 20rpx;" @click="changecount(index)" placeholder="商品库存"/>
<button @click="deldantiaoguige(index)" v-if="formData.attributeListPrice.length>1" style="width: 240rpx;height: 60rpx;line-height: 60rpx;color: red;border:none;background: #fff;">删除</button>
</view>
<!-- <view @click="checkSpec('guige')" style="margin-top: 5px;width: 80px;height: 30px;text-align: center;line-height: 30px;background: rgba(0, 35, 28, 1);border-radius: 30px;color: rgba(166, 255, 234, 1);">
选择规格
</view> -->
</view>
</uni-forms-item>
<uni-forms-item label="拼团信息" name="productGroupBuyPrices">
<view>
<view v-for="(item,index) in formData.productGroupBuyPrices" :key="index" style="display: flex;margin-top:10rpx;">
<input class="content-input" v-model="item.groupCount" style="padding-right: 20rpx;margin-right: 20rpx;width: 100px;" placeholder="成团人数" />
<input class="content-input" v-model="item.groupPrice" style="padding-right: 20rpx;width: 100px;" placeholder="成团价格"/>
<view @click="delGroup(index)" v-if="formData.productGroupBuyPrices.length>1" style="width: 240rpx;height: 60rpx;line-height: 60rpx;color: red;border:none;background: #fff;">删除</view>
</view>
<view @click="addGroup()" style="margin-top: 10rpx;width: 160rpx;height: 60rpx;text-align: center;line-height: 60rpx;background: rgba(0, 35, 28, 1);border-radius: 60rpx;color: rgba(166, 255, 234, 1);">
新增拼团
</view>
</view>
</uni-forms-item>
<uni-forms-item label="商品属性" name="attributeList1">
<view style="display: flex;flex-direction: column;">
<view v-for="(value,key) in Array.from(formData.attributeList1)" :key="key" style="display: flex;flex-wrap: wrap;align-items: center;margin-bottom: 10rpx;">
{{value[0]}}(可选{{value[1].canbuy || 1}}):
<view v-for="(item,index) in value[1].title" :key="index">
{{item}}
</view>
</view>
<view @click="checkSpec('shuxing')" style="width: 160rpx;height: 60rpx;text-align: center;line-height: 60rpx;background: rgba(0, 35, 28, 1);border-radius: 60rpx;color: rgba(166, 255, 234, 1);">
选择属性
</view>
</view>
<u-upload :fileList="formData.productPicture" @afterRead="afterRead" @delete="deletePic" name="1"
multiple :maxCount="1"></u-upload>
</uni-forms-item>
<uni-forms-item label="商品分类" name="categoryId">
<view class="content-list">
<view class="list-val">
<input type="text" placeholder="请选择商品分类" disabled :value="typeItem.categoryName"
style="border-bottom: 1px solid #fff;text-align: center;" @tap="goGategoryLow">
<uni-icons type="right" size="16"
style="margin-left: 40rpx;line-height: 70rpx;"></uni-icons>
<uni-forms-item label="可售时间" name="sellTime">
<view style="display: flex;flex-direction: column;">
<view style="line-height: 74rpx;">
<radio :checked="formData.sellTime==0" name="sellTime" @click="checkSellTime(0)" />全时段售卖
<radio :checked="formData.sellTime==1" name="sellTime" @click="checkSellTime(1)" />自定义时段
</view>
<view style="display: flex;" v-if="formData.sellTime == 1">
<picker mode="time" v-model="formData.sellBeginTime" start="00:00" end="23:59" @change="selectDateRange($event,'start')">
<view class="uni-input">{{formData.sellBeginTime}}</view>
</picker>
<view style="width: 50rpx;height: 50rpx;line-height: 50rpx;text-align: center;">-</view>
<picker mode="time" v-model="formData.sellEndTime" start="00:00" end="23:59" @change="selectDateRange($event,'end')">
<view class="uni-input">{{formData.sellEndTime}}</view>
</picker>
</view>
</view>
</uni-forms-item>
<uni-forms-item label="打包盒价格" name="productName" required>
<uni-easyinput type="text" v-model="formData.productName" placeholder="请输入打包盒价格" trim="all" />
<uni-forms-item label="设置加料" name="isMoreBuy">
<view style="line-height: 74rpx;">
<radio :checked="formData.isMoreBuy==0" name="isMoreBuy" @click="checkisMoreBuy('0')" />
<radio :checked="formData.isMoreBuy==1" name="isMoreBuy" @click="checkisMoreBuy('1')" />
</view>
</uni-forms-item>
<uni-forms-item label="商品单位" name="productName" required>
<uni-easyinput type="text" v-model="formData.productName" placeholder="非必填,个/斤/500g" trim="all" />
<uni-forms-item label="餐盒费" name="lunchBox">
<input type="digit" class="content-input" v-model="formData.lunchBox" placeholder="请输入餐盒费">
</uni-forms-item>
<uni-forms-item label="起售数量" name="startPayNum">
<input type="digit" class="content-input" v-model="formData.startPayNum" placeholder="请输入起售数量">
</uni-forms-item>
<uni-forms-item label="详细图文" name="startPayNum">
<view class="xiangxi-box">
<sp-editor
:keys="keys"
@init="initEditor"
@input="inputOver"
@upinImage="upinImage"
@overMax="overMax">
</sp-editor>
</view>
</uni-forms-item>
</uni-forms>
<view>
<button @tap.stop="submit()">保存</button>
</view>
</view>
<!-- 添加分类弹出层 -->
<uni-popup ref="addTypeDialog" background-color="#fff">
<view class="add-popup-content">
<view style="height:900rpx;display: flex;">
<view class="content-left">
<view class="left-box" v-for="(item,index) in categoryData" :key="index"
:class="item.parentId ? 'left-box-hover':''" @tap="clickLeftBtn(index)">
<text style="width: 100%;height: 100rpx;line-height: 100rpx;display: inline-block;overflow: hidden;"
:class="item.parentId ? 'red' :''">{{item.title}}</text>
</view>
</view>
<view style="flex: 1;position: relative;padding: 20rpx;">
<view v-for="(item,index) in categorySonData" :key="index" @tap="checkSpecValue(index)" class="content-low" :class="item.checked?'checked':''">
{{item.title}}
</view>
<view style="position: absolute;bottom: 0;">
<view style="font-size: 28rpx;line-height: 60rpx;font-weight: 700;">
该分类可选数量
</view>
<input type="digit" class="content-input" v-model="currentCanbuy" placeholder="该分类可选几个(默认1)">
</view>
</view>
</view>
<view slot="footer" style="display: flex;padding-left: 40rpx;margin-top: 20rpx;">
<button type="text" @tap="$refs.addTypeDialog.close()" style="margin-right: 20rpx;">取消</button>
<button type="text" @tap="guigeSubmit">提交</button>
</view>
</view>
</uni-popup>
</view>
</template>
@ -41,29 +157,802 @@
export default {
data() {
return {
dataList: {},
modalType:0,
maxSelect:1,
currentCanbuy:1,
canbuyMap:{},
categoryData:[],
categoryIndex: 0,
modalclassType:'',
categorySonData:[],
specValueArr:[],
attrValueArr:[],
editorIns: null,
typeItem: {},
formData: {
productName: '',
productPicture: '',
categoryId: '',
productPictures: []
id: '',
shopId: '',
attrId:'',
categoryId: '', //id
categoryName: '', //
productPicture: '', //
productName: '', //
orderFiled: '', //
lunchBox: 0, //
startPayNum: '', //
attributeListPrice: [{ //
specPrice: "",
specNum: 9999
}],
shopId:'',
sellTime: 0, //
isMoreBuy: 0,
sellBeginTime: '', //---
sellEndTime: '', //---
attributeList: '',
productGroupBuyPrices: [],
attributeList1: new Map(), //
productIntro: "" //
},
rules: {
productName: {
rules: [{
required: true,
errorMessage: '请输入名称',
}]
},
categoryId: {
rules: [{
required: true,
errorMessage: '请选择商品分类',
}, ],
},
},
}
},
filters: {
},
onShow() {
this.attrId = uni.getStorageSync('attrId');
uni.authorize({
scope: 'scope.writePhotosAlbum',
success() {
},
fail() {
uni.showToast({
title: "您未授权,图片上传功能可能会出现错误",
icon: 'none'
})
}
})
this.typeItem = JSON.parse(JSON.stringify(this.typeItem)) || ''
if (this.typeItem) {
this.formData.categoryId = this.typeItem.id
}
this.formData.shopId = uni.getStorageSync('shopId')
},
onLoad(option) {
this.getGategoryList()
if (option.dataList != undefined && option.dataList != null && option.dataList != 'undefined') {
this.dataList = JSON.parse(option.dataList)
this.NB.sendRequest("/app/product/getById/" + this.dataList.id, {}, false, 'POST', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
this.modalType = 1
this.formData.id = res.result.id
this.formData.shopId = res.result.shopId
this.formData.categoryName = res.result.categoryName
this.formData.orderFiled = res.result.orderFiled
this.formData.lunchBox = res.result.lunchBox
this.formData.startPayNum = res.result.startPayNum
this.formData.attributeListPrice = JSON.parse(res.result.attributeListPrice)
this.formData.shopId = res.result.shopId
this.formData.sellTime = res.result.sellBeginTime !=''?1:0
this.formData.isMoreBuy = res.result.isMoreBuy
this.formData.sellBeginTime = res.result.sellBeginTime
this.formData.sellEndTime = res.result.sellEndTime
this.formData.attributeList = res.result.attributeList
this.formData.productGroupBuyPrices = res.result.productGroupBuyPrices
this.formData.attributeList1 = new Map()
this.formData.productName = res.result.productName
this.formData.productPicture = res.result.productPicture
this.formData.productIntro = res.result.productIntro
this.formData.categoryId = res.result.categoryId
this.edit(this.formData)
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
}
},
methods: {
/**
* 获取输入内容
* @param {Object} e {html,text} 内容的html文本和text文本
*/
inputOver(e) {
//
console.log('==== inputOver :', e)
this.productIntro = e
},
/**
* 超出最大内容限制
* @param {Object} e {html,text} 内容的html文本和text文本
*/
overMax(e) {
//
console.log('==== overMax :', e)
},
/**
* 编辑器就绪
* @param {Object} editor 编辑器实例你可以自定义调用editor实例的方法
* @tutorial editor组件 https://uniapp.dcloud.net.cn/component/editor.html#editor-%E7%BB%84%E4%BB%B6
* @tutorial 相关api https://uniapp.dcloud.net.cn/api/media/editor-context.html
*/
initEditor(editor) {
this.editorIns = editor //
//
},
/**
* 直接运行示例工程插入图片无法正常显示的看这里
* 因为插件默认采用云端存储图片的方式
* 以$emit('upinImage', tempFiles, this.editorCtx)的方式回调
* @param {Object} tempFiles
* @param {Object} editorCtx
*/
upinImage(tempFiles, editorCtx) {
/**
* 本地临时插入图片预览
* 注意这里仅是示例本地图片预览因为需要将图片先上传到云端再将图片插入到编辑器中
* 正式开发时还请将此处注释并解开下面 使用 uniCloud.uploadFile 上传图片的示例方法 的注释
* @tutorial https://uniapp.dcloud.net.cn/api/media/editor-context.html#editorcontext-insertimage
*/
// #ifdef MP-WEIXIN
// tempFilePath
editorCtx.insertImage({
src: tempFiles[0].tempFilePath,
width: '80%', // 100%便
success: function() {}
})
// #endif
// #ifndef MP-WEIXIN
editorCtx.insertImage({
src: tempFiles[0].path,
width: '80%', // 100%便
success: function() {}
})
// #endif
/**
* 使用 uniCloud.uploadFile 上传图片的示例方法可适用多选上传
* 正式开发环境中请将上面 本地临时插入图片预览 注释后模仿以下写法
*/
// tempFiles.forEach(async (item) => {
// uni.showLoading({
// title: '',
// mask: true
// })
// let upfile = await uniCloud.uploadFile({
// filePath: item.path,
// // policy_does_not_allow_file_overwrite
// // cloudPath / cloudstorage
// cloudPath: `cloudstorage/${item.name}`,
// cloudPathAsRealPath: true
// })
// editorCtx.insertImage({
// src: upfile.fileID,
// width: '80%', // 100%便
// success: function () {
// uni.hideLoading()
// }
// })
// })
},
//
goGategoryLow() {
uni.navigateTo({
url: '/package1/myCenter/addType'
})
},
//
getGategoryList() {
this.NB.sendRequest("/app/productCategory/list", {
shopId:uni.getStorageSync('shopId')
}, false, 'get', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
if (res.result.length > 0) {
if(this.formData.categoryId != '' && this.formData.categoryId != undefined){
for(let i=0;i<res.result.length;i++){
if(res.result[i].id == this.formData.categoryId){
this.typeItem = res.result[i]
}
}
}else{
this.typeItem = res.result[0]
this.formData.categoryId = this.typeItem.id
}
}
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
},
//
submit() {
let that = this;
// this.$refs.form.validate((valid) => {
// if (valid) {
if (this.modalType == 0) {
// id
delete this.formData.id;
if(this.formData.isMoreBuy != 1){
this.formData.isMoreBuy = 0
}
this.formData.attributeListPrice = JSON.stringify(this.formData.attributeListPrice)
this.formData.attributeList = Object.fromEntries(this.formData.attributeList1)
this.formData.attributeList = JSON.stringify(this.formData.attributeList)
this.NB.sendRequest("/app/product/save",this.formData, false, 'post', 'application/json').then((res) => {
if (res.code == 200) {
uni.showToast({
title: "操作成功",
icon: 'none'
})
uni.navigateBack()
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
} else if (this.modalType == 1) {
//
this.formData.attributeListPrice = JSON.stringify(this.formData.attributeListPrice)
this.formData.attributeList = Object.fromEntries(this.formData.attributeList1)
this.formData.attributeList = JSON.stringify(this.formData.attributeList)
this.formData.productPictures = []
this.NB.sendRequest("/app/product/edit",this.formData, false, 'post', 'application/json').then((res) => {
if (res.code == 200) {
uni.showToast({
title: "操作成功",
icon: 'none'
})
uni.navigateBack()
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
}
// }
// });
},
back() {
uni.navigateBack()
},
checkisMoreBuy(type){
this.formData.isMoreBuy = type;
},
checkSellTime(type){
this.formData.sellTime = type;
},
selectDateRange(e,type){
if(type == 'start'){
this.formData.sellBeginTime = e.detail.value
}else{
this.formData.sellEndTime = e.detail.value
}
},
guigeSubmit(){
if(this.modalclassType == 'shuxing'){
// canbuy
if(this.typeToAttrName){
this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1
}
for(let i=0;i<this.attrValueArr.length;i++){
let parentName = this.attrValueArr[i].parentName
let canbuyVal = parseInt(this.canbuyMap[parentName]) || 1
if(this.formData.attributeList1.size == 0){
//set has get
let data = {
title:[],
canbuy: canbuyVal
}
data.title.push(this.attrValueArr[i].title)
this.formData.attributeList1.set(parentName,data)
}else{
if(this.formData.attributeList1.has(parentName) && this.formData.attributeList1.get(parentName).title.indexOf(this.attrValueArr[i].title) == -1){
this.formData.attributeList1.get(parentName).title.push(this.attrValueArr[i].title)
this.formData.attributeList1.get(parentName).canbuy = canbuyVal
}else{
let data = {
title:[],
canbuy: canbuyVal
}
data.title.push(this.attrValueArr[i].title)
this.formData.attributeList1.set(parentName,data)
}
}
}
}else{
//guige
let message = []
for(let i=0;i<this.specValueArr.length;i++){
for(let m=0;m<this.formData.attributeListPrice.length;m++){
if(this.specValueArr[i].id == this.formData.attributeListPrice[m].id){
this.specValueArr[i].specPrice = this.formData.attributeListPrice[m].specPrice
this.specValueArr[i].specName = this.formData.attributeListPrice[m].specName
this.specValueArr[i].specNum = this.formData.attributeListPrice[m].specNum
}
}
message.push({
id:this.specValueArr[i].id,
specName:this.specValueArr[i].specName == undefined ? this.specValueArr[i].title : this.specValueArr[i].specName,
specPrice:this.specValueArr[i].specPrice == undefined ? '' : this.specValueArr[i].specPrice,
specNum:this.specValueArr[i].specNum == undefined ? 9999 : this.specValueArr[i].specNum
})
}
this.formData.attributeListPrice = message
}
this.$forceUpdate()
this.$refs.addTypeDialog.close()
},
add() {
if (!this.selectNode.id) {
this.$Message.warning("请先选择一个分类");
return;
}
this.modalType = 0;
this.$refs.form.resetFields();
this.form.sort = this.data.length + 1;
this.formData = {
id:'',
shopId:'',
categoryId:'', //id
categoryName:'', //
productPicture:'', //
productName:'', //
lunchBox:0, //
startPayNum:'', //
orderFiled:'',//
attributeListPrice:[{ //
specPrice:"",
specNum:9999
}],
sellTime:0, //
sellBeginTime:'', //---
sellEndTime:'', //---
attributeList:'',
productGroupBuyPrices:[],
attributeList1:new Map(), //
productIntro:"" //
}
this.specValueArr = []
this.attrValueArr = []
this.formData.shopId = this.shopId
this.formData.categoryId = this.selectNode.id
this.formData.categoryName = this.selectNode.categoryName
this.modalVisible = true;
},
edit(v) {
this.modalType = 1;
// null""
for (let attr in v) {
if (v[attr] == null) {
v[attr] = "";
}
}
let str = JSON.stringify(v);
let data = JSON.parse(str);
console.log('111111',data)
this.formData = data;
// attributeListstring
let attrObj = this.formData.attributeList
if (typeof attrObj === 'string' && attrObj !== '') {
attrObj = JSON.parse(attrObj)
}
if (!attrObj || typeof attrObj !== 'object') {
attrObj = {}
}
this.formData.attributeList1 = new Map(Object.entries(attrObj));
// attributeListPricestring
let priceArr = this.formData.attributeListPrice
if (typeof priceArr === 'string' && priceArr !== '') {
priceArr = JSON.parse(priceArr)
}
if (!Array.isArray(priceArr)) {
priceArr = [{specPrice: "", specNum: 9999}]
}
this.formData.attributeListPrice = priceArr
// canbuyMapcanbuy1
this.canbuyMap = {}
this.attrValueArr = []
this.formData.attributeList1.forEach((value, key) => {
value.canbuy = value.canbuy || 1
this.canbuyMap[key] = value.canbuy
for(let i = 0;i<value.title.length;i++){
this.attrValueArr.push({
parentName:key,
title:value.title[i]
})
}
});
// attributeListPricespecValueArr
this.specValueArr = JSON.parse(JSON.stringify(this.formData.attributeListPrice))
this.formData.sellTime = this.formData.sellBeginTime != '' ? 1 : 0
this.modalVisible = true;
},
checkSpecValue(index){
this.categorySonData[index].checked = !this.categorySonData[index].checked
if(this.modalclassType == 'shuxing'){
if(this.categorySonData[index].checked == true){
this.categorySonData[index].parentName = this.typeToAttrName
this.attrValueArr.push(this.categorySonData[index])
}else{
for(let i=0;i<this.attrValueArr.length;i++){
if(this.categorySonData[index].title == this.attrValueArr[i].title){
this.attrValueArr.splice(i,1)
}
}
}
}else{
//guige
if(this.categorySonData[index].checked == true){
this.specValueArr.push(this.categorySonData[index])
}else{
for(let i=0;i<this.specValueArr.length;i++){
if(this.categorySonData[index].id == this.specValueArr[i].id){
this.specValueArr.splice(i,1)
}
}
}
}
this.$forceUpdate()
},
//
clickLeftBtn(index) {
// canbuy
if(this.typeToAttrName){
this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1
}
for (var i = 0; i < this.categoryData.length; i++) {
if (i == index) {
this.categoryData[i].parentId = true
} else {
this.categoryData[i].parentId = false
}
}
this.categoryIndex = index
this.typeToAttrName = this.categoryData[this.categoryIndex].title
// canbuy
this.currentCanbuy = this.canbuyMap[this.typeToAttrName] || 1
this.getCateGorySon(this.categoryData[this.categoryIndex].id)
},
pictureAdd(id, huan) {
let that = this
uni.chooseMedia({
count: 9,
mediaType: ['image'],
sourceType: ['album', 'camera'],
success(res) {
uni.showLoading({
title: '加载中...',
mask: true
})
for (let i = 0; i < res.tempFiles.length; i++) {
that.upLoadFile(res.tempFiles[i].tempFilePath)
}
}
})
},
checkSpec(type){
let that = this
this.$refs.addTypeDialog.open()
this.modalclassType = type
this.NB.sendRequest("/app/productAttribute/selectByCategoryId",{categoryId:that.attrId}, false, 'post', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
that.categoryData = res.result
for (var i = 0; i < that.categoryData.length; i++) {
that.categoryData[i].title = that.categoryData[i].attributeName
if (i == that.categoryIndex) {
that.categoryData[i].parentId = true
} else {
that.categoryData[i].parentId = false
}
}
//parent
that.typeToAttrName = res.result[that.categoryIndex].title
// canbuy
that.currentCanbuy = that.canbuyMap[that.typeToAttrName] || 1
that.getCateGorySon(res.result[that.categoryIndex].id)
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
},
getCateGorySon(id){
let that = this
this.NB.sendRequest("/app/productAttributeValue/selectByAttributeId",{
id: id,
}, false, 'get', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
that.categorySonData = res.result
for (var i = 0; i < that.categorySonData.length; i++) {
that.categorySonData[i].title = that.categorySonData[i].value
that.$set(that.categorySonData[i], 'checked', false)
}
if(that.modalclassType == 'shuxing'){
for (var i = 0; i < that.categorySonData.length; i++) {
for (var m = 0; m < that.attrValueArr.length; m++) {
if(that.attrValueArr[m].title == that.categorySonData[i].title && that.attrValueArr[m].parentName == that.typeToAttrName){
that.$set(that.categorySonData[i], 'checked', true)
}
}
}
}else{
//guige
for (var i = 0; i < that.categorySonData.length; i++) {
for (var m = 0; m < that.specValueArr.length; m++) {
if(that.specValueArr[m].id == that.categorySonData[i].id){
that.$set(that.categorySonData[i], 'checked', true)
}
}
}
}
console.log()
that.$forceUpdate(that.categorySonData)
that.$forceUpdate(that.categoryData)
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
},
deldantiaoguige(index){
for (var m = 0; m < this.specValueArr.length; m++) {
if(this.specValueArr[m].id == this.formData.attributeListPrice[index].id){
this.specValueArr.splice(m,1)
this.formData.attributeListPrice.splice(index,1)
console.log("11",this.formData.attributeListPrice)
if(this.formData.attributeListPrice.length == 1){
this.formData.attributeListPrice = []
this.formData.attributeListPrice.push({
specName:"",
specPrice:'',
specNum:9999
})
this.specValueArr = []
}
this.$forceUpdate()
return
}
}
},
delGroup(index){
this.formData.productGroupBuyPrices.splice(index,1)
},
changePrice(index){
this.specValueArr[index].specPrice = this.formData.attributeListPrice[index].specPrice
},
changeCount(index){
this.specValueArr[index].specNum = this.formData.attributeListPrice[index].specNum
},
addGroup(){
let data = {
groupCount:'',
groupPrice:0
}
this.formData.productGroupBuyPrices.push(data)
},
async upLoadFile(path) {
let that = this;
let hiver_token = uni.getStorageSync("hiver_token")
await uni.uploadFile({
url: that.tui.interfaceUrl() + '/upload/file',
filePath: path,
name: 'file',
header: {
"content-type": "multipart/form-data",
'accessToken': hiver_token
},
formData: {},
success: (uploadFileRes) => {
let pathData = JSON.parse(uploadFileRes.data)
that.formData.productPicture = pathData.result
that.$forceUpdate()
},
fail: (err) => {
uni.hideLoading();
uni.showToast({
title: JSON.stringify(err),
icon: 'none'
})
}
});
await setTimeout(res => {
uni.hideLoading();
}, 1000)
}
}
}
</script>
<style lang="scss">
page,.page1{
page {
width: 100%;
height: 100%;
font-size: 24rpx;
background: #F5F8F5;
color: #00231C;
}
.page1 {
width: 100%;
height: 100%;
font-size: 24rpx;
position: relative;
}
.title {
background: url('https://jewel-shop.oss-cn-beijing.aliyuncs.com/8bc15960c2dc40268e295d6dd23aecce.png') no-repeat;
width: 100%;
height: 54%;
}
.title-sreach {
width: 100%;
display: flex;
height: 200rpx;
position: relative;
}
.back-btn {
position: absolute;
bottom: 0;
left: 0;
}
.title-name {
padding-top: 110rpx;
font-size: 36rpx;
font-weight: 700;
flex: 1;
text-align: center;
}
.formBox {
padding: 20rpx 26rpx;
border-radius: 14rpx;
box-shadow: 0 1px 20rpx 4rpx #e2e2e2;
background-color: #fff;
position: fixed;
top: 200rpx;
left: 2.5%;
width: 95%;
overflow: scroll;
height: 85%;
}
.upload-img {
width: 160rpx;
height: 160rpx;
}
button {
height: 90rpx;
line-height: 90rpx;
font-size: 36rpx;
background: linear-gradient(90deg, rgba(227, 255, 150, 1), rgba(166, 255, 234, 1));
border-radius: 20rpx;
font-weight: 700;
flex: 1;
}
.content-input {
width: auto;
position: relative;
overflow: hidden;
flex: 1;
line-height: 1;
font-size: 28rpx;
height: 70rpx;
border: 4rpx solid #eee;
padding-left: 20rpx;
border-radius: 10rpx;
}
.add-popup-content {
align-items: center;
justify-content: center;
padding: 30rpx 30rpx 30rpx 0;
width: 600rpx;
height: 1050rpx;
background-color: #fff;
overflow: scroll;
border-radius: 20rpx;
}
.xiangxi-box{
flex: 1;
border: 1px solid #eee;
border-radius: 20rpx;
}
.left-box {
width: 100%;
height: 100rpx;
font-size: 28rpx;
text-align: center;
line-height: 100rpx;
border-bottom: 1px solid #fff;
}
.left-box-hover {
width: 100%;
height: 100rpx;
font-size: 28rpx;
text-align: center;
line-height: 50rpx;
border-bottom: 1px solid #fff;
background-color: #fff;
}
.content-left {
width: 160rpx;
background: #eee;
height: 900rpx;
overflow: scroll;
scrollbar-width: none;
}
.content-low{
height: 60rpx;
padding: 0 10rpx;
border: 1px solid #eee;
display: inline-block;
margin: 10rpx;
font-weight: bold;
line-height: 60rpx;
}
.checked{
background: #60F3FF;
color: #fff !important;
}
.uni-input{
width: 200rpx;
height: 50rpx;
line-height: 50rpx;
border-radius: 10rpx;
border: 1px solid #eee;
text-align: center;
}
</style>

2
pages/login/login.vue

@ -316,6 +316,7 @@
//
checkShop(item) {
let that = this;
console.log('item、有没有attrid1',item)
uni.getSystemInfo({
success: function (res1) {
that.NB.sendRequest('/auth/chooseShop', {
@ -336,6 +337,7 @@
uni.setStorageSync('schoolShop',res.result.shop)
uni.setStorageSync('schoolShop',res.result.shop)
uni.setStorageSync('shopTakeaway',item.shopTakeaway)
uni.setStorageSync('attrId',item.shop.attrId)
uni.setStorageSync('area',JSON.stringify(item))
uni.setStorageSync("isShop",true)
setTimeout(() => {

268
pages/shop/addGoods.vue

@ -28,7 +28,6 @@
</view>
</view>
</view>
</uni-forms-item>
<uni-forms-item label="排名" name="orderFiled">
<input type="digit" class="content-input" v-model="formData.orderFiled" placeholder="请输入排名">
@ -57,9 +56,9 @@
<uni-forms-item label="拼团信息" name="productGroupBuyPrices">
<view>
<view v-for="(item,index) in formData.productGroupBuyPrices" :key="index" style="display: flex;margin-top:10rpx;">
<input class="content-input" v-model="item.groupCount" style="padding-right: 20rpx;margin-right: 20rpx;" placeholder="成团人数" />
<input class="content-input" v-model="item.groupPrice" style="padding-right: 20rpx;" placeholder="成团价格"/>
<button @click="delGroup(index)" v-if="formData.productGroupBuyPrices.length>1" style="width: 240rpx;height: 60rpx;line-height: 60rpx;color: red;border:none;background: #fff;">删除</button>
<input class="content-input" v-model="item.groupCount" style="padding-right: 20rpx;margin-right: 20rpx;width: 100px;" placeholder="成团人数" />
<input class="content-input" v-model="item.groupPrice" style="padding-right: 20rpx;width: 100px;" placeholder="成团价格"/>
<view @click="delGroup(index)" v-if="formData.productGroupBuyPrices.length>1" style="width: 240rpx;height: 60rpx;line-height: 60rpx;color: red;border:none;background: #fff;">删除</view>
</view>
<view @click="addGroup()" style="margin-top: 10rpx;width: 160rpx;height: 60rpx;text-align: center;line-height: 60rpx;background: rgba(0, 35, 28, 1);border-radius: 60rpx;color: rgba(166, 255, 234, 1);">
新增拼团
@ -68,8 +67,8 @@
</uni-forms-item>
<uni-forms-item label="商品属性" name="attributeList1">
<view style="display: flex;flex-direction: column;">
<view v-for="(value,key) in Array.from(formData.attributeList1)" :key="index" style="display: flex;">
{{value[0]}}:
<view v-for="(value,key) in Array.from(formData.attributeList1)" :key="key" style="display: flex;flex-wrap: wrap;align-items: center;margin-bottom: 10rpx;">
{{value[0]}}(可选{{value[1].canbuy || 1}}):
<view v-for="(item,index) in value[1].title" :key="index">
{{item}}
</view>
@ -126,16 +125,24 @@
<!-- 添加分类弹出层 -->
<uni-popup ref="addTypeDialog" background-color="#fff">
<view class="add-popup-content">
<view style="height:900rpx;">
<view class="content-left" style="float: left;">
<view style="height:900rpx;display: flex;">
<view class="content-left">
<view class="left-box" v-for="(item,index) in categoryData" :key="index"
:class="item.parentId ? 'left-box-hover':''" @tap="clickLeftBtn(index)">
<text style="width: 100%;height: 100rpx;line-height: 100rpx;display: inline-block;overflow: hidden;"
:class="item.parentId ? 'red' :''">{{item.title}}</text>
</view>
</view>
<view v-for="(item,index) in categorySonData" :key="index" @tap="checkSpecValue(index)" class="content-low" :class="item.checked?'checked':''">
{{item.title}}
<view style="flex: 1;position: relative;padding: 20rpx;">
<view v-for="(item,index) in categorySonData" :key="index" @tap="checkSpecValue(index)" class="content-low" :class="item.checked?'checked':''">
{{item.title}}
</view>
<view style="position: absolute;bottom: 0;">
<view style="font-size: 28rpx;line-height: 60rpx;font-weight: 700;">
该分类可选数量
</view>
<input type="digit" class="content-input" v-model="currentCanbuy" placeholder="该分类可选几个(默认1)">
</view>
</view>
</view>
<view slot="footer" style="display: flex;padding-left: 40rpx;margin-top: 20rpx;">
@ -153,6 +160,9 @@
return {
dataList: {},
modalType:0,
maxSelect:1,
currentCanbuy:1,
canbuyMap:{},
categoryData:[],
categoryIndex: 0,
modalclassType:'',
@ -164,6 +174,7 @@
formData: {
id: '',
shopId: '',
attrId:'',
categoryId: '', //id
categoryName: '', //
productPicture: '', //
@ -205,15 +216,7 @@
},
onShow() {
// uni.authorize({
// scope: 'scope.writePhotosAlbum',
// success() {
// },
// fail() {
// this.tui.toast("")
// }
// })
this.attrId = uni.getStorageSync('attrId');
this.typeItem = JSON.parse(JSON.stringify(this.typeItem)) || ''
if (this.typeItem) {
this.formData.categoryId = this.typeItem.id
@ -222,9 +225,10 @@
},
onLoad(option) {
this.getGategoryList()
if (option.dataList) {
if (option.dataList != undefined && option.dataList != null && option.dataList != 'undefined') {
this.dataList = JSON.parse(option.dataList)
this.NB.sendRequest("/app/product/getById/"+ this.dataList.id, {}, false, 'POST', 'application/json').then((res) => {
this.NB.sendRequest("/app/product/getById/" + this.dataList.id, {}, false, 'POST', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
this.modalType = 1
this.formData.id = res.result.id
@ -248,8 +252,12 @@
this.formData.categoryId = res.result.categoryId
this.edit(this.formData)
} else {
this.tui.toast(res.message)
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
}
},
@ -341,15 +349,14 @@
//
goGategoryLow() {
uni.navigateTo({
url: '/pages/shop/addType'
url: '/package1/myCenter/addType'
})
},
//
getGategoryList() {
this.NB.sendRequest("/app/productCategory/list", {
shopId:uni.getStorageSync('shopId')
}, false, 'get', 'application/json').then((res) => {
}, false, 'get', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
if (res.result.length > 0) {
if(this.formData.categoryId != '' && this.formData.categoryId != undefined){
@ -365,8 +372,12 @@
}
} else {
this.tui.toast(res.message)
uni.showToast({
title: res.message,
icon: 'none'
})
}
uni.hideLoading()
}).catch((res) => {})
},
//
@ -384,12 +395,21 @@
this.formData.attributeList = Object.fromEntries(this.formData.attributeList1)
this.formData.attributeList = JSON.stringify(this.formData.attributeList)
this.NB.sendRequest("/app/product/save", this.formData, false, 'post', 'application/json').then((res) => {
if(res.code == 200){
that.tui.toast("操作成功");
this.NB.sendRequest("/app/product/save",this.formData, false, 'post', 'application/json').then((res) => {
if (res.code == 200) {
uni.showToast({
title: "操作成功",
icon: 'none'
})
uni.navigateBack()
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
}).catch(() => {});
uni.hideLoading()
}).catch((res) => {})
} else if (this.modalType == 1) {
//
this.formData.attributeListPrice = JSON.stringify(this.formData.attributeListPrice)
@ -397,12 +417,21 @@
this.formData.attributeList = JSON.stringify(this.formData.attributeList)
this.formData.productPictures = []
this.NB.sendRequest("/app/product/edit", this.formData, false, 'post', 'application/json').then((res) => {
if(res.code == 200){
that.tui.toast("操作成功");
this.NB.sendRequest("/app/product/edit",this.formData, false, 'post', 'application/json').then((res) => {
if (res.code == 200) {
uni.showToast({
title: "操作成功",
icon: 'none'
})
uni.navigateBack()
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
}).catch(() => {});
uni.hideLoading()
}).catch((res) => {})
}
// }
// });
@ -425,23 +454,32 @@
},
guigeSubmit(){
if(this.modalclassType == 'shuxing'){
// canbuy
if(this.typeToAttrName){
this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1
}
for(let i=0;i<this.attrValueArr.length;i++){
let parentName = this.attrValueArr[i].parentName
let canbuyVal = parseInt(this.canbuyMap[parentName]) || 1
if(this.formData.attributeList1.size == 0){
//set has get
let data = {
title:[]
title:[],
canbuy: canbuyVal
}
data.title.push(this.attrValueArr[i].title)
this.formData.attributeList1.set(this.attrValueArr[i].parentName,data)
this.formData.attributeList1.set(parentName,data)
}else{
if(this.formData.attributeList1.has(this.attrValueArr[i].parentName) && this.formData.attributeList1.get(this.attrValueArr[i].parentName).title.indexOf(this.attrValueArr[i].title) == -1){
this.formData.attributeList1.get(this.attrValueArr[i].parentName).title.push(this.attrValueArr[i].title)
if(this.formData.attributeList1.has(parentName) && this.formData.attributeList1.get(parentName).title.indexOf(this.attrValueArr[i].title) == -1){
this.formData.attributeList1.get(parentName).title.push(this.attrValueArr[i].title)
this.formData.attributeList1.get(parentName).canbuy = canbuyVal
}else{
let data = {
title:[]
title:[],
canbuy: canbuyVal
}
data.title.push(this.attrValueArr[i].title)
this.formData.attributeList1.set(this.attrValueArr[i].parentName,data)
this.formData.attributeList1.set(parentName,data)
}
}
}
@ -517,11 +555,33 @@
let data = JSON.parse(str);
console.log('111111',data)
this.formData = data;
this.formData.attributeList1 = JSON.parse(this.formData.attributeList)
this.formData.attributeList1 = new Map(Object.entries(this.formData.attributeList1));
this.formData.attributeListPrice = JSON.parse(this.formData.attributeListPrice)
// attributeListstring
let attrObj = this.formData.attributeList
if (typeof attrObj === 'string' && attrObj !== '') {
attrObj = JSON.parse(attrObj)
}
if (!attrObj || typeof attrObj !== 'object') {
attrObj = {}
}
this.formData.attributeList1 = new Map(Object.entries(attrObj));
// attributeListPricestring
let priceArr = this.formData.attributeListPrice
if (typeof priceArr === 'string' && priceArr !== '') {
priceArr = JSON.parse(priceArr)
}
if (!Array.isArray(priceArr)) {
priceArr = [{specPrice: "", specNum: 9999}]
}
this.formData.attributeListPrice = priceArr
// canbuyMapcanbuy1
this.canbuyMap = {}
this.attrValueArr = []
this.formData.attributeList1.forEach((value, key) => {
value.canbuy = value.canbuy || 1
this.canbuyMap[key] = value.canbuy
for(let i = 0;i<value.title.length;i++){
this.attrValueArr.push({
parentName:key,
@ -529,7 +589,8 @@
})
}
});
this.specValueArr = this.formData.attributeListPrice
// attributeListPricespecValueArr
this.specValueArr = JSON.parse(JSON.stringify(this.formData.attributeListPrice))
this.formData.sellTime = this.formData.sellBeginTime != '' ? 1 : 0
@ -564,6 +625,10 @@
},
//
clickLeftBtn(index) {
// canbuy
if(this.typeToAttrName){
this.canbuyMap[this.typeToAttrName] = parseInt(this.currentCanbuy) || 1
}
for (var i = 0; i < this.categoryData.length; i++) {
if (i == index) {
this.categoryData[i].parentId = true
@ -573,6 +638,8 @@
}
this.categoryIndex = index
this.typeToAttrName = this.categoryData[this.categoryIndex].title
// canbuy
this.currentCanbuy = this.canbuyMap[this.typeToAttrName] || 1
this.getCateGorySon(this.categoryData[this.categoryIndex].id)
},
pictureAdd(id, huan) {
@ -593,82 +660,75 @@
})
},
checkSpec(type){
let that = this
this.$refs.addTypeDialog.open()
this.modalclassType = type
this.NB.sendRequest("/dictData/getByCondition", {
name: "",
status: "",
pageNumber: 1,
pageSize: 100000,
sort: 'sortOrder',
order: 'asc',
dictId: '2026945661353725952'
}, false, 'GET', 'application/json').then((res) => {
if(res.code == 200){
this.categoryData = res.result.content
for (var i = 0; i < this.categoryData.length; i++) {
if (i == this.categoryIndex) {
this.categoryData[i].parentId = true
this.NB.sendRequest("/app/productAttribute/selectByCategoryId",{categoryId:that.attrId}, false, 'post', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
that.categoryData = res.result
for (var i = 0; i < that.categoryData.length; i++) {
that.categoryData[i].title = that.categoryData[i].attributeName
if (i == that.categoryIndex) {
that.categoryData[i].parentId = true
} else {
this.categoryData[i].parentId = false
that.categoryData[i].parentId = false
}
}
//parent
this.typeToAttrName = res.result.content[this.categoryIndex].title
this.getCateGorySon(res.result.content[this.categoryIndex].id)
that.typeToAttrName = res.result[that.categoryIndex].title
// canbuy
that.currentCanbuy = that.canbuyMap[that.typeToAttrName] || 1
that.getCateGorySon(res.result[that.categoryIndex].id)
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
}).catch(() => {});
uni.hideLoading()
}).catch((res) => {})
},
getCateGorySon(id){
let that = this
this.NB.sendRequest("/dictData/getByCondition", {
name: "",
status: "",
pageNumber: 1,
pageSize: 100000,
sort: 'sortOrder',
order: 'asc',
dictId: id
}, false, 'GET', 'application/json').then((res) => {
if(res.code == 200){
this.categorySonData = res.result.content
if(this.modalclassType == 'shuxing'){
for (var i = 0; i < this.categorySonData.length; i++) {
if(this.attrValueArr.length>0){
let index1 = false
for (var m = 0; m < this.attrValueArr.length; m++) {
if(this.attrValueArr[m].title == this.categorySonData[i].title){
index1 = true
this.categorySonData[i].checked = true
}
}
if(index1){
this.categorySonData[i].checked = true
this.NB.sendRequest("/app/productAttributeValue/selectByAttributeId",{
id: id,
}, false, 'get', 'application/x-www-form-urlencoded').then((res) => {
if (res.code == 200) {
that.categorySonData = res.result
for (var i = 0; i < that.categorySonData.length; i++) {
that.categorySonData[i].title = that.categorySonData[i].value
that.$set(that.categorySonData[i], 'checked', false)
}
if(that.modalclassType == 'shuxing'){
for (var i = 0; i < that.categorySonData.length; i++) {
for (var m = 0; m < that.attrValueArr.length; m++) {
if(that.attrValueArr[m].title == that.categorySonData[i].title && that.attrValueArr[m].parentName == that.typeToAttrName){
that.$set(that.categorySonData[i], 'checked', true)
}
}else{
this.categorySonData[i].checked = false
}
}
}else{
//guige
for (var i = 0; i < this.categorySonData.length; i++) {
if(this.specValueArr.length>0){
for (var m = 0; m < this.specValueArr.length; m++) {
if(this.specValueArr[m].id == this.categorySonData[i].id){
this.categorySonData[i].checked = true
}
for (var i = 0; i < that.categorySonData.length; i++) {
for (var m = 0; m < that.specValueArr.length; m++) {
if(that.specValueArr[m].id == that.categorySonData[i].id){
that.$set(that.categorySonData[i], 'checked', true)
}
}else{
this.categorySonData[i].checked = false
}
}
}
console.log()
that.$forceUpdate(that.categorySonData)
that.$forceUpdate(that.categoryData)
} else {
uni.showToast({
title: res.message,
icon: 'none'
})
}
}).catch(() => {});
uni.hideLoading()
}).catch((res) => {})
},
deldantiaoguige(index){
for (var m = 0; m < this.specValueArr.length; m++) {
@ -710,7 +770,7 @@
let that = this;
let hiver_token = uni.getStorageSync("hiver_token")
await uni.uploadFile({
url: getApp().globalData.mainurl + '/upload/file',
url: that.tui.interfaceUrl() + '/upload/file',
filePath: path,
name: 'file',
header: {
@ -758,7 +818,7 @@
.title {
background: url('https://jewel-shop.oss-cn-beijing.aliyuncs.com/8bc15960c2dc40268e295d6dd23aecce.png') no-repeat;
width: 100%;
height: 13%;
height: 54%;
}
.title-sreach {
@ -785,6 +845,10 @@
border-radius: 14rpx;
box-shadow: 0 1px 20rpx 4rpx #e2e2e2;
background-color: #fff;
position: fixed;
top: 200rpx;
left: 2.5%;
width: 90%;
overflow: scroll;
height: 85%;
}

19
pages/shop/goodsList.vue

@ -37,12 +37,16 @@
</view>
<view class="box-right-num"></view>
<view class="box-right-price">
<view class="price-box">
<text>{{item.attributeListPrice | sliceMsg}}</text>
<text>价格</text>
</view>
<view class="price-box">
<text>{{item.lunchBox}}</text>
<text>餐盒费</text>
</view>
<view class="price-box">
<text>{{item.startPayNum}}</text>
<text>{{item.startPayNum?item.startPayNum:0}}</text>
<text>起售数量</text>
</view>
<view class="price-box" @tap="changeShow(index,'shopList')" style="flex: 1;text-align: right;padding-top: 26rpx;">
@ -151,7 +155,16 @@
}
},
filters: {
sliceMsg(val) {
var name = ''
if (typeof(val) == 'string') {
let newObj = JSON.parse(val)
for (let as in newObj) {
name = newObj[as].specPrice
}
}
return name;
},
},
onShow() {
this.getGategoryList()
@ -380,8 +393,6 @@
},
//
getGategoryList() {
this.NB.sendRequest("/app/productCategory/list", {
shopId:this.shopId
}, false, 'get', 'application/json').then((res) => {

Loading…
Cancel
Save