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

完成导入产品线功能

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