提交 15096493 authored 作者: 刘旭's avatar 刘旭

完成导入产品线功能

上级 ab31c6be
......@@ -34,7 +34,10 @@ export const getProductLineItemAdd = (data: any) =>
// 产品线-删除组成商品
export const getProductLineReAdd = (data: any) =>
request('/wx/productLine/reAdd', 'POST', data);
// 产品线-导入
export const productLineUpload = (data: any) =>
request('/wx/productLine/upload', 'POST', data);
export const getLineSpecification = (data: any) =>
request('/wx/productLine/getSpecification', 'POST', data);
\ No newline at end of file
......@@ -724,8 +724,6 @@ export default {
that.checkInpath(index1);
// 如果全部选完
that.checkSelectShop();
console.log(this.goodsInfo, 'all');
}
},
// 检测是否已经选完sku
......
......@@ -4,10 +4,24 @@
<view class="u-menu-wrap">
<view class="right-cates">
<view class="right-cates-list">
<block v-for="(item, index) in lineList">
<u-image :width="item?.imageWidth" :height="item?.imageHeight" mode="scaleToFill"
:src="baseUrl + item.url"></u-image>
</block>
<u-cell-group v-if="flag">
<u-cell-item icon="" :title="item.goodsName" :arrow="false"
v-for="(item, index) in lineList">
<!-- <template #title>
{{ item.goodsName }}
</template> -->
<template #right-icon>
<view style="margin-left: 30rpx;">
<u-tag v-show="item.size" :text="item.size" type="info" size="mini"
style="margin-right: 10rpx;" />
<u-tag v-show="item.SDTrack" :text="item.SDTrack" type="info" size="mini"
style="margin-right: 10rpx;" />
<u-tag v-show="item.Segs" :text="item.Segs" type="info" size="mini" />
</view>
</template>
</u-cell-item>
</u-cell-group>
<view style="height: 50px;" />
</view>
</view>
......@@ -28,12 +42,14 @@
<script lang="ts" setup>
import { ref, nextTick, onMounted } from 'vue';
import { onLoad, onBackPress } from '@dcloudio/uni-app';
import { onBackPress } from '@dcloudio/uni-app';
import {
addProductLineCart,
productLineCollect,
delProductLineCollect,
getProductLineIndex,
getLineSpecification,
getProductLineReAdd
} from '@/api/productLine';
import config from '@/utils/config';
import setTitle from './components/setTitle.vue';
......@@ -42,13 +58,11 @@ let baseUrl = config.baseUrl;
let lineList: any = ref([]); //右侧tabber数据
let setTitleRef = ref();
let star = ref(); // 控制收藏
let itemHeight = ref(40)
let flag = ref(true)
let model = ref({
show: false,
content: '确定重置所选产品?',
});
let flag = ref(false);
let options = ref([
// {
......@@ -78,36 +92,58 @@ let buttonGroup = ref([
]);
let lineId = ref(); // 修改的产品线id
let windowHeight = ref() // 屏幕的高度
let collectData = ref({})
// onLoad(() => {
// // uploadLine()
// uni.$on('importData', (res: any) => {
// console.log(res);
// })
// });
let specificationData = ref([] as any)
onMounted(() => {
lineList.value = []
setTitleRef.value.title = ''
uni.$on('importProductLineData', (res: any) => {
// 判断是否为导入产品线
lineId.value = null
if (res.data.lineId) {
lineId.value = res.data.lineId
setTitleRef.value.title = res.data.lineName
} else lineId.value = null // 判断是否为导入产品线
let dataArr = [] as any
// 集合goodsId数组
res.data.cartList.map((item: any) => {
if (item.goodsId) dataArr.push(item.goodsId)
})
// 获取规格键值集合
getLineSpecification(dataArr).then((res: any) => {
if (res.data.code === 200) specificationData.value = res.data.data
})
handleEditProductLineData(res.data)
console.log(res.data);
// console.log(res.data);
})
})
let fromTop = ref() // + 到顶部的距离
// 动态获取 + 到顶部的距离
let getInfo = () => {
nextTick(() => {
let query = uni.createSelectorQuery().in(this).select('.add');
query.boundingClientRect((res: any) => {
fromTop.value = res?.top + 90
// console.log(res, 'Top.value', res?.top);
}).exec()
// 匹配规格 SDTrack: 单轨/双轨 size: 长度(MM) Segs: 分段数
let matchSpecifications = () => {
lineList.value.forEach((line: any) => {
for (let spec in specificationData.value) {
if (line.goodsId == spec) {
for (let item in specificationData.value[spec])
if (item === "长度(MM)" || item === "单轨/双轨" || item === "分段数") {
specificationData.value[spec][item].map((i: any) => {
let index = line.specifications.indexOf(i.value)
if (index !== -1) {
switch (i.specification) {
case '长度(MM)':
line['size'] = i.value
break;
case '单轨/双轨':
line['SDTrack'] = i.value
break;
case '分段数':
line['Segs'] = i.value
break;
}
}
})
}
}
}
})
}
......@@ -116,7 +152,7 @@ let initProductLine = (lineId: number) => {
// 获取产品线详细数据
getProductLineIndex({ lineId }).then((res: any) => {
if (res.data.code === 200) {
handleEditProductLineData(res.data.data)
// handleEditProductLineData(res.data.data)
}
});
};
......@@ -127,36 +163,19 @@ let handleEditProductLineData = (editData: any) => {
// 处理子组件数据更新延迟问题
nextTick(() => {
// 处理数据
editData.cartList.forEach((item: any) => {
item['name'] = item.goodsName;
item['show'] = false;
item['url'] = item.picUrl;
item['status'] = 1;
});
// editData.cartList.forEach((item: any) => {
// item['name'] = item.goodsName;
// item['url'] = item.picUrl;
// });
// 合并数据
lineList.value = [...editData.cartList, ...lineList.value]
if (editData.cartList.length >= 15) itemHeight.value = 28
if (editData.lineName)
setTitleRef.value.title = editData.lineName;
if (!editData.isUpload) heightChange()
else getImageInfo()
flag.value = true;
});
}
// 控制列表的高度
let heightChange = () => {
nextTick(() => {
getInfo()
getImageInfo()
setTimeout(() => {
if (windowHeight.value - fromTop.value < 100) {
if (itemHeight.value === 25) return
itemHeight.value = itemHeight.value - 5
}
matchSpecifications()
}, 50)
})
getImageInfo()
});
}
// 获取图片尺寸
......@@ -253,7 +272,23 @@ let addCart = () => {
});
// console.log(data, '加入购物车成功');
// 添加到购物车
addProductLineCart(data).then((res: any) => {
data['isUpload'] = true
if (lineId.value) {
data['lineId'] = lineId.value
getProductLineReAdd(data).then((res: any) => {
if (res.data.code === 200) {
uni.showToast({
title: '保存购物车成功',
icon: 'none',
});
lineList.value = []
setTitleRef.value.title = ''
setTimeout(() => {
uni.reLaunch({ url: './productLine' })
}, 50)
}
})
} else addProductLineCart(data).then((res: any) => {
if (res.data.code === 200) {
uni.showToast({
title: '加入购物车成功',
......@@ -261,7 +296,9 @@ let addCart = () => {
});
lineList.value = []
setTitleRef.value.title = ''
uni.navigateBack()
setTimeout(() => {
uni.reLaunch({ url: './productLine' })
}, 50)
}
});
});
......@@ -280,6 +317,7 @@ let buyNow = () => {
title: '请先删除带红色图标的失效商品',
icon: 'none',
});
data['isUpload'] = true
addProductLineCart(data).then((res: any) => {
if (res.data.code === 200) {
if (!uni.getStorageSync('addressId')) {
......@@ -341,13 +379,12 @@ let onConfirm = () => {
// 返回刷新页面
onBackPress((options: any) => {
if (options.from === 'backbutton') {
let pages = getCurrentPages(); //获取所有页面的数组对象
let currPage: any = pages[pages.length - 2]; //当前页面
uni.reLaunch({
url: '/' + currPage.route,
});
}
// if (options.from === 'backbutton') {
// uni.navigateBack()
// }
setTimeout(() => {
uni.reLaunch({ url: './productLine' })
}, 50)
})
</script>
......@@ -355,6 +392,12 @@ onBackPress((options: any) => {
<style lang="scss" scoped>
$nav-heigth: var(--window-bottom);
:deep(.u-cell_title) {
// min-width: 100px;
// max-width: 200px;
width: 150px;
}
.add {
position: absolute;
width: 180px;
......@@ -380,7 +423,7 @@ $nav-heigth: var(--window-bottom);
min-height: 100vh;
.right-cates-list {
width: 80px;
width: 100%;
display: flex;
flex-direction: column;
justify-content: flex-start;
......@@ -413,5 +456,6 @@ $nav-heigth: var(--window-bottom);
width: 100%;
display: inline;
transform: none;
z-index: 999;
}
</style>
......@@ -177,7 +177,18 @@ let initProductLine = (lineId: number) => {
// 获取产品线详细数据
getProductLineIndex({ lineId }).then((res: any) => {
if (res.data.code === 200) {
handleEditProductLineData(res.data.data)
console.log(res.data.data);
if (res.data.data.cartList.length > 20) {
uni.navigateTo({
url: './importProductLine',
success: () => {
setTimeout(() => {
uni.$emit('importProductLineData', { data: res.data.data })
}, 300);
}
})
}
else handleEditProductLineData(res.data.data)
}
});
};
......@@ -606,6 +617,7 @@ let uploadLine = () => {
count: 0,
extension: ['.xlsx'],
success(res: any) {
let fileName = res.tempFiles[0].name
flag.value = false;
uni.showLoading({
title: '加载中'
......@@ -617,18 +629,17 @@ let uploadLine = () => {
header: { Authorization: uni.getStorageSync('token') },
success(uploadFileRes: any) {
uni.hideLoading()
let res = JSON.parse(uploadFileRes.data)
if (res.code === 200) {
if (res.data.cartList.length <= 20) {
console.log(res);
let fileRes = JSON.parse(uploadFileRes.data)
if (!fileRes.data.isError) {
if (fileRes.data.cartList.length <= 20) {
// 判断是否为导入产品线
isUpload.value = res.data.isUpload
isUpload.value = fileRes.data.isUpload
// 清空标题
store.title = '';
setTitleRef.value.title = store.title;
lineId.value = null
// console.log(res.data.isUpload);
handleEditProductLineData(res.data)
handleEditProductLineData(fileRes.data)
} else {
uni.showToast({
title: '导入商品数量超出上限,跳转页面后,将只用于下单或加入购物车',
......@@ -638,13 +649,29 @@ let uploadLine = () => {
url: './importProductLine',
success: () => {
setTimeout(() => {
uni.$emit('importProductLineData', { data: res.data })
uni.$emit('importProductLineData', { data: fileRes.data })
}, 300);
}
})
}
})
}
} else {
flag.value = true;
let key = fileRes.data.key
uni.downloadFile({
url: baseUrl + '/wx/productLine/error/download/' + key,
header: { 'Authorization': uni.getStorageSync('token') },
success: (res: any) => {
let downloadElement = document.createElement('a');
downloadElement.href = res.tempFilePath;
downloadElement.download = fileName; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(res.tempFilePath); //释放掉blob对象
}
})
}
},
fail() {
......
......@@ -77,7 +77,7 @@ let orderBtnList = ref([
},
{
url: '/static/my/wenjianshengchengguize.png',
text: '待生',
text: '待生',
badge: 1,
type: 'error',
},
......
......@@ -2,8 +2,8 @@ const CONFIG: any = {
// 开发环境配置
development: {
assetsPath: 'http://192.168.60:81', // 静态资源路径
// baseUrl: 'http://192.168.0.9:8089', // 后台接口请求地址
baseUrl: 'http://192.168.0.60:81', // 后台接口请求地址
baseUrl: 'http://192.168.0.9:8089', // 后台接口请求地址
// baseUrl: 'http://192.168.0.60:81', // 后台接口请求地址
hostUrl: 'http://192.168.0.60:81', // H5地址(前端运行地址)
websocketUrl: '', // websocket服务端地址
},
......
......@@ -2,8 +2,8 @@ import config from './config';
const baseUrl = config.baseUrl;
// 封装公共申请办法
function request(url: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE', data?: object | any) {
return new Promise(function(resolve, reject) {
function request(url: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE', data?: object | any, responseType?: string) {
return new Promise(function (resolve, reject) {
let header: any;
uni.showLoading({
title: '加载中...',
......@@ -34,6 +34,7 @@ function request(url: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE', data?:
method: method,
data: data,
header: header,
responseType,
success(res: any) {
uni.hideLoading();
if (res.data.code == 200) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论