|
@@ -1,45 +1,235 @@
|
|
<template>
|
|
<template>
|
|
- <div>
|
|
|
|
- <el-tag :key="tag" v-for="tag in dynamicTags" closable :disable-transitions="false" @close="handleClose(tag)">
|
|
|
|
- {{tag}}
|
|
|
|
- </el-tag>
|
|
|
|
- <el-input class="input-new-tag" v-if="inputVisible" v-model="inputValue" ref="saveTagInput" size="small"
|
|
|
|
- @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm">
|
|
|
|
- </el-input>
|
|
|
|
- <el-button v-else class="button-new-tag" size="small" @click="showInput">+ New Tag</el-button>
|
|
|
|
|
|
+ <div class="by-tab">
|
|
|
|
+ <div v-for="(item,index) of columns" :key="index">
|
|
|
|
+ <div class="title">{{item.title}} <i class="el-icon-circle-close" @click="closeGroup(index)"></i> </div>
|
|
|
|
+ <el-tag class="item-tab" :disable-transitions="true" :key="i" v-for="(tag,i) of item.list" closable
|
|
|
|
+ @close="handleClose(tag,index)">
|
|
|
|
+ {{tag}}
|
|
|
|
+ </el-tag>
|
|
|
|
+ <by-input class="input-new-tag" :ref="'getValue_'+index"></by-input>
|
|
|
|
+ <el-button class="button-new-tag" @click="showInput(index)">添加</el-button>
|
|
|
|
+ </div>
|
|
|
|
+ <div style="margin: 20px 0;" v-if="!isAdd" key='item'>
|
|
|
|
+ <button class="el-button mr15 el-button--primary el-button--small" @click="isAdd=true">添加新规格</button>
|
|
|
|
+ <button class="el-button el-button--success el-button--small" @click="generateNow">立即生成</button>
|
|
|
|
+ </div>
|
|
|
|
+ <div style="display: flex;margin: 20px 0;" v-else key='item2'>
|
|
|
|
+ <div class="flex-item">
|
|
|
|
+ <label>规格:</label>
|
|
|
|
+ <div class="el-input el-input--small" style="width: 250px;">
|
|
|
|
+ <input type="text" v-model="norms" placeholder="请输入规格" class="el-input__inner">
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="flex-item">
|
|
|
|
+ <label>规格值:</label>
|
|
|
|
+ <div class="el-input el-input--small" style="width: 250px;">
|
|
|
|
+ <input type="text" v-model="normsValue" placeholder="请输入规格值" class="el-input__inner">
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ <button @click="doComfirm" class="el-button el-button--primary el-button--small"><span>确定</span></button>
|
|
|
|
+ <button @click="isAdd=false" class="el-button el-button--danger el-button--small"><span>取消</span></button>
|
|
|
|
+ </div>
|
|
|
|
+ <div v-if="isTable"><by-table :propConfig="config" ref="table"></by-table></div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
import { Component, Prop, Vue, Mixins, Watch } from "vue-property-decorator";
|
|
import { Component, Prop, Vue, Mixins, Watch } from "vue-property-decorator";
|
|
- import VueViews from '@/benyun/compVue/VueViews'
|
|
|
|
|
|
+ import VueViews from '@/benyun/compVue/VueViews';
|
|
@Component
|
|
@Component
|
|
export default class Tab extends VueViews {
|
|
export default class Tab extends VueViews {
|
|
- dynamicTags = ['标签一', '标签二', '标签三']
|
|
|
|
- inputVisible = false
|
|
|
|
- inputValue = ''
|
|
|
|
|
|
+ inputValue : any = ''
|
|
|
|
+ norms : any = ''
|
|
|
|
+ normsValue : any = ''
|
|
|
|
+ isAdd : any = false
|
|
|
|
+ isTable : any = false
|
|
|
|
+ tableData : any = ''
|
|
|
|
+ config : any = {
|
|
|
|
+ attr: {
|
|
|
|
+ size: 'mini',
|
|
|
|
+ height: 486,
|
|
|
|
+ align: 'center',
|
|
|
|
+ },
|
|
|
|
+ columns: [
|
|
|
|
+ {
|
|
|
|
+ title: '价格',
|
|
|
|
+ field: 'price',
|
|
|
|
+ component: 'by-input',
|
|
|
|
+ // compConfig: {
|
|
|
|
+ // attrs: {
|
|
|
|
+ // placeholder: 0
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '库存',
|
|
|
|
+ field: 'stock',
|
|
|
|
+ component: 'by-input'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '保质期(天)',
|
|
|
|
+ field: 'shelfLife',
|
|
|
|
+ component: 'by-input'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '重量',
|
|
|
|
+ field: 'weight',
|
|
|
|
+ component: 'by-input'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '长',
|
|
|
|
+ field: 'length',
|
|
|
|
+ component: 'by-input'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '宽',
|
|
|
|
+ field: 'width',
|
|
|
|
+ component: 'by-input'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '高',
|
|
|
|
+ field: 'height',
|
|
|
|
+ component: 'by-input'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '体积',
|
|
|
|
+ field: 'volume',
|
|
|
|
+ component: 'by-input'
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ width: '80px',
|
|
|
|
+ title: '操作',
|
|
|
|
+ action: true,
|
|
|
|
+ plugins: [{
|
|
|
|
+ icon: 'el-icon-delete',
|
|
|
|
+ name: '删除',
|
|
|
|
+ audit: '',
|
|
|
|
+ event: {
|
|
|
|
+ click: (item : any) => {
|
|
|
|
+ (this as any).doDelete(item)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }]
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ columns : Array<any> = [
|
|
|
|
+ {
|
|
|
|
+ title: '尺寸',
|
|
|
|
+ field: 'title',
|
|
|
|
+ list: ['7.5', '5.8', '6.6']
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ title: '颜色',
|
|
|
|
+ field: 'color',
|
|
|
|
+ list: ['black', 'white', 'red']
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
|
|
- handleClose(tag : any) {
|
|
|
|
- this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
|
|
|
|
|
|
+ showInput(index : any) {
|
|
|
|
+ let inputValue = (this as any).$refs['getValue_' + index][0].getValue();
|
|
|
|
+ console.log(this.columns[index]);
|
|
|
|
+ if (this.columns[index].list.indexOf(inputValue) !== -1) return (this as any).$refs['getValue_' + index][0].clearValue();
|
|
|
|
+ if (inputValue) {
|
|
|
|
+ this.columns[index].list.push(inputValue);
|
|
|
|
+ }
|
|
|
|
+ (this as any).$refs['getValue_' + index][0].clearValue();
|
|
}
|
|
}
|
|
- showInput() {
|
|
|
|
- this.inputVisible = true;
|
|
|
|
- this.$nextTick(() => {
|
|
|
|
- (this as any).$refs.saveTagInput.$refs.input.focus();
|
|
|
|
|
|
+ // 立即生成
|
|
|
|
+ generateNow() {
|
|
|
|
+ this.isTable = true;
|
|
|
|
+ this.forFun(this.columns[0], 0);
|
|
|
|
+ let data = (this as any).$lodash.cloneDeep(this.config);
|
|
|
|
+ let newColumns = (this as any).$lodash.cloneDeep(this.columns).reverse();
|
|
|
|
+ // console.log(newColumns);
|
|
|
|
+ this.tableData.map((v : any, i : any) => {
|
|
|
|
+ v.dataIndex = i
|
|
|
|
+ })
|
|
|
|
+ newColumns.map((v : any) => {
|
|
|
|
+ data.columns.unshift({
|
|
|
|
+ title: v.title,
|
|
|
|
+ field: v.field
|
|
|
|
+ })
|
|
});
|
|
});
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ (this as any).$refs.table.setValue(this.tableData); // 设置表格数据
|
|
|
|
+ (this as any).$refs.table.setTableConfig(data); // 设置表格配置
|
|
|
|
+ }, 0)
|
|
}
|
|
}
|
|
- handleInputConfirm() {
|
|
|
|
- let inputValue = this.inputValue;
|
|
|
|
- if (inputValue) {
|
|
|
|
- this.dynamicTags.push(inputValue);
|
|
|
|
|
|
+ // 添加新规格
|
|
|
|
+ doComfirm() {
|
|
|
|
+ if (!this.normsValue || !this.norms) return (this as any).$message({ type: "warning", message: '请添加完整的规格!' })
|
|
|
|
+ let obj : any = {
|
|
|
|
+ title: this.norms,
|
|
|
|
+ list: [this.normsValue]
|
|
}
|
|
}
|
|
- this.inputVisible = false;
|
|
|
|
- this.inputValue = '';
|
|
|
|
|
|
+ this.columns.push(obj);
|
|
|
|
+ this.norms = '';
|
|
|
|
+ this.normsValue = '';
|
|
|
|
+ this.isAdd = false;
|
|
|
|
+ }
|
|
|
|
+ // 排序生成
|
|
|
|
+ forFun(data : any, i : number, v ?: any) {
|
|
|
|
+ if (data.list) {
|
|
|
|
+ let d : Array<any> = [];
|
|
|
|
+ // data.list = data.list.reverse()
|
|
|
|
+ data.list.forEach((item : any) => {
|
|
|
|
+ if (i == 0) { // 第一次循环
|
|
|
|
+ let obj : any = {}
|
|
|
|
+ obj[data.field] = item
|
|
|
|
+ d.push(obj);
|
|
|
|
+ } else {
|
|
|
|
+ // v = v.reverse()
|
|
|
|
+ v.forEach((ele : any) => {
|
|
|
|
+ let obj : any = {};
|
|
|
|
+ obj = (this as any).$lodash.clone(ele);
|
|
|
|
+ obj[data.field] = item
|
|
|
|
+ d.push(obj);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ i++
|
|
|
|
+ if (this.columns[i]) {
|
|
|
|
+ this.forFun(this.columns[i], i, d);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ this.tableData = d;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 删除表格数据
|
|
|
|
+ doDelete(item:any){
|
|
|
|
+ this.tableData.splice(item.dataIndex, 1);
|
|
|
|
+ }
|
|
|
|
+ // 删除标签
|
|
|
|
+ handleClose(tag : any, index : any) {
|
|
|
|
+ // console.log(tag);
|
|
|
|
+ this.columns[index].list.splice(this.columns[index].list.indexOf(tag), 1);
|
|
|
|
+ }
|
|
|
|
+ // 删除数组
|
|
|
|
+ closeGroup(index : any) {
|
|
|
|
+ this.columns.splice(index, 1)
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
<style lang="scss" scoped>
|
|
|
|
+ .by-tab {
|
|
|
|
+ .title {
|
|
|
|
+ // padding: 10px 0 0;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ .item-tab {
|
|
|
|
+ margin-right: 16px;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .input-new-tag {
|
|
|
|
+ width: 130px;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ .flex-item {
|
|
|
|
+ margin-right: 20px;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
</style>
|
|
</style>
|