bussiness.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList"
  4. :before-open="beforeOpen" v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
  5. @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange" @current-change="currentChange"
  6. @size-change="sizeChange" @refresh-change="refreshChange" @on-load="onLoad">
  7. <template slot="menuLeft">
  8. <el-button type="danger" size="small" icon="el-icon-delete" plain v-if="permission.bussiness_delete" @click="handleDelete">删
  9. </el-button>
  10. <el-button type="success" size="small" icon="el-icon-upload" plain v-if="permission.bussiness_generateapi" @click="generateDoc">
  11. 生成api文档
  12. </el-button>
  13. </template>
  14. <template slot="maxLimitForm" slot-scope="scope">
  15. <avue-input-number v-model="scope.row.maxLimit" precision="2" controls-position></avue-input-number>
  16. </template>
  17. <template slot="apiFilePath" slot-scope="scope">
  18. <el-tab v-if="scope.row.apiFilePath == null">无</el-tab>
  19. <el-tab v-if="scope.row.apiFilePath != null&&scope.row.apiFilePath != ''">有</el-tab>
  20. </template>
  21. </avue-crud>
  22. </basic-container>
  23. </template>
  24. <script>
  25. import {
  26. getList,
  27. getDetail,
  28. add,
  29. update,
  30. remove,
  31. generateApi
  32. } from "@/api/guosen/bussiness";
  33. import {
  34. mapGetters
  35. } from "vuex";
  36. import md5 from 'js-md5'
  37. export default {
  38. data() {
  39. return {
  40. form: {},
  41. query: {},
  42. loading: true,
  43. page: {
  44. pageSize: 10,
  45. currentPage: 1,
  46. total: 0
  47. },
  48. selectionList: [],
  49. option: {
  50. height: 'auto',
  51. calcHeight: 30,
  52. tip: false,
  53. searchShow: true,
  54. searchMenuSpan: 6,
  55. border: true,
  56. index: true,
  57. viewBtn: true,
  58. selection: true,
  59. dialogClickModal: false,
  60. dialogWidth: "30%",
  61. column: [{
  62. label: "商户号名称",
  63. labelWidth: 130,
  64. prop: "name",
  65. span: 24,
  66. rules: [{
  67. required: true,
  68. message: "请输入商户号名称",
  69. trigger: "blur"
  70. }]
  71. },
  72. {
  73. label: "每日提现上限",
  74. labelWidth: 130,
  75. span: 24,
  76. prop: "maxLimit",
  77. formslot: true,
  78. rules: [{
  79. required: true,
  80. message: "请输入每日提现上限",
  81. trigger: "blur"
  82. }]
  83. },
  84. {
  85. label: "服务费率(千分比)",
  86. prop: "serviceRate",
  87. labelWidth: 130,
  88. width: 300,
  89. span: 24,
  90. rules: [{
  91. required: true,
  92. message: "请输入关联账号的名称",
  93. trigger: "blur"
  94. }]
  95. },
  96. {
  97. label: "账号",
  98. prop: "userName",
  99. labelWidth: 130,
  100. display: true,
  101. span: 24,
  102. rules: [{
  103. required: true,
  104. message: "请输入关联账号的名称",
  105. trigger: "blur"
  106. }]
  107. },
  108. {
  109. label: "密码",
  110. prop: "userPassword",
  111. labelWidth: 130,
  112. span: 24,
  113. display: true,
  114. hide: true,
  115. rules: [{
  116. required: true,
  117. message: "请输入关联账号的密码",
  118. trigger: "blur"
  119. }]
  120. },
  121. {
  122. label: "api文档",
  123. prop: "apiFilePath",
  124. slot: true,
  125. display: false,
  126. hide: true
  127. },
  128. {
  129. label: "回调地址",
  130. prop: "recallUrl",
  131. labelWidth: 130,
  132. span: 24,
  133. hide: true,
  134. addDisplay: false,
  135. editDisplay: false,
  136. rules: [{
  137. required: false,
  138. message: "请输入回调地址,比如:http://xxx.xxx.xxx.xxx/xxx",
  139. trigger: "blur"
  140. }]
  141. },
  142. {
  143. label: "关联账号的id",
  144. prop: "accountId",
  145. hide: true,
  146. display: false,
  147. rules: [{
  148. required: true,
  149. message: "请输入关联账号的id",
  150. trigger: "blur"
  151. }]
  152. },
  153. {
  154. label: "余额(元)",
  155. prop: "remain",
  156. display: false,
  157. rules: [{
  158. required: true,
  159. message: "请输入关联账号的id",
  160. trigger: "blur"
  161. }]
  162. },
  163. ]
  164. },
  165. data: []
  166. };
  167. },
  168. computed: {
  169. ...mapGetters(["permission"]),
  170. permissionList() {
  171. return {
  172. addBtn: this.vaildData(this.permission.bussiness_add, false),
  173. viewBtn: this.vaildData(this.permission.bussiness_view, false),
  174. delBtn: this.vaildData(this.permission.bussiness_delete, false),
  175. editBtn: this.vaildData(this.permission.bussiness_edit, false)
  176. };
  177. },
  178. ids() {
  179. let ids = [];
  180. this.selectionList.forEach(ele => {
  181. ids.push(ele.id);
  182. });
  183. return ids.join(",");
  184. }
  185. },
  186. methods: {
  187. rowSave(row, done, loading) {
  188. row.userPassword = md5(row.userPassword)
  189. add(row).then(() => {
  190. this.onLoad(this.page);
  191. this.$message({
  192. type: "success",
  193. message: "操作成功!"
  194. });
  195. done();
  196. }, error => {
  197. loading();
  198. window.console.log(error);
  199. });
  200. },
  201. rowUpdate(row, index, done, loading) {
  202. if(row.userPassword){
  203. row.userPassword = md5(row.userPassword)
  204. }
  205. update(row).then(() => {
  206. this.onLoad(this.page);
  207. this.$message({
  208. type: "success",
  209. message: "操作成功!"
  210. });
  211. done();
  212. }, error => {
  213. loading();
  214. console.log(error);
  215. });
  216. },
  217. rowDel(row) {
  218. this.$confirm("确定将选择数据删除?", {
  219. confirmButtonText: "确定",
  220. cancelButtonText: "取消",
  221. type: "warning"
  222. })
  223. .then(() => {
  224. return remove(row.id);
  225. })
  226. .then(() => {
  227. this.onLoad(this.page);
  228. this.$message({
  229. type: "success",
  230. message: "操作成功!"
  231. });
  232. });
  233. },
  234. generateDoc(){
  235. if (this.selectionList.length === 0) {
  236. this.$message.warning("请选择至少一条数据");
  237. return;
  238. }
  239. this.$confirm("确定重新生成api文档吗?", {
  240. confirmButtonText: "确定",
  241. cancelButtonText: "取消",
  242. type: "warning"
  243. })
  244. .then(() => {
  245. return generateApi(this.ids);
  246. })
  247. .then(() => {
  248. this.onLoad(this.page);
  249. this.$message({
  250. type: "success",
  251. message: "操作成功!"
  252. });
  253. this.$refs.crud.toggleSelection();
  254. });
  255. },
  256. handleDelete() {
  257. if (this.selectionList.length === 0) {
  258. this.$message.warning("请选择至少一条数据");
  259. return;
  260. }
  261. this.$confirm("确定将选择数据删除?", {
  262. confirmButtonText: "确定",
  263. cancelButtonText: "取消",
  264. type: "warning"
  265. })
  266. .then(() => {
  267. return remove(this.ids);
  268. })
  269. .then(() => {
  270. this.onLoad(this.page);
  271. this.$message({
  272. type: "success",
  273. message: "操作成功!"
  274. });
  275. this.$refs.crud.toggleSelection();
  276. });
  277. },
  278. beforeOpen(done, type) {
  279. if (["edit", "view"].includes(type)) {
  280. let userPasswordProp = this.findObject(this.option.column, "userPassword");
  281. if(type == 'edit'){
  282. userPasswordProp.rules[0].required = false;
  283. }else{
  284. userPasswordProp.rules[0].required = true;
  285. }
  286. getDetail(this.form.id).then(res => {
  287. this.form = res.data.data;
  288. });
  289. }
  290. done();
  291. },
  292. searchReset() {
  293. this.query = {};
  294. this.onLoad(this.page);
  295. },
  296. searchChange(params, done) {
  297. this.query = params;
  298. this.page.currentPage = 1;
  299. this.onLoad(this.page, params);
  300. done();
  301. },
  302. selectionChange(list) {
  303. this.selectionList = list;
  304. },
  305. selectionClear() {
  306. this.selectionList = [];
  307. this.$refs.crud.toggleSelection();
  308. },
  309. currentChange(currentPage) {
  310. this.page.currentPage = currentPage;
  311. },
  312. sizeChange(pageSize) {
  313. this.page.pageSize = pageSize;
  314. },
  315. refreshChange() {
  316. this.onLoad(this.page, this.query);
  317. },
  318. onLoad(page, params = {}) {
  319. this.loading = true;
  320. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  321. const data = res.data.data;
  322. this.page.total = data.total;
  323. this.data = data.records;
  324. this.loading = false;
  325. this.selectionClear();
  326. });
  327. }
  328. }
  329. };
  330. </script>
  331. <style>
  332. </style>