level.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. var indexPage = new Vue({
  5. el: "#indexPage",
  6. data() {
  7. return {
  8. indexList: [],
  9. isAjax: true,
  10. }
  11. },
  12. mounted() {
  13. this.getindexList();
  14. },
  15. methods: {
  16. getindexList() {
  17. let that = this;
  18. that.isAjax = true;
  19. Fast.api.ajax({
  20. url: 'shopro/commission/level/index',
  21. loading: false,
  22. type: 'GET',
  23. }, function (ret, res) {
  24. that.indexList = res.data;
  25. that.isAjax = false;
  26. return false
  27. }, function (ret, res) {
  28. that.isAjax = false;
  29. })
  30. },
  31. operation(opttype, id) {
  32. let that = this;
  33. switch (opttype) {
  34. case 'create':
  35. Fast.api.open('shopro/commission/level/add', '新建分销商等级', {
  36. callback(data) {
  37. that.getindexList();
  38. }
  39. })
  40. break;
  41. case 'edit':
  42. Fast.api.open('shopro/commission/level/edit?level=' + id, '编辑分销商等级', {
  43. callback(data) {
  44. that.getindexList();
  45. }
  46. })
  47. break;
  48. }
  49. },
  50. tableCellClassName({
  51. columnIndex
  52. }) {
  53. if (columnIndex == 0 || columnIndex == 7) {
  54. return 'cell-left';
  55. }
  56. return '';
  57. },
  58. },
  59. })
  60. },
  61. add: function () {
  62. Controller.detailInit('add');
  63. Controller.api.bindevent();
  64. },
  65. edit: function () {
  66. Controller.detailInit('edit');
  67. Controller.api.bindevent();
  68. },
  69. detailInit: function (type) {
  70. var detailPage = new Vue({
  71. el: "#detailPage",
  72. data() {
  73. return {
  74. optType: type,
  75. formData: {
  76. level: '',
  77. name: '',
  78. image: '',
  79. commission_rules: {
  80. commission_1: '0.00',
  81. commission_2: '0.00',
  82. commission_3: '0.00',
  83. },
  84. upgrade_type: 0,
  85. upgrade_rules: ''
  86. },
  87. upgradeCondition: [{
  88. title: '用户消费金额',
  89. key: 'total_consume',
  90. value: '',
  91. }, {
  92. title: '一级用户人数',
  93. key: 'child_user_count_1',
  94. value: '',
  95. }, {
  96. title: '二级用户人数',
  97. key: 'child_user_count_2',
  98. value: '',
  99. }, {
  100. title: '团队用户人数',
  101. key: 'child_user_count',
  102. value: '',
  103. }, {
  104. title: '直推分销订单金额',
  105. key: 'order_money',
  106. value: '',
  107. }, {
  108. title: '一级分销订单金额',
  109. key: 'child_order_money_1',
  110. value: '',
  111. }, {
  112. title: '二级分销订单金额',
  113. key: 'child_order_money_2',
  114. value: '',
  115. }, {
  116. title: '团队分销订单金额',
  117. key: 'child_order_money',
  118. value: '',
  119. }, {
  120. title: '直推分销订单数量',
  121. key: 'order_count',
  122. value: '',
  123. }, {
  124. title: '一级分销订单数量',
  125. key: 'child_order_count_1',
  126. value: '',
  127. }, {
  128. title: '二级分销订单数量',
  129. key: 'child_order_count_2',
  130. value: '',
  131. }, {
  132. title: '团队分销订单数量',
  133. key: 'child_order_count',
  134. value: '',
  135. }, {
  136. title: '一级分销商人数',
  137. key: 'child_agent_count_1',
  138. value: '',
  139. }, {
  140. title: '二级分销商人数',
  141. key: 'child_agent_count_2',
  142. value: '',
  143. }, {
  144. title: '团队分销商人数',
  145. key: 'child_agent_count',
  146. value: '',
  147. }, {
  148. title: '团队分销商等级统计',
  149. key: 'child_agent_level',
  150. value: [],
  151. }, {
  152. title: '一级分销商等级统计',
  153. key: 'child_agent_level_1',
  154. value: [],
  155. }],
  156. upgradeConditionBak: [],
  157. upgradeConditionInit: [{
  158. title: '用户消费金额',
  159. key: 'total_consume',
  160. value: '',
  161. }, {
  162. title: '一级用户人数',
  163. key: 'child_user_count_1',
  164. value: '',
  165. }, {
  166. title: '二级用户人数',
  167. key: 'child_user_count_2',
  168. value: '',
  169. }, {
  170. title: '团队用户人数',
  171. key: 'child_user_count',
  172. value: '',
  173. }, {
  174. title: '直推分销订单金额',
  175. key: 'order_money',
  176. value: '',
  177. }, {
  178. title: '一级分销订单金额',
  179. key: 'child_order_money_1',
  180. value: '',
  181. }, {
  182. title: '二级分销订单金额',
  183. key: 'child_order_money_2',
  184. value: '',
  185. }, {
  186. title: '团队分销订单金额',
  187. key: 'child_order_money',
  188. value: '',
  189. }, {
  190. title: '直推分销订单数量',
  191. key: 'order_count',
  192. value: '',
  193. }, {
  194. title: '一级分销订单数量',
  195. key: 'child_order_count_1',
  196. value: '',
  197. }, {
  198. title: '二级分销订单数量',
  199. key: 'child_order_count_2',
  200. value: '',
  201. }, {
  202. title: '团队分销订单数量',
  203. key: 'child_order_count',
  204. value: '',
  205. }, {
  206. title: '一级分销商人数',
  207. key: 'child_agent_count_1',
  208. value: '',
  209. }, {
  210. title: '二级分销商人数',
  211. key: 'child_agent_count_2',
  212. value: '',
  213. }, {
  214. title: '团队分销商人数',
  215. key: 'child_agent_count',
  216. value: '',
  217. }, {
  218. title: '团队分销商等级统计',
  219. key: 'child_agent_level',
  220. value: [],
  221. }, {
  222. title: '一级分销商等级统计',
  223. key: 'child_agent_level_1',
  224. value: [],
  225. }],
  226. goods_ids_list: null,
  227. levelList: [{
  228. title: '一级',
  229. value: '1',
  230. }, {
  231. title: '二级',
  232. value: '2',
  233. }, {
  234. title: '三级',
  235. value: '3',
  236. }, {
  237. title: '四级',
  238. value: '4',
  239. }, {
  240. title: '五级',
  241. value: '5',
  242. }, {
  243. title: '六级',
  244. value: '6',
  245. }, {
  246. title: '七级',
  247. value: '7',
  248. }, {
  249. title: '八级',
  250. value: '8',
  251. }, {
  252. title: '九级',
  253. value: '9',
  254. }, {
  255. title: '十级',
  256. value: '10',
  257. }],
  258. levelOptions: [],
  259. selectLevelOptionsLength: 0,
  260. moveLevel: '',
  261. editId: null,
  262. deleteDialog: false,
  263. existLevel: [],
  264. }
  265. },
  266. mounted() {
  267. this.initData();
  268. },
  269. methods: {
  270. //init 数据
  271. initData() {
  272. let that = this;
  273. that.existLevel = Config.existLevel;
  274. that.levelOptions = []
  275. Fast.api.ajax({
  276. url: 'shopro/commission/level/index',
  277. loading: false,
  278. type: 'GET',
  279. }, function (ret, res) {
  280. that.levelOptions = res.data;
  281. if (that.optType == 'edit') {
  282. that.formData = Config.row;
  283. that.editId = Config.row.level;
  284. //判断下面的等级选择
  285. let selectLevel = [];
  286. that.levelOptions.forEach((item, index) => {
  287. if (item.level < that.formData.level) {
  288. selectLevel.push(item)
  289. }
  290. })
  291. that.selectLevelOptionsLength = selectLevel.length;
  292. that.existLevel.splice(that.existLevel.indexOf(Config.row.level), 1)
  293. that.formData.upgrade_rules = JSON.parse(that.formData.upgrade_rules)
  294. for (key in that.formData.upgrade_rules) {
  295. that.upgradeCondition.forEach(i => {
  296. if (key == i.key) {
  297. i.value = that.formData.upgrade_rules[key];
  298. i.selected = true;
  299. }
  300. })
  301. }
  302. that.upgradeConditionBak = JSON.parse(JSON.stringify(that.upgradeCondition))
  303. }
  304. return false
  305. })
  306. },
  307. childAgentCountAdd(index) {
  308. if (this.formData.level) {
  309. this.upgradeCondition[index].value.push({
  310. level: '',
  311. count: ''
  312. })
  313. } else {
  314. this.$notify({
  315. title: '警告',
  316. message: '请先选择等级',
  317. type: 'warning'
  318. });
  319. }
  320. },
  321. childAgentCountDelete(zindex, index) {
  322. this.upgradeCondition[zindex].value.splice(index, 1)
  323. },
  324. //选择等级徽章
  325. bgimageAdd() {
  326. let that = this;
  327. Fast.api.open("general/attachment/select?multiple=false", "选择", {
  328. callback: function (data) {
  329. that.formData.image = data.url;
  330. that.$forceUpdate();
  331. }
  332. });
  333. return false;
  334. },
  335. //选择条件
  336. selectCondition(index) {
  337. this.upgradeCondition[index].selected = !this.upgradeCondition[index].selected;
  338. if (!this.upgradeCondition[index].selected) {
  339. this.upgradeCondition[index].value = ""
  340. }
  341. this.$forceUpdate();
  342. },
  343. //条件删除
  344. conditionDelete(index) {
  345. this.upgradeCondition[index].selected = false;
  346. this.upgradeCondition[index].value = ""
  347. this.$forceUpdate();
  348. },
  349. selectLevel(index) {
  350. //赋值level
  351. this.formData.level = this.levelList[index].value;
  352. //控制添加按钮是否显示
  353. let selectLevel = [];
  354. this.levelOptions.forEach((item, index) => {
  355. if (item.level < this.formData.level && item.level != this.editId) {
  356. selectLevel.push(item)
  357. }
  358. })
  359. this.selectLevelOptionsLength = selectLevel.length;
  360. //清空条件
  361. this.upgradeCondition = JSON.parse(JSON.stringify(this.upgradeConditionInit));
  362. if (this.editId == this.formData.level) {
  363. this.upgradeCondition = JSON.parse(JSON.stringify(this.upgradeConditionBak));
  364. }
  365. },
  366. addGoods(index) {
  367. let that = this;
  368. let multiple = false;
  369. let type = '';
  370. let ids = that.upgradeCondition[index].value ? that.upgradeCondition[index].value : '';
  371. let params = {
  372. multiple: multiple,
  373. type: type,
  374. ids: ids
  375. }
  376. shoproSelectGoods(params, "选择商品").then(data => {
  377. that.upgradeCondition[index].value = data.data.id;
  378. that.goods_ids_list = data.data;
  379. that.$forceUpdate();
  380. }).catch(error => {
  381. });
  382. return false;
  383. },
  384. formDelete() {
  385. this.deleteDialog = true
  386. },
  387. deleteDialogClose(type) {
  388. this.deleteDialog = false;
  389. if (type == 'define') {
  390. Fast.api.ajax({
  391. url: ajaxUrl,
  392. loading: true,
  393. data: formSubmit
  394. }, function (ret, res) {})
  395. }
  396. },
  397. formSubmit(formName) {
  398. let that = this;
  399. if (that.formData.level == "") {
  400. this.$notify({
  401. title: '警告',
  402. message: '等级权重未填写',
  403. type: 'warning'
  404. });
  405. return false;
  406. }
  407. if (that.formData.name == "") {
  408. this.$notify({
  409. title: '警告',
  410. message: '等级名称未填写',
  411. type: 'warning'
  412. });
  413. return false;
  414. }
  415. if (Number(that.formData.commission_rules.commission_1) + Number(that.formData.commission_rules.commission_2) + Number(that.formData.commission_rules.commission_3) > 100) {
  416. this.$notify({
  417. title: '警告',
  418. message: '佣金比例之和不可超过100',
  419. type: 'warning'
  420. });
  421. return false;
  422. }
  423. if (Number(that.formData.commission_rules.commission_1) < 0 || Number(that.formData.commission_rules.commission_2) < 0 || Number(that.formData.commission_rules.commission_3) < 0) {
  424. this.$notify({
  425. title: '警告',
  426. message: '佣金比例不可小于0',
  427. type: 'warning'
  428. });
  429. return false;
  430. }
  431. let upgrade_rules = {}
  432. let nowrite = true
  433. let condition = 0;
  434. that.upgradeCondition.forEach(k => {
  435. if (k.selected) {
  436. upgrade_rules[k.key] = k.value
  437. if (k.value === "") {
  438. nowrite = false;
  439. };
  440. if (k.key == 'agent_level') {
  441. k.value.length > 0
  442. if (k.value.length == 0) {
  443. nowrite = false;
  444. } else {
  445. k.value.forEach(i => {
  446. if (i.level == "" || i.count == "") {
  447. nowrite = false;
  448. }
  449. })
  450. }
  451. }
  452. condition++
  453. }
  454. })
  455. that.formData.upgrade_rules = JSON.stringify(upgrade_rules)
  456. if (that.formData.level != 1) {
  457. if (condition == 0) {
  458. this.$notify({
  459. title: '警告',
  460. message: '至少选择一个升级条件',
  461. type: 'warning'
  462. });
  463. return false;
  464. }
  465. if (!nowrite) {
  466. this.$notify({
  467. title: '警告',
  468. message: '升级条件必须填写完整',
  469. type: 'warning'
  470. });
  471. return false;
  472. }
  473. }
  474. var formSubmit = JSON.parse(JSON.stringify(that.formData));
  475. for (key in formSubmit.commission_rules) {
  476. formSubmit.commission_rules[key] = Number(formSubmit.commission_rules[key]).toFixed(2)
  477. }
  478. formSubmit.commission_rules = JSON.stringify(formSubmit.commission_rules)
  479. if (this.optType == 'edit') {
  480. formSubmit.new_level = formSubmit.level;
  481. delete formSubmit.level;
  482. }
  483. // return false;
  484. let ajaxUrl = "shopro/commission/level/add"
  485. if (this.optType == 'edit') {
  486. ajaxUrl = 'shopro/commission/level/edit?level=' + that.editId
  487. }
  488. Fast.api.ajax({
  489. url: ajaxUrl,
  490. loading: true,
  491. data: formSubmit
  492. }, function (ret, res) {
  493. Fast.api.close()
  494. return false;
  495. })
  496. },
  497. },
  498. })
  499. },
  500. api: {
  501. bindevent: function () {
  502. Form.api.bindevent($("form[role=form]"));
  503. }
  504. }
  505. };
  506. return Controller;
  507. });