index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  4. <el-form-item label="二维码名称" prop="name">
  5. <el-input
  6. v-model.trim="queryParams.name"
  7. placeholder="请输入身份信息"
  8. clearable
  9. size="small"
  10. style="width: 140px"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  16. <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  17. <el-button
  18. type="primary"
  19. plain
  20. icon="el-icon-plus"
  21. size="mini"
  22. @click="handleAdd"
  23. v-hasPermi="['system:admin:add']"
  24. >新增</el-button>
  25. </el-form-item>
  26. </el-form>
  27. <el-table v-loading="loading" :data="adminList" @selection-change="handleSelectionChange" height="calc(100vh - 10vh - 120px)">
  28. <!-- <el-table-column type="selection" width="55" align="center" /> -->
  29. <el-table-column label="二维码名称" align="center" prop="name" show-overflow-tooltip />
  30. <el-table-column label="渠道名称" align="center" prop="topChannelName" show-overflow-tooltip />
  31. <el-table-column label="二维码" align="center" prop="qrPath" show-overflow-tooltip >
  32. <template slot-scope="scope" >
  33. <el-image
  34. v-if="scope.row.qrPath"
  35. style="width: 100px; height: 100px"
  36. :preview-src-list="[scope.row.qrPath]"
  37. :src="scope.row.qrPath">
  38. </el-image>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="创建时间" align="center" prop="createTime" show-overflow-tooltip >
  42. <template slot-scope="scope">
  43. <span>{{ parseTime(scope.row.createTime) }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  47. <template slot-scope="scope">
  48. <el-button
  49. size="mini"
  50. type="text"
  51. icon="el-icon-edit"
  52. @click="handleUpdate(scope.row)"
  53. v-hasPermi="['system:admin:edit']"
  54. >修改</el-button>
  55. <el-button
  56. size="mini"
  57. type="text"
  58. icon="el-icon-delete"
  59. @click="handleDelete(scope.row)"
  60. v-hasPermi="['system:admin:remove']"
  61. >删除</el-button>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <pagination
  66. v-show="total>0"
  67. :total="total"
  68. :page.sync="queryParams.current"
  69. :limit.sync="queryParams.size"
  70. @pagination="getList"
  71. />
  72. <!-- 添加或修改参数配置对话框 -->
  73. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :before-close="cancel" :close-on-click-modal="false">
  74. <el-form ref="form" :model="form" :rules="rules" label-width="100px" >
  75. <el-row :gutter="20">
  76. <el-col :span="16">
  77. <el-form-item label="二维码名称" prop="name">
  78. <el-input v-model.trim="form.name" placeholder="请输入二维码名称" @input="forceUpdate" maxlength="15" show-word-limit />
  79. </el-form-item>
  80. </el-col>
  81. <el-col :span="16">
  82. <el-form-item label="渠道名称" prop="topChannelId">
  83. <el-select v-model.trim="form.topChannelId" placeholder="请选择渠道名称" @input="forceUpdate" >
  84. <el-option
  85. v-for="dict in channelList"
  86. :key="dict.id"
  87. :label="dict.name"
  88. :value="dict.id"/>
  89. </el-select>
  90. </el-form-item>
  91. </el-col>
  92. </el-row>
  93. </el-form>
  94. <div slot="footer" class="dialog-footer">
  95. <el-button type="primary" @click="submitForm" v-if="!loading">确 定</el-button>
  96. <el-button :loading="loading" type="primary" @click="submitForm" v-else>提交中...</el-button>
  97. <el-button @click="cancel">取 消</el-button>
  98. </div>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import { addCode, updataCode, delCode, listCode, channlPageCode, getBs } from "@/api/recharge/qrCode";
  104. import QRCode from 'qrcode'
  105. export default {
  106. name: "admin",
  107. data() {
  108. return {
  109. // 遮罩层
  110. loading: true,
  111. // 导出遮罩层
  112. exportLoading: false,
  113. // 选中数组
  114. ids: [],
  115. // 非单个禁用
  116. single: true,
  117. // 非多个禁用
  118. multiple: true,
  119. // 显示搜索条件
  120. showSearch: true,
  121. // 总条数
  122. total: 0,
  123. // 参数表格数据
  124. adminList: [],
  125. // 充值渠道下拉
  126. channelList: [],
  127. // 弹出层标题
  128. title: "",
  129. // 是否显示弹出层
  130. open: false,
  131. // 查询参数
  132. queryParams: {
  133. current: 1,
  134. size: 10,
  135. name: undefined,
  136. topChannelName: undefined,
  137. },
  138. // 表单参数
  139. form: {
  140. name:'',
  141. topChannelId:''
  142. },
  143. codeUrl:null,
  144. // 表单校验
  145. rules: {
  146. name: [
  147. { required: true, message: "二维码名称不能为空", trigger: "blur" }
  148. ],
  149. topChannelName: [
  150. { required: true, message: "渠道名称不能为空", trigger: "blur" }
  151. ],
  152. }
  153. };
  154. },
  155. created() {
  156. this.getList();
  157. channlPageCode().then(response => this.channelList = response.data);
  158. },
  159. methods: {
  160. forceUpdate(){ //重置form
  161. this.form = JSON.parse(JSON.stringify(this.form));
  162. },
  163. /** 查询参数列表 */
  164. getList() {
  165. this.loading = true;
  166. listCode(this.addDateRange(this.queryParams)).then(response => {
  167. var data = response.data.records
  168. for(let i =0;i<data.length; i++){
  169. QRCode.toDataURL(data[i].qrPath,{type: "image/png", //类型
  170. quality: 0.5, //图片质量A Number between 0 and 1
  171. width: 500, //高度
  172. height: 500, //宽度
  173. errorCorrectionLevel: "L", //容错率
  174. margin: 1, //外边距
  175. color: {
  176. dark: "#000000", //前景色
  177. light: "#ffffff" //背景色
  178. }}
  179. ).then(imgData => {
  180. data[i].qrPath = imgData
  181. });
  182. }
  183. this.adminList = data;
  184. this.total = response.data.total;
  185. this.loading = false;
  186. });
  187. },
  188. // 取消按钮
  189. cancel() {
  190. this.open = false;
  191. this.reset();
  192. },
  193. // 表单重置
  194. reset() {
  195. this.form = {
  196. ids: undefined,
  197. name: undefined,
  198. topChannelName: undefined,
  199. topChannelId:undefined
  200. };
  201. this.resetForm("form");
  202. },
  203. /** 搜索按钮操作 */
  204. handleQuery() {
  205. this.queryParams.current = 1;
  206. this.getList();
  207. },
  208. /** 重置按钮操作 */
  209. resetQuery() {
  210. this.dateRange = [];
  211. this.resetForm("queryForm");
  212. this.handleQuery();
  213. },
  214. /** 新增按钮操作 */
  215. handleAdd() {
  216. this.reset();
  217. this.open = true;
  218. this.title = "添加参数";
  219. },
  220. // 多选框选中数据
  221. handleSelectionChange(selection) {
  222. this.ids = selection.map(item => item.id)
  223. this.single = selection.length!=1
  224. this.multiple = !selection.length
  225. },
  226. /** 修改按钮操作 */
  227. handleUpdate(row) {
  228. Object.assign(this.form, row.id ? this.adminList.find(val=>val.id === row.id) : this.adminList.find(val=>val.id === this.ids[0]))
  229. this.open = true;
  230. this.title = "修改参数";
  231. },
  232. /** 提交按钮 */
  233. submitForm(row) {
  234. this.$refs["form"].validate(valid => {
  235. if (valid) {
  236. this.loading = true
  237. if (this.form.id != undefined) {
  238. updataCode(this.form).then(response => {
  239. this.loading = false
  240. this.msgSuccess("修改成功");
  241. this.open = false;
  242. this.getList();
  243. }).catch(()=>{
  244. this.loading = false,
  245. this.open = false
  246. })
  247. } else {
  248. addCode(this.form).then(response => {
  249. this.loading = false
  250. this.msgSuccess("新增成功");
  251. this.open = false;
  252. this.getList();
  253. }).catch(()=>{
  254. this.loading = false,
  255. this.open = false
  256. })
  257. }
  258. }
  259. });
  260. },
  261. /** 删除按钮操作 */
  262. handleDelete(row) {
  263. const ids = row.id || this.ids;
  264. this.$confirm('是否确认删除', "警告", {
  265. confirmButtonText: "确定",
  266. cancelButtonText: "取消",
  267. type: "warning"
  268. }).then(function(res) {
  269. return delCode(ids);
  270. }).then(() => {
  271. this.getList();
  272. this.msgSuccess("删除成功");
  273. }).catch(() => {});
  274. },
  275. }
  276. };
  277. </script>