Commit 9fae0f1e by zhangquan

模板配置开发

1 parent 5f24d8bf
<template>
<GLDialog bigTitle="选择商品优惠券" mode="big" :visible.sync="isVisible" :show-close="true" :before-close="handleClose" :close-on-click-modal="false" @onOk="onOk" @onCancel="onCancel">
<div class="dialog_body">
<div class="table_body">
<GLCombiForm :rowNumber="1" class="dialog_search" ref="searchRef" :formObj="dialogSearchForm" :formData="dialogFormData" @handleOk="handleOk" @handleRest="handleRest"></GLCombiForm>
<div class="dialog_table">
<GLTable :pageSizes="pageSizes" ref="tableRef" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun" :searchForm="dialogSearchForm" :tableParams="tableParams" :getListApi="getListApi" @selectionTable="selectionTable()">
<div class="good_name" slot="goodName" slot-scope="scope">
<img v-if="scope.scope.appearance == 1" src="@/assets/coupon.png" alt="" />
<img v-else src="@/assets/directCharge.png" alt="" />
<!-- {{ scope.scope.appearance == 2 ? scope.scope.productName + (scope.scope.denomination || '') : scope.scope.productName }} -->
{{ scope.scope.productName }}
</div>
</GLTable>
</div>
</div>
<div class="selected_list">
<p class="list_title">已选({{ selectedSum }})</p>
<div class="list_gifts">
<div v-for="(val, key) in signList" :key="key">
<div class="gift_box" v-if="val && val.length">
<img v-if="key == 'couponList'" class="gift_label" src="@/assets/coupon.png" alt="" />
<img v-else class="gift_label" src="@/assets/directCharge.png" alt="" />
<div class="gift_content">
<div class="gift_item" v-for="(item, index) in val" :key="index">
<img class="muti_icon" src="@/assets/muti-selected.png" @click="handleGiftDelete(key, item, index)" />
<!-- <img class="muti_icon" src="@/assets/muti-no-select.png" @click="handleGiftDelete(item, index)" /> -->
<el-tooltip effect="dark" placement="top" :disabled="item.productName.length <= 8">
<p :class="['gift_coupon_name', 'ellipsis-1', item.status == '3' ? 'txt-grey' : '']">{{ item.productName.length > 8 ? item.productName.slice(0, 8) + '...' : item.productName }}</p>
<div slot="content">{{ item.productName }}</div>
</el-tooltip>
<div class="gift_sum">
<el-input-number :disabled="item.status == '3'" class="sum_input" v-model="item.couponAmount" :min="1" :max="9999" size="mini" label="描述文字"></el-input-number>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</GLDialog>
</template>
<script>
import { utils } from 'glsx-common'
export default {
name: 'index',
props: ['isVisible', 'selectedGoodsList'],
data() {
return {
copyList: [],
firstOpen: true,
resetTable: false,
signList : {
couponList: [],
directChargeList: []
},
giftList: [],
pageSizes: [10, 20, 30, 40, 50],
dialogSearchForm: {
brandName: '',
productName: '',
status: 1
},
dialogFormData: [
{
label: '商品品牌',
name: 'brandName',
type: 'select',
optionList: [],
optionId: 'brandName',
optionLabel: 'brandName',
isClear: true
},
{
label: '商品名称',
name: 'productName',
type: 'input',
isClear: true
}
],
getListApi: this.$apis.orderApi.getGoodsList,
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
tableParams: {
listName: 'list',
mutiSelectName: 'goodsIndex',
mutiSelectUniqueKey: 'id',
tableOption: false,
tableColumns: [
{
label: '品牌',
prop: 'brandName'
},
{
label: '商品名称',
minWidth: 220,
addHtml: 'goodName'
},
{
label: '券面额',
width: 110,
prop: 'denomination'
},
{
label: '有效期',
width: 110,
prop: 'validityPeriod'
}
]
}
}
},
computed:{
selectedSum(){
return this.signList?.couponList?.length + this.signList?.directChargeList?.length
}
},
created() {
this.getAllBrandList()
},
mounted(){
},
methods: {
getAllBrandList() {
this.$apis.orderApi.getAllBrandList().then(res => {
const item = this.dialogFormData.find(item => item.name === 'brandName')
item.optionList = [...res.data]
})
},
handleOk() {
this.resetTable = true
this.$refs.tableRef.refreshTable()
},
handleRest() {
this.dialogSearchForm = {
brandName: '',
productName: '',
status: 1
}
this.handleOk()
},
onOk() {
// let list = this.$refs.tableRef.mutiSelectArr[this.tableParams.mutiSelectName] || []
// list = [...this.couponList, ...list]
// for (let i = 0; i < this.selectedGoodsList.length; i++) {
// let idx = list.findIndex(item => item.id == this.selectedGoodsList[i].id)
// if (idx > -1) {
// list.splice(idx, 1)
// }
// }
// list.map(item => this.$set(item, 'newCost', Number((item.lineationPrice - item.costPrice).toFixed(1))))
this.$emit('confirmDialog', [...this.signList.directChargeList, ...this.signList.couponList])
this.handleClose()
},
onCancel() {
this.handleClose()
},
handleClose() {
this.$emit('closeDialog')
},
// 点击选中卡券
selectionTable(){
let list = [...this.$refs.tableRef.mutiSelectArr[this.tableParams.mutiSelectName], ...this.copyList] || []
if(this.resetTable) {
list = [...this.signList.directChargeList, ...this.signList.couponList] || []
this.copyList = utils.deepClone(list)
this.resetTable = false
};
list.map(item => this.$set(item, 'couponAmount', 1))
this.filterCoupon(list)
},
// 选中的优惠券分成卡券和直充
filterCoupon(list){
this.signList.directChargeList = list.map(item=> {
const target = this.signList.directChargeList.find(row=> row.id == item.id)
if(target) {
item.couponAmount = target.couponAmount
}
return item
}).filter(item => item.appearance==2)
this.signList.couponList = list.map(item=> {
const target = this.signList.directChargeList.find(row=> row.id == item.id)
if(target) {
item.couponAmount = target.couponAmount
}
return item
}).filter(item => item.appearance==1)
},
//删除选中行
delSelectedRow(row){
this.$nextTick(() => {
let idx = this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].data.findIndex(item => item.id == row.id)
if (idx > -1) {
try {
this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].data[idx], false)
// let id = this.copyList.findIndex(item => item.id == row.id)
// if (id > -1) this.copyList.splice(id, 1)
} catch (err) {
console.log(err)
}
}
})
},
// 点击删除
handleGiftDelete(key, item, idx){
this.signList[key].splice(idx, 1)
this.delSelectedRow(item)
},
//更新表格设置选中的行
setTableFinishFun() {
console.log(this.signList.directChargeList, this.signList.couponList)
this.$nextTick(()=>{
if(this.firstOpen){
this.copyList = utils.deepClone(this.selectedGoodsList)
console.log(333)
this.filterCoupon(this.copyList)
this.firstOpen = false
}
let list = [...this.signList.directChargeList, ...this.signList.couponList]
this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable']?.data?.forEach((row,rowIdx) => {
let idx = list.findIndex(item => item.id == row.id)
try {
console.log(444)
if(idx>-1){
let id = this.copyList.findIndex(item => item.id == row.id)
if (id > -1 && this.copyList?.length) this.copyList.splice(id, 1)
this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].data[rowIdx], true)
}else{
this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].toggleRowSelection(this.$refs.tableRef.$refs[this.tableParams.mutiSelectName + 'MutiTable'].data[rowIdx], false)
}
} catch (err) {
console.log(err)
}
})
})
}
}
}
</script>
<style lang="scss" scoped>
.container {
/deep/ .table-header {
display: inline-flex !important;
align-items: center;
justify-content: center;
padding: 0 !important;
.el-button {
min-width: 0;
}
}
.good_name {
img {
width: 40px;
height: 20px;
vertical-align: text-bottom;
}
}
.dialog_body{
display: flex;
}
.table_body {
border: 1px solid #e5e5e5;
margin-right: 10px;
.dialog_search {
padding: 20px 20px 0;
/deep/ .el-form-item {
width: 270px;
&:last-child{
width: 130px;
.el-button{
vertical-align: middle;
}
}
}
}
.coupon_type {
width: 100%;
display: inline-block;
border-bottom: 1px solid #eee;
.type {
display: inline-block;
height: 40px;
width: 70px;
line-height: 40px;
font-weight: 500;
text-align: center;
font-size: 16px;
cursor: pointer;
}
.active_type {
color: #5850ff;
border-bottom: 2px solid #5850ff;
}
}
.dialog_table {
padding: 0 20px 20px;
}
}
.selected_list {
width: 280px;
border-radius: 2px;
border: 1px solid #eeeeee;
flex-shrink: 0;
.list_title {
height: 54px;
line-height: 54px;
font-size: 16px;
font-weight: 500;
color: #333333;
border-bottom: 1px solid #f1f1f1;
padding: 0 17px;
}
.list_gifts {
height: 61vh;
padding: 0 16px;
overflow-y: scroll;
.gift_box{
padding: 16px 0 20px;
}
.gift_label {
width: 40px;
height: 20px;
margin-bottom: 10px;
vertical-align: text-bottom;
}
.gift_content {
&:last-child {
border-bottom: 0px;
}
border-bottom: 1px solid #e5e5e5;
.gift_item {
&:last-child {
margin-bottom: 0;
}
margin-bottom: 20px;
display: inline-flex;
align-items: center;
.muti_icon {
cursor: pointer;
}
.gift_coupon_name {
display: inline-block;
width: 109px;
margin: 0 5px 0 7px;
}
/deep/ .gift_sum {
display: inline-block;
width: 82px;
text-align: right;
.el-input-number--mini .el-input__inner {
padding: 0 10px;
}
.sum_input {
display: inline-block;
width: 82px;
}
.el-input--mini .el-input__inner {
border: 0px;
}
.el-input-number--mini .el-input-number__decrease,
.el-input-number--mini .el-input-number__increase {
width: 20px !important;
border: 0px;
background-color: #fff;
}
}
}
}
}
}
}
</style>
<template>
<div class="container">
<div class="nav">
<div style="display: inline-block;">
<div v-if="curIdx>index || curIdx==-1" class="configItem" :ref="'tempRef'+index" @click="checkedTemp(item)" :class="{curConfigItem:curConfigId==item.id}" v-for="item,index in rowList" :key="item.id">{{ item.name }}</div>
</div>
<div v-if="showInput" class="inputArea"><el-input maxLength="15" ref="addInput" @blur="inputBlur" v-model="configName" class="input"></el-input></div>
<div v-else class="configItem addBtn" style="cursor: pointer;" @click="addTemplate"><i class="el-icon-plus"></i></div>
<div v-if="curIdx > -1" class="configItem pullBtn" style="cursor: pointer;" @click="slideDown">
<i class="el-icon-arrow-down"></i>
<div class="pullDownArea">
<div class="pullDownItem" @click="checkedTemp(item)" :class="{curConfigItem:curConfigId==item.id}" v-for="item,index in colList" :key="item.id">{{ item.name }}</div>
</div>
</div>
</div>
<div ref="main" class="main">
<el-button type="primary" style="margin-bottom: 16px;" size="small" @click="addCoupon" class="el-icon-plus">添加优惠券</el-button>
<GLTable ref="tableRef" :pageConf="pageConf" :searchForm="searchForm" :tableParams="tableParams" :tableData="couponFormObj.selectedGoodsList">
<div class="good_name" slot="goodName" slot-scope="scope">
<img v-if="scope.scope.appearance == 1" src="@/assets/coupon.png" alt="" />
<img v-else src="@/assets/directCharge.png" alt="" />
<!-- {{ scope.scope.appearance == 2 ? scope.scope.productName + (scope.scope.denomination || '') : scope.scope.productName }} -->
{{ scope.scope.productName }}
</div>
<div slot="auth-button" slot-scope="scope">
<GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
</div>
</GLTable>
</div>
<select-coupon-dialog @confirmDialog="confirmDialog" @closeDialog="closeDialog" :selectedGoodsList="couponFormObj.selectedGoodsList" v-if="isVisible" :isVisible="isVisible"></select-coupon-dialog>
</div>
</template>
<script>
import selectCouponDialog from './components/selectCouponDialog.vue'
export default {
name: 'index',
components: {
selectCouponDialog
},
data() {
return {
curConfigId: 1,
showInput: false,
isVisible: false,
configName: '',
curIdx: -1,
couponFormObj: {
selectedGoodsList: []
},
editForm: {
merchantId: ''
},
templateList: [
{
name:'定保',
id: 1
},
{
name:'续保模板',
id: 2
},
{
name:'节假日模板',
id: 3
}
],
rowList: [],
colList: [],
getListApi: this.$apis.goodsCouponApi.getCouponsList,
pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
searchForm: {
brandName: '',
goodsName: '',
appearance: '',
status: ''
},
buttonList: [
{
type: 'el-button',
name: '删除',
attrs: {
type: 'text',
fn: '删除'
},
listeners: {
click: row => this.del(row.scope)
}
}
],
tableParams: {
listName: 'list',
tableOption: true,
tableColumns: [
{
label: '品牌',
prop: 'brandName'
},
{
label: '商品名称',
minWidth: 220,
addHtml: 'goodName'
},
{
label: '数量',
prop: 'couponAmount'
},
{
label: '券面额',
width: 110,
prop: 'denomination'
},
{
label: '有效期',
width: 110,
prop: 'validityPeriod'
}
]
},
}
},
created() {
},
mounted(){
this.getTemplateList()
},
methods: {
getTemplateList(){
this.calcWidth()
},
addTemplate(){
this.showInput = true
this.$nextTick(()=>{
this.$refs.addInput.focus()
})
},
checkedTemp(item){
this.curConfigId = item.id
},
addCoupon(){
this.isVisible = true
},
calcWidth(){
let calculated = false
let mainW = this.$refs.main.offsetWidth
this.$nextTick(()=>{
this.rowList.reduce((pre, cur,index) => {
let curW = this.$refs?.['tempRef'+index]?.[0]?.offsetWidth
if((pre + curW) > mainW-500 && !calculated) {
this.curIdx = index
calculated = true
}
return pre + curW
},0);
console.log( this.curIdx)
this.colList = this.curIdx >-1 ? this.templateList.slice(this.curIdx) : []
this.rowList = this.curIdx >-1 ? this.templateList.slice(0, this.curIdx) : this.templateList
})
},
slideDown(){
},
inputBlur(e){
this.showInput = false
if(this.configName) {
this.templateList.push({
name: this.configName,
id: parseInt(Math.random(1)*10000)
})
this.configName = ''
}
this.calcWidth()
},
closeDialog() {
this.isVisible = false
},
confirmDialog(e) {
this.couponFormObj.selectedGoodsList = e || []
},
}
}
</script>
<style lang="scss" scoped>
.container {
.nav{
.inputArea{
display: inline-block;
height: 40px;
line-height: 40px;
border-radius: 4px 4px 0 0;
margin-right: 1px;
.input{
width: 245px;
/deep/ .el-input__inner{
vertical-align: baseline;
box-sizing: border-box;
border: none;
}
}
}
.configItem{
display: inline-block;
padding: 0 20px;
height: 40px;
line-height: 40px;
background-color: #F8F8F8;
border-radius: 4px 4px 0 0;
margin-right: 1px;
color: #666666;
letter-spacing: 0;
text-align: center;
cursor: pointer;
}
.curConfigItem{
background-color: #fff;
color: #5850FF;
font-weight: 500;
}
.addBtn, .pullBtn{
width: 50px;
box-sizing: border-box;
padding: 0;
position: relative;
i{
border: 1px dashed #999;
color: #999;
}
}
.pullBtn{
&:hover{
.pullDownArea{
display: block;
}
}
.pullDownArea{
display: none;
position: absolute;
width: 200px;
max-height: 200px;
overflow-y: auto;
right: 0;
background-color: #fff;
z-index: 2;
box-shadow: 0 3px 6px -4px #0000001f, 0 6px 16px 0 #00000014, 0 9px 28px 8px #0000000d;
border-radius: 4px;
.pullDownItem{
height: 36px;
line-height: 36px;
font-weight: 400;
padding: 0 15px;
font-size: 14px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
color: #666666;
background-color: #F8F8F8;
&:hover{
background-color: #f5f7fa;
}
}
.curConfigItem{
background-color: #fff;
color: #5850FF;
font-weight: 500;
}
}
}
}
.main{
background-color: #fff;
padding: 16px 20px;
.good_name {
img {
width: 40px;
height: 20px;
vertical-align: text-bottom;
}
}
}
}
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!