|
- //author:func
- //date:20161024
- //促销规则
-
- var current_page = "1";
- var page_size = "15";
- var line_id = '';
- var line_type = '';
- var ticket_id = '';
-
- var trHTML = '';
-
- window.onload = function() {
- line_type = getPar('line_type');
- ticket_id = getPar('ticket_id');
- line_id = getPar('line_id');
- trHTML = $('#tbody').html();
- httpTopInfo();
- httpFirstData();
- }
- //头部信息
- function httpTopInfo() {
- var param = {
- tp: "promotionRule_getPromotionBase",
- line_id: line_id,
- ticket_id: ticket_id
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- var base = res_data['base'];
- $('#seat_type').html(base['seat_type_name']);
- $('#crow').html(base['human_type_name']);
- $('#cus_price').html(base['cus_price']);
- $('#prod_price').html(base['prod_price']);
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
- //第一次加载列表
- function httpFirstData() {
- current_page = 1;
- var param = {
- tp: "promotionRule_getPromotionRuleList",
- page_size: page_size,
- current_page: current_page,
- line_id: line_id,
- ticket_id: ticket_id
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
-
- setTableHTML(res_data);
- $('#tbody').show();
- //处理分页
- if(res_data['page']['total_count'] <= 0) {
- $('.pageDiv').hide();
- } else {
- $(".pageDiv").createPage({
- pageCount: res_data['page']['total_page'], //总页数
- current: current_page, //当前页
- turndown: 'true', //是否显示跳转框,显示为true,不现实为false,一定记得加上引号...
- backFn: function(p) {
- current_page = p;
- httpData();
- }
- });
- $('.pageDiv').show();
- }
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
-
- }
-
- //请求
- function httpData() {
- var param = {
- tp: "promotionRule_getPromotionRuleList",
- page_size: page_size,
- current_page: current_page,
- line_id: line_id,
- ticket_id: ticket_id
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- setTableHTML(res_data);
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
- //设置表格HTML
- function setTableHTML(res_data) {
- var rule_list = res_data['rule_list'];
- var HTML = '';
- for(var i = 0, m = rule_list.length; i < m; i++) {
- var dict = rule_list[i];
- var tempHTML = trHTML;
- var objstr=JSON.stringify(dict);
- objstr=objstr.replace(/"/g,'"');
- tempHTML = tempHTML.replace('[data-param]', objstr);
- tempHTML = tempHTML.replace('[promotion-id]', dict['promotion_id']);
- tempHTML = tempHTML.replace('[促销类型]', dict['discount_type_name']);
- tempHTML = tempHTML.replace('[促销内容]', "立减 " + dict['off_value'] + " 元");
- tempHTML = tempHTML.replace('[促销时间]', dict['discount_day_type_name']);
- tempHTML = tempHTML.replace('[促销渠道]', dict['supplier_name']);
- var imgstr = '';
- if(dict['is_onsale'] == "1") {
- imgstr = '<img data-is-onsale="' + dict['is_onsale'] + '" onclick="onOffLine(this)" style="width: 33px;height: 30px;cursor: pointer;" src="images/on.png" />';
- } else {
- imgstr = '<img data-is-onsale="' + dict['is_onsale'] + '" onclick="onOffLine(this)" style="width: 33px;height: 30px;cursor: pointer;" src="images/off.png" />'
- }
- tempHTML = tempHTML.replace('[上线]', imgstr);
- HTML += tempHTML;
- }
- $('#tbody').html(HTML);
- }
- //上下线
- function onOffLine(obj) {
- var _promotion_id = $(obj).closest('tr').attr('data-promotion-id');
- var _status = $(obj).attr('data-is-onsale');
- _status = _status == 1 ? "stop" : "start";
- var param = {
- tp: "promotionRule_ruleStatus",
- status: _status,
- promotion_id: _promotion_id
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- var imgstr = '';
- var is_onsale = '';
- if(_status == 'stop') {
- imgstr = 'images/off.png';
- is_onsale = 0;
- } else {
- imgstr = 'images/on.png';
- is_onsale = 1;
- }
- $(obj).attr('src', imgstr);
- $(obj).attr('data-is-onsale', is_onsale);
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
-
- //删除规则
- function delRule(obj) {
- var _promotion_id = $(obj).closest('tr').attr('data-promotion-id');
- var param = {
- tp: "promotionRule_delPromotion",
- promotion_id: _promotion_id
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- httpData();
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
- //弹出添加促销层
- function addRegular(obj) {
- var param = {
- tp: "promotionRule_getRuleBaseInfo",
- line_id: line_id,
- ticket_id: ticket_id,
- line_type: line_type
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- setAddDivHTML(res_data);
- $(".add_promotion_type").show();
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
-
- }
-
- //加载添加DIV 的数据
- function setAddDivHTML(res_data) {
- //促销类型
- var discount_type = res_data['discount_type'];
- var promotion_typeHTML = '<option value="">请选择</option>';
- for(var i = 0, m = discount_type.length; i < m; i++) {
- var dict = discount_type[i];
- var tempHTML = '<option value="' + dict['id'] + '">' + dict['type_name'] + '</option>';
- promotion_typeHTML += tempHTML;
- }
- $('select[name="promotion_type"]').html(promotion_typeHTML);
- //促销时间
- var discount_time = res_data['discount_time'];
- var promotion_timeHTML = '';
- for(var i = 0, m = discount_time.length; i < m; i++) {
- var dict = discount_time[i];
- var tempHTML = '<label style="margin-right: 20px;">' +
- '<input name="promotion_time" type="radio" checked="checked" value="' + dict['id'] + '" />' +
- '<span>' + dict['type_name'] + '</span>' +
- '</label>';
- promotion_timeHTML += tempHTML;
- }
- $('#promotion_time').html(promotion_timeHTML);
- //促销渠道
- var promotion_channel = res_data['channel_list'];
- var promotion_channelHTML = '<label style="margin-right: 20px;">' +
- '<input type="checkbox" onclick="chooseAllChannel(this)" name="channelAll" value="" />' +
- '<span style="margin-right: 15px;">全选</span>' +
- '</label>';
- for(var i = 0, m = promotion_channel.length; i < m; i++) {
- var dict = promotion_channel[i];
- var tempHTML = '<label style="margin-right: 20px;">' +
- '<input type="checkbox" name="channel" value="' + dict['channel_id'] + '" />' +
- '<span style="margin-right: 15px;">' + dict['supplier_name'] + '</span>' +
- '</label>';
- promotion_channelHTML += tempHTML;
- }
- $('#promotion_channel').html(promotion_channelHTML);
- }
- //添加保存
- function saveAdd(obj) {
- var _discount_type = $('select[name="promotion_type"]').val(); //促销类型
- if(""==_discount_type.trim()){
- ZZAlertInfo('请选择促销类型');
- return;
- }
- var _discount_price = $('#promotion_price').val(); // 促销内容 立减元
- if(""==_discount_price.trim()){
- ZZAlertInfo('请填写促销内容');
- return;
- }
- var _discount_time = $('input[name="promotion_time"]:checked').val(); //促销时间
- if(""==_discount_time.trim()){
- ZZAlertInfo('请选择促销时间');
- return;
- }
- var _discount_channel = '',
-
- _channel_arr = [];
- $('input[name="channel"]').each(function(index, domEle) {
- if(domEle.checked) {
- _channel_arr.push($(this).val());
- }
- })
- _discount_channel = _channel_arr.join(',');
- if(""==_discount_channel.trim()){
- ZZAlertInfo('请选择促销渠道');
- return;
- }
- var param = {
- tp: "promotionRule_addPromotionRule",
- line_id: line_id,
- ticket_id: ticket_id,
- discount_type: _discount_type,
- off_value: _discount_price,
- discount_day_type: _discount_time,
- channel_id: _discount_channel
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info'])
- } else {
- $('.add_promotion_type').hide();
- httpData();
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
- //修改规则
- var _datajson=null;
- function updateRule(obj){
- var datajson=$(obj).closest('tr').attr('data-param');
- datajson=JSON.parse(datajson);
- _datajson=datajson;
- var param = {
- tp: "promotionRule_getRuleBaseInfo",
- line_id: line_id,
- ticket_id: ticket_id,
- line_type: line_type
- }
- ZZLog(base_api + "lineManager/index.php" + JSON.stringify(param));
- $.ajax({
- type: "post",
- url: base_api + "lineManager/index.php",
- data: param,
- dataType: "json",
- success: function(res_data) {
- ZZLog(res_data);
- if(res_data['code'] != "0") {
- ZZAlertInfo(res_data['info']);
- } else {
- setUpdateDiv(res_data);
- $('.update_promotion_type').show();
- }
- },
- error: function(e) {
- ZZLog(e);
- }
- });
- }
-
- function setUpdateDiv(res_data){
- var _channel_name=_datajson['supplier_name'];
- $('#update_promotion_channel').children().find('span').text(_channel_name);
- $('.update_type').html(_datajson['discount_type_name']);
- $('#update_promotion_price').val(_datajson['off_value']);
- //促销时间
- var discount_time = res_data['discount_time'];
- var promotion_timeHTML = '';
- for(var i = 0, m = discount_time.length; i < m; i++) {
- var dict = discount_time[i];
- var cstr='';
- if(dict['id']==_datajson['discount_day_type']){
- cstr='<input name="update_promotion_time" type="radio" checked="checked" value="' + dict['id'] + '" />';
- }else{
- cstr='<input name="update_promotion_time" type="radio" value="' + dict['id'] + '" />';
- }
- var tempHTML = '<label style="margin-right: 20px;">' +
- cstr +
- '<span>' + dict['type_name'] + '</span>' +
- '</label>';
- promotion_timeHTML += tempHTML;
- }
- $('#update_promotion_time').html(promotion_timeHTML);
- }
- //保存修改
- function saveUpdate(obj){
- var _off_value=$('#update_promotion_price').val();
- var _discount_time = $('input[name="update_promotion_time"]:checked').val(); //促销时间
- var _promotion_id=_datajson['promotion_id']
- if(""==_promotion_id.trim()){
- ZZAlertInfo('缺少唯一id');
- return;
- }
- if(""==_off_value.trim()){
- ZZAlertInfo('请输入促销内容');
- $('#update_promotion_price').focus();
- return;
- }
- if(""==_discount_time.trim()){
- ZZAlertInfo('请选择促销时间');
- return;
- }
- var param={
- tp:"promotionRule_updatePromotion",
- promotion_id:_promotion_id,
- off_value:_off_value,
- discount_day_type:_discount_time
- }
- ZZLog(base_api+"lineManager/index.php"+JSON.stringify(param));
- $.ajax({
- type:"post",
- url:base_api+"lineManager/index.php",
- data:param,
- dataType:"json",
- success:function(res_data){
- ZZLog(res_data);
- if(res_data['code']!="0"){
- ZZAlertInfo(res_data['info']);
- }else{
-
- }
- },error:function(e){
- ZZLog(e);
- }
- });
- }
- //全选
- function chooseAllChannel(obj) {
- $(obj).closest('#promotion_channel').children().find('input[name="channel"]').attr('checked', obj.checked);
- $(obj).closest('#promotion_channel').children().find('input[name="channel"]').prop('checked', obj.checked);
- }
- //取消添加
- function cannelAdd(obj) {
- $(".add_promotion_type").hide();
- }
- //取消修改
- function cannelAmend(obj) {
- $(".add_promotion_type").hide();
- }
- //取消添加
- function cannelUpdate(obj) {
- $(".update_promotion_type").hide();
- }
- //取消修改
- function cannelUpdate(obj) {
- $(".update_promotion_type").hide();
- }
|