config.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted, getCurrentInstance } = Vue
  5. const index = {
  6. setup() {
  7. const { proxy } = getCurrentInstance();
  8. const state = reactive({
  9. data: [],
  10. tabActive: null,
  11. configis_upgrade: false,
  12. })
  13. const type = reactive({
  14. data: {
  15. api: Config.configList.filter((item) => {
  16. if (item.status) return item;
  17. })
  18. }
  19. })
  20. const form = reactive({
  21. model: {},
  22. rules: {
  23. rechargewithdraw: {
  24. recharge: {
  25. quick_amounts: {
  26. money: [{ required: true, message: '请输入金额', trigger: 'blur' }],
  27. gift: [{ required: true, message: '请输入内容', trigger: 'blur' }],
  28. }
  29. }
  30. },
  31. commission: {
  32. agent_form: {
  33. background_image: [{ required: true, message: '请选择表单背景图', trigger: 'blur' }],
  34. content: {
  35. type: [{ required: true, message: '表单类型', trigger: 'change' }],
  36. name: [{ required: true, message: '表单名称', trigger: 'blur' }],
  37. },
  38. },
  39. }
  40. },
  41. })
  42. function getData() {
  43. if (!state.tabActive) return;
  44. if (state.tabActive == 'shopro/config/platform') {
  45. getPlatformStatus()
  46. } else if (state.tabActive == 'shopro/pay_config') {
  47. getPayConfig()
  48. } else {
  49. Fast.api.ajax({
  50. url: state.tabActive,
  51. type: 'GET',
  52. }, function (ret, res) {
  53. form.model = res.data;
  54. // 用户配置
  55. if (state.tabActive == 'shopro/config/user') {
  56. getGroupSelect()
  57. }
  58. if (state.tabActive == 'shopro/config/dispatch') {
  59. form.model.sender.area_arr = []
  60. form.model.sender.area_arr.push(form.model.sender.province_name)
  61. form.model.sender.area_arr.push(form.model.sender.city_name)
  62. form.model.sender.area_arr.push(form.model.sender.district_name)
  63. express.form.model = form.model.kdniao.express
  64. getExpressSelect()
  65. getAreaSelect()
  66. }
  67. if (state.tabActive == 'shopro/config/commission') {
  68. if (form.model.become_agent.type == 'goods') {
  69. getGoodsList(form.model.become_agent.value);
  70. }
  71. if (!Config.is_pro) {
  72. state.configis_upgrade = true
  73. }
  74. }
  75. if (state.tabActive == 'shopro/config/chat') {
  76. getChatConfig()
  77. }
  78. return false
  79. }, function (ret, res) { })
  80. }
  81. }
  82. // 基础配置
  83. function onSelectRichtext(type) {
  84. Fast.api.open(`shopro/data/richtext/select`, '选择富文本', {
  85. callback(data) {
  86. form.model[type].id = data.id;
  87. form.model[type].title = data.title;
  88. }
  89. })
  90. }
  91. // 用户配置
  92. const group = reactive({
  93. select: []
  94. })
  95. function getGroupSelect() {
  96. Fast.api.ajax({
  97. url: 'shopro/user/group/select',
  98. type: 'GET',
  99. }, function (ret, res) {
  100. group.select = res.data
  101. return false
  102. }, function (ret, res) { })
  103. }
  104. // 平台配置
  105. const platform = reactive({
  106. data: [{
  107. value: 'H5',
  108. label: 'H5',
  109. color: '#fc800e',
  110. },
  111. {
  112. value: 'WechatOfficialAccount',
  113. label: '微信公众号',
  114. color: '#07c160',
  115. },
  116. {
  117. value: 'WechatMiniProgram',
  118. label: '微信小程序',
  119. color: '#6f74e9',
  120. },
  121. {
  122. value: 'App',
  123. label: 'App',
  124. color: '#806af6',
  125. }],
  126. status: {},
  127. })
  128. function getPlatformStatus() {
  129. Fast.api.ajax({
  130. url: 'shopro/config/platformStatus',
  131. type: 'GET',
  132. }, function (ret, res) {
  133. platform.status = res.data
  134. return false
  135. }, function (ret, res) { })
  136. }
  137. function onEditPlatform(item) {
  138. Fast.api.open(`shopro/config/platform/platform/${item.value}?platform=${item.value}&label=${item.label}`, `平台-${item.label}`, {
  139. callback() {
  140. getData()
  141. }
  142. })
  143. }
  144. // 物流配置
  145. const area = reactive({
  146. select: []
  147. })
  148. function getAreaSelect() {
  149. Fast.api.ajax({
  150. url: 'shopro/data/area/select',
  151. type: 'GET',
  152. }, function (ret, res) {
  153. area.select = res.data;
  154. return false
  155. }, function (ret, res) { })
  156. }
  157. const express = reactive({
  158. form: {
  159. model: {}
  160. },
  161. })
  162. const deliverCompany = reactive({
  163. loading: false,
  164. select: [],
  165. pagination: {
  166. page: 1,
  167. list_rows: 10,
  168. total: 0,
  169. }
  170. })
  171. function getExpressSelect(keyword) {
  172. let search = {};
  173. if (keyword) {
  174. search = { keyword: keyword };
  175. }
  176. Fast.api.ajax({
  177. url: 'shopro/data/express',
  178. type: 'GET',
  179. data: {
  180. page: deliverCompany.pagination.page,
  181. list_rows: deliverCompany.pagination.list_rows,
  182. search: JSON.stringify(search),
  183. }
  184. }, function (ret, res) {
  185. deliverCompany.select = res.data.data
  186. deliverCompany.pagination.total = res.data.total
  187. return false
  188. }, function (ret, res) { })
  189. }
  190. function onChangeExpressCode(code) {
  191. express.form.model = {}
  192. express.form.model.code = code
  193. express.form.model.name = proxy.$refs[`express-${code}`][0].label;
  194. }
  195. function remoteMethod(keyword) {
  196. deliverCompany.loading = true;
  197. setTimeout(() => {
  198. deliverCompany.loading = false;
  199. getExpressSelect(keyword);
  200. }, 200);
  201. }
  202. function onThinkApi() {
  203. window.open('https://docs.topthink.com/think-api/1835396');
  204. }
  205. // 充值提现
  206. function onAddTemplate() {
  207. form.model.recharge.quick_amounts.push({
  208. money: '',
  209. gift: '',
  210. });
  211. }
  212. function onDeleteTemplate(index) {
  213. form.model.recharge.quick_amounts.splice(index, 1);
  214. }
  215. // 分销配置
  216. function onChangeBecomeAgentType(type) {
  217. if (type === 'user') {
  218. form.model.invite_lock = 'share';
  219. }
  220. if (type === 'apply') {
  221. form.model.agent_form.status = '1';
  222. }
  223. if (type === 'goods') {
  224. tempGoods.list = [];
  225. }
  226. form.model.become_agent.value = '';
  227. }
  228. const tempGoods = reactive({
  229. list: [],
  230. });
  231. async function getGoodsList(ids) {
  232. Fast.api.ajax({
  233. url: 'shopro/goods/goods/select',
  234. type: 'GET',
  235. data: {
  236. type: 'select',
  237. search: JSON.stringify({ id: [ids, 'in'] }),
  238. },
  239. }, function (ret, res) {
  240. tempGoods.list = res.data;
  241. return false
  242. }, function (ret, res) { })
  243. }
  244. function onSelectGoods() {
  245. let ids = [];
  246. tempGoods.list.forEach((i) => {
  247. ids.push(i.id);
  248. });
  249. Fast.api.open(`shopro/goods/goods/select?multiple=true&ids=${ids.join(',')}`, "选择商品", {
  250. callback(data) {
  251. tempGoods.list = data;
  252. let ids = [];
  253. tempGoods.list.forEach((item) => {
  254. ids.push(item.id);
  255. });
  256. form.model.become_agent.value = ids.join(',');
  257. }
  258. })
  259. }
  260. function onDeleteGoods(index) {
  261. tempGoods.list.splice(index, 1);
  262. let ids = [];
  263. tempGoods.list.forEach((gl) => {
  264. ids.push(gl.id);
  265. });
  266. form.model.become_agent.value = ids.join(',');
  267. }
  268. const become_register_options = [
  269. {
  270. value: 'text',
  271. label: '文本内容',
  272. },
  273. {
  274. value: 'number',
  275. label: '纯数字',
  276. },
  277. {
  278. value: 'image',
  279. label: '上传图片',
  280. },
  281. ];
  282. function onAddContent() {
  283. form.model.agent_form.content.push({
  284. type: '',
  285. name: '',
  286. });
  287. }
  288. function onDeleteContent(index) {
  289. form.model.agent_form.content.splice(index, 1);
  290. }
  291. // 支付配置
  292. const payConfig = reactive({
  293. data: []
  294. })
  295. function getPayConfig() {
  296. Fast.api.ajax({
  297. url: 'shopro/pay_config',
  298. type: 'GET',
  299. }, function (ret, res) {
  300. payConfig.data = res.data.data
  301. pagination.total = res.data.total
  302. return false
  303. }, function (ret, res) { })
  304. }
  305. const pagination = reactive({
  306. page: 1,
  307. list_rows: 10,
  308. total: 0,
  309. })
  310. function onCommandPayConfig(item) {
  311. Fast.api.ajax({
  312. url: `shopro/pay_config/edit/id/${item.id}`,
  313. type: 'POST',
  314. data: {
  315. status: item.type
  316. }
  317. }, function (ret, res) {
  318. getPayConfig()
  319. }, function (ret, res) { })
  320. }
  321. function onAddPayConfig() {
  322. Fast.api.open('shopro/pay_config/add?type=add', "添加", {
  323. callback() {
  324. getPayConfig()
  325. }
  326. })
  327. }
  328. function onEditPayConfig(id) {
  329. Fast.api.open(`shopro/pay_config/edit?type=edit&id=${id}`, "编辑", {
  330. callback() {
  331. getPayConfig()
  332. }
  333. })
  334. }
  335. function onDeletePayConfig(id) {
  336. Fast.api.ajax({
  337. url: `shopro/pay_config/delete/id/${id}`,
  338. type: 'DELETE',
  339. }, function (ret, res) {
  340. getPayConfig()
  341. }, function (ret, res) { })
  342. }
  343. function onRecyclebinPayConfig() {
  344. Fast.api.open(`shopro/pay_config/recyclebin`, "回收站", {
  345. callback() {
  346. getPayConfig()
  347. }
  348. })
  349. }
  350. // 客服配置
  351. const chat = reactive({
  352. config: {}
  353. })
  354. function getChatConfig() {
  355. Fast.api.ajax({
  356. url: `shopro/chat/index/init`,
  357. type: 'GET',
  358. }, function (ret, res) {
  359. chat.config = res.data
  360. return false
  361. }, function (ret, res) { })
  362. }
  363. function onConfirm() {
  364. const submitForm = JSON.parse(JSON.stringify(form.model))
  365. if (state.tabActive == 'shopro/config/dispatch') {
  366. if (submitForm.sender.area_arr) {
  367. submitForm.sender.province_name = submitForm.sender.area_arr[0]
  368. submitForm.sender.city_name = submitForm.sender.area_arr[1]
  369. submitForm.sender.district_name = submitForm.sender.area_arr[2]
  370. delete submitForm.sender.area_arr
  371. } else {
  372. submitForm.sender.province_name = ''
  373. submitForm.sender.city_name = ''
  374. submitForm.sender.district_name = ''
  375. }
  376. submitForm.kdniao.express = express.form.model
  377. }
  378. if (state.tabActive == 'shopro/config/redis') {
  379. if (submitForm.empty_password) {
  380. delete submitForm.password
  381. }
  382. }
  383. proxy.$refs['formRef'].validate((valid) => {
  384. if (valid) {
  385. Fast.api.ajax({
  386. url: state.tabActive,
  387. type: 'POST',
  388. data: submitForm,
  389. }, function (ret, res) {
  390. }, function (ret, res) { })
  391. }
  392. });
  393. }
  394. function onOper(type) {
  395. switch (type) {
  396. case 'close':
  397. state.configis_upgrade = false
  398. break;
  399. case 'refresh':
  400. window.location.reload();
  401. break;
  402. case 'upgrade':
  403. window.open("https://www.fastadmin.net/store/shopro.html")
  404. break;
  405. }
  406. }
  407. onMounted(() => {
  408. state.tabActive = type.data.api.length ? type.data.api[0].name : null;
  409. getData()
  410. })
  411. return {
  412. onClipboard,
  413. state,
  414. type,
  415. form,
  416. getData,
  417. onSelectRichtext,
  418. group,
  419. platform,
  420. onEditPlatform,
  421. area,
  422. express,
  423. deliverCompany,
  424. getExpressSelect,
  425. onChangeExpressCode,
  426. remoteMethod,
  427. onThinkApi,
  428. onAddTemplate,
  429. onDeleteTemplate,
  430. onChangeBecomeAgentType,
  431. tempGoods,
  432. onSelectGoods,
  433. onDeleteGoods,
  434. become_register_options,
  435. onAddContent,
  436. onDeleteContent,
  437. payConfig,
  438. pagination,
  439. onCommandPayConfig,
  440. onAddPayConfig,
  441. onEditPayConfig,
  442. onDeletePayConfig,
  443. onRecyclebinPayConfig,
  444. chat,
  445. onConfirm,
  446. onOper
  447. }
  448. }
  449. }
  450. createApp('index', index);
  451. },
  452. platform: () => {
  453. const { reactive, onMounted, getCurrentInstance } = Vue
  454. const platform = {
  455. setup() {
  456. const { proxy } = getCurrentInstance();
  457. const state = reactive({
  458. platform: new URLSearchParams(location.search).get('platform'),
  459. label: new URLSearchParams(location.search).get('label'),
  460. })
  461. const form = reactive({
  462. model: {
  463. app_id: '',
  464. secret: '',
  465. status: '',
  466. payment: {
  467. alipay: '',
  468. wechat: '',
  469. methods: [],
  470. },
  471. share: {
  472. methods: [],
  473. forwardInfo: {
  474. title: '',
  475. subtitle: '',
  476. image: '',
  477. },
  478. linkAddress: '',
  479. posterInfo: {
  480. user_bg: '',
  481. goods_bg: '',
  482. groupon_bg: '',
  483. },
  484. },
  485. download: {
  486. android: '',
  487. ios: '',
  488. local: '',
  489. },
  490. },
  491. rules: {}
  492. })
  493. function getDetail() {
  494. Fast.api.ajax({
  495. url: `shopro/config/platform/platform/${state.platform}`,
  496. type: 'GET',
  497. }, function (ret, res) {
  498. form.model = res.data;
  499. if (isEmpty(form.model.share)) {
  500. form.model.share = {
  501. methods: [],
  502. forwardInfo: {
  503. title: '',
  504. subtitle: '',
  505. image: '',
  506. },
  507. linkAddress: '',
  508. posterInfo: {
  509. user_bg: '',
  510. goods_bg: '',
  511. groupon_bg: '',
  512. },
  513. };
  514. }
  515. if (isEmpty(form.model.download)) {
  516. form.model.download = {
  517. android: '',
  518. ios: '',
  519. local: '',
  520. };
  521. }
  522. if (state.platform != 'H5' && !form.model.share.methods.includes('forward')) {
  523. form.model.share.methods.push('forward');
  524. }
  525. if (form.model.payment.wechat === 0) {
  526. form.model.payment.wechat = ''
  527. }
  528. if (form.model.payment.alipay === 0) {
  529. form.model.payment.alipay = ''
  530. }
  531. return false
  532. }, function (ret, res) { })
  533. }
  534. function onConfiguration() {
  535. if (state.platform == 'H5') {
  536. window.open('https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter2_6_1.shtml');
  537. }
  538. if (state.platform == 'App') {
  539. window.open('https://open.weixin.qq.com/');
  540. }
  541. }
  542. const payConfig = reactive({
  543. select: {
  544. alipay: [],
  545. wechat: [],
  546. }
  547. })
  548. function getPayConfigSelect() {
  549. Fast.api.ajax({
  550. url: 'shopro/pay_config/select',
  551. type: 'GET',
  552. }, function (ret, res) {
  553. payConfig.select.alipay = []
  554. payConfig.select.wechat = []
  555. res.data.forEach(item => {
  556. if (item.type == 'alipay') {
  557. payConfig.select.alipay.push(item)
  558. }
  559. if (item.type == 'wechat') {
  560. payConfig.select.wechat.push(item)
  561. }
  562. })
  563. return false
  564. }, function (ret, res) { })
  565. }
  566. function onAddPayConfig() {
  567. Fast.api.open('shopro/pay_config/add?type=add', "添加", {
  568. callback() {
  569. getPayConfigSelect()
  570. }
  571. })
  572. }
  573. function onConfirm() {
  574. proxy.$refs['formRef'].validate((valid) => {
  575. if (valid) {
  576. Fast.api.ajax({
  577. url: `shopro/config/platform/platform/${state.platform}`,
  578. type: 'POST',
  579. data: form.model,
  580. }, function (ret, res) {
  581. Fast.api.close()
  582. }, function (ret, res) { })
  583. }
  584. });
  585. }
  586. onMounted(() => {
  587. getPayConfigSelect()
  588. getDetail()
  589. })
  590. return {
  591. state,
  592. form,
  593. onConfiguration,
  594. payConfig,
  595. onAddPayConfig,
  596. onConfirm,
  597. }
  598. }
  599. }
  600. createApp('platform', platform);
  601. },
  602. };
  603. return Controller;
  604. });