pay_config.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => { },
  4. add: () => {
  5. Controller.form();
  6. },
  7. edit: () => {
  8. Controller.form();
  9. },
  10. form: () => {
  11. const { reactive, onMounted, getCurrentInstance } = Vue
  12. const addEdit = {
  13. setup() {
  14. const { proxy } = getCurrentInstance();
  15. const state = reactive({
  16. type: new URLSearchParams(location.search).get('type'),
  17. id: new URLSearchParams(location.search).get('id')
  18. })
  19. const form = reactive({
  20. model: {
  21. name: '',
  22. type: 'wechat',
  23. params: {
  24. app_id: '',
  25. mode: '0',
  26. mch_secret_cert: '',
  27. mch_public_cert_path: '',
  28. alipay_public_cert_path: '',
  29. app_public_cert_path: '',
  30. alipay_root_cert_path: '',
  31. app_secret_cert: '',
  32. service_provider_id: '',
  33. mch_id: '',
  34. mch_secret_key: '',
  35. sub_mch_id: '',
  36. sub_mch_secret_key: '',
  37. sub_mch_public_cert_path: '',
  38. sub_mch_secret_cert: '',
  39. },
  40. status: 'normal',
  41. },
  42. rules: {
  43. name: [{ required: true, message: '请输入标题', trigger: 'blur' }],
  44. params: {
  45. mch_id: [{ required: true, message: '请输入商户号', trigger: 'blur' }],
  46. mch_secret_key: [{ required: true, message: '请输入商户密钥', trigger: 'blur' }],
  47. mch_secret_cert: [{ required: true, message: '请上传商户key证书', trigger: 'blur' }],
  48. mch_public_cert_path: [{ required: true, message: '请上传商户证书', trigger: 'blur' }],
  49. app_id: [{ required: true, message: '请输入主商户AppId', trigger: 'blur' }],
  50. sub_mch_id: [{ required: true, message: '请输入子商户号', trigger: 'blur' }],
  51. alipay_public_cert_path: [
  52. { required: true, message: '请上传支付宝公钥证书', trigger: 'blur' },
  53. ],
  54. app_public_cert_path: [{ required: true, message: '请上传应用公钥证书', trigger: 'blur' }],
  55. alipay_root_cert_path: [{ required: true, message: '请上传支付宝根证书', trigger: 'blur' }],
  56. app_secret_cert: [{ required: true, message: '请输入私钥', trigger: 'blur' }],
  57. service_provider_id: [{ required: true, message: '请输入主商户ID', trigger: 'blur' }],
  58. },
  59. },
  60. })
  61. function getDetail() {
  62. Fast.api.ajax({
  63. url: `shopro/pay_config/detail/id/${state.id}`,
  64. type: 'GET',
  65. }, function (ret, res) {
  66. form.model = res.data;
  67. return false
  68. }, function (ret, res) { })
  69. }
  70. function onAjaxUpload(id) {
  71. var formData = new FormData();
  72. formData.append("file", $('#' + id)[0].files[0]);
  73. formData.append('shopro_type', 'simple');
  74. $.ajax({
  75. type: "POST",
  76. url: "ajax/upload",
  77. data: formData,
  78. cache: false,
  79. processData: false,
  80. contentType: false,
  81. success: function (res) {
  82. if (res.code == 1) {
  83. form.model.params[id] = res.data.url
  84. } else {
  85. Toastr.error(res.msg);
  86. }
  87. },
  88. })
  89. }
  90. function onConfirm() {
  91. proxy.$refs['formRef'].validate((valid) => {
  92. if (valid) {
  93. Fast.api.ajax({
  94. url: state.type == 'add' ? 'shopro/pay_config/add' : `shopro/pay_config/edit/id/${state.id}`,
  95. type: 'POST',
  96. data: JSON.parse(JSON.stringify(form.model))
  97. }, function (ret, res) {
  98. Fast.api.close()
  99. }, function (ret, res) { })
  100. }
  101. });
  102. }
  103. onMounted(() => {
  104. state.type == 'edit' && getDetail()
  105. })
  106. return {
  107. state,
  108. form,
  109. onAjaxUpload,
  110. onConfirm
  111. }
  112. }
  113. }
  114. createApp('addEdit', addEdit);
  115. },
  116. recyclebin: () => {
  117. const { reactive, onMounted } = Vue
  118. const { ElMessageBox } = ElementPlus
  119. const recyclebin = {
  120. setup() {
  121. const state = reactive({
  122. data: [],
  123. order: '',
  124. sort: '',
  125. })
  126. function getData() {
  127. Fast.api.ajax({
  128. url: 'shopro/pay_config/recyclebin',
  129. type: 'GET',
  130. data: {
  131. page: pagination.page,
  132. list_rows: pagination.list_rows,
  133. order: state.order,
  134. sort: state.sort,
  135. },
  136. }, function (ret, res) {
  137. state.data = res.data.data
  138. pagination.total = res.data.total
  139. return false
  140. }, function (ret, res) { })
  141. }
  142. function onChangeSort({ prop, order }) {
  143. state.order = order == 'ascending' ? 'asc' : 'desc';
  144. state.sort = prop;
  145. getData();
  146. }
  147. const pagination = reactive({
  148. page: 1,
  149. list_rows: 10,
  150. total: 0,
  151. })
  152. const batchHandle = reactive({
  153. data: [],
  154. })
  155. function onChangeSelection(val) {
  156. batchHandle.data = val
  157. }
  158. function onBatchHandle(type) {
  159. let ids = []
  160. batchHandle.data.forEach((item) => {
  161. ids.push(item.id)
  162. })
  163. switch (type) {
  164. case 'restore':
  165. onRestore(ids.join(','))
  166. break;
  167. case 'destroy':
  168. ElMessageBox.confirm('此操作将销毁, 是否继续?', '提示', {
  169. confirmButtonText: '确定',
  170. cancelButtonText: '取消',
  171. type: 'warning',
  172. }).then(() => {
  173. onDestroy(ids.join(','))
  174. });
  175. break;
  176. case 'all':
  177. ElMessageBox.confirm('此操作将清空回收站, 是否继续?', '提示', {
  178. confirmButtonText: '确定',
  179. cancelButtonText: '取消',
  180. type: 'warning',
  181. }).then(() => {
  182. onDestroy('all')
  183. });
  184. break;
  185. }
  186. }
  187. function onRestore(id) {
  188. Fast.api.ajax({
  189. url: `shopro/pay_config/restore/id/${id}`,
  190. type: 'POST',
  191. }, function (ret, res) {
  192. getData()
  193. }, function (ret, res) { })
  194. }
  195. function onDestroy(id) {
  196. Fast.api.ajax({
  197. url: `shopro/pay_config/destroy/id/${id}`,
  198. type: 'POST',
  199. }, function (ret, res) {
  200. getData()
  201. }, function (ret, res) { })
  202. }
  203. onMounted(() => {
  204. getData()
  205. })
  206. return {
  207. state,
  208. getData,
  209. onChangeSort,
  210. pagination,
  211. batchHandle,
  212. onChangeSelection,
  213. onBatchHandle,
  214. onRestore,
  215. onDestroy,
  216. }
  217. }
  218. }
  219. createApp('recyclebin', recyclebin);
  220. },
  221. };
  222. return Controller;
  223. });