consumer exceed

This commit is contained in:
caoqianming 2020-08-24 11:01:00 +08:00
parent acff3881cc
commit 65fa087d93
7 changed files with 229 additions and 178 deletions

View File

@ -28,7 +28,7 @@
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
@row-dblclick="handleChose2"
>
<el-table-column type="index" width="50"></el-table-column>
<el-table-column type="index" width="100" :index="indexMethod"></el-table-column>
<el-table-column label="单位名称">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
@ -140,6 +140,9 @@ export default {
},
handleChose2(row, column, event){
this.$emit('handleChose',row);
},
indexMethod(index) {
return (this.listQuery.page-1)*this.listQuery.limit + index + 1;
}
}
};

View File

@ -52,16 +52,16 @@
/>
</el-select>
<el-date-picker
v-model="datevalue"
type="daterange"
align="right"
unlink-panels
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions">
</el-date-picker>
v-model="datevalue"
type="daterange"
align="right"
unlink-panels
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd"
:picker-options="pickerOptions"
></el-date-picker>
<!-- <el-select
v-model="listQuery.is_paid"
placeholder="是否缴费"
@ -121,8 +121,18 @@
</div>
<el-button slot="reference" icon="el-icon-upload2">Excel导入</el-button>
</el-popover>
<el-button type="primary" icon="el-icon-download" @click="exportConsumer" v-if="checkPermission(['consumer__export'])">导出Excel</el-button>
<el-button type="danger" icon="el-icon-delete" @click="handleDeletes" v-if="checkPermission(['consumer__deletes'])">批量删除</el-button>
<el-button
type="primary"
icon="el-icon-download"
@click="exportConsumer"
v-if="checkPermission(['consumer__export'])"
>导出Excel</el-button>
<el-button
type="danger"
icon="el-icon-delete"
@click="handleDeletes"
v-if="checkPermission(['consumer__deletes'])"
>批量删除</el-button>
<el-checkbox
v-model="showCreate"
class="filter-item"
@ -142,30 +152,30 @@
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column align="center" label="姓名">
<el-table-column label="姓名">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
<el-table-column align="header-center" label="手机号" sortable="custom" prop="username">
<el-table-column label="手机号" sortable="custom" prop="username">
<template slot-scope="scope">{{ scope.row.username }}</template>
</el-table-column>
<el-table-column align="header-center" label="小程序OpenId">
<el-table-column label="小程序OpenId" :show-overflow-tooltip="true">
<template slot-scope="scope">{{ scope.row.openid }}</template>
</el-table-column>
<el-table-column align="header-center" label="用户类型">
<el-table-column label="用户类型">
<template slot-scope="scope">{{ scope.row.role_name }}</template>
</el-table-column>
<el-table-column align="header-center" label="单位" sortable="custom" prop="company">
<el-table-column label="单位" sortable="custom" prop="company">
<template
slot-scope="scope"
v-if="scope.row.company_name != null"
>{{ scope.row.company_name }}</template>
</el-table-column>
<el-table-column align="center" label="缴费学科">
<el-table-column label="缴费学科">
<template slot-scope="scope">
<el-tag v-for="item in scope.row.subjects_name" :key="item">{{ item }}</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="工作类别" sortable="custom" prop="workscope">
<el-table-column label="工作类别" sortable="custom" prop="workscope">
<template slot-scope="scope">
<el-tag v-if="scope.row.workscope_name">{{ scope.row.workscope_name }}</el-tag>
</template>
@ -173,34 +183,36 @@
<el-table-column label="创建信息" sortable="custom" prop="create_time" v-if="showCreate">
<template slot-scope="scope">
<span>{{ scope.row.create_admin_.username }}/</span>
<span>{{ scope.row.create_time }}</span>
<span>{{ scope.row.create_time.substring(0,10) }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="操作" >
<el-table-column align="left" label="操作" fixed="right" width="200">
<template slot-scope="scope">
<el-button
type="primary"
size="small"
@click="handleEdit(scope)"
icon="el-icon-edit"
:disabled="!checkPermission(['consumer_update'])"
v-if="!scope.row.is_superconsumer"
></el-button>
<el-button
type="danger"
size="small"
@click="handleDelete(scope)"
icon="el-icon-delete"
:disabled="!checkPermission(['consumer_delete'])"
v-if="!scope.row.is_superconsumer"
></el-button>
<el-button
type="primary"
size="small"
@click="handleUnbind(scope)"
:disabled="!checkPermission(['consumer_unbind'])"
v-if="scope.row.username&&scope.row.openid"
>解绑微信</el-button>
<el-button-group>
<el-button
type="primary"
size="small"
@click="handleEdit(scope)"
icon="el-icon-edit"
:disabled="!checkPermission(['consumer_update'])"
v-if="!scope.row.is_superconsumer"
></el-button>
<el-button
type="danger"
size="small"
@click="handleDelete(scope)"
icon="el-icon-delete"
:disabled="!checkPermission(['consumer_delete'])"
v-if="!scope.row.is_superconsumer"
></el-button>
<el-button
type="primary"
size="small"
@click="handleUnbind(scope)"
:disabled="!checkPermission(['consumer_unbind'])"
v-if="scope.row.username&&scope.row.openid"
>解微</el-button>
</el-button-group>
</template>
</el-table-column>
</el-table>
@ -228,14 +240,9 @@
<el-input v-model="consumer.username" placeholder="手机号" />
</el-form-item>
<el-form-item label="单位" prop="company">
<el-input
placeholder="单位"
v-model="consumer.company_.name"
readonly
>
<el-button slot="append" icon="el-icon-search" @click="choose()"></el-button>
</el-input>
<el-input placeholder="单位" v-model="consumer.company_.name" readonly>
<el-button slot="append" icon="el-icon-search" @click="choose()"></el-button>
</el-input>
<!-- <el-select
v-model="consumer.company"
placeholder="单位"
@ -254,7 +261,7 @@
:label="item.label"
:value="item.value"
></el-option>
</el-select> -->
</el-select>-->
</el-form-item>
<el-form-item label="缴费学科" prop="subjects">
<el-select v-model="consumer.subjects" placeholder="缴费学科" style="width:100%" multiple>
@ -286,6 +293,14 @@
></el-option>
</el-select>
</el-form-item>
<el-form-item label="账号过期" prop="exceed_date">
<el-date-picker
v-model="consumer.exceed_date"
type="date"
placeholder="选择日期"
value-format="yyyy-MM-dd">
</el-date-picker>
</el-form-item>
</el-form>
<div style="text-align:right;">
<el-button type="danger" @click="dialogVisible=false">取消</el-button>
@ -314,7 +329,7 @@ import {
exportConsumer,
deleteConsumers,
unbindConsumer,
getConsumerRoleAll
getConsumerRoleAll,
} from "@/api/crm";
import { getSubjectAll } from "@/api/question";
import { getWorkScopeAll } from "@/api/examtest";
@ -322,36 +337,36 @@ import { getCompanyList } from "@/api/crm";
import { genTree, deepClone } from "@/utils";
import checkPermission from "@/utils/permission";
import { upUrl } from "@/api/file";
import { getUserList } from "@/api/user"
import { getUserList } from "@/api/user";
import { getToken } from "@/utils/auth";
import Pagination from "@/components/Pagination"; // secondary package based on el-pagination
import Companychose from "@/views/crm/companychose"
import Companychose from "@/views/crm/companychose";
const defaultConsumer = {
id: "",
name: "",
username: "",
company: null,
company_:{},
company_: {},
subjects: [],
workscope: null,
role:3
role: 3,
};
const listQuery = {
page: 1,
limit: 20,
search: ""
search: "",
};
export default {
components: { Pagination, Companychose },
watch: {
filterOrgText(val) {
this.$refs.tree.filter(val);
}
},
},
data() {
return {
dgVisiable:false,
dgVisiable: false,
tableKey: 0,
showCreate: true,
upUrl: upUrl(),
@ -364,104 +379,109 @@ export default {
listQuery: {
page: 1,
limit: 20,
search: ""
search: "",
},
enabledOptions: [
{ key: "true", display_name: "已缴" },
{ key: "false", display_name: "未缴" }
{ key: "false", display_name: "未缴" },
],
dialogVisible: false,
dialogType: "new",
rule1: {
name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
username: [
{ required: true, message: "请输入手机号", trigger: "change", pattern: /^1[345789]\d{9}$/, }
{
required: true,
message: "请输入手机号",
trigger: "change",
pattern: /^1[3456789]\d{9}$/,
},
],
role: [
{ required: true, message: "请选择", trigger: "change" }
],
workscope: [
{ required: true, message: "请选择", trigger: "change"}
],
subjects: [
{ required: true, message: "请选择", trigger: "change"}
]
role: [{ required: true, message: "请选择", trigger: "change" }],
workscope: [{ required: true, message: "请选择", trigger: "change" }],
subjects: [{ required: true, message: "请选择", trigger: "change" }],
exceed_date: [{ required: true, message: "请选择", trigger: "change" }],
},
filterOrgText: "",
treeLoding: false,
companyData: [],
subjectData: [],
workscopeData: [],
roleData:[],
roleData: [],
selects: [],
pickerOptions: {
shortcuts: [{
text: '最近一天',
pickerOptions: {
shortcuts: [
{
text: "最近一天",
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一周',
picker.$emit("pick", [start, end]);
},
},
{
text: "最近一周",
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
picker.$emit("pick", [start, end]);
},
},
{
text: "最近一个月",
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
picker.$emit("pick", [start, end]);
},
},
{
text: "最近三个月",
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}]
},
datevalue: '',
adminOptions:[]
picker.$emit("pick", [start, end]);
},
},
],
},
datevalue: "",
adminOptions: [],
};
},
computed: {},
watch:{
datevalue:'setTimeRange',
watch: {
datevalue: "setTimeRange",
},
created() {
this.getList()
this.getCompanyList()
this.getSubjectAll()
this.getWorkScopeAll()
this.getConsumerRoleAll()
this.getAdminOptions()
this.getList();
this.getCompanyList();
this.getSubjectAll();
this.getWorkScopeAll();
this.getConsumerRoleAll();
this.getAdminOptions();
},
methods: {
checkPermission,
handleUploadSuccess(res, file) {
if (res.code == 200) {
const loading = this.$loading({ text: "正在导入中..." });
importConsumer(res.data).then(response => {
importConsumer(res.data).then((response) => {
loading.close();
if (response.code == 200) {
this.$message({
message: "导入成功",
type: "success"
type: "success",
});
this.getList(listQuery);
} else if (response.code == 206) {
this.$message({
message: "部分未成功" + response.data,
type: "success"
type: "success",
});
this.getList(listQuery);
} else {
@ -478,7 +498,7 @@ export default {
},
getList() {
this.listLoading = true;
getConsumerList(this.listQuery).then(response => {
getConsumerList(this.listQuery).then((response) => {
this.consumerList = response.data.results;
this.total = response.data.count;
this.listLoading = false;
@ -486,30 +506,30 @@ export default {
},
getCompanyList() {
this.treeLoding = true;
getCompanyList().then(response => {
getCompanyList().then((response) => {
this.companyData = genTree(response.data.results);
this.treeLoding = false;
});
},
searchCompany(val) {
this.treeLoding = true;
getCompanyList({search:val, perm:'all'}).then(response => {
getCompanyList({ search: val, perm: "all" }).then((response) => {
this.companyData = genTree(response.data.results);
this.treeLoding = false;
});
},
getSubjectAll() {
getSubjectAll().then(response => {
getSubjectAll().then((response) => {
this.subjectData = genTree(response.data);
});
},
getWorkScopeAll() {
getWorkScopeAll().then(response => {
getWorkScopeAll().then((response) => {
this.workscopeData = genTree(response.data);
});
},
getConsumerRoleAll() {
getConsumerRoleAll().then(response => {
getConsumerRoleAll().then((response) => {
this.roleData = genTree(response.data);
});
},
@ -517,7 +537,7 @@ export default {
this.listQuery = {
page: 1,
limit: 20,
search: ""
search: "",
};
this.getList();
},
@ -535,8 +555,8 @@ export default {
},
handleEdit(scope) {
this.consumer = Object.assign({}, scope.row); // copy obj
if(this.consumer.company_ == null){
this.consumer.company_ = {}
if (this.consumer.company_ == null) {
this.consumer.company_ = {};
}
this.dialogType = "edit";
this.dialogVisible = true;
@ -545,70 +565,82 @@ export default {
});
},
handleUnbind(scope) {
unbindConsumer(scope.row.id).then(res => {
if(res.code>=200){
this.$message({
type: "success",
message: "解绑成功!"
});
this.getList()
}
}).catch(err => {
console.error(err)
this.$confirm("确认解除该账户的微信绑定吗!", "警告", {
type: "warning",
})
.then(() => {
unbindConsumer(scope.row.id)
.then((res) => {
this.$message({
type: "success",
message: "解绑成功!",
});
this.getList();
})
.catch((err) => {
console.error(err);
});
})
.catch((err) => {
console.error(err);
});
},
handleDelete(scope) {
this.$confirm("确认删除该用户吗?将丢失数据!", "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "error"
type: "error",
})
.then(async () => {
await deleteConsumer(scope.row.id);
this.consumerList.splice(scope.row.index, 1);
this.$message({
type: "success",
message: "成功删除!"
message: "成功删除!",
});
})
.catch(err => {
.catch((err) => {
console.error(err);
});
},
handleDeletes() {
if(this.selects.length){
this.$confirm("确认删除这"+ this.selects.length + "位用户吗?将丢失数据!", "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "error"
})
if (this.selects.length) {
this.$confirm(
"确认删除这" + this.selects.length + "位用户吗?将丢失数据!",
"警告",
{
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "error",
}
)
.then(async () => {
const { code } = await deleteConsumers({ ids: this.selects });
if (code >= 200) {
this.getList()
this.getList();
this.$message({
type: "success",
message: "成功删除!"
message: "成功删除!",
});
}
})
.catch(err => {
.catch((err) => {
console.error(err);
});
}else{
} else {
this.$message({
message: '请先选择',
type: 'warning'
message: "请先选择",
type: "warning",
});
}
},
async confirmUser(form) {
this.$refs[form].validate(valid => {
this.$refs[form].validate((valid) => {
if (valid) {
const isEdit = this.dialogType === "edit";
if (isEdit) {
let consumer = this.consumer;
updateConsumer(this.consumer.id, consumer).then(res => {
updateConsumer(this.consumer.id, consumer).then((res) => {
// for (let index = 0; index < this.consumerList.length; index++) {
// if (this.consumerList[index].id === this.consumer.id) {
// this.consumerList.splice(
@ -621,29 +653,16 @@ export default {
// }
this.getList();
this.dialogVisible = false;
if (res.code >= 200) {
this.$notify({
title: "成功",
message: "编辑成功",
type: "success",
duration: 2000
});
}
this.$message.success('成功')
});
} else {
createConsumer(this.consumer).then(res => {
createConsumer(this.consumer).then((res) => {
// this.consumer = res.data
// this.consumerList.unshift(this.consumer)
this.getList();
this.dialogVisible = false;
if (res.code >= 200) {
this.$notify({
title: "成功",
message: "新增成功",
type: "success",
duration: 2000
});
}
this.$message.success('成功')
});
}
} else {
@ -653,7 +672,7 @@ export default {
},
exportConsumer() {
const loading = this.$loading();
exportConsumer(this.listQuery).then(response => {
exportConsumer(this.listQuery).then((response) => {
loading.close();
window.open(response.data.path, "_blank");
});
@ -674,16 +693,16 @@ export default {
}
this.selects = selects;
},
setTimeRange(){
this.listQuery.min_create = this.datevalue[0],
this.listQuery.max_create = this.datevalue[1],
this.getList()
setTimeRange() {
(this.listQuery.min_create = this.datevalue[0]),
(this.listQuery.max_create = this.datevalue[1]),
this.getList();
},
getAdminOptions(){
if(checkPermission(['admin'])){
getUserList().then(res=>{
this.adminOptions = genTree(res.data.results)
})
getAdminOptions() {
if (checkPermission(["admin"])) {
getUserList().then((res) => {
this.adminOptions = genTree(res.data.results);
});
}
},
choose() {
@ -692,11 +711,10 @@ export default {
chooseComplete(val) {
this.dgVisiable = false;
if (val) {
this.consumer.company_ = val
this.consumer.company = val.id
this.consumer.company_ = val;
this.consumer.company = val.id;
}
},
}
},
};
</script>

View File

@ -23,7 +23,7 @@ function request(url, method, data) {
msg = JSON.stringify(res.data.msg)
}
if (msg.indexOf('该操作的权限')!=-1){
msg = '权限不足,请注册登陆或联系课程顾问'
msg = '权限不足或账户过期,请联系课程顾问'
}
wx.showToast({
title: msg,

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.4 on 2020-08-24 02:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('crm', '0021_company_create_admin'),
]
operations = [
migrations.AddField(
model_name='consumer',
name='exceed_date',
field=models.DateField(blank=True, null=True, verbose_name='账号过期'),
),
]

View File

@ -73,6 +73,7 @@ class Consumer(CommonModel):
realname = models.CharField('真实姓名', max_length=100, null=True, blank=True)
create_admin = models.ForeignKey(UserProfile, default=1, on_delete=models.DO_NOTHING)
exceed_date = models.DateField('账号过期', null=True, blank=True)
class Meta:

View File

@ -3,7 +3,7 @@ from rbac.models import UserProfile
from crm.models import Consumer
from rest_framework.permissions import IsAuthenticated
from django.core.cache import cache
from django.utils import timezone
# 学员接口列表
ConsumerPerms = [
'paper_view',
@ -23,6 +23,8 @@ VistorPerms = [
]
def get_consumerperm_list(consumer):
perms = consumer.role.perms.values_list('code', flat=True)
if consumer.exceed_date < timezone.now():
perms.append('account_exceed')
cache.get_or_set('cperms_'+str(consumer.id), perms)
return perms
@ -49,6 +51,8 @@ class MyPermission(RbacPermission):
if perms:
if not hasattr(view, 'perms_map'):
return True
elif 'account_exceed' in perms: #账户过期
return False
else:
perms_map = view.perms_map
_method = request._request.method.lower()

View File

@ -2,7 +2,7 @@ import json
import random
import warnings
from calendar import timegm
from datetime import datetime
from datetime import date, datetime, timedelta
import requests
from django.db.models import Q
@ -372,6 +372,7 @@ class ConsumerViewSet(ModelViewSet):
obj.role = roleobj
except:
pass
obj.exceed_date = datetime.now() + timedelta(days=90)
obj.save()
m = m + 1
return Response(status=status.HTTP_200_OK)
@ -413,6 +414,12 @@ class ConsumerViewSet(ModelViewSet):
print(i.id)
return Response(status=status.HTTP_200_OK)
@action(methods=['get'], detail=False,
url_path='correctexceed', url_name='correct_exceed', perms_map=[{'*':'correct_exceed'}])
def correctexceed(self, request):
Consumer.objects.exclude(exceed_date=None).update(exceed_date = datetime(2020,12,31))
return Response(status=status.HTTP_200_OK)
class ConsumerMPLoginView(APIView):
"""
小程序登陆颁发token