activity.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 检测是否安装 redis
  5. this.checkRedis();
  6. var activityIndex = new Vue({
  7. el: "#activityIndex",
  8. data() {
  9. return {
  10. tipCloseFlag: true,
  11. activityOptions: [{
  12. value: 'all',
  13. label: '全部'
  14. }, {
  15. value: 'seckill',
  16. label: '秒杀活动'
  17. }, {
  18. value: 'groupon',
  19. label: '拼团活动'
  20. }],
  21. statusOptins: [{
  22. value: 'all',
  23. label: '全部'
  24. }, {
  25. value: 'nostart',
  26. label: '未开始'
  27. }, {
  28. value: 'ing',
  29. label: '进行中'
  30. }, {
  31. value: 'ended',
  32. label: '已结束'
  33. }],
  34. searchForm: {
  35. title: '',
  36. type: "all",
  37. status: "all",
  38. activitytime: [],
  39. },
  40. searchFormInit: {
  41. title: '',
  42. type: "all",
  43. status: "all",
  44. activitytime: [],
  45. },
  46. searchOp: {
  47. title: 'like',
  48. type: "=",
  49. status: "=",
  50. activitytime: 'range',
  51. },
  52. activityData: [],
  53. offset: 0,
  54. limit: 10,
  55. currentPage: 1,
  56. totalPage: 0,
  57. }
  58. },
  59. mounted() {
  60. this.getType()
  61. this.getActivityData()
  62. },
  63. methods: {
  64. getType() {
  65. var that = this;
  66. Fast.api.ajax({
  67. url: 'shopro/activity/activity/getType',
  68. loading: false,
  69. type: 'GET',
  70. }, function (ret, res) {
  71. that.activityOptions = res.data.activity_type
  72. that.statusOptins = res.data.activity_status
  73. return false;
  74. })
  75. },
  76. getActivityData(offset, limit) {
  77. var that = this;
  78. that.offset = (offset || offset == 0) ? offset : that.offset
  79. that.limit = limit ? limit : that.limit
  80. let filter = {}
  81. let op = {}
  82. for (key in that.searchForm) {
  83. if (key == 'activitytime') {
  84. if (that.searchForm[key]) {
  85. if (that.searchForm[key].length > 0) {
  86. filter[key] = that.searchForm[key].join(' - ');
  87. }
  88. }
  89. } else if (key == 'type' || key == 'status') {
  90. if (that.searchForm[key] != '' && that.searchForm[key] != 'all') {
  91. filter[key] = that.searchForm[key];
  92. }
  93. } else if (key == 'title') {
  94. if (that.searchForm[key] != '') {
  95. filter[key] = that.searchForm[key];
  96. }
  97. }
  98. }
  99. for (key in filter) {
  100. op[key] = that.searchOp[key]
  101. }
  102. Fast.api.ajax({
  103. url: 'shopro/activity/activity/index',
  104. loading: true,
  105. type: 'GET',
  106. data: {
  107. offset: that.offset,
  108. limit: that.limit,
  109. filter: JSON.stringify(filter),
  110. op: JSON.stringify(op)
  111. }
  112. }, function (ret, res) {
  113. that.activityData = res.data.rows;
  114. that.totalPage = res.data.total
  115. return false;
  116. })
  117. },
  118. screenEmpty() {
  119. this.searchForm = JSON.parse(JSON.stringify(this.searchFormInit))
  120. this.getActivityData(0, 10)
  121. },
  122. handleSizeChange(val) {
  123. this.getActivityData(0, val)
  124. },
  125. handleCurrentChange(val) {
  126. this.offset = (val - 1) * this.limit
  127. this.getActivityData(this.offset, this.limit)
  128. },
  129. activityAdd() {
  130. let that = this;
  131. Fast.api.open(`shopro/activity/activity/add`, '新建活动', {
  132. callback() {
  133. that.getActivityData()
  134. }
  135. })
  136. },
  137. activityEdit(row) {
  138. let that = this;
  139. Fast.api.open(`shopro/activity/activity/edit?ids=${row.id}`, '编辑活动', {
  140. callback() {
  141. that.getActivityData()
  142. }
  143. })
  144. },
  145. activityView(row) {
  146. Fast.api.open(`shopro/activity/activity/edit?ids=${row.id}&type=view`, '查看活动')
  147. },
  148. activityDelete(row) {
  149. let that = this;
  150. Fast.api.ajax({
  151. url: `shopro/activity/activity/del/ids/${row.id}`,
  152. loading: true,
  153. type: 'POST',
  154. data: {}
  155. }, function (ret, res) {
  156. that.getActivityData()
  157. })
  158. },
  159. activityRecyclebin() {
  160. Fast.api.open("shopro/activity/activity/recyclebin", "查看历史活动");
  161. },
  162. activityTipsClose() {
  163. this.tipCloseFlag = false
  164. },
  165. },
  166. })
  167. },
  168. recyclebin: function () {
  169. // 初始化表格参数配置
  170. Table.api.init({
  171. extend: {
  172. 'dragsort_url': ''
  173. }
  174. });
  175. var table = $("#table");
  176. // 初始化表格
  177. table.bootstrapTable({
  178. url: 'shopro/activity/activity/recyclebin' + location.search,
  179. pk: 'id',
  180. sortName: 'id',
  181. commonSearch: false,
  182. columns: [
  183. [
  184. { checkbox: true },
  185. { field: 'id', title: __('Id') },
  186. { field: 'title', title: __('Title'), align: 'left' },
  187. {
  188. field: 'deletetime',
  189. title: __('Deletetime'),
  190. operate: 'RANGE',
  191. addclass: 'datetimerange',
  192. formatter: Table.api.formatter.datetime
  193. }
  194. ]
  195. ]
  196. });
  197. // 为表格绑定事件
  198. Table.api.bindevent(table);
  199. },
  200. add: function () {
  201. Controller.detailInit('add')
  202. },
  203. sku: function () {
  204. Vue.directive('enterNumber', {
  205. inserted: function (el) {
  206. let changeValue = (el, type) => {
  207. const e = document.createEvent('HTMLEvents')
  208. e.initEvent(type, true, true)
  209. el.dispatchEvent(e)
  210. }
  211. el.addEventListener("keyup", function (e) {
  212. let input = e.target;
  213. let reg = new RegExp('^((?:(?:[1-9]{1}\\d*)|(?:[0]{1}))(?:\\.(?:\\d){0,2})?)(?:\\d*)?$');
  214. let matchRes = input.value.match(reg);
  215. if (matchRes === null) {
  216. input.value = "";
  217. } else {
  218. if (matchRes[1] !== matchRes[0]) {
  219. input.value = matchRes[1];
  220. }
  221. }
  222. changeValue(input, 'input')
  223. });
  224. }
  225. });
  226. Vue.directive('positiveInteger', {
  227. inserted: function (el) {
  228. el.addEventListener("keypress", function (e) {
  229. e = e || window.event;
  230. let charcode = typeof e.charCode == 'number' ? e.charCode : e.keyCode;
  231. let re = /\d/;
  232. if (!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) {
  233. if (e.preventDefault) {
  234. e.preventDefault();
  235. } else {
  236. e.returnValue = false;
  237. }
  238. }
  239. });
  240. }
  241. });
  242. var skuPrice = new Vue({
  243. el: "#skuPrice",
  244. data() {
  245. return {
  246. skuList: Config.skuList,
  247. skuPrice: Config.skuPrice,
  248. actSkuPrice: Config.actSkuPrice,
  249. type: '',
  250. activity_status: '',
  251. }
  252. },
  253. mounted() {
  254. let actSkuPrice = decodeURI(new URLSearchParams(location.search).get('actSkuPrice'))
  255. this.activity_status = new URLSearchParams(location.search).get('activity_status')
  256. this.type = new URLSearchParams(location.search).get('type')
  257. if (actSkuPrice) {
  258. JSON.parse(actSkuPrice).forEach(i => {
  259. this.actSkuPrice.forEach(e => {
  260. if (i.sku_price_id == e.sku_price_id) {
  261. e.price = i.price
  262. e.status = i.status
  263. e.stock = i.stock
  264. }
  265. })
  266. })
  267. }
  268. },
  269. methods: {
  270. changeStatus(i) {
  271. let status = this.actSkuPrice[i].status === 'up' ? 'down' : 'up';
  272. this.$set(this.actSkuPrice[i], 'status', status)
  273. },
  274. submitForm() {
  275. this.$confirm('确认提交吗', '提示', {
  276. confirmButtonText: '确定',
  277. cancelButtonText: '取消',
  278. type: 'warning'
  279. }).then(() => {
  280. let isSubmit = true
  281. isSubmit = !(this.actSkuPrice.every(function (item, index, array) {
  282. return item.status == 'down';
  283. }))
  284. this.actSkuPrice.forEach(i => {
  285. if (i.status == 'up' && !i.stock) {
  286. isSubmit = false
  287. }
  288. if (i.status == 'up' && !i.price) {
  289. isSubmit = false
  290. }
  291. })
  292. if (isSubmit) {
  293. Fast.api.close(JSON.stringify(this.actSkuPrice));
  294. } else {
  295. this.$message({
  296. message: '请把信息填写完整',
  297. type: 'warning'
  298. });
  299. }
  300. }).catch(() => {
  301. this.$message({
  302. type: 'info',
  303. message: '已取消'
  304. });
  305. });
  306. },
  307. activityStock(i,field){
  308. if(Number(this.skuPrice[i][field])<Number(this.actSkuPrice[i][field])){
  309. this.actSkuPrice[i][field]=this.skuPrice[i][field]
  310. }
  311. }
  312. },
  313. })
  314. },
  315. edit: function () {
  316. Controller.detailInit('edit')
  317. },
  318. detailInit: function (type) {
  319. Vue.directive('positiveInteger', {
  320. inserted: function (el) {
  321. el.addEventListener("keypress", function (e) {
  322. e = e || window.event;
  323. let charcode = typeof e.charCode == 'number' ? e.charCode : e.keyCode;
  324. let re = /\d/;
  325. if (!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) {
  326. if (e.preventDefault) {
  327. e.preventDefault();
  328. } else {
  329. e.returnValue = false;
  330. }
  331. }
  332. });
  333. }
  334. });
  335. var activityDetail = new Vue({
  336. el: "#activityDetail",
  337. data() {
  338. var checkDiscounts = (rule, value, callback) => {
  339. if (value && value.length == 0 && (this.activityForm.type == 'full_reduce' || this.activityForm.type == 'full_discount')) {
  340. callback(new Error('请编辑优惠条件'));
  341. } else {
  342. callback();
  343. }
  344. }
  345. var checkTeamNum = (rule, value, callback) => {
  346. if(value!=0){
  347. callback();
  348. }else{
  349. callback(new Error('成团人数必须大于0'));
  350. }
  351. }
  352. return {
  353. optType: new URLSearchParams(location.search).get('type') ? new URLSearchParams(location.search).get('type') : type,
  354. pickerOptions: {
  355. disabledDate: time => {
  356. if (this.activityForm.dateTime[0]) {
  357. return time.getTime() < Date.now() - 8.64e7 || time.getTime() > this.activityForm.dateTime[0];
  358. }
  359. return time.getTime() < Date.now() - 8.64e7;
  360. }
  361. },
  362. activityForm: {
  363. title: '',
  364. type: 'seckill',
  365. starttime: '',
  366. endtime: '',
  367. richtext_id: '',
  368. richtext_title: '',
  369. goods_list: [],
  370. goods_ids: '',
  371. dateTime: [],
  372. rules: {},
  373. },
  374. activityFormInit: {
  375. title: '',
  376. type: 'seckill',
  377. starttime: '',
  378. endtime: '',
  379. richtext_id: '',
  380. richtext_title: '',
  381. goods_list: [],
  382. goods_ids: '',
  383. dateTime: [],
  384. rules: {},
  385. },
  386. rules: {
  387. title: [{ required: true, message: '请输入活动名称', trigger: 'blur' }],
  388. type: [{ required: true, message: '请选择活动类型', trigger: 'blur' }],
  389. dateTime: [{ required: true, message: '请选择活动时间', trigger: 'blur' }],
  390. temp_team_num: [{ required: true, message: '请输入成团人数', trigger: 'change' },
  391. { validator: checkTeamNum, trigger: 'change' }],
  392. temp_discounts: [{ required: true, validator: checkDiscounts, trigger: 'blur' }],
  393. temp_full_num: [{ required: true, message: '请输入消费金额', trigger: 'blur' }],
  394. goods_list: [{ required: true, message: '请输入选择商品', trigger: 'blur' }],
  395. },
  396. isDisabled: false,
  397. someIsDisabled: true,
  398. selectedGoodsType: 'some',
  399. selectedFlag: true,
  400. activityTypeList: [{
  401. label: '秒杀活动',
  402. icon: 'seckill',
  403. type: 'seckill',
  404. rules: {
  405. activity_auto_close: "",
  406. limit_buy: "",
  407. order_auto_close: "",
  408. }
  409. }, {
  410. label: '拼团活动',
  411. icon: 'groupon',
  412. type: 'groupon',
  413. rules: {
  414. activity_auto_close: "",
  415. fictitious_num: "",
  416. is_alone: "1",
  417. is_fictitious: "0",
  418. limit_buy: "",
  419. order_auto_close: "",
  420. team_card: "1",
  421. team_num: "2",
  422. valid_time: ""
  423. }
  424. }, {
  425. label: '满额立减',
  426. icon: 'full_reduce',
  427. type: 'full_reduce',
  428. rules: {
  429. type: 'money',
  430. discounts: []
  431. }
  432. }, {
  433. label: '满额折扣',
  434. icon: 'full_discount',
  435. type: 'full_discount',
  436. rules: {
  437. type: 'money',
  438. discounts: []
  439. }
  440. }, {
  441. label: '满额包邮',
  442. icon: 'free_shipping',
  443. type: 'free_shipping',
  444. rules: {
  445. type: 'money',
  446. province_except: '',
  447. city_except: '',
  448. area_except: '',
  449. area_text: '',
  450. full_num: ''
  451. }
  452. }],
  453. }
  454. },
  455. mounted() {
  456. this.initData()
  457. },
  458. methods: {
  459. initData() {
  460. if (this.optType == 'view' || this.optType == 'edit') {
  461. this.initForm(Config.activity.type)
  462. for (key in this.activityForm) {
  463. if (Config.activity[key]) {
  464. if (key == 'rules') {
  465. this.activityForm[key] = Config.activity.rule_arr
  466. } else {
  467. this.activityForm[key] = Config.activity[key]
  468. }
  469. }
  470. };
  471. this.tempRule()
  472. // 处理活动时间
  473. this.activityForm.dateTime = [];
  474. this.activityForm.dateTime.push(moment(this.activityForm.starttime * 1000).format("YYYY-MM-DD HH:mm:ss"));
  475. this.activityForm.dateTime.push(moment(this.activityForm.endtime * 1000).format("YYYY-MM-DD HH:mm:ss"));
  476. // 处理所有商品
  477. if (this.activityForm.goods_ids == '') {
  478. this.selectedGoodsType = 'all'
  479. }
  480. if (this.optType == 'view') {
  481. this.isDisabled = true
  482. } else if (this.optType == 'edit') {
  483. if (Config.activity.status == 'end') {
  484. this.isDisabled = true
  485. } else if (Config.activity.status == 'ing') {
  486. this.isDisabled = true
  487. this.someIsDisabled = false
  488. }
  489. }
  490. } else {
  491. this.initForm()
  492. }
  493. },
  494. initForm(type) {
  495. // 选中之后不可点击
  496. if (type && this.activityForm.type == type) {
  497. return false
  498. }
  499. this.activityForm = JSON.parse(JSON.stringify(this.activityFormInit))
  500. if (type) {
  501. this.activityForm.type = type
  502. }
  503. this.activityTypeList.forEach(a => {
  504. if (a.type == this.activityForm.type) {
  505. this.activityForm.rules = a.rules
  506. }
  507. })
  508. this.tempRule()
  509. this.selectedGoodsType = 'some';
  510. if (this.$refs['activityForm']) {
  511. this.$refs['activityForm'].clearValidate();//重置form检测
  512. }
  513. },
  514. tempRule() {
  515. for (key in this.activityForm.rules) {
  516. this.$set(this.activityForm, 'temp_' + key, this.activityForm.rules[key])
  517. }
  518. },
  519. richtextSelect() {
  520. let that = this;
  521. Fast.api.open("shopro/richtext/select", "选择活动说明", {
  522. callback: function (data) {
  523. that.activityForm.richtext_id = data.data.id;
  524. that.activityForm.richtext_title = data.data.title
  525. }
  526. });
  527. },
  528. goodsSelect() {
  529. let that = this;
  530. let selectedGoodsList = that.activityForm.goods_list ? that.activityForm.goods_list : [];
  531. let idsArr = []
  532. selectedGoodsList.forEach(i => {
  533. idsArr.push(i.id)
  534. })
  535. parent.Fast.api.open("shopro/goods/goods/select?multiple=true&type=activity&ids=" + idsArr.join(','), "选择商品", {
  536. callback: function (data) {
  537. let resData = []
  538. let goodsList = []
  539. if (Array.isArray(data.data)) {
  540. resData = data.data
  541. } else {
  542. resData.push(data.data)
  543. }
  544. resData.forEach(e => {
  545. if (idsArr.includes(e.id)) {
  546. selectedGoodsList.forEach(i => {
  547. if (e.id == i.id) {
  548. goodsList.push(i)
  549. }
  550. })
  551. } else {
  552. goodsList.push(JSON.parse(JSON.stringify({
  553. actSkuPrice: "",
  554. dispatch_type_text: e.dispatch_type_text,
  555. id: e.id,
  556. image: e.image,
  557. opt: 0,
  558. status_text: e.status_text,
  559. title: e.title,
  560. type_text: e.type_text,
  561. })))
  562. }
  563. })
  564. that.activityForm.goods_list = goodsList;
  565. }
  566. });
  567. },
  568. goodsDelete(index) {
  569. this.activityForm.goods_list.splice(index, 1)
  570. },
  571. activitySku(id, index, actSkuPrice) {
  572. let that = this;
  573. let activity_id = Config.activity ? Config.activity.id : ''
  574. let activity_status = Config.activity ? Config.activity.status : ''
  575. let activity_type = Config.activity ? Config.activity.type : that.activityForm.type
  576. // activity_status actSkuPrice自用
  577. parent.Fast.api.open(`shopro/activity/activity/sku?activity_id=${activity_id}&id=${id}&type=${that.optType}&activitytime=${that.activityForm.dateTime.join(' - ')}&activity_type=${activity_type}&activity_status=${activity_status}&actSkuPrice=${actSkuPrice}`, "设置活动商品", {
  578. callback: function (data) {
  579. that.$set(that.activityForm.goods_list[index], "opt", 1)
  580. that.$set(that.activityForm.goods_list[index], "actSkuPrice", data)
  581. }
  582. });
  583. },
  584. discountsAdd() {
  585. this.activityForm.temp_discounts.push({ full: '', discount: '' })
  586. },
  587. discountsDelete(index) {
  588. this.activityForm.temp_discounts.splice(index, 1)
  589. },
  590. areaSelect() {
  591. let that = this;
  592. let parmas = {
  593. name: that.activityForm.temp_area_text,
  594. province_ids: that.activityForm.temp_province_except,
  595. city_ids: that.activityForm.temp_city_except,
  596. area_ids: that.activityForm.temp_area_except,
  597. }
  598. Fast.api.open('shopro/area/select?parmas=' + encodeURI(JSON.stringify(parmas)), '区域选择', {
  599. callback(data) {
  600. that.activityForm.temp_area_text = data.data.name.join(',');
  601. that.activityForm.temp_province_except = data.data.province.join(',')
  602. that.activityForm.temp_city_except = data.data.city.join(',')
  603. that.activityForm.temp_area_except = data.data.area.join(',')
  604. }
  605. })
  606. },
  607. changeGoodsType(val) {
  608. this.activityForm.goods_list = []
  609. if (val == 'all') {
  610. this.activityForm.goods_list = [{}]
  611. }
  612. this.activityForm.goods_ids = ''
  613. },
  614. changeFreeShippingType() {
  615. this.activityForm.temp_full_num = ''
  616. },
  617. submitForm(activityForm) {
  618. let that = this;
  619. let submitForm = JSON.parse(JSON.stringify(that.activityForm))
  620. that.$refs[activityForm].validate((valid) => {
  621. if (valid) {
  622. if (this.activityForm.type == 'full_reduce' || this.activityForm.type == 'full_discount') {
  623. let isSub = true
  624. this.activityForm.temp_discounts.forEach(d => {
  625. if (Number(d.full) <= 0 || Number(d.discount) <= 0) {
  626. isSub = false
  627. }
  628. if(this.activityForm.type == 'full_reduce' && submitForm.temp_type=='money'){
  629. if(Number(d.full) < Number(d.discount)){
  630. isSub = false
  631. }
  632. }
  633. if(this.activityForm.type == 'full_discount'){
  634. if(0> Number(d.discount) || Number(d.discount)>10){
  635. isSub = false
  636. }
  637. }
  638. })
  639. if (!isSub) {
  640. this.$message({
  641. message: '优惠条件填写有误、优惠金额不可大于消费金额或折扣不可小于0大于10',
  642. type: 'warning'
  643. });
  644. return false
  645. }
  646. }
  647. // 处理时间
  648. submitForm.starttime = submitForm.dateTime[0];
  649. submitForm.endtime = submitForm.dateTime[1];
  650. delete submitForm.dateTime
  651. // 处理goods_ids
  652. let goods_ids = []
  653. submitForm.goods_list.forEach(i => {
  654. if (i.id) {
  655. goods_ids.push(i.id)
  656. }
  657. })
  658. if (goods_ids.length > 0) {
  659. submitForm.goods_ids = goods_ids.join(',')
  660. } else {
  661. submitForm.goods_ids = ''
  662. submitForm.goods_list = []
  663. }
  664. // 处理rules
  665. for (key in submitForm.rules) {
  666. submitForm.rules[key] = submitForm['temp_' + key]
  667. delete submitForm['temp_' + key]
  668. }
  669. let reqUrl = that.optType == 'add' ? 'shopro/activity/activity/add' : `shopro/activity/activity/edit/ids/${Config.activity.id}`
  670. // return false
  671. Fast.api.ajax({
  672. url: reqUrl,
  673. loading: true,
  674. type: 'POST',
  675. data: JSON.parse(JSON.stringify(submitForm))
  676. }, function (ret, res) {
  677. if (res.code == 1) {
  678. Fast.api.close()
  679. }
  680. })
  681. } else {
  682. this.selectedFlag = false
  683. return false;
  684. }
  685. });
  686. },
  687. },
  688. })
  689. },
  690. api: {
  691. bindevent: function () {
  692. Form.api.bindevent($("form[role=form]"));
  693. }
  694. },
  695. select: function () {
  696. // 初始化表格参数配置
  697. Table.api.init({
  698. extend: {
  699. index_url: 'shopro/activity/activity/index?page_type=select&type=' + Backend.api.query('type'),
  700. }
  701. });
  702. var table = $("#table");
  703. // 初始化表格
  704. table.bootstrapTable({
  705. url: $.fn.bootstrapTable.defaults.extend.index_url,
  706. pk: 'id',
  707. sortName: 'id',
  708. columns: [
  709. [
  710. { checkbox: true },
  711. { field: 'id', title: __('Id') },
  712. { field: 'title', title: __('Title') },
  713. { field: 'goods_ids', title: __('Goods_ids') },
  714. { field: 'type', title: __('Type') },
  715. // { field: 'description', title: __('Description') },
  716. { field: 'starttime', title: __('Starttime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
  717. { field: 'endtime', title: __('Endtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
  718. { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
  719. { field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
  720. {
  721. field: 'operate', title: __('Operate'), events: {
  722. 'click .btn-chooseone': function (e, value, row, index) {
  723. var multiple = Backend.api.query('multiple');
  724. multiple = multiple == 'true' ? true : false;
  725. Fast.api.close({ data: row, multiple: multiple });
  726. },
  727. }, formatter: function () {
  728. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  729. }
  730. }
  731. ]
  732. ]
  733. });
  734. // 选中多个
  735. $(document).on("click", ".btn-choose-multi", function () {
  736. var couponsArr = new Array();
  737. $.each(table.bootstrapTable("getAllSelections"), function (i, j) {
  738. couponsArr.push(j.id);
  739. });
  740. var multiple = Backend.api.query('multiple');
  741. multiple = multiple == 'true' ? true : false;
  742. let row = {}
  743. row.ids = couponsArr.join(",")
  744. Fast.api.close({ data: row, multiple: multiple });
  745. });
  746. // 为表格绑定事件
  747. Table.api.bindevent(table);
  748. require(['upload'], function (Upload) {
  749. Upload.api.plupload($("#toolbar .plupload"), function () {
  750. $(".btn-refresh").trigger("click");
  751. });
  752. });
  753. },
  754. checkRedis: function () {
  755. if (!Config.hasRedis) {
  756. Layer.confirm('检测到系统未配置 Redis,添加的活动将不能得到有效控制,确定要继续吗?', {
  757. btn: ['确认', '取消']
  758. }, function () {
  759. Layer.closeAll();
  760. return true;
  761. }, function () {
  762. Layer.closeAll();
  763. if (window.parent) {
  764. window.parent.Layer.closeAll();
  765. }
  766. return false;
  767. });
  768. }
  769. }
  770. };
  771. return Controller;
  772. });