index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <div class="app-container">
  3. <doc-alert title="支付功能开启" url="https://doc.iocoder.cn/pay/build/" />
  4. <!-- 搜索工作栏 -->
  5. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  6. <el-form-item label="应用名" prop="name">
  7. <el-input v-model="queryParams.name" placeholder="请输入应用名" clearable
  8. @keyup.enter.native="handleQuery"/>
  9. </el-form-item>
  10. <el-form-item label="开启状态" prop="status">
  11. <el-select v-model="queryParams.status" placeholder="请选择开启状态" clearable>
  12. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="parseInt(dict.value)" :label="dict.label"
  13. :value="parseInt(dict.value)"/>
  14. </el-select>
  15. </el-form-item>
  16. <el-form-item label="创建时间" prop="createTime">
  17. <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
  18. range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  22. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <!-- 操作工具栏 -->
  26. <el-row :gutter="10" class="mb8">
  27. <el-col :span="1.5">
  28. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  29. v-hasPermi="['pay:app:create']">新增
  30. </el-button>
  31. </el-col>
  32. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  33. </el-row>
  34. <!-- 列表 -->
  35. <el-table v-loading="loading" :data="list">
  36. <el-table-column label="应用编号" align="center" prop="id"/>
  37. <el-table-column label="应用名" align="center" prop="name"/>
  38. <el-table-column label="开启状态" align="center" prop="status">
  39. <template v-slot="scope">
  40. <el-switch v-model="scope.row.status" :active-value="0" :inactive-value="1"
  41. @change="handleStatusChange(scope.row)"/>
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="支付宝配置" align="center">
  45. <el-table-column :label="payChannelEnum.ALIPAY_APP.name" align="center">
  46. <template v-slot="scope">
  47. <el-button type="success" icon="el-icon-check" circle
  48. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.ALIPAY_APP.code)"
  49. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_APP.code)">
  50. </el-button>
  51. <el-button v-else type="danger" icon="el-icon-close" circle
  52. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_APP.code)">
  53. </el-button>
  54. </template>
  55. </el-table-column>
  56. <el-table-column :label="payChannelEnum.ALIPAY_PC.name" align="center">
  57. <template v-slot="scope">
  58. <el-button type="success" icon="el-icon-check" circle
  59. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.ALIPAY_PC.code)"
  60. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_PC.code)">
  61. </el-button>
  62. <el-button v-else type="danger" icon="el-icon-close" circle
  63. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_PC.code)">
  64. </el-button>
  65. </template>
  66. </el-table-column>
  67. <el-table-column :label="payChannelEnum.ALIPAY_WAP.name" align="center">
  68. <template v-slot="scope">
  69. <el-button type="success" icon="el-icon-check" circle
  70. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.ALIPAY_WAP.code)"
  71. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_WAP.code)">
  72. </el-button>
  73. <el-button v-else type="danger" icon="el-icon-close" circle
  74. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_WAP.code)">
  75. </el-button>
  76. </template>
  77. </el-table-column>
  78. <el-table-column :label="payChannelEnum.ALIPAY_QR.name" align="center">
  79. <template v-slot="scope">
  80. <el-button type="success" icon="el-icon-check" circle
  81. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.ALIPAY_QR.code)"
  82. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_QR.code)">
  83. </el-button>
  84. <el-button v-else type="danger" icon="el-icon-close" circle
  85. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_QR.code)">
  86. </el-button>
  87. </template>
  88. </el-table-column>
  89. <el-table-column :label="payChannelEnum.ALIPAY_BAR.name" align="center">
  90. <template v-slot="scope">
  91. <el-button type="success" icon="el-icon-check" circle
  92. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.ALIPAY_BAR.code)"
  93. @click="handleChannel(scope.row,payChannelEnum.ALIPAY_BAR.code)">
  94. </el-button>
  95. <el-button v-else type="danger" icon="el-icon-close" circle
  96. @click="handleChannel(scope.row, payChannelEnum.ALIPAY_BAR.code)">
  97. </el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table-column>
  101. <el-table-column label="微信配置" align="center">
  102. <el-table-column :label="payChannelEnum.WX_LITE.name" align="center">
  103. <template v-slot="scope">
  104. <el-button type="success" icon="el-icon-check" circle
  105. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.WX_LITE.code)"
  106. @click="handleChannel(scope.row, payChannelEnum.WX_LITE.code)">
  107. </el-button>
  108. <el-button v-else type="danger" icon="el-icon-close" circle
  109. @click="handleChannel(scope.row, payChannelEnum.WX_LITE.code)">
  110. </el-button>
  111. </template>
  112. </el-table-column>
  113. <el-table-column :label="payChannelEnum.WX_PUB.name" align="center">
  114. <template v-slot="scope">
  115. <el-button type="success" icon="el-icon-check" circle
  116. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.WX_PUB.code)"
  117. @click="handleChannel(scope.row, payChannelEnum.WX_PUB.code)">
  118. </el-button>
  119. <el-button v-else type="danger" icon="el-icon-close" circle
  120. @click="handleChannel(scope.row, payChannelEnum.WX_PUB.code)">
  121. </el-button>
  122. </template>
  123. </el-table-column>
  124. <el-table-column :label="payChannelEnum.WX_APP.name" align="center">
  125. <template v-slot="scope">
  126. <el-button type="success" icon="el-icon-check" circle
  127. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.WX_APP.code)"
  128. @click="handleChannel(scope.row, payChannelEnum.WX_APP.code)">
  129. </el-button>
  130. <el-button v-else type="danger" icon="el-icon-close" circle
  131. @click="handleChannel(scope.row, payChannelEnum.WX_APP.code)">
  132. </el-button>
  133. </template>
  134. </el-table-column>
  135. <el-table-column :label="payChannelEnum.WX_NATIVE.name" align="center">
  136. <template v-slot="scope">
  137. <el-button type="success" icon="el-icon-check" circle
  138. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.WX_NATIVE.code)"
  139. @click="handleChannel(scope.row, payChannelEnum.WX_NATIVE.code)">
  140. </el-button>
  141. <el-button v-else type="danger" icon="el-icon-close" circle
  142. @click="handleChannel(scope.row, payChannelEnum.WX_NATIVE.code)">
  143. </el-button>
  144. </template>
  145. </el-table-column>
  146. <el-table-column :label="payChannelEnum.WX_BAR.name" align="center">
  147. <template v-slot="scope">
  148. <el-button type="success" icon="el-icon-check" circle
  149. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.WX_BAR.code)"
  150. @click="handleChannel(scope.row, payChannelEnum.WX_BAR.code)">
  151. </el-button>
  152. <el-button v-else type="danger" icon="el-icon-close" circle
  153. @click="handleChannel(scope.row, payChannelEnum.WX_BAR.code)">
  154. </el-button>
  155. </template>
  156. </el-table-column>
  157. </el-table-column>
  158. <el-table-column label="模拟支付配置" align="center">
  159. <el-table-column :label="payChannelEnum.MOCK.name" align="center">
  160. <template v-slot="scope">
  161. <el-button type="success" icon="el-icon-check" circle
  162. v-if="isChannelExists(scope.row.channelCodes, payChannelEnum.MOCK.code)"
  163. @click="handleChannel(scope.row, payChannelEnum.MOCK.code)">
  164. </el-button>
  165. <el-button v-else type="danger" icon="el-icon-close" circle
  166. @click="handleChannel(scope.row, payChannelEnum.MOCK.code)">
  167. </el-button>
  168. </template>
  169. </el-table-column>
  170. </el-table-column>
  171. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  172. <template v-slot="scope">
  173. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  174. v-hasPermi="['pay:app:update']">修改
  175. </el-button>
  176. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  177. v-hasPermi="['pay:app:delete']">删除
  178. </el-button>
  179. </template>
  180. </el-table-column>
  181. </el-table>
  182. <!-- 分页组件 -->
  183. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  184. @pagination="getList"/>
  185. <!-- 对话框(添加 / 修改) -->
  186. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  187. <el-form ref="form" :model="form" :rules="rules" label-width="160px">
  188. <el-form-item label="应用名" prop="name">
  189. <el-input v-model="form.name" placeholder="请输入应用名"/>
  190. </el-form-item>
  191. <el-form-item label="开启状态" prop="status">
  192. <el-radio-group v-model="form.status">
  193. <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)" :key="parseInt(dict.value)" :label="parseInt(dict.value)">
  194. {{ dict.label }}
  195. </el-radio>
  196. </el-radio-group>
  197. </el-form-item>
  198. <el-form-item label="支付结果的回调地址" prop="orderNotifyUrl">
  199. <el-input v-model="form.orderNotifyUrl" placeholder="请输入支付结果的回调地址"/>
  200. </el-form-item>
  201. <el-form-item label="退款结果的回调地址" prop="refundNotifyUrl">
  202. <el-input v-model="form.refundNotifyUrl" placeholder="请输入退款结果的回调地址"/>
  203. </el-form-item>
  204. <el-form-item label="备注" prop="remark">
  205. <el-input v-model="form.remark" placeholder="请输入备注"/>
  206. </el-form-item>
  207. </el-form>
  208. <div slot="footer" class="dialog-footer">
  209. <el-button type="primary" @click="submitForm">确 定</el-button>
  210. <el-button @click="cancel">取 消</el-button>
  211. </div>
  212. </el-dialog>
  213. <!-- 对话框(支付应用的配置) -->
  214. <weixin-channel-form ref="weixinChannelFormRef" @success="getList" />
  215. <alipay-channel-form ref="alipayChannelFormRef" @success="getList" />
  216. <mock-channel-form ref="mockChannelFormRef" @success="getList" />
  217. </div>
  218. </template>
  219. <script>
  220. import { createApp, updateApp, changeAppStatus, deleteApp, getApp, getAppPage } from "@/api/pay/app";
  221. import { PayChannelEnum, CommonStatusEnum } from "@/utils/constants";
  222. import weixinChannelForm from "@/views/pay/app/components/weixinChannelForm";
  223. import alipayChannelForm from "@/views/pay/app/components/alipayChannelForm";
  224. import mockChannelForm from '@/views/pay/app/components/mockChannelForm';
  225. export default {
  226. name: "PayApp",
  227. components: {
  228. weixinChannelForm,
  229. alipayChannelForm,
  230. mockChannelForm
  231. },
  232. data() {
  233. return {
  234. // 遮罩层
  235. loading: true,
  236. // 显示搜索条件
  237. showSearch: true,
  238. // 总条数
  239. total: 0,
  240. // 支付应用信息列表
  241. list: [],
  242. // 弹出层标题
  243. title: "",
  244. // 是否显示弹出层
  245. open: false,
  246. // 查询参数
  247. queryParams: {
  248. pageNo: 1,
  249. pageSize: 10,
  250. name: null,
  251. status: null,
  252. createTime: []
  253. },
  254. // 表单参数
  255. form: {},
  256. // 表单校验
  257. rules: {
  258. name: [{required: true, message: "应用名不能为空", trigger: "blur"}],
  259. status: [{required: true, message: "开启状态不能为空", trigger: "blur"}],
  260. orderNotifyUrl: [{required: true, message: "支付结果的回调地址不能为空", trigger: "blur"}],
  261. refundNotifyUrl: [{required: true, message: "退款结果的回调地址不能为空", trigger: "blur"}],
  262. },
  263. // 支付渠道枚举
  264. payChannelEnum: PayChannelEnum,
  265. };
  266. },
  267. created() {
  268. this.getList();
  269. },
  270. methods: {
  271. /** 查询列表 */
  272. getList() {
  273. this.loading = true;
  274. // 执行查询
  275. getAppPage(this.queryParams).then(response => {
  276. this.list = response.data.list;
  277. this.total = response.data.total;
  278. this.loading = false;
  279. });
  280. },
  281. /** 取消按钮 */
  282. cancel() {
  283. this.open = false;
  284. this.reset();
  285. },
  286. /** 表单重置 */
  287. reset() {
  288. this.form = {
  289. id: undefined,
  290. name: undefined,
  291. status: CommonStatusEnum.ENABLE,
  292. remark: undefined,
  293. orderNotifyUrl: undefined,
  294. refundNotifyUrl: undefined,
  295. };
  296. this.resetForm("form");
  297. },
  298. /** 搜索按钮操作 */
  299. handleQuery() {
  300. this.queryParams.pageNo = 1;
  301. this.getList();
  302. },
  303. /** 重置按钮操作 */
  304. resetQuery() {
  305. this.resetForm("queryForm");
  306. this.handleQuery();
  307. },
  308. /** 新增按钮操作 */
  309. handleAdd() {
  310. this.reset();
  311. this.open = true;
  312. this.title = "添加支付应用信息";
  313. },
  314. /** 修改按钮操作 */
  315. handleUpdate(row) {
  316. this.reset();
  317. const id = row.id;
  318. getApp(id).then(response => {
  319. this.form = response.data;
  320. this.open = true;
  321. this.title = "修改支付应用信息";
  322. });
  323. },
  324. // 用户状态修改
  325. handleStatusChange(row) {
  326. let text = row.status === CommonStatusEnum.ENABLE ? "启用" : "停用";
  327. this.$modal.confirm('确认要"' + text + '""' + row.name + '"应用吗?').then(function () {
  328. return changeAppStatus(row.id, row.status);
  329. }).then(() => {
  330. this.$modal.msgSuccess(text + "成功");
  331. }).catch(function () {
  332. row.status = row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE
  333. : CommonStatusEnum.ENABLE;
  334. });
  335. },
  336. /** 提交按钮 */
  337. submitForm() {
  338. this.$refs["form"].validate(valid => {
  339. if (!valid) {
  340. return;
  341. }
  342. // 修改的提交
  343. if (this.form.id != null) {
  344. updateApp(this.form).then(response => {
  345. this.$modal.msgSuccess("修改成功");
  346. this.open = false;
  347. this.getList();
  348. });
  349. return;
  350. }
  351. // 添加的提交
  352. createApp(this.form).then(response => {
  353. this.$modal.msgSuccess("新增成功");
  354. this.open = false;
  355. this.getList();
  356. });
  357. });
  358. },
  359. /** 删除按钮操作 */
  360. handleDelete(row) {
  361. this.$modal.confirm('是否确认删除支付应用信息编号为"' + row.id + '"的数据项?').then(function () {
  362. return deleteApp(row.id);
  363. }).then(() => {
  364. this.getList();
  365. this.$modal.msgSuccess("删除成功");
  366. }).catch(() => {
  367. this.$message({
  368. type: 'info',
  369. message: '已取消删除'
  370. });
  371. });
  372. },
  373. /**
  374. * 修改支付渠道信息
  375. */
  376. handleChannel(row, code) {
  377. if (code.indexOf('alipay_') === 0) {
  378. this.$refs['alipayChannelFormRef'].open(row.id, code);
  379. return
  380. }
  381. if (code.indexOf('wx_') === 0) {
  382. this.$refs['weixinChannelFormRef'].open(row.id, code);
  383. return
  384. }
  385. if (code === 'mock') {
  386. this.$refs['mockChannelFormRef'].open(row.id, code);
  387. return
  388. }
  389. },
  390. /**
  391. * 根据渠道编码判断渠道列表中是否存在
  392. *
  393. * @param channels 渠道列表
  394. * @param channelCode 渠道编码
  395. */
  396. isChannelExists(channels, channelCode) {
  397. return channels && channels.indexOf(channelCode) !== -1;
  398. }
  399. }
  400. }
  401. </script>