sj
2 years ago
15 changed files with 350 additions and 38 deletions
@ -0,0 +1,27 @@
|
||||
import request from '@/utils/request' |
||||
|
||||
export function add(data) { |
||||
return request({ |
||||
url: 'bxg/api/yxStoreHotList', |
||||
method: 'post', |
||||
data |
||||
}) |
||||
} |
||||
|
||||
export function del(ids) { |
||||
return request({ |
||||
url: 'bxg/api/yxStoreHotList/', |
||||
method: 'delete', |
||||
data: ids |
||||
}) |
||||
} |
||||
|
||||
export function edit(data) { |
||||
return request({ |
||||
url: 'bxg/api/yxStoreHotList', |
||||
method: 'put', |
||||
data |
||||
}) |
||||
} |
||||
|
||||
export default { add, edit, del } |
@ -0,0 +1,281 @@
|
||||
<template> |
||||
<div class="app-container"> |
||||
<!--工具栏--> |
||||
<div class="head-container"> |
||||
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'--> |
||||
<crudOperation :permission="permission" /> |
||||
<!--表单组件--> |
||||
<el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px"> |
||||
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px"> |
||||
<!-- <el-form-item label="榜单列表ID">--> |
||||
<!-- <el-input v-model="form.id" style="width: 370px;" />--> |
||||
<!-- </el-form-item>--> |
||||
<el-form-item label="榜单名称" prop="listName"> |
||||
<el-input v-model="form.listName" style="width: 370px;" /> |
||||
</el-form-item> |
||||
<el-form-item label="商品列表"> |
||||
<el-cascader |
||||
:props="props" |
||||
clearable |
||||
@change="cascaderChange($event)" |
||||
v-model="productList" |
||||
placeholder="试试搜索:眼镜" |
||||
:options="cateList" |
||||
ref="quitCascader" |
||||
filterable></el-cascader> |
||||
</el-form-item> |
||||
|
||||
<el-form-item label="是否显示"> |
||||
<!-- <el-input v-model="form.isShow" style="width: 370px;" />--> |
||||
<el-radio-group v-model="form.isShow" style="width: 178px"> |
||||
<el-radio :label="1">显示</el-radio> |
||||
<el-radio :label="0">隐藏</el-radio> |
||||
</el-radio-group> |
||||
</el-form-item> |
||||
<el-form-item label="排序"> |
||||
<el-input v-model="form.sort" style="width: 370px;" type="number" /> |
||||
</el-form-item> |
||||
<!-- <el-form-item label="添加时间">--> |
||||
<!-- <el-input v-model="form.createTime" style="width: 370px;" />--> |
||||
<!-- </el-form-item>--> |
||||
<!-- <el-form-item label="updateTime">--> |
||||
<!-- <el-input v-model="form.updateTime" style="width: 370px;" />--> |
||||
<!-- </el-form-item>--> |
||||
<!-- <el-form-item label="删除状态">--> |
||||
<!-- <el-input v-model="form.isDel" style="width: 370px;" />--> |
||||
<!-- </el-form-item>--> |
||||
<!-- <el-form-item label="tenantId">--> |
||||
<!-- <el-input v-model="form.tenantId" style="width: 370px;" />--> |
||||
<!-- </el-form-item>--> |
||||
</el-form> |
||||
<div slot="footer" class="dialog-footer"> |
||||
<el-button type="text" @click="crud.cancelCU">取消</el-button> |
||||
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button> |
||||
</div> |
||||
</el-dialog> |
||||
<!--表格渲染--> |
||||
<el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler"> |
||||
<el-table-column type="selection" width="55" /> |
||||
<el-table-column v-if="columns.visible('id')" prop="id" label="榜单列表ID" /> |
||||
<el-table-column v-if="columns.visible('listName')" prop="listName" label="榜单名称" /> |
||||
<el-table-column v-if="columns.visible('sort')" prop="sort" label="排序" /> |
||||
<el-table-column v-if="columns.visible('productlist')" prop="productlist" label="商品列表" > |
||||
<template slot-scope="scope"> |
||||
<div v-for="(item,index) in JSON.parse(scope.row.productList)"> |
||||
<span>top{{index+1}}:{{item.storeName}}</span> |
||||
</div> |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column v-if="columns.visible('isShow')" label="状态" align="center" prop="isShow"> |
||||
<template slot-scope="scope"> |
||||
<div> |
||||
<el-tag v-if="scope.row.isShow === 1" :type="''">显示</el-tag> |
||||
<el-tag v-else :type=" 'info' ">隐藏</el-tag> |
||||
</div> |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column v-if="columns.visible('createTime')" prop="createTime" label="添加时间"> |
||||
<template slot-scope="scope"> |
||||
<span>{{ parseTime(scope.row.createTime) }}</span> |
||||
</template> |
||||
</el-table-column> |
||||
<el-table-column v-if="columns.visible('updateTime')" prop="updateTime" label="更新时间"> |
||||
<template slot-scope="scope"> |
||||
<span>{{ parseTime(scope.row.updateTime) }}</span> |
||||
</template> |
||||
</el-table-column> |
||||
<!-- <el-table-column v-if="columns.visible('isDel')" prop="isDel" label="删除状态" />--> |
||||
<!-- <el-table-column v-if="columns.visible('tenantId')" prop="tenantId" label="tenantId" />--> |
||||
<el-table-column v-permission="['admin','yxStoreHotList:edit','yxStoreHotList:del']" label="操作" width="150px" align="center"> |
||||
<template slot-scope="scope"> |
||||
<udOperation |
||||
:data="scope.row" |
||||
:permission="permission" |
||||
/> |
||||
</template> |
||||
</el-table-column> |
||||
</el-table> |
||||
<!--分页组件--> |
||||
<pagination /> |
||||
</div> |
||||
</div> |
||||
</template> |
||||
|
||||
<script> |
||||
import Cookies from "js-cookie"; |
||||
import crudYxStoreHotList from '@/api/bxg/yxStoreHotList' |
||||
import CRUD, { presenter, header, form, crud } from '@crud/crud' |
||||
import rrOperation from '@crud/RR.operation' |
||||
import crudOperation from '@crud/CRUD.operation' |
||||
import udOperation from '@crud/UD.operation' |
||||
import pagination from '@crud/Pagination' |
||||
import MaterialList from "@/components/material"; |
||||
import {getInfo} from "@/api/bxg/yxStoreProduct"; |
||||
import {initData} from "@/api/bxg/data"; |
||||
|
||||
// crud交由presenter持有 |
||||
const defaultCrud = CRUD({ title: '热门榜单', url: 'bxg/api/yxStoreHotList', sort: 'id,desc', crudMethod: { ...crudYxStoreHotList }}) |
||||
const defaultForm = { id: null, listName: null, sort: null, productList: null, isShow: 1, |
||||
createTime: null, updateTime: null, isDel: null, tenantId: Cookies.get('tenantId') } |
||||
export default { |
||||
name: 'YxStoreHotList', |
||||
components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList}, |
||||
mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()], |
||||
data() { |
||||
return { |
||||
oldProductList:[], |
||||
props: { multiple: true }, |
||||
productList:[], |
||||
cateList:[], |
||||
permission: { |
||||
add: ['admin', 'yxStoreHotList:add'], |
||||
edit: ['admin', 'yxStoreHotList:edit'], |
||||
del: ['admin', 'yxStoreHotList:del'] |
||||
}, |
||||
rules: { |
||||
listName: [ |
||||
{ required: true, message: '榜单名称不能为空', trigger: 'blur' } |
||||
] |
||||
} } |
||||
}, |
||||
watch: { |
||||
}, |
||||
mounted () { |
||||
this.getInfo(); |
||||
}, |
||||
methods: { |
||||
//需要使显示循序变为点击顺序 |
||||
// cascaderChange(val) { |
||||
// this.oldProductList= val; |
||||
// //如果只选了一个不需要判断,正常显示 |
||||
// if (val.length<=1){ |
||||
// // this.oldProductList=[] |
||||
// }else { |
||||
// // productList=this.getCascader(val,this.$refs.cascader.getCheckedNodes()); |
||||
// // this.label = productList.label; //回显的数据 |
||||
// console.log('val',val, this.oldProductList,) |
||||
// this.productList=[]; |
||||
// // console.log('1111',val) |
||||
// } |
||||
// }, |
||||
cascaderChange(val) { |
||||
this.productList=[] |
||||
let productList=[] |
||||
productList=this.getCascader(val,this.oldProductList); |
||||
this.productList = productList //回显的数据 |
||||
this.oldProductList=productList; |
||||
this.form.productList=JSON.stringify(this.productList.map(item=>item[1])); |
||||
this.$refs.quitCascader.inputValue="你想要框内显示的值" |
||||
}, |
||||
getCascader(newVal,oldVal) { |
||||
let productList = [] |
||||
console.log('val',newVal,'element',oldVal) |
||||
//这次只选了一个,返回选择的 |
||||
if(newVal.length <= 1) { |
||||
productList=newVal; |
||||
//比上一次的减少了 |
||||
}else if(newVal.length < this.oldProductList.length) { |
||||
let newValList=newVal.map(item=>item[1]) |
||||
let oldValList=oldVal.map(item=>item[1]) |
||||
let diff = newValList.concat(oldValList).filter((value, index, arr) => { |
||||
return arr.indexOf(value) === arr.lastIndexOf(value) |
||||
}); |
||||
oldVal.forEach((item,index)=> { |
||||
diff.forEach(ele=>{ |
||||
if(item[1]==ele) { |
||||
oldVal.splice(index,1) |
||||
} |
||||
}) |
||||
}) |
||||
productList=oldVal |
||||
//新增 |
||||
}else { |
||||
let newValList=newVal.map(item=>item[1]) |
||||
let oldValList=oldVal.map(item=>item[1]) |
||||
let diff = newValList.concat(oldValList).filter((value, index, arr) => { |
||||
return arr.indexOf(value) === arr.lastIndexOf(value) |
||||
}); |
||||
// console.log('newValList',newValList,oldValList,diff) |
||||
newVal.forEach((item)=> { |
||||
diff.forEach(ele=>{ |
||||
if(item[1]==ele) { |
||||
oldVal.push(item) |
||||
} |
||||
}) |
||||
}); |
||||
productList=oldVal |
||||
console.log('productList',productList) |
||||
} |
||||
return productList; |
||||
}, |
||||
change(val){ |
||||
console.log('选的子级',val) |
||||
let productList=val.map(item=>item[1]) |
||||
this.form.productList=JSON.stringify(productList) |
||||
console.log('选的子级',this.form.productList) |
||||
}, |
||||
async getInfo(){ |
||||
//查询商品分类 |
||||
let that = this; |
||||
await getInfo(0).then( res => { |
||||
//商品分类 |
||||
that.cateList = res.cateList |
||||
}) |
||||
for (const item of that.cateList) { |
||||
await initData('/bxg/api/yxStoreProduct', { |
||||
page: 0, |
||||
size: 999, |
||||
sort: 'id,desc', |
||||
cateId:item.value, |
||||
}).then(data=>{ |
||||
data.content.forEach(ele=>{ |
||||
//不能直接使用ele,会有浅拷贝问题 |
||||
// let ele1=JSON.parse(JSON.stringify(ele)) |
||||
// that.$set(ele,'value',ele1) |
||||
that.$set(ele,'value',ele.id) |
||||
that.$set(ele,'label',ele.storeName) |
||||
} |
||||
) |
||||
that.$set(item,'children',data.content) |
||||
}) |
||||
} |
||||
console.log(that.cateList,'that.cateList') |
||||
}, |
||||
// 获取数据前设置好接口地址 |
||||
[CRUD.HOOK.beforeRefresh]() { |
||||
return true |
||||
}, // 新增与编辑前做的操作 |
||||
[CRUD.HOOK.afterToCU](crud, form) { |
||||
if (form.productList && form.id) { |
||||
let data=JSON.parse(this.form.productList) |
||||
console.log('data',data) |
||||
data.forEach(item=>{ |
||||
let product=[Number(item.cateId),Number(item.id)] |
||||
this.productList.push(product) |
||||
}) |
||||
// product=select |
||||
console.log( '111',this.productList,typeof(this.product)); |
||||
} |
||||
}, |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
</script> |
||||
|
||||
<style scoped> |
||||
.table-img { |
||||
display: inline-block; |
||||
text-align: center; |
||||
background: #ccc; |
||||
color: #fff; |
||||
white-space: nowrap; |
||||
position: relative; |
||||
overflow: hidden; |
||||
vertical-align: middle; |
||||
width: 32px; |
||||
height: 32px; |
||||
line-height: 32px; |
||||
} |
||||
</style> |
Loading…
Reference in new issue