goods.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. const {
  2. contains
  3. } = require("jquery");
  4. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  5. var Controller = {
  6. index: function () {
  7. var indexPage = new Vue({
  8. el: "#indexPage",
  9. data() {
  10. return {
  11. goodTypeOptions: [{
  12. name: "全部",
  13. type: "all"
  14. },
  15. {
  16. name: "实体商品",
  17. type: "normal"
  18. },
  19. {
  20. name: "虚拟商品",
  21. type: "virtual"
  22. }
  23. ],
  24. activityTypeOptions: [{
  25. name: "全部",
  26. type: "all"
  27. },
  28. {
  29. name: "拼团",
  30. type: "groupon"
  31. },
  32. {
  33. name: "秒杀",
  34. type: "seckill"
  35. }, {
  36. name: "积分",
  37. type: "score"
  38. }
  39. ],
  40. commissionTypeOptions: [{
  41. name: "全部",
  42. type: "all"
  43. },
  44. {
  45. name: "默认规则",
  46. type: "0"
  47. },
  48. {
  49. name: "独立规则",
  50. type: "1"
  51. }, {
  52. name: "批量规则",
  53. type: "2"
  54. }
  55. ],
  56. commissionStatusOptions: [{
  57. name: "全部",
  58. type: "all"
  59. },
  60. {
  61. name: "不参与",
  62. type: "0"
  63. },
  64. {
  65. name: "参与",
  66. type: "1"
  67. }
  68. ],
  69. searchForm: {
  70. goods_title: '',
  71. goods_type: 'all',
  72. activity_type: 'all',
  73. self_rules: 'all',
  74. commission_goods_status: 'all',
  75. },
  76. searchFormInit: {
  77. goods_title: '',
  78. goods_type: 'all',
  79. activity_type: 'all',
  80. self_rules: 'all',
  81. commission_goods_status: 'all',
  82. },
  83. listData: [],
  84. multipleSelection: [],
  85. currentPage: 1,
  86. totalPage: 0,
  87. offset: 0,
  88. limit: 10,
  89. isAjax: true,
  90. tableAjax: false,
  91. allcheckeds:false,
  92. }
  93. },
  94. mounted() {
  95. this.getListData();
  96. },
  97. methods: {
  98. getListData() {
  99. let that = this;
  100. if (!that.isAjax) {
  101. that.tableAjax = true;
  102. }
  103. Fast.api.ajax({
  104. url: 'shopro/commission/goods/index',
  105. loading: false,
  106. type: 'GET',
  107. data: {
  108. limit: that.limit,
  109. offset: that.offset,
  110. goods_title: that.searchForm.goods_title,
  111. goods_type: that.searchForm.goods_type,
  112. activity_type: that.searchForm.activity_type == 'score' ? 'all' : that.searchForm.activity_type,
  113. app_type: that.searchForm.activity_type == 'score' ? 'score' : 'all',
  114. self_rules: that.searchForm.self_rules,
  115. commission_goods_status: that.searchForm.commission_goods_status,
  116. }
  117. }, function (ret, res) {
  118. that.listData = res.data.rows;
  119. that.totalPage = res.data.total;
  120. that.isAjax = false;
  121. that.tableAjax = false;
  122. return false
  123. }, function (ret, res) {
  124. that.isAjax = false;
  125. that.tableAjax = false;
  126. })
  127. },
  128. screenEmpty() {
  129. this.searchForm = JSON.parse(JSON.stringify(this.searchFormInit))
  130. },
  131. operation(opttype, row) {
  132. let that = this;
  133. switch (opttype) {
  134. case 'join':
  135. let isJoin = true;
  136. let idsArrjoin = [];
  137. if (row == 0) {
  138. that.multipleSelection.forEach(i => {
  139. if (!i.commission) {
  140. isJoin = false;
  141. }
  142. idsArrjoin.push(i.id)
  143. })
  144. } else {
  145. isJoin = row.commission ? true : false
  146. idsArrjoin.push(row.id)
  147. }
  148. if (!isJoin) {
  149. this.$alert('请先设置商品规则', {
  150. confirmButtonText: '确定',
  151. cancelButtonText: '取消',
  152. type: 'warning'
  153. }).then(() => {
  154. Fast.api.open('shopro/commission/goods/edit?ids=' + idsArrjoin.join(','), '设置佣金', {
  155. callback(data) {
  156. that.getListData()
  157. }
  158. })
  159. }).catch(() => {
  160. this.$message({
  161. type: 'info',
  162. message: '已关闭'
  163. });
  164. });
  165. } else {
  166. Fast.api.ajax({
  167. url: 'shopro/commission/goods/commission_status',
  168. type: 'POST',
  169. data: {
  170. ids: idsArrjoin.join(','),
  171. status: 1
  172. },
  173. loading: true,
  174. }, function (ret, res) {
  175. that.getListData();
  176. return false;
  177. })
  178. }
  179. break;
  180. case 'nojoin':
  181. let idsArrno = [];
  182. if (row == 0) {
  183. that.multipleSelection.forEach(i => {
  184. idsArrno.push(i.id)
  185. })
  186. } else {
  187. idsArrno.push(row.id)
  188. }
  189. Fast.api.ajax({
  190. url: 'shopro/commission/goods/commission_status',
  191. type: 'POST',
  192. data: {
  193. ids: idsArrno.join(','),
  194. status: 0
  195. },
  196. loading: true,
  197. }, function (ret, res) {
  198. that.getListData();
  199. return false;
  200. })
  201. break;
  202. case 'edit':
  203. let idsArredit = [];
  204. if (row == 0) {
  205. that.multipleSelection.forEach(i => {
  206. idsArredit.push(i.id)
  207. })
  208. } else {
  209. idsArredit.push(row.id)
  210. }
  211. Fast.api.open('shopro/commission/goods/edit?ids=' + idsArredit.join(','), '设置佣金', {
  212. callback(data) {
  213. that.getListData()
  214. }
  215. })
  216. break;
  217. }
  218. },
  219. tableCellClassName({
  220. columnIndex
  221. }) {
  222. if (columnIndex == 2 || columnIndex == 5) {
  223. return 'cell-left';
  224. }
  225. return '';
  226. },
  227. pageSizeChange(val) {
  228. this.offset = 0;
  229. this.limit = val;
  230. this.currentPage = 1;
  231. this.getListData();
  232. },
  233. pageCurrentChange(val) {
  234. this.offset = (val - 1) * this.limit;
  235. this.currentPage = val;
  236. this.getListData();
  237. },
  238. handleSelectionChange(val) {
  239. this.multipleSelection = val;
  240. if(this.multipleSelection.length==this.listData.length){
  241. this.allcheckeds=true
  242. }else{
  243. this.allcheckeds=false
  244. }
  245. },
  246. changeAllcheckeds(val){
  247. if(val){
  248. this.listData.forEach(row => {
  249. this.$refs.multipleTable.toggleRowSelection(row,true);
  250. });
  251. }else{
  252. this.$refs.multipleTable.clearSelection();
  253. }
  254. }
  255. },
  256. })
  257. },
  258. edit: function () {
  259. Controller.detailInit('edit');
  260. Controller.api.bindevent();
  261. },
  262. detailInit: function (type) {
  263. Vue.directive('enterNumber', {
  264. inserted: function (el) {
  265. let changeValue = (el, type) => {
  266. const e = document.createEvent('HTMLEvents')
  267. e.initEvent(type, true, true)
  268. el.dispatchEvent(e)
  269. }
  270. el.addEventListener("keyup", function (e) {
  271. let input = e.target;
  272. let reg = new RegExp('^((?:(?:[1-9]{1}\\d*)|(?:[0]{1}))(?:\\.(?:\\d){0,2})?)(?:\\d*)?$');
  273. let matchRes = input.value.match(reg);
  274. if (matchRes === null) {
  275. input.value = "";
  276. } else {
  277. if (matchRes[1] !== matchRes[0]) {
  278. input.value = matchRes[1];
  279. }
  280. }
  281. changeValue(input, 'input')
  282. });
  283. }
  284. });
  285. var detailPage = new Vue({
  286. el: "#detailPage",
  287. data() {
  288. return {
  289. optType: type,
  290. isalone: new URLSearchParams(location.search).get('ids').indexOf(',') == -1 ? 0 : 1,
  291. ids: new URLSearchParams(location.search).get('ids'),
  292. goodsDetail: {},
  293. levelList: [],
  294. self_rules: 0,
  295. status: 1,
  296. commission_rules: {},
  297. commission_rules_bak0: null,
  298. commission_rules_bak1: null,
  299. commission_rules_bak2: null,
  300. batchShow: {
  301. 1: false,
  302. 2: false,
  303. 3: false
  304. },
  305. batchList: {
  306. rate: '',
  307. money: ''
  308. },
  309. isLevelChange: false,
  310. isSkuPriceChange: false,
  311. radioEnd: 0,
  312. commission_config: '0',
  313. commission_config_obj: {
  314. commission_level: '1',
  315. self_buy: '0',
  316. commission_price_type: 'goods_price',
  317. commission_event: 'payed'
  318. },
  319. commission_order_status: 1,
  320. }
  321. },
  322. mounted() {
  323. this.getStoreList();
  324. if (!Config.row[0].commission || (Config.row[0].commission && (Config.row[0].commission.commission_config == '' || Config.row[0].commission.commission_config == 0))) {
  325. this.commission_config = 0;
  326. this.commission_config_obj = Config.defaultCommissionConfig;
  327. this.commission_config_obj.commission_level = Config.defaultCommissionConfig.commission_level == 0 ? '1' : Config.defaultCommissionConfig.commission_level;
  328. } else if (Config.row[0].commission && Config.row[0].commission.commission_config instanceof Object) {
  329. this.commission_config = 1;
  330. this.commission_config_obj = Config.row[0].commission.commission_config;
  331. }
  332. },
  333. methods: {
  334. changeCommissionConfig(value) {
  335. if (value == 1) {
  336. if (!Config.row[0].commission || (Config.row[0].commission && (Config.row[0].commission.commission_config == '' || Config.row[0].commission.commission_config == 0))) {
  337. this.commission_config_obj = Config.defaultCommissionConfig;
  338. this.commission_config_obj.commission_level = Config.defaultCommissionConfig.commission_level == 0 ? '1' : Config.defaultCommissionConfig.commission_level;
  339. } else if (Config.row[0].commission && Config.row[0].commission.commission_config instanceof Object) {
  340. this.commission_config_obj = Config.row[0].commission.commission_config;
  341. }
  342. }
  343. },
  344. getStoreList() {
  345. let that = this;
  346. Fast.api.ajax({
  347. url: 'shopro/commission/level/index',
  348. loading: false,
  349. type: 'GET',
  350. }, function (ret, res) {
  351. that.levelList = res.data;
  352. that.getGoodsList()
  353. return false
  354. })
  355. },
  356. inputChange() {
  357. this.$forceUpdate()
  358. },
  359. selfRulesChange(value) {
  360. let that = this;
  361. that.radioEnd = 0;
  362. if (that['commission_rules_bak' + value]) {
  363. that.commission_rules = that['commission_rules_bak' + value]
  364. that.radioEnd = value;
  365. } else {
  366. that.commission_rules = {}
  367. that.assembleData(value)
  368. }
  369. },
  370. getGoodsList() {
  371. let that = this;
  372. if (that.isalone == 0) {
  373. that.goodsDetail = Config.row[0];
  374. if (Config.row[0].commission) {
  375. that.commission_rules = JSON.parse(JSON.stringify(Config.row[0].commission.commission_rules))
  376. that.status = Config.row[0].commission.status;
  377. that.self_rules = Config.row[0].commission.self_rules
  378. that.commission_order_status = Config.row[0].commission.commission_order_status;
  379. that.assembleData(Config.row[0].commission.self_rules)
  380. } else {
  381. that.status = 1;
  382. that.self_rules = 0
  383. that.assembleData(0)
  384. }
  385. } else {
  386. that.status = 1;
  387. that.self_rules = 2
  388. that.assembleData(2)
  389. }
  390. },
  391. batchSet(commission, type) {
  392. if (type == 'define') {
  393. if (this.self_rules == 1) {
  394. for (key in this.commission_rules) {
  395. for (k in this.commission_rules[key]) {
  396. this.commission_rules[key][k][commission].rate = '';
  397. this.commission_rules[key][k][commission].money = '';
  398. }
  399. }
  400. if (this.batchList.rate) {
  401. for (key in this.commission_rules) {
  402. for (k in this.commission_rules[key]) {
  403. this.commission_rules[key][k][commission].rate = this.batchList.rate;
  404. }
  405. }
  406. } else if (this.batchList.money) {
  407. for (key in this.commission_rules) {
  408. for (k in this.commission_rules[key]) {
  409. this.commission_rules[key][k][commission].money = this.batchList.money;
  410. }
  411. }
  412. }
  413. } else if (this.self_rules == 2) {
  414. for (key in this.commission_rules) {
  415. this.commission_rules[key][commission].rate = '';
  416. this.commission_rules[key][commission].money = '';
  417. }
  418. if (this.batchList.rate) {
  419. for (key in this.commission_rules) {
  420. this.commission_rules[key][commission].rate = this.batchList.rate;
  421. }
  422. } else if (this.batchList.money) {
  423. for (key in this.commission_rules) {
  424. this.commission_rules[key][commission].money = this.batchList.money;
  425. }
  426. }
  427. }
  428. }
  429. this.batchShow[commission] = false;
  430. this.batchList.rate = ''
  431. this.batchList.money = ''
  432. },
  433. formSubmit() {
  434. let that = this;
  435. if (that.status == 1) {
  436. let commission_rules = JSON.parse(JSON.stringify(that.commission_rules))
  437. let isWrite = true;
  438. if (that.self_rules == 0) {
  439. commission_rules = ''
  440. } else if (that.self_rules == 1) {
  441. for (key in commission_rules) {
  442. for (k in commission_rules[key]) {
  443. for (g in commission_rules[key][k]) {
  444. if (commission_rules[key][k][g].rate === '' && commission_rules[key][k][g].money === '') {
  445. isWrite = false;
  446. } else {
  447. if (commission_rules[key][k][g].rate !== '') {
  448. delete commission_rules[key][k][g].money
  449. } else if (commission_rules[key][k][g].money !== '') {
  450. delete commission_rules[key][k][g].rate
  451. }
  452. }
  453. }
  454. }
  455. }
  456. } else {
  457. for (key in commission_rules) {
  458. for (k in commission_rules[key]) {
  459. if (commission_rules[key][k].rate === '') {
  460. isWrite = false;
  461. }
  462. }
  463. }
  464. };
  465. if (!isWrite) {
  466. this.$notify({
  467. title: '警告',
  468. message: '请将数据填写完整',
  469. type: 'warning'
  470. });
  471. return false;
  472. };
  473. let commission_config = {}
  474. if (that.commission_config == 1) {
  475. commission_config = that.commission_config_obj
  476. } else {
  477. commission_config = 0
  478. }
  479. // return false;
  480. let ajaxUrl = 'shopro/commission/goods/edit'
  481. Fast.api.ajax({
  482. url: ajaxUrl,
  483. loading: true,
  484. data: {
  485. ids: that.ids,
  486. status: that.status,
  487. self_rules: that.self_rules,
  488. commission_order_status: that.commission_order_status,
  489. commission_rules: JSON.stringify(commission_rules),
  490. commission_config: JSON.stringify(commission_config)
  491. }
  492. }, function (ret, res) {
  493. Fast.api.close();
  494. return false;
  495. })
  496. } else {
  497. Fast.api.ajax({
  498. url: 'shopro/commission/goods/commission_status',
  499. type: 'POST',
  500. data: {
  501. ids: that.ids,
  502. status: that.status
  503. },
  504. loading: true,
  505. }, function (ret, res) {
  506. Fast.api.close();
  507. return false;
  508. })
  509. }
  510. },
  511. assembleData(value) {
  512. let that = this;
  513. if (value == 0) {
  514. that.commission_rules = ""
  515. } else if (value == 1) {
  516. var rate_money = {
  517. 1: {
  518. rate: '',
  519. money: ''
  520. },
  521. 2: {
  522. rate: '',
  523. money: ''
  524. },
  525. 3: {
  526. rate: '',
  527. money: ''
  528. }
  529. }
  530. Config.row[0].sku_price.forEach(i => {
  531. if (that.commission_rules[i.id]) {
  532. that.levelList.forEach(j => {
  533. if (that.commission_rules[i.id][j.level]) {
  534. for (key in that.commission_rules[i.id][j.level]) {
  535. if (!that.commission_rules[i.id][j.level][key].rate) {
  536. that.$set(that.commission_rules[i.id][j.level][key], 'rate', '')
  537. } else if (!that.commission_rules[i.id][j.level][key].money) {
  538. that.$set(that.commission_rules[i.id][j.level][key], 'money', '')
  539. }
  540. }
  541. } else {
  542. that.$set(that.commission_rules[i.id], j.level, JSON.parse(JSON.stringify(rate_money)))
  543. }
  544. })
  545. } else {
  546. that.commission_rules[i.id] = {}
  547. that.levelList.forEach(j => {
  548. that.$set(that.commission_rules[i.id], j.level, JSON.parse(JSON.stringify(rate_money)))
  549. })
  550. }
  551. })
  552. } else if (value == 2) {
  553. let rate_money2 = {
  554. 1: {
  555. rate: '',
  556. },
  557. 2: {
  558. rate: '',
  559. },
  560. 3: {
  561. rate: '',
  562. }
  563. }
  564. that.levelList.forEach(i => {
  565. if (that.commission_rules[i.level]) {} else {
  566. that.$set(that.commission_rules, i.level, {})
  567. that.$set(that.commission_rules, i.level, JSON.parse(JSON.stringify(rate_money2)))
  568. }
  569. })
  570. }
  571. // return false;
  572. if (value == 1) {
  573. for (sku in that.commission_rules) {
  574. let issku = Config.row[0].sku_price.some(s => {
  575. if (s.id == sku) {
  576. return true
  577. } else {
  578. return false
  579. }
  580. })
  581. if (!issku) {
  582. delete that.commission_rules[sku]
  583. }
  584. if (issku) {
  585. for (key in that.commission_rules[sku]) {
  586. let isexistence = that.levelList.some(i => {
  587. if (i.level == key) {
  588. return true
  589. } else {
  590. return false
  591. }
  592. })
  593. if (!isexistence) {
  594. delete that.commission_rules[key]
  595. }
  596. }
  597. }
  598. }
  599. }
  600. if (value == 2) {
  601. for (key in that.commission_rules) {
  602. let isexistence = that.levelList.some(i => {
  603. if (i.level == key) {
  604. return true
  605. } else {
  606. return false
  607. }
  608. })
  609. if (!isexistence) {
  610. delete that.commission_rules[key]
  611. }
  612. }
  613. }
  614. that['commission_rules_bak' + value] = JSON.parse(JSON.stringify(that.commission_rules))
  615. that.radioEnd = value
  616. }
  617. },
  618. })
  619. },
  620. api: {
  621. bindevent: function () {
  622. Form.api.bindevent($("form[role=form]"));
  623. }
  624. }
  625. };
  626. return Controller;
  627. });