define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'clipboard'], function ($, undefined, Backend, Table, Form, Clipboard) { function goodsShowStatus(type) { if (type == '1') {//书币充值 $('.js_vip_group').addClass('hide'); $('.js_kandian_group').removeClass('hide'); } else if (type == '2') {//VIP充值 $('.js_vip_group').removeClass('hide'); $('.js_kandian_group').addClass('hide'); } } function ajaxReturn(id) { var trigger; $.ajax({ url: 'special/recharge/tpl/copy', data: {'tpl_id': id}, type: 'post', async: false, success: function (res) { if (res.code == 1) { var stxt = res.data.url; trigger = document.querySelector('#many_copy_dom'); $('#many_copy_dom').html(stxt); } else { Toastr.error(res.msg); } } }); return trigger; } var clipboard = new Clipboard('.btn-operate-copy', { target: function (trigger) { var id = $(trigger).parent().parent().find('td').eq(1).text(); return ajaxReturn(id); } }); clipboard.on('success',function (data) { Toastr.success('复制成功'); }).on('error',function (data) { Toastr.error('复制失败'); }); $(document).on('click', '.js_choose_goods', function () { Fast.api.open('goods/select?goods_category=activity&business_line=' + Config.business_line, '选择商品', { callback: function (data) { var goodsItem = data[0]; $('.js_selected_goods_show_type_text').text(goodsItem.show_type_text); $('.js_selected_goods_type_text').text(goodsItem.type_text); $('.js_selected_goods_money').text(goodsItem.money); $('.js_selected_goods_kandian').text(goodsItem.kandian); $('.js_selected_goods_free_kandian').text(goodsItem.free_kandian); $('.js_selected_goods_icon').text(goodsItem.icon); $('.js_selected_goods_id').val(goodsItem.id); $('.js_selected_goods_free_day').text(goodsItem.free_day); $('.js_selected_goods_day').text(goodsItem.day); goodsShowStatus(goodsItem.type); } }); }); var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'special/recharge/tpl/index', add_url: 'special/recharge/tpl/add', edit_url: 'special/recharge/tpl/edit', del_url: 'special/recharge/tpl/del', multi_url: 'special/recharge/tpl/multi', table: 'special_recharge_tpl', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, pk: 'id', sortName: 'id', columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'title', title: __('标题'), operate: 'LIKE %...%'}, {field: 'goods_id', title: __('Goods_id')}, {field: 'type', title: __('商品类型'), formatter: function (value, row) { return value == 1 ? "书币" : "VIP"; }, operate:false}, {field: 'money', title: __('金额'), operate:false}, {field: 'kandian', title: __('书币'), operate:false}, {field: 'free_kandian', title: __('免费书币'), operate:false}, {field: 'day', title: __('VIP天数'), operate:false}, {field: 'channel_id', title: __('Channel_id')}, {field: 'cost', title: __('Cost'), operate:'BETWEEN'}, {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}}, {field: 'status_text', title: __('Status'), operate:false}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:Controller.api.formatter.showChBtn()} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { $("#add-form").data("validator-options", { ignore: ':hidden', beforeSubmit: function (form) { if ($("#c-goods_id").val() == '' || $("#c-goods_id").val() <= 0) { Toastr.error("请选择商品"); return false; } if ($("#c-channel_id").val() == '' || $("#c-channel_id").val() <= 0) { Toastr.error("请填写渠道ID"); $("#c-channel_id").focus(); return false; } if ($(".js_vip_group").hasClass("hide")) { //看点 if ($("#c-cost").val() == '' || $("#c-cost").val() <= 0) { Toastr.error("请填写原价"); $("#c-cost").focus(); return false; } } } }); Controller.api.bindevent(); }, edit: function () { goodsType = $('.js_selected_goods_type').val(); goodsShowStatus(goodsType); window.canSubmit = false; $("#edit-form").data("validator-options", { ignore: ':hidden', beforeSubmit: function (form) { console.log($(this)); if (window.canSubmit) { return true; } if ($("#c-goods_id").val() == '' || $("#c-goods_id").val() <= 0) { Toastr.error("请选择商品"); return false; } if ($("#c-channel_id").val() == '' || $("#c-channel_id").val() <= 0) { Toastr.error("请填写渠道ID"); $("#c-channel_id").focus(); return false; } if ($(".js_vip_group").hasClass("hide")) { //看点 if ($("#c-cost").val() == '' || $("#c-cost").val() <= 0) { Toastr.error("请填写原价"); $("#c-cost").focus(); return false; } } //弹出提示 layer.confirm('当前活动正在进行中,如果编辑可能会影响进行中的活动,是否编辑?', {title: "确定编辑"}, function (index) { layer.close(index); window.canSubmit = true; $("form").submit(); }, function (index) { layer.close(index); }); return false; } }); Controller.api.bindevent(); }, api: { bindevent: function () { Form.api.bindevent($("form[role=form]")); }, formatter: { showChBtn: function(){ return [ { name: 'copy_url', text: '复制链接', title: '复制链接', classname: 'btn btn-click btn-operate-copy', icon: 'fa fa-copy copy', } ]; }, } } }; return Controller; });