level.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: () => {
  4. const { reactive, onMounted } = Vue
  5. const index = {
  6. setup() {
  7. const state = reactive({
  8. data: [],
  9. })
  10. function getData() {
  11. Fast.api.ajax({
  12. url: 'shopro/commission/level',
  13. type: 'GET',
  14. }, function (ret, res) {
  15. state.data = res.data
  16. return false
  17. }, function (ret, res) { })
  18. }
  19. function onAdd() {
  20. Fast.api.open(`shopro/commission/level/add?type=add`, "添加", {
  21. callback() {
  22. getData()
  23. }
  24. })
  25. }
  26. function onEdit(id) {
  27. Fast.api.open(`shopro/commission/level/edit?type=edit&id=${id}`, "编辑", {
  28. callback() {
  29. getData()
  30. }
  31. })
  32. }
  33. function onDelete(id) {
  34. Fast.api.ajax({
  35. url: `shopro/commission/level/delete/id/${id}`,
  36. type: 'POST',
  37. }, function (ret, res) {
  38. getData();
  39. }, function (ret, res) { })
  40. }
  41. onMounted(() => {
  42. getData()
  43. })
  44. return {
  45. state,
  46. getData,
  47. onAdd,
  48. onEdit,
  49. onDelete,
  50. }
  51. }
  52. }
  53. createApp('index', index);
  54. },
  55. add: () => {
  56. Controller.form();
  57. },
  58. edit: () => {
  59. Controller.form();
  60. },
  61. form: () => {
  62. const { reactive, onMounted, getCurrentInstance } = Vue
  63. const addEdit = {
  64. setup() {
  65. const { proxy } = getCurrentInstance();
  66. const state = reactive({
  67. type: new URLSearchParams(location.search).get('type'),
  68. id: new URLSearchParams(location.search).get('id')
  69. })
  70. const form = reactive({
  71. model: {
  72. level: null,
  73. name: '',
  74. image: '',
  75. commission_rules: {
  76. commission_1: '0.00',
  77. commission_2: '0.00',
  78. commission_3: '0.00',
  79. },
  80. upgrade_type: 0,
  81. upgrade_rules: {},
  82. },
  83. rules: {
  84. level: [{ required: true, message: '请选择等级权重', trigger: 'blur' }],
  85. name: [{ required: true, message: '请输入等级名称', trigger: 'blur' }],
  86. commission_rules: {
  87. commission: [{ required: true, message: '佣金比例', trigger: 'blur' }],
  88. },
  89. upgrade_rules: [
  90. {
  91. validator: (rule, value, callback) => {
  92. if (isEmpty(value)) {
  93. callback(new Error('请填写升级条件'));
  94. } else {
  95. callback();
  96. }
  97. },
  98. trigger: 'blur',
  99. },
  100. ],
  101. upgrade_rules_inner: {
  102. rules: [{ required: true, message: '请输入', trigger: 'blur' }],
  103. level: [{ required: true, message: '请选择分销商等级', trigger: 'blur' }],
  104. },
  105. },
  106. })
  107. function getDetail() {
  108. Fast.api.ajax({
  109. url: `shopro/commission/level/detail/id/${state.id}`,
  110. type: 'GET',
  111. }, function (ret, res) {
  112. form.model = res.data;
  113. if (!isObject(form.model.upgrade_rules)) form.model.upgrade_rules = {};
  114. // level=1时 等级权重不可修改
  115. if (form.model.level == 1) {
  116. level.data = [
  117. {
  118. name: '一级',
  119. level: 1,
  120. },
  121. ];
  122. level.existLevel = [];
  123. level.data.forEach((e) => {
  124. level.existLevel.push(e.level);
  125. });
  126. } else {
  127. level.data = JSON.parse(JSON.stringify(defaultLevel));
  128. }
  129. let index = level.existLevel.findIndex((l) => l == form.model.level);
  130. level.existLevel.splice(index, 1);
  131. return false
  132. }, function (ret, res) { })
  133. }
  134. const defaultLevel = [
  135. {
  136. name: '一级',
  137. level: 1,
  138. },
  139. {
  140. name: '二级',
  141. level: 2,
  142. },
  143. {
  144. name: '三级',
  145. level: 3,
  146. },
  147. {
  148. name: '四级',
  149. level: 4,
  150. },
  151. {
  152. name: '五级',
  153. level: 5,
  154. },
  155. {
  156. name: '六级',
  157. level: 6,
  158. },
  159. {
  160. name: '七级',
  161. level: 7,
  162. },
  163. {
  164. name: '八级',
  165. level: 8,
  166. },
  167. {
  168. name: '九级',
  169. level: 9,
  170. },
  171. {
  172. name: '十级',
  173. level: 10,
  174. },
  175. ];
  176. function onSelectLevel(l) {
  177. if (!level.existLevel.includes(l)) {
  178. form.model.level = l;
  179. // 清空规则
  180. form.model.upgrade_rules = {};
  181. }
  182. }
  183. const level = reactive({
  184. data: [],
  185. select: [],
  186. existLevel: [],
  187. });
  188. function getLevelSelect() {
  189. Fast.api.ajax({
  190. url: `shopro/commission/level/select`,
  191. type: 'GET',
  192. }, function (ret, res) {
  193. level.select = res.data;
  194. level.select.forEach((e) => {
  195. level.existLevel.push(e.level);
  196. });
  197. return false
  198. }, function (ret, res) { })
  199. }
  200. const upgradeCondition = {
  201. user: {
  202. total_consume: {
  203. name: '用户消费金额',
  204. },
  205. child_user_count_1: {
  206. name: '一级用户人数',
  207. },
  208. child_user_count_2: {
  209. name: '二级用户人数',
  210. },
  211. child_user_count_all: {
  212. name: '团队用户人数',
  213. },
  214. },
  215. order_money: {
  216. child_order_money_0: {
  217. name: '自购分销订单总金额',
  218. },
  219. child_order_money_1: {
  220. name: '一级分销订单金额',
  221. },
  222. child_order_money_2: {
  223. name: '二级分销订单金额',
  224. },
  225. child_order_money_all: {
  226. name: '团队分销订单金额',
  227. },
  228. },
  229. order_count: {
  230. child_order_count_0: {
  231. name: '自购分销订单数量',
  232. },
  233. child_order_count_1: {
  234. name: '一级分销订单数量',
  235. },
  236. child_order_count_2: {
  237. name: '二级分销订单数量',
  238. },
  239. child_order_count_all: {
  240. name: '团队分销订单数量',
  241. },
  242. },
  243. agent_count: {
  244. child_agent_count_1: {
  245. name: '一级分销商人数',
  246. },
  247. child_agent_count_2: {
  248. name: '二级分销商人数',
  249. },
  250. child_agent_count_all: {
  251. name: '团队分销商人数',
  252. },
  253. },
  254. agent_level: {
  255. child_agent_level_all: {
  256. name: '团队分销商等级统计',
  257. },
  258. child_agent_level_1: {
  259. name: '一级分销商等级统计',
  260. },
  261. },
  262. };
  263. function onSelectUpgradeCondition(key) {
  264. form.model.upgrade_rules[key] = '';
  265. if (key == 'child_agent_level_all' || key == 'child_agent_level_1') {
  266. form.model.upgrade_rules[key] = [
  267. {
  268. level: '',
  269. count: '',
  270. },
  271. ];
  272. }
  273. }
  274. function onAddUpgradeRules(key) {
  275. form.model.upgrade_rules[key].push({
  276. level: '',
  277. count: '',
  278. });
  279. }
  280. function onDeleteRules(key, index) {
  281. if (key == 'child_agent_level_all' || key == 'child_agent_level_1') {
  282. form.model.upgrade_rules[key].splice(index, 1);
  283. if (form.model.upgrade_rules[key].length == 0) delete form.model.upgrade_rules[key];
  284. } else {
  285. delete form.model.upgrade_rules[key];
  286. }
  287. }
  288. function initUnit(key) {
  289. if (key.includes('child_user_count') || key.includes('child_agent_count')) {
  290. return '人';
  291. }
  292. if (key.includes('total_consume') || key.includes('child_order_money')) {
  293. return '元';
  294. }
  295. if (key.includes('child_order_count')) {
  296. return '单';
  297. }
  298. }
  299. function onConfirm() {
  300. proxy.$refs['formRef'].validate((valid) => {
  301. if (valid) {
  302. Fast.api.ajax({
  303. url: state.type == 'add' ? 'shopro/commission/level/add' : `shopro/commission/level/edit/id/${state.id}`,
  304. type: 'POST',
  305. data: JSON.parse(JSON.stringify(form.model))
  306. }, function (ret, res) {
  307. Fast.api.close()
  308. }, function (ret, res) { })
  309. }
  310. });
  311. }
  312. onMounted(() => {
  313. getLevelSelect()
  314. if (state.type == 'add') {
  315. level.data = JSON.parse(JSON.stringify(defaultLevel));
  316. } else if (state.type == 'edit') {
  317. getDetail()
  318. }
  319. })
  320. return {
  321. state,
  322. form,
  323. onSelectLevel,
  324. defaultLevel,
  325. level,
  326. getLevelSelect,
  327. upgradeCondition,
  328. onSelectUpgradeCondition,
  329. onAddUpgradeRules,
  330. onDeleteRules,
  331. initUnit,
  332. onConfirm
  333. }
  334. }
  335. }
  336. createApp('addEdit', addEdit);
  337. },
  338. select: () => {
  339. const { reactive, onMounted } = Vue
  340. const select = {
  341. setup() {
  342. const state = reactive({
  343. level: new URLSearchParams(location.search).get('level'),
  344. data: [],
  345. })
  346. function getData() {
  347. Fast.api.ajax({
  348. url: 'shopro/commission/level/select',
  349. type: 'GET',
  350. }, function (ret, res) {
  351. state.data = res.data
  352. return false
  353. }, function (ret, res) { })
  354. }
  355. function onSelect(level) {
  356. state.level = level;
  357. }
  358. function onConfirm() {
  359. Fast.api.close(state.level)
  360. }
  361. onMounted(() => {
  362. getData()
  363. })
  364. return {
  365. state,
  366. getData,
  367. onSelect,
  368. onConfirm,
  369. }
  370. }
  371. }
  372. createApp('select', select);
  373. },
  374. };
  375. return Controller;
  376. });