新增商品列表拖拽排序

This commit is contained in:
gyq
2024-06-06 09:13:37 +08:00
parent 526aeda953
commit 192c37c946
6 changed files with 74 additions and 13 deletions

View File

@@ -1,10 +1,10 @@
ENV = 'development' ENV = 'development'
# 接口地址 # 接口地址
# VUE_APP_BASE_API = 'http://192.168.2.44:8000' VUE_APP_BASE_API = 'http://192.168.2.42:8000'
# VUE_APP_BASE_API = 'http://192.168.2.133:8000' # VUE_APP_BASE_API = 'http://192.168.2.133:8000'
# VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn' # VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn'
VUE_APP_BASE_API = 'https://cashieradmin.sxczgkj.cn' # VUE_APP_BASE_API = 'https://cashieradmin.sxczgkj.cn'
# VUE_APP_BASE_API = 'http://192.168.2.96:8000' # VUE_APP_BASE_API = 'http://192.168.2.96:8000'
VUE_APP_WS_API = 'ws://192.168.2.128:8000' VUE_APP_WS_API = 'ws://192.168.2.128:8000'

View File

@@ -2,8 +2,8 @@ ENV = 'production'
# 如果使用 Nginx 代理后端接口,那么此处需要改为 '/',文件查看 Docker 部署篇Nginx 配置 # 如果使用 Nginx 代理后端接口,那么此处需要改为 '/',文件查看 Docker 部署篇Nginx 配置
# 接口地址,注意协议,如果你没有配置 ssl需要将 https 改为 http # 接口地址,注意协议,如果你没有配置 ssl需要将 https 改为 http
VUE_APP_BASE_API = 'https://cashieradmin.sxczgkj.cn' # VUE_APP_BASE_API = 'https://cashieradmin.sxczgkj.cn'
# VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn' VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn'
# VUE_APP_BASE_API = 'http://192.168.2.98:8000' # VUE_APP_BASE_API = 'http://192.168.2.98:8000'
# 如果接口是 http 形式, wss 需要改为 ws # 如果接口是 http 形式, wss 需要改为 ws
VUE_APP_WS_API = 'wss://123.56.110.252 VUE_APP_WS_API = 'wss://123.56.110.252

View File

@@ -45,7 +45,7 @@
"path-to-regexp": "2.4.0", "path-to-regexp": "2.4.0",
"qs": "^6.10.1", "qs": "^6.10.1",
"screenfull": "4.2.0", "screenfull": "4.2.0",
"sortablejs": "1.8.4", "sortablejs": "^1.15.2",
"vue": "^2.6.14", "vue": "^2.6.14",
"vue-amap": "^0.5.10", "vue-amap": "^0.5.10",
"vue-clipboard2": "^0.3.3", "vue-clipboard2": "^0.3.3",

View File

@@ -443,3 +443,15 @@ export function queryAllShopUser(params) {
} }
}); });
} }
/**
* 修改商品排序
* @returns
*/
export function upProSort(data) {
return request({
url: `/api/tbProduct/upProSort`,
method: "post",
data
});
}

View File

@@ -18,8 +18,8 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary">查询</el-button> <el-button type="primary" @click="getTableData">查询</el-button>
<el-button>重置</el-button> <el-button @click="resetHandle">重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
</div> </div>
@@ -122,8 +122,10 @@ export default {
methods: { methods: {
// 重置查询 // 重置查询
resetHandle() { resetHandle() {
this.tableData.page = 0; this.tableData.page = 0
this.query.name = '' this.query.name = ''
this.query.telphone = ''
this.query.status = 1
this.getTableData() this.getTableData()
}, },
// 分页回调 // 分页回调
@@ -133,8 +135,8 @@ export default {
}, },
// 获取商品列表 // 获取商品列表
async getTableData() { async getTableData() {
this.tableData.loading = true
try { try {
this.tableData.loading = true
const res = await storageList({ const res = await storageList({
...this.query, ...this.query,
page: this.tableData.page, page: this.tableData.page,

View File

@@ -31,8 +31,9 @@
</el-col> </el-col>
</el-row> </el-row>
</div> </div>
<div class="head-container"> <div class="head-container" id="table_drag">
<el-table :data="tableData.data" v-loading="tableData.loading"> <el-table ref="table" :data="tableData.data" v-loading="tableData.loading">
<el-table-column prop="id" label="ID" width="50px"></el-table-column>
<el-table-column label="商品信息"> <el-table-column label="商品信息">
<template v-slot="scope"> <template v-slot="scope">
<div class="shop_info"> <div class="shop_info">
@@ -79,7 +80,9 @@
</el-table-column> </el-table-column>
<el-table-column label="操作" width="200"> <el-table-column label="操作" width="200">
<template v-slot="scope"> <template v-slot="scope">
<router-link :to="{ path: '/product/add_shop', query: { goods_id: scope.row.id } }"> <el-button type="text" icon="el-icon-rank">排序</el-button>
<router-link :to="{ path: '/product/add_shop', query: { goods_id: scope.row.id } }"
style="margin-left: 20px !important;">
<el-button type="text" icon="el-icon-edit">编辑</el-button> <el-button type="text" icon="el-icon-edit">编辑</el-button>
</router-link> </router-link>
<el-popconfirm title="确定删除吗?" @confirm="delTableHandle([scope.row.id])"> <el-popconfirm title="确定删除吗?" @confirm="delTableHandle([scope.row.id])">
@@ -98,9 +101,10 @@
</template> </template>
<script> <script>
import Sortable from 'sortablejs'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import settings from '@/settings' import settings from '@/settings'
import { tbProduct, tbShopCategoryGet, tbProductDelete, tbProductIsHot } from '@/api/shop' import { tbProduct, tbShopCategoryGet, tbProductDelete, tbProductIsHot, upProSort } from '@/api/shop'
export default { export default {
data() { data() {
return { return {
@@ -124,8 +128,41 @@ export default {
mounted() { mounted() {
this.getTableData() this.getTableData()
this.tbShopCategoryGet() this.tbShopCategoryGet()
this.$nextTick(() => {
this.tableDrag()
})
}, },
methods: { methods: {
//表格拖炸
tableDrag() {
const el = document.querySelector('#table_drag .el-table__body-wrapper tbody')
new Sortable(el, {
animation: 150,
onEnd: async e => {
console.log('拖拽结束===', e);
if (e.oldIndex == e.newIndex) return
let oid = this.tableData.data[e.oldIndex].id
let nid = this.tableData.data[e.newIndex].id
let ids = this.tableData.data.map(item => item.id)
// let arr = [...this.tableData.data] // 获取表数据
// arr.splice(e.oldIndex, 1, ...arr.splice(e.newIndex, 1, arr[e.oldIndex])); // 数据处理
// this.$nextTick(() => {
// this.tableData.data = [...arr]
// })
try {
await upProSort({
strId: oid,
endId: nid,
ids: ids
})
// await this.getTableData()
window.location.reload();
} catch (error) {
console.log(error);
}
}
});
},
// 设置热门 // 设置热门
async changeHot(e, row) { async changeHot(e, row) {
console.log(row) console.log(row)
@@ -145,6 +182,7 @@ export default {
this.query.name = '' this.query.name = ''
this.query.categoryId = '' this.query.categoryId = ''
this.query.typeEnum = '' this.query.typeEnum = ''
this.tableData.page = 0
this.getTableData() this.getTableData()
}, },
// 分页回调 // 分页回调
@@ -199,6 +237,15 @@ export default {
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.handle {
font-size: 18px;
color: #999;
&:hover {
cursor: grab;
}
}
.shop_info { .shop_info {
display: flex; display: flex;