| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445 |
- <style>
- .table-body {
- padding: 20px;
- background-color: #fff;
- }
- .input-item {
- display: inline-block;
- width: 250px;
- margin: 0 0 20px;
- }
- .input-item .el-input__inner {
- border-right: 0;
- }
- .input-item .el-input__inner:hover {
- border: 1px solid #dcdfe6;
- border-right: 0;
- outline: 0;
- }
- .input-item .el-input__inner:focus {
- border: 1px solid #dcdfe6;
- border-right: 0;
- outline: 0;
- }
- .input-item .el-input-group__append {
- background-color: #fff;
- border-left: 0;
- width: 10%;
- padding: 0;
- }
- .input-item .el-input-group__append .el-button {
- padding: 0;
- }
- .input-item .el-input-group__append .el-button {
- margin: 0;
- }
- .table-body .el-button {
- padding: 0 !important;
- border: 0;
- margin: 0 5px;
- }
- .el-table th > .cell {
- color: #333;
- font-weight: bold;
- font-size: 14px;
- }
- .el-table__footer-wrapper, .el-table__header-wrapper {
- border-bottom: 1.4px solid #D6D6D6;
- }
- .el-button--primary2 {
- color: #FFF;
- background-color: #03C5FF;
- border-color: #03C5FF;
- }
- </style>
- <div id="app" v-cloak>
- <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
- <div slot="header">
- <div>
- <span>卡密列表</span>
- </div>
- </div>
- <div class="table-body">
- <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
- @click="handle('import')" size="small">导入记录
- </el-button>
- <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
- @click="$navigate({r:'card-secret/card-secret/download-template'})" size="small">下载导入模板
- </el-button>
- <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
- @click="import_dialog()" size="small">导入卡密
- </el-button>
- <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
- @click="addgsForm()" size="small">添加卡密
- </el-button>
- <div class="input-item" style="float: left;">
- <el-input @keyup.enter.native="search" size="small"
- placeholder="搜索卡密名称"
- v-model="keyword"
- clearable
- @clear="search">
- <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
- </el-input>
- </div>
- <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
- <el-table-column prop="id" label="卡密序号" min-width="80" align="center"></el-table-column>
- <el-table-column label="卡号" min-width="150" align="center">
- <template slot-scope="scope">
- <com-ellipsis :line="1">{{scope.row.name}}</com-ellipsis>
- </template>
- </el-table-column>
- <el-table-column label="密码" min-width="100" align="center">
- <template slot-scope="scope">
- <com-ellipsis :line="1">{{scope.row.password}}</com-ellipsis>
- </template>
- </el-table-column>
- <el-table-column label="状态" min-width="100" align="center">
- <template slot-scope="scope">
- <span v-if="scope.row.use_status == 2">待领取</span>
- <span v-if="scope.row.use_status == 3">已领取</span>
- <span v-if="scope.row.use_status == 1">未领取</span>
- <span v-if="scope.row.use_status == 4">已失效</span>
- </template>
- </el-table-column>
- <el-table-column prop="scope" width="180" label="创建时间">
- <template slot-scope="scope">
- {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
- </template>
- </el-table-column>
- <el-table-column
- label="操作"
- min-width="180"
- align="center">
- <template slot-scope="scope">
- <el-button circle size="mini" type="text" @click="getEdit(scope.row)">
- 修改
- </el-button>
- <el-button circle size="mini" type="text" @click="handle('delete',scope.row)">
- 删除
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <div style="text-align: right;margin: 20px 0;">
- <el-pagination v-if="pagination" :page-size="pagination.pageSize"
- style="display: inline-block;float: right;" background @current-change="pageChange"
- layout="prev, pager, next" :total="pagination.total_count">
- </el-pagination>
- </div>
- </div>
- <!-- 弹框添加分类开始-->
- <el-dialog :title="title" width="30%" :visible.sync="dialogAddgsVisible"
- @close="closeDialogAddgsVisible" :modal-append-to-body="false">
- <el-form :model="addForm" ref="addForm" :rules="addRule" :inline="true" @submit.native.prevent label-width="100px">
- <el-form-item label="卡号" prop="name">
- <el-input v-model="addForm.name" onkeyup="value=value.replace(/[^\d|a-z|A-Z]/g,'')" placeholder="请输入卡密名称"></el-input>
- </el-form-item>
- <el-form-item label="卡密" prop="password">
- <el-input v-model="addForm.password" @input="passwordChange" onkeyup="value=value.replace(/[^\d|a-z|A-Z]/g,'')" placeholder="请输入密码"></el-input>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="dialogAddgsVisible = false">取 消</el-button>
- <el-button type="primary" :loading="btnLoading" @click="handle('edit','addForm')">确 定</el-button>
- </span>
- </el-dialog>
- <!-- 弹框添加分类结束-->
- <!-- 导入弹窗开始-->
- <el-dialog @close="dialogColse" title="导入" :visible.sync="dialogFormVisible">
- <el-form :model="form" label-width="150px" ref="form">
- <el-form-item label="导入模板">
- <div>
- <com-upload class="flex flex-y-center" v-loading="uploading" :disabled="uploading" :fields="upload_type" @start="handleStart" @success="handleSuccess" @complete="handleComplete" :max="1" accept=".csv" style="width: 40%;float: left;margin-right: 20px;">
- <el-input size="small" :disabled="true" v-model="attachments[0].name" class="input-with-select">
- <el-button slot="append">选择文件</el-button>
- </el-input>
- </com-upload>
- </div>
- </el-form-item>
- <div class="tips-text" style="margin-left: 150px;">仅支持csv格式的文件</div>
- </el-form>
- <div slot="footer">
- <el-button size="small" @click="dialogFormVisible = false">取 消</el-button>
- <el-button size="small" type="primary" @click="handle('submit',form)">提 交</el-button>
- </div>
- </el-dialog>
- <!-- 导入弹窗结束-->
- </el-card>
- </div>
- <script>
- const app = new Vue({
- el: '#app',
- data() {
- var validatePass = (rule, value, callback) => {
- var reg = /^[\u4e00-\u9fa5\w]+$/;
- if (reg.test(value)) {
- callback();
- }else{
- callback(new Error('规则名不能含有特殊字符'));
- }
- };
- return {
- list: [],
- id: null,
- sort: 0,
- keyword: '',
- cate_id:'',
- loading: false,
- loadingError: false,
- uploading: false,
- dialogErrorVisible: false,
- dialogFormVisible: false,
- export_id: 0,
- upload_type: {upload_type:'files'},
- express_companys: [],
- export_status_arr: [
- {name: '处理中', status: 0},
- {name: '已完成', status: 1},
- ],
- attachments: [{name: ''}],
- listLoading: false,
- btnLoading: false,
- pagination:null,
- page: 1,
- pageCount: 0,
- form:{
- file:null,
- cate_id:'',
- },
- //弹框配置
- addForm: {
- id : '',
- name : '',
- password:'',
- status : 1,
- sort:99,
- },
- addRule: {
- name: [
- {required: true, message: '请填写卡号', trigger: 'change'},
- {
- validator: (rule, value, callback) => {
- if(value.length>50||value.length<0){
- callback('最大长度在1-8个字内');
- }
- callback();
- }
- },
- {
- validator:validatePass,
- trigger: 'blur'
- },
- ],
- password:[
- {required: true, message: '请填写卡密', trigger: 'change'},
- {
- validator: (rule, value, callback) => {
- if(value.length>50||value.length<0){
- callback('最大长度在1-8个字内');
- }
- callback();
- }
- },
- {
- validator:validatePass,
- trigger: 'blur'
- },
- ],
- },
- title:'',
- dialogAddgsVisible: false,
- dataList: [],
- // 对话框显示与否
- dialogVisible: false,
- dataloading: false,
- addGroupVisible: false,
- };
- },
- methods: {
- sortChange(){
- this.$forceUpdate();
- },
- import_dialog(){
- this.form.cate_id = this.cate_id;
- this.dialogFormVisible = true;
- },
- handleStart(files) {
- this.uploading = true;
- },
- handleSuccess(file) {
- if (file.response && file.response.data && file.response.data.code === 0) {
- const newItem = {
- url: file.response.data.data.url,
- name: file.response.data.data.name,
- };
- this.attachments.unshift(newItem);
- }
- },
- handleComplete(files) {
- this.form.file = this.attachments[0].url;
- this.uploading = false;
- },
- handleExpressChange(e){
- let index = this.express_companys.findIndex(v => v.id == e);
- this.form.express_id = this.express_companys[index].id;
- this.form.express_name = this.express_companys[index].name;
- },
- search() {
- this.page = 1;
- this.getList();
- },
- pageChange(currentPage) {
- let self = this;
- self.page = currentPage; //console.log(currentPage,999999);
- self.getList();
- },
- getList() {
- let self = this;
- self.listLoading = true;
- request({
- params: {
- r: 'card-secret/card-secret/index',
- page: self.page,
- keyword: this.keyword,
- cate_id:self.cate_id,
- },
- method: 'get',
- }).then(e => {
- self.listLoading = false;
- self.list = e.data.data.list;
- this.pagination = e.data.data.pagination;
- this.pagination.pageSize = e.data.data.page_size;
- this.pagination.total_count = e.data.data.count;
- }).catch(e => {
- console.log(e);
- });
- },
- getEdit(data) {
- this.dialogAddgsVisible = true;
- this.title = "卡密编辑";
- this.addForm.id = data.id;
- this.addForm.name = data.name;
- this.addForm.password = data.password;
- this.addForm.sort = data.sort;
- },
- handle(type,data = null){
- switch (type) {
- case 'submit':
- this.send(data, 'card-secret/card-secret/import',(resp) => {
- navigateTo({
- r: 'card-secret/import-log/index',
- cate_id: this.cate_id,
- });
- });
- break;
- case 'delete':// 删除
- this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {type: 'warning'}).then(() => {this.send({id: data.id,status:-1,type:'1'},'card-secret/card-secret/edit');})
- break;
- case 'import':
- navigateTo({
- r: 'card-secret/import-log/index',
- cate_id: this.cate_id,
- });
- break;
- case 'edit':
- this.$refs[data].validate((valid) => {
- let self = this;
- if (valid) {
- if(this.addForm.id){
- this.send({name : self.addForm.name,password:self.addForm.password,id:this.addForm.id},'card-secret/card-secret/edit');
- }else{
- this.send({name : self.addForm.name,password:self.addForm.password,cate_id:self.cate_id},'card-secret/card-secret/edit');
- }
- } else {
- console.log('error submit!!');
- return false;
- }
- });
- break;
- }
- },
- send(data,r,callback){
- let self = this;
- self.btnLoading = true;
- request({
- params: {
- r: r,
- },
- method: 'post',
- data:data,
- }).then(e => {
- this.dialogAddgsVisible = false;
- this.btnLoading = false;
- if (e.data.code == 0) {
- self.$message.success(e.data.msg);
- self.getList();
- } else {
- self.$message.error(e.data.msg);
- }
- if (callback) callback(e.data);
- }).catch(e => {
- console.log(e);
- });
- },
- /**
- *点击新增按钮,弹出新增模态框
- * @param
- */
- addgsForm() {
- this.dialogAddgsVisible = true;
- this.title = "新增卡密";
- this.addForm.id = '';
- this.addForm.sort = 99;
- },
- /**
- *关闭或取消模态框,清空值
- * @param
- */
- closeDialogAddgsVisible() {
- this.$refs.addForm.resetFields();//element封装的方法,清空模态框的值
- this.title = "" //初始化title的值
- this.addForm = {//初始化addForm中的值
- name: "",
- }
- },
- // 弹框关闭事件回调
- dialogColse() {
- this.form = {
- express_id: null,
- express_name: null,
- file: null,
- };
- },
- },
- mounted: function () {
- this.cate_id = getQuery('id');
- this.getList();
- }
- });
- </script>
|