master
lion 2 years ago
parent ba5a1ccc59
commit b3d7cd177b

@ -44,3 +44,21 @@ export function destroy (data,isLoading=true) {
isLoading isLoading
}) })
} }
export function categoryYears(params,isLoading=true) {
return request({
method: "get",
url: "/api/admin/get-years",
params,
isLoading
})
}
export function categoryTypes(params,isLoading=true) {
return request({
method: "get",
url: "/api/admin/get-category-types",
params,
isLoading
})
}

@ -15,7 +15,8 @@
size="mini" @click="addRules">新增</el-button> size="mini" @click="addRules">新增</el-button>
</template> </template>
<template slot-scope="scope" style="display: flex;"> <template slot-scope="scope" style="display: flex;">
<Button style="margin-right:5px" size="small" type="primary" @click="submitRules(scope.row)"></Button> <Button v-if="!scope.row.isEdit" style="margin-right:5px" size="small" type="primary" @click="submitRules(scope.row)"></Button>
<Button v-else style="margin-right:5px" size="small" type="primary" @click="scope.row.isEdit=false"></Button>
<el-popover width="180" <el-popover width="180"
:ref="`${scope.row.id}-${scope.$index}`" :ref="`${scope.row.id}-${scope.$index}`"
@ -50,7 +51,7 @@
</template> </template>
<template v-slot:footerContent> <template v-slot:footerContent>
<Button @click="isShow=false"></Button> <Button @click="isShow=false,$emit('refresh')"></Button>
</template> </template>
</xy-dialog> </xy-dialog>
@ -83,6 +84,7 @@ import { index,store,save,destroy} from "@/api/category/rule.js"
customFn: row => { customFn: row => {
return(<el-date-picker v-model={row.start_at} return(<el-date-picker v-model={row.start_at}
type="date" type="date"
disabled={row.isEdit}
format="yyyy-MM-dd" format="yyyy-MM-dd"
value-format="yyyy-MM-dd" value-format="yyyy-MM-dd"
placeholder="选择日期"> placeholder="选择日期">
@ -95,6 +97,7 @@ import { index,store,save,destroy} from "@/api/category/rule.js"
return(<el-date-picker v-model={row.end_at} return(<el-date-picker v-model={row.end_at}
type="date" type="date"
format="yyyy-MM-dd" format="yyyy-MM-dd"
disabled={row.isEdit}
value-format="yyyy-MM-dd" value-format="yyyy-MM-dd"
placeholder="选择日期"> placeholder="选择日期">
</el-date-picker>) </el-date-picker>)
@ -104,20 +107,20 @@ import { index,store,save,destroy} from "@/api/category/rule.js"
prop: "quantity", prop: "quantity",
width:80, width:80,
customFn: row => { customFn: row => {
return(<el-input type='text' v-model={row.quantity}></el-input>) return(<el-input type='text' disabled={row.isEdit} v-model={row.quantity}></el-input>)
} }
},{ },{
label: "备注", label: "备注",
prop: "remark", prop: "remark",
customFn: row => { customFn: row => {
return(<el-input type='textarea' v-model={row.remark}></el-input>) return(<el-input type='textarea' disabled={row.isEdit} v-model={row.remark}></el-input>)
} }
},{ },{
label: "排序", label: "排序",
prop: "myindex", prop: "myindex",
width:80, width:80,
customFn: row => { customFn: row => {
return(<el-input type='text' v-model={row.myindex}></el-input>) return(<el-input type='text' disabled={row.isEdit} v-model={row.myindex}></el-input>)
} }
} }
], ],
@ -136,12 +139,16 @@ import { index,store,save,destroy} from "@/api/category/rule.js"
const res = await index({ const res = await index({
category_id:this.category_id category_id:this.category_id
}) })
res.map(item=>{
item.isEdit = true
})
this.categoryRuleList = res this.categoryRuleList = res
console.log("this.categoryRuleList",this.categoryRuleList)
}, },
addRules(){ addRules(){
this.categoryRuleList.push({ this.categoryRuleList.push({
category_id:this.category_id, category_id:this.category_id,
isEdit:false,
start_at:'', start_at:'',
end_at:'', end_at:'',
quantity:1, quantity:1,

@ -17,7 +17,7 @@
</div> </div>
<div> <div>
<span style="margin-right:15px;display: inline-block;">类型 </span> <span style="margin-right:15px;display: inline-block;">类型 </span>
<el-radio-group @change="changeCategoryType" v-model="select.categoryType"> <el-radio-group @change="changeCategoryType" v-model="select.category_type_id">
<el-radio style="margin-right:5px" v-for="item in categoryTypeList" border <el-radio style="margin-right:5px" v-for="item in categoryTypeList" border
:label="item.id">{{item.title}}</el-radio> :label="item.id">{{item.title}}</el-radio>
</el-radio-group> </el-radio-group>
@ -44,8 +44,8 @@
<div> <div>
<div style="margin-bottom:15px;"> <div style="margin-bottom:15px;">
<el-button @click="$refs['create'].setType('add'), <el-button v-if="select.category_type_id" @click="$refs['create'].setType('add'),
$refs['create'].setForm('type_id', select.categoryType), $refs['create'].setForm('type_id', select.category_type_id),
$refs['create'].setForm('year', select.year.toString()), $refs['create'].setForm('year', select.year.toString()),
$refs['create'].show()" plain>新建{{select.year}}{{select.categoryTypeName}}清单</el-button> $refs['create'].show()" plain>新建{{select.year}}{{select.categoryTypeName}}清单</el-button>
</div> </div>
@ -55,53 +55,67 @@
$refs['create'].setType('editor'); $refs['create'].setType('editor');
$refs['create'].show(); $refs['create'].show();
}" @destroyed="getList"> }" @destroyed="getList">
<template #edit="{ row }"> <template v-slot:btns>
<Button v-if="row._type !== 'type'" size="small" type="primary" @click="$refs['create'].setId(row.id), <el-table-column align='center' fixed="right" label="操作" width="220" header-align="center">
$refs['create'].setType('editor'), <template slot="header" slot-scope="scope">
$refs['create'].show();">编辑</Button> <el-button
</template> size="mini" @click="">整体克隆</el-button>
<template #delete="{ row, column, $index }"> </template>
<el-popover width="180" v-if="row._type !== 'type'" :ref="`${column.id}-${$index}`" trigger="hover"> <template slot-scope="scope">
<template> <div style="display: flex;">
<div> <Button v-if="scope.row._type !== 'type'" size="small" type="primary" @click="$refs['create'].setId(scope.row.id),
<p style="padding-bottom: 10px;">确定要删除吗</p> $refs['create'].setType('editor'),
<div style="text-align: right;margin: 0;"> $refs['create'].show();">编辑</Button>
<el-button size="mini" type="text" @click="$refs[`${column.id}-${$index}`].doClose()"></el-button> <el-popover width="180" v-if="scope.row._type !== 'type'" :ref="`${scope.row.id}-${scope.$index}`" trigger="hover">
<el-button type="primary" size="mini" <template>
@click="$refs['xyTable'].deleteClick(row, 'delete')">确定</el-button> <div>
</div> <p style="padding-bottom: 10px;">确定要删除吗</p>
</div> <div style="text-align: right;margin: 0;">
</template> <el-button size="mini" type="text" @click="$refs[`${scope.row.id}-${scope.$index}`].doClose()"></el-button>
<template #reference> <el-button type="primary" size="mini"
<div style="margin-right: 6px;height: 100%;width: 100%;"> @click="$refs['xyTable'].deleteClick(scope.row, 'delete')">确定</el-button>
<Button type="error" size="small" @click="$refs[`${column.id}-${$index}`].doShow()"> </div>
删除 </div>
</Button> </template>
</div> <template #reference>
</template> <div style="margin-right: 6px;height: 100%;width: 100%;">
</el-popover> <Button type="error" size="small" @click="$refs[`${scope.row.id}-${scope.$index}`].doShow()">
</template> 删除
<template #pid="{ row }"> </Button>
<Button size="small" type="primary" @click="createChild(row)"></Button> </div>
</template> </template>
</el-popover>
<Button size="small" type="primary" @click="createChild(scope.row)"></Button>
</div>
</template>
</el-table-column>
</template>
</xy-table> </xy-table>
</div> </div>
<create ref="create" :options="list" @refresh="getList"></create> <create ref="create" :options="list" @refresh="getList"></create>
<categorySetting ref="categorySetting"></categorySetting> <categorySetting ref="categorySetting"></categorySetting>
<createRules ref="createRules"></createRules> <createRules ref="createRules" @refresh="getList"></createRules>
</div> </div>
</template> </template>
<script> <script>
import { import {
index, index,
destroy destroy,
} from "@/api/category" categoryYears,
import { categoryTypes
index as categoryType } from "@/api/category"
} from "@/api/categoryType"
import { import {
authMixin authMixin
} from "@/mixin/authMixin"; } from "@/mixin/authMixin";
@ -126,8 +140,8 @@
yearList: [], yearList: [],
categoryTypeList:[], categoryTypeList:[],
select: { select: {
year: parseInt(this.$moment().format('YYYY')), year: '',
categoryType:'', category_type_id:'',
categoryTypeName:'' categoryTypeName:''
}, },
isStartSelect: false, isStartSelect: false,
@ -172,6 +186,11 @@
} }
} }
>规则设置</el-button> >规则设置</el-button>
<div>{
row.rules.map(item=>{
return(<div>{item.start_at}~{item.end_at}不少于{item.quantity}</div>)
})
}</div>
</div>) </div>)
} }
}, },
@ -181,9 +200,10 @@
}] }]
} }
}, },
created() { created() {
this.getPastYears()
this.getList() this.getList()
this.yearList = this.getPastYears(5) // this.yearList = this.getPastYears(5)
this.getCategoryType() this.getCategoryType()
// this.select.year = this.$moment().format('YYYY') // this.select.year = this.$moment().format('YYYY')
}, },
@ -191,13 +211,10 @@
index, index,
destroy, destroy,
getCategoryType(){ getCategoryType(){
categoryType({ categoryTypes().then(res=>{
page:1, this.categoryTypeList = res
page_size:9999 // this.select.categoryType = res.data.length>0?res.data[0].id:''
}).then(res=>{ // this.select.categoryTypeName = res.data.length>0?res.data[0].title:''
this.categoryTypeList = res.data
this.select.categoryType = res.data.length>0?res.data[0].id:''
this.select.categoryTypeName = res.data.length>0?res.data[0].title:''
}) })
}, },
@ -213,6 +230,7 @@
this.select.categoryTypeName = item.title this.select.categoryTypeName = item.title
} }
}) })
this.getList()
} }
}, },
@ -254,29 +272,34 @@
} }
}) })
}, },
getPastYears(years) { getPastYears(years) {
const currentYear = new Date().getFullYear(); categoryYears().then(res=>{
return Array.from({ this.yearList = res.years
length: years this.select.year = res.selected_year
}, (_, index) => currentYear - index); })
}, },
async getList() { async getList() {
let res = await index({ let res = await index({
year:this.select.year year:this.select.year,
category_type_id:this.select.category_type_id
}); });
this.formatList(res); this.formatList(res);
this.list = res; this.list = res;
}, },
createChild(row) { createChild(row) {
let category_type_id = this.select.category_type_id
if(row.type_id){
category_type_id = row.type_id
}
if (row._type === 'type') { if (row._type === 'type') {
this.$refs['create'].setForm('type_id', this.select.categoryType); this.$refs['create'].setForm('type_id', category_type_id);
this.$refs['create'].setForm('pid', 0); this.$refs['create'].setForm('pid', 0);
this.$refs['create'].setForm('year', this.select.year.toString()); this.$refs['create'].setForm('year', this.select.year.toString());
this.$refs['create'].setType('add'); this.$refs['create'].setType('add');
this.$refs['create'].show(); this.$refs['create'].show();
} else { } else {
this.$refs['create'].setForm('type_id', this.select.categoryType); this.$refs['create'].setForm('type_id', category_type_id);
this.$refs['create'].setForm('pid', row.id); this.$refs['create'].setForm('pid', row.id);
this.$refs['create'].setForm('year', this.select.year.toString()); this.$refs['create'].setForm('year', this.select.year.toString());
this.$refs['create'].setType('add'); this.$refs['create'].setType('add');
@ -285,7 +308,12 @@
}, },
createRules(row){ createRules(row){
console.log(row) console.log(row)
this.$refs['createRules'].category_id = row.id if(row._type==='type'){
this.$refs['createRules'].category_id = row._id
}else{
this.$refs['createRules'].category_id = row.id
}
this.$refs['createRules'].title = row.title; this.$refs['createRules'].title = row.title;
this.$refs['createRules'].isShow = true; this.$refs['createRules'].isShow = true;
} }

Loading…
Cancel
Save