refactor: 接口路径变更和删除依赖包

Former-commit-id: 528a17fec4091a54ae63c7cc612c7671d0ed56ae
This commit is contained in:
郝先瑞
2022-07-05 08:03:39 +08:00
parent 410c5ed56d
commit c14a00a14f
26 changed files with 510 additions and 359 deletions

View File

@@ -53,10 +53,7 @@
<single-upload v-model="item.url" :show-close="true" />
<div v-if="item.url">
<el-link
type="danger"
class="button"
v-if="item.main == true"
<el-link type="danger" class="button" v-if="item.main == true"
>商品主图</el-link
>
<el-link
@@ -64,7 +61,8 @@
class="button"
v-else
@click="changeMainPicture(index)"
>设为主图</el-link>
>设为主图</el-link
>
</div>
<div v-else>
@@ -120,7 +118,7 @@ const state = reactive({
brandOptions: [] as Array<any>,
// 商品图册
pictures: [
{ url: undefined, main: true }, // main = true 代表主图,可切换
{ url: undefined, main: true }, // maintrue代表主图可切换
{ url: undefined, main: false },
{ url: undefined, main: false },
{ url: undefined, main: false },
@@ -142,10 +140,12 @@ function loadData() {
});
const goodsId = goodsInfo.value.id;
if (goodsId) {
// 主图
const mainPicUrl = goodsInfo.value.picUrl;
if (mainPicUrl) {
state.pictures.filter((item) => item.main)[0].url = mainPicUrl;
}
// 商品副图
const subPicUrls = goodsInfo.value.subPicUrls;
if (subPicUrls && subPicUrls.length > 0) {
for (let i = 1; i <= subPicUrls.length; i++) {
@@ -175,18 +175,21 @@ function handlePrev() {
function handleNext() {
dataFormRef.value.validate((valid: any) => {
if (valid) {
// 商品图
// 商品
const mainPicUrl = state.pictures
.filter((item) => item.main == true && item.url)
.map((item) => item.url);
if (mainPicUrl && mainPicUrl.length > 0) {
goodsInfo.value.picUrl = mainPicUrl[0];
}
const subPicUrl = state.pictures
// 商品副图
const subPicUrls = state.pictures
.filter((item) => item.main == false && item.url)
.map((item) => item.url);
if (subPicUrl && subPicUrl.length > 0) {
goodsInfo.value.subPicUrls = subPicUrl;
if (subPicUrls && subPicUrls.length > 0) {
goodsInfo.value.subPicUrls = subPicUrls;
} else {
goodsInfo.value.subPicUrls = [];
}
emit('next');
}

View File

@@ -180,34 +180,23 @@
</template>
<script setup lang="ts">
import {
computed,
nextTick,
onMounted,
reactive,
ref,
toRefs,
watch,
} from 'vue';
import { computed, onMounted, reactive, ref, toRefs, watch } from 'vue';
import { useRouter } from 'vue-router';
import { Plus, Minus } from '@element-plus/icons-vue';
import { ElNotification, ElMessage, ElTable, ElForm } from 'element-plus';
// API 引用
import { listAttributes } from '@/api/pms/attribute';
import { addGoods, updateGoods } from '@/api/pms/goods';
import { addSpu, updateSpu } from '@/api/pms/goods';
// 自定义组件引用
import SvgIcon from '@/components/SvgIcon/index.vue';
import SingleUpload from '@/components/Upload/SingleUpload.vue';
// import Sortable from 'sortablejs'
const emit = defineEmits(['prev', 'next', 'update:modelValue']);
/* const proxy = getCurrentInstance(); */
const router = useRouter();
/* const specTableRef = ref(ElTable); */
const specFormRef = ref(ElForm);
const skuFormRef = ref(ElForm);
@@ -326,10 +315,6 @@ function loadData() {
handleSpecChange();
handleSpecReorder();
nextTick(() => {
// registerSpecDragSortEvent()
});
}
/**
@@ -349,28 +334,6 @@ function handleSpecReorder() {
});
}
/**
* 注册拖拽排序事件
*/
/*function registerSpecDragSortEvent() {
const el = specTableRef.value.$el.querySelectorAll('.el-table__body-wrapper > table > tbody')[0]
Sortable.create(el, {
ghostClass: 'sortable-ghost', // Class name for the drop placeholder,
setData: function (dataTransfer: any) {
dataTransfer.setData('Text', '')
},
onEnd: (evt: any) => {
// oldIndex 拖拽行当前所在索引
// newIndex 拖拽行目标索引
const targetRow = state.specForm.specList.splice(evt.oldIndex, 1)[0] // 返回被删除的行
state.specForm.specList.splice(evt.newIndex, 0, targetRow) // 拼接
generateSkuList() // 重新生成sku
handleSpecChange()
handleSpecReorder()
}
})
}*/
/**
* 根据商品规格笛卡尔积生成SKU列表
*
@@ -623,7 +586,7 @@ function submitForm() {
const goodsId = goodsInfo.value.id;
if (goodsId) {
// 编辑商品提交
updateGoods(goodsId, submitsData).then(() => {
updateSpu(goodsId, submitsData).then(() => {
router.push({ path: '/pms/goods' });
ElNotification({
title: '提示',
@@ -633,7 +596,7 @@ function submitForm() {
});
} else {
// 新增商品提交
addGoods(submitsData).then(() => {
addSpu(submitsData).then(() => {
router.push({ path: '/pms/goods' });
ElNotification({
title: '提示',
@@ -648,21 +611,6 @@ function submitForm() {
});
}
/* function openFullScreen() {
state.loading = (proxy as any).$loading({
lock: true,
text: "商品信息提交中,请等待...",
spinner: "el-icon-loading",
background: "rgba(0, 0, 0, 0.7)",
});
}
function closeFullScreen() {
if (state.loading) {
(state.loading as any).close();
}
} */
function handlePrev() {
emit('prev');
}

View File

@@ -51,7 +51,7 @@ import GoodsInfo from './components/GoodsInfo.vue';
import GoodsAttribute from './components/GoodsAttribute.vue';
import GoodsStock from './components/GoodsStock.vue';
import { getGoodsDetail } from '@/api/pms/goods';
import { getSpuDetail } from '@/api/pms/goods';
import { useRoute } from 'vue-router';
import { GoodsDetail } from '@/types/api/pms/goods';
@@ -74,7 +74,7 @@ function loadData() {
const goodsId = route.query.goodsId as string;
if (goodsId) {
getGoodsDetail(goodsId).then((response) => {
getSpuDetail(goodsId).then((response) => {
state.goodsInfo = response.data;
state.goodsInfo.originPrice = (state.goodsInfo.originPrice as any) / 100;
state.goodsInfo.price = (state.goodsInfo.price as any) / 100;

View File

@@ -18,7 +18,7 @@ import {
Delete,
View,
} from '@element-plus/icons-vue';
import { listPageGoods, deleteGoods } from '@/api/pms/goods';
import { listSpuPages, deleteSpu } from '@/api/pms/goods';
import { listCascadeCategories } from '@/api/pms/category';
import { GoodsItem, GoodsQueryParam } from '@/types/api/pms/goods';
import { moneyFormatter } from '@/utils/filter';
@@ -59,7 +59,7 @@ const {
function handleQuery() {
state.loading = true;
listPageGoods(state.queryParams).then(({ data }) => {
listSpuPages(state.queryParams).then(({ data }) => {
state.goodsList = data.list;
state.total = data.total;
state.loading = false;
@@ -100,7 +100,7 @@ function handleDelete(row: any) {
type: 'warning',
})
.then(function () {
return deleteGoods(ids);
return deleteSpu(ids);
})
.then(() => {
ElMessage.success('删除成功');