index.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <style>
  2. .table-body {
  3. padding: 20px;
  4. background-color: #fff;
  5. }
  6. .input-item {
  7. display: inline-block;
  8. width: 250px;
  9. margin: 0 0 20px;
  10. }
  11. .input-item .el-input__inner {
  12. border-right: 0;
  13. }
  14. .input-item .el-input__inner:hover {
  15. border: 1px solid #dcdfe6;
  16. border-right: 0;
  17. outline: 0;
  18. }
  19. .input-item .el-input__inner:focus {
  20. border: 1px solid #dcdfe6;
  21. border-right: 0;
  22. outline: 0;
  23. }
  24. .input-item .el-input-group__append {
  25. background-color: #fff;
  26. border-left: 0;
  27. width: 10%;
  28. padding: 0;
  29. }
  30. .input-item .el-input-group__append .el-button {
  31. padding: 0;
  32. }
  33. .input-item .el-input-group__append .el-button {
  34. margin: 0;
  35. }
  36. .table-body .el-button {
  37. padding: 0 !important;
  38. border: 0;
  39. margin: 0 5px;
  40. }
  41. .el-table th > .cell {
  42. color: #333;
  43. font-weight: bold;
  44. font-size: 14px;
  45. }
  46. .el-table__footer-wrapper, .el-table__header-wrapper {
  47. border-bottom: 1.4px solid #D6D6D6;
  48. }
  49. .el-button--primary2 {
  50. color: #FFF;
  51. background-color: #03C5FF;
  52. border-color: #03C5FF;
  53. }
  54. </style>
  55. <div id="app" v-cloak>
  56. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  57. <div slot="header">
  58. <div>
  59. <span>卡密列表</span>
  60. </div>
  61. </div>
  62. <div class="table-body">
  63. <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
  64. @click="handle('import')" size="small">导入记录
  65. </el-button>
  66. <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
  67. @click="$navigate({r:'card-secret/card-secret/download-template'})" size="small">下载导入模板
  68. </el-button>
  69. <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
  70. @click="import_dialog()" size="small">导入卡密
  71. </el-button>
  72. <el-button class="el-button--primary2" style="padding: 9px 15px!important; float: right;" type="primary"
  73. @click="addgsForm()" size="small">添加卡密
  74. </el-button>
  75. <div class="input-item" style="float: left;">
  76. <el-input @keyup.enter.native="search" size="small"
  77. placeholder="搜索卡密名称"
  78. v-model="keyword"
  79. clearable
  80. @clear="search">
  81. <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
  82. </el-input>
  83. </div>
  84. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  85. <el-table-column prop="id" label="卡密序号" min-width="80" align="center"></el-table-column>
  86. <el-table-column label="卡号" min-width="150" align="center">
  87. <template slot-scope="scope">
  88. <com-ellipsis :line="1">{{scope.row.name}}</com-ellipsis>
  89. </template>
  90. </el-table-column>
  91. <el-table-column label="密码" min-width="100" align="center">
  92. <template slot-scope="scope">
  93. <com-ellipsis :line="1">{{scope.row.password}}</com-ellipsis>
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="状态" min-width="100" align="center">
  97. <template slot-scope="scope">
  98. <span v-if="scope.row.use_status == 2">待领取</span>
  99. <span v-if="scope.row.use_status == 3">已领取</span>
  100. <span v-if="scope.row.use_status == 1">未领取</span>
  101. <span v-if="scope.row.use_status == 4">已失效</span>
  102. </template>
  103. </el-table-column>
  104. <el-table-column prop="scope" width="180" label="创建时间">
  105. <template slot-scope="scope">
  106. {{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}
  107. </template>
  108. </el-table-column>
  109. <el-table-column
  110. label="操作"
  111. min-width="180"
  112. align="center">
  113. <template slot-scope="scope">
  114. <el-button circle size="mini" type="text" @click="getEdit(scope.row)">
  115. 修改
  116. </el-button>
  117. <el-button circle size="mini" type="text" @click="handle('delete',scope.row)">
  118. 删除
  119. </el-button>
  120. </template>
  121. </el-table-column>
  122. </el-table>
  123. <div style="text-align: right;margin: 20px 0;">
  124. <el-pagination v-if="pagination" :page-size="pagination.pageSize"
  125. style="display: inline-block;float: right;" background @current-change="pageChange"
  126. layout="prev, pager, next" :total="pagination.total_count">
  127. </el-pagination>
  128. </div>
  129. </div>
  130. <!-- 弹框添加分类开始-->
  131. <el-dialog :title="title" width="30%" :visible.sync="dialogAddgsVisible"
  132. @close="closeDialogAddgsVisible" :modal-append-to-body="false">
  133. <el-form :model="addForm" ref="addForm" :rules="addRule" :inline="true" @submit.native.prevent label-width="100px">
  134. <el-form-item label="卡号" prop="name">
  135. <el-input v-model="addForm.name" onkeyup="value=value.replace(/[^\d|a-z|A-Z]/g,'')" placeholder="请输入卡密名称"></el-input>
  136. </el-form-item>
  137. <el-form-item label="卡密" prop="password">
  138. <el-input v-model="addForm.password" @input="passwordChange" onkeyup="value=value.replace(/[^\d|a-z|A-Z]/g,'')" placeholder="请输入密码"></el-input>
  139. </el-form-item>
  140. </el-form>
  141. <span slot="footer" class="dialog-footer">
  142. <el-button @click="dialogAddgsVisible = false">取 消</el-button>
  143. <el-button type="primary" :loading="btnLoading" @click="handle('edit','addForm')">确 定</el-button>
  144. </span>
  145. </el-dialog>
  146. <!-- 弹框添加分类结束-->
  147. <!-- 导入弹窗开始-->
  148. <el-dialog @close="dialogColse" title="导入" :visible.sync="dialogFormVisible">
  149. <el-form :model="form" label-width="150px" ref="form">
  150. <el-form-item label="导入模板">
  151. <div>
  152. <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;">
  153. <el-input size="small" :disabled="true" v-model="attachments[0].name" class="input-with-select">
  154. <el-button slot="append">选择文件</el-button>
  155. </el-input>
  156. </com-upload>
  157. </div>
  158. </el-form-item>
  159. <div class="tips-text" style="margin-left: 150px;">仅支持csv格式的文件</div>
  160. </el-form>
  161. <div slot="footer">
  162. <el-button size="small" @click="dialogFormVisible = false">取 消</el-button>
  163. <el-button size="small" type="primary" @click="handle('submit',form)">提 交</el-button>
  164. </div>
  165. </el-dialog>
  166. <!-- 导入弹窗结束-->
  167. </el-card>
  168. </div>
  169. <script>
  170. const app = new Vue({
  171. el: '#app',
  172. data() {
  173. var validatePass = (rule, value, callback) => {
  174. var reg = /^[\u4e00-\u9fa5\w]+$/;
  175. if (reg.test(value)) {
  176. callback();
  177. }else{
  178. callback(new Error('规则名不能含有特殊字符'));
  179. }
  180. };
  181. return {
  182. list: [],
  183. id: null,
  184. sort: 0,
  185. keyword: '',
  186. cate_id:'',
  187. loading: false,
  188. loadingError: false,
  189. uploading: false,
  190. dialogErrorVisible: false,
  191. dialogFormVisible: false,
  192. export_id: 0,
  193. upload_type: {upload_type:'files'},
  194. express_companys: [],
  195. export_status_arr: [
  196. {name: '处理中', status: 0},
  197. {name: '已完成', status: 1},
  198. ],
  199. attachments: [{name: ''}],
  200. listLoading: false,
  201. btnLoading: false,
  202. pagination:null,
  203. page: 1,
  204. pageCount: 0,
  205. form:{
  206. file:null,
  207. cate_id:'',
  208. },
  209. //弹框配置
  210. addForm: {
  211. id : '',
  212. name : '',
  213. password:'',
  214. status : 1,
  215. sort:99,
  216. },
  217. addRule: {
  218. name: [
  219. {required: true, message: '请填写卡号', trigger: 'change'},
  220. {
  221. validator: (rule, value, callback) => {
  222. if(value.length>50||value.length<0){
  223. callback('最大长度在1-8个字内');
  224. }
  225. callback();
  226. }
  227. },
  228. {
  229. validator:validatePass,
  230. trigger: 'blur'
  231. },
  232. ],
  233. password:[
  234. {required: true, message: '请填写卡密', trigger: 'change'},
  235. {
  236. validator: (rule, value, callback) => {
  237. if(value.length>50||value.length<0){
  238. callback('最大长度在1-8个字内');
  239. }
  240. callback();
  241. }
  242. },
  243. {
  244. validator:validatePass,
  245. trigger: 'blur'
  246. },
  247. ],
  248. },
  249. title:'',
  250. dialogAddgsVisible: false,
  251. dataList: [],
  252. // 对话框显示与否
  253. dialogVisible: false,
  254. dataloading: false,
  255. addGroupVisible: false,
  256. };
  257. },
  258. methods: {
  259. sortChange(){
  260. this.$forceUpdate();
  261. },
  262. import_dialog(){
  263. this.form.cate_id = this.cate_id;
  264. this.dialogFormVisible = true;
  265. },
  266. handleStart(files) {
  267. this.uploading = true;
  268. },
  269. handleSuccess(file) {
  270. if (file.response && file.response.data && file.response.data.code === 0) {
  271. const newItem = {
  272. url: file.response.data.data.url,
  273. name: file.response.data.data.name,
  274. };
  275. this.attachments.unshift(newItem);
  276. }
  277. },
  278. handleComplete(files) {
  279. this.form.file = this.attachments[0].url;
  280. this.uploading = false;
  281. },
  282. handleExpressChange(e){
  283. let index = this.express_companys.findIndex(v => v.id == e);
  284. this.form.express_id = this.express_companys[index].id;
  285. this.form.express_name = this.express_companys[index].name;
  286. },
  287. search() {
  288. this.page = 1;
  289. this.getList();
  290. },
  291. pageChange(currentPage) {
  292. let self = this;
  293. self.page = currentPage; //console.log(currentPage,999999);
  294. self.getList();
  295. },
  296. getList() {
  297. let self = this;
  298. self.listLoading = true;
  299. request({
  300. params: {
  301. r: 'card-secret/card-secret/index',
  302. page: self.page,
  303. keyword: this.keyword,
  304. cate_id:self.cate_id,
  305. },
  306. method: 'get',
  307. }).then(e => {
  308. self.listLoading = false;
  309. self.list = e.data.data.list;
  310. this.pagination = e.data.data.pagination;
  311. this.pagination.pageSize = e.data.data.page_size;
  312. this.pagination.total_count = e.data.data.count;
  313. }).catch(e => {
  314. console.log(e);
  315. });
  316. },
  317. getEdit(data) {
  318. this.dialogAddgsVisible = true;
  319. this.title = "卡密编辑";
  320. this.addForm.id = data.id;
  321. this.addForm.name = data.name;
  322. this.addForm.password = data.password;
  323. this.addForm.sort = data.sort;
  324. },
  325. handle(type,data = null){
  326. switch (type) {
  327. case 'submit':
  328. this.send(data, 'card-secret/card-secret/import',(resp) => {
  329. navigateTo({
  330. r: 'card-secret/import-log/index',
  331. cate_id: this.cate_id,
  332. });
  333. });
  334. break;
  335. case 'delete':// 删除
  336. this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {type: 'warning'}).then(() => {this.send({id: data.id,status:-1,type:'1'},'card-secret/card-secret/edit');})
  337. break;
  338. case 'import':
  339. navigateTo({
  340. r: 'card-secret/import-log/index',
  341. cate_id: this.cate_id,
  342. });
  343. break;
  344. case 'edit':
  345. this.$refs[data].validate((valid) => {
  346. let self = this;
  347. if (valid) {
  348. if(this.addForm.id){
  349. this.send({name : self.addForm.name,password:self.addForm.password,id:this.addForm.id},'card-secret/card-secret/edit');
  350. }else{
  351. this.send({name : self.addForm.name,password:self.addForm.password,cate_id:self.cate_id},'card-secret/card-secret/edit');
  352. }
  353. } else {
  354. console.log('error submit!!');
  355. return false;
  356. }
  357. });
  358. break;
  359. }
  360. },
  361. send(data,r,callback){
  362. let self = this;
  363. self.btnLoading = true;
  364. request({
  365. params: {
  366. r: r,
  367. },
  368. method: 'post',
  369. data:data,
  370. }).then(e => {
  371. this.dialogAddgsVisible = false;
  372. this.btnLoading = false;
  373. if (e.data.code == 0) {
  374. self.$message.success(e.data.msg);
  375. self.getList();
  376. } else {
  377. self.$message.error(e.data.msg);
  378. }
  379. if (callback) callback(e.data);
  380. }).catch(e => {
  381. console.log(e);
  382. });
  383. },
  384. /**
  385. *点击新增按钮,弹出新增模态框
  386. * @param
  387. */
  388. addgsForm() {
  389. this.dialogAddgsVisible = true;
  390. this.title = "新增卡密";
  391. this.addForm.id = '';
  392. this.addForm.sort = 99;
  393. },
  394. /**
  395. *关闭或取消模态框,清空值
  396. * @param
  397. */
  398. closeDialogAddgsVisible() {
  399. this.$refs.addForm.resetFields();//element封装的方法,清空模态框的值
  400. this.title = "" //初始化title的值
  401. this.addForm = {//初始化addForm中的值
  402. name: "",
  403. }
  404. },
  405. // 弹框关闭事件回调
  406. dialogColse() {
  407. this.form = {
  408. express_id: null,
  409. express_name: null,
  410. file: null,
  411. };
  412. },
  413. },
  414. mounted: function () {
  415. this.cate_id = getQuery('id');
  416. this.getList();
  417. }
  418. });
  419. </script>