index.vue 8.9 KB

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