From 8c55ab2701c99cec16eff92a26fefdf77fcdd28f Mon Sep 17 00:00:00 2001
From: liujie <liujie>
Date: 星期一, 25 九月 2023 16:17:44 +0800
Subject: [PATCH] app接口修改

---
 cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js |  305 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 260 insertions(+), 45 deletions(-)

diff --git a/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js b/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js
index 76ed00a..467b12e 100644
--- a/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js
+++ b/cloud-server-management/src/main/webapp/static/modular/system/tCoupon/TCouponInfo.js
@@ -4,7 +4,8 @@
 var couponInfoDlg = {
     couponInfoData: {},
     goodsPicArray: [], //商品图片数组
-    goodsCover: '' //商品封面图
+    goodsCover: '', //商品封面图
+    storeIds: [],
 };
 
 /**
@@ -79,6 +80,27 @@
 function scopeOfApplication1() {
     $("#storeSelect").hide();
     $("#citySelect").hide();
+
+    //移除指定门店的数据:
+    // 找到 tbody 元素
+    var tbody = document.getElementById("coun");
+
+    // 移除所有子元素(即行)
+    while (tbody.firstChild) {
+        tbody.removeChild(tbody.firstChild);
+    }
+    couponInfoDlg.storeIds = [];
+
+    //移除指城市的数据:
+    num = 0;
+    var cityDemoDiv = document.getElementById("cityDemo");
+
+    cityDemoDiv.innerHTML = ""; // 将内容置为空字符串
+    var provinceSelect = document.getElementById("provinceData");
+    var cityDataSelect = document.getElementById("cityData");
+    provinceSelect.innerHTML = '<option value="">请选择</option>';
+    cityDataSelect.innerHTML = '<option value="">请选择</option>';
+    getProvince(null);
 }
 /**
  * 指定城市
@@ -86,6 +108,18 @@
 function scopeOfApplication2() {
     $("#storeSelect").hide();
     $("#citySelect").show();
+
+    //移除指定门店的数据:
+    // 找到 tbody 元素
+    var tbody = document.getElementById("coun");
+    // 移除所有子元素(即行)
+    while (tbody.firstChild) {
+        tbody.removeChild(tbody.firstChild);
+    }
+    couponInfoDlg.storeIds = [];
+
+
+
 }
 /**
  * 指定门店
@@ -93,6 +127,19 @@
 function scopeOfApplication3() {
     $("#storeSelect").show();
     $("#citySelect").hide();
+
+    //移除指城市的数据:
+    num = 0;
+    var cityDemoDiv = document.getElementById("cityDemo");
+
+    cityDemoDiv.innerHTML = ""; // 将内容置为空字符串
+    var provinceSelect = document.getElementById("provinceData");
+    var cityDataSelect = document.getElementById("cityData");
+    provinceSelect.innerHTML = '<option value="">请选择</option>';
+    cityDataSelect.innerHTML = '<option value="">请选择</option>';
+    getProvince(null);
+
+
 }
 
 /**
@@ -212,8 +259,9 @@
 }
 
 
-var num = 0;
+let num = 0;
 couponInfoDlg.addBranch = function () {
+    num = num+1;
     var a= "";
     a = "<div style=\'margin-left: 25%\' class=\"col-sm-9 control-label\">\n" +
         "                            <select class=\"col-sm-1\"  id=\'provinceData"+num+"\' style=\"margin-top: 1%;width: 25%\" onchange=\'changeCity("+num+")\'>\n" +
@@ -228,9 +276,41 @@
         "                        </div>";
     $("#cityDemo").append($(a));
     getProvince(num);
-    num=num+1
 }
 
+
+couponInfoDlg.selecUserOpt = function (arrays){
+    //获取所有的值
+    var subArr= this.storeIds;
+    $(".timeClass").each(function () {
+        subArr.push($(this).find("input[name*='id']").val());
+    });
+    var str = '';
+    for(var i in arrays){
+        var b = true;
+        for(var j in subArr){
+            if(arrays[i].id === Number(subArr[j])){
+                b = false;
+                break
+            }
+        }
+        if(b){
+            str += '<tr class="timeClass">' +
+                '<td><input type="hidden" id="id" name="id" value="'+arrays[i].id+'"><input type="hidden" id="provinceCity" name="provinceCity" value="'+arrays[i].provinceCity+'">' + arrays[i].provinceCity + '</td>' +
+                '<td><input type="hidden" id="accountName" name="accountName" value="'+arrays[i].accountName+'">' + arrays[i].accountName + '</td>' +
+                '<td><input type="hidden" id="name" name="name" value="'+arrays[i].name+'">' + arrays[i].name + '</td><td><button onclick="deleteSub(this)">移除</button></td></tr>';
+            this.storeIds.push(arrays[i].id);
+        }
+    }
+    $("#coun").append(str);
+}
+
+function deleteSub(e) {
+    var row = $(e).closest('tr');
+    var value = row.find('#id').val();
+    couponInfoDlg.storeIds.splice(couponInfoDlg.storeIds.indexOf(parseInt(value)), 1)
+    $(e).parent().parent().remove();
+}
 
 
 couponInfoDlg.delete = function (o) {
@@ -242,68 +322,130 @@
  */
 couponInfoDlg.addSubmit = function () {
 
-    var resultData = {};
-    // 用户权限
-    var userType = $('#userType').val();
+    var cityIds = [];
     // 优惠券名称
-    var couponName = $('#name').val;
+    var couponName = $('#name').val();
+    if (couponName === undefined || couponName === '' || couponName === null){
+        return Feng.error('优惠券名称不能为空');
+    }
     // 优惠券类型
-    var prescription = $('#prescription').val();
+    let prescription = $(":radio[name='prescription']:checked").val();
+    // 满xx金额
+    let conditionalAmount = $('#conditionalAmount').val();
+    // 减xx金额
+    let deductionAmount = $('#deductionAmount').val();
+    // 可抵扣xx金额
+    let voucherAmount = $('#voucherAmount').val();
+    // 体验券名称
+    let experienceName = $('#experienceName').val();
+    if (prescription === '1'){
+        if (conditionalAmount === undefined || conditionalAmount === '' || conditionalAmount === null){
+            return Feng.error('条件金额不能为空');
+        }
+        if (deductionAmount === undefined || deductionAmount === '' || deductionAmount === null){
+            return Feng.error('减扣金额不能为空');
+        }
+    }
+    if (prescription === '2'){
+        if (voucherAmount === undefined || voucherAmount === '' || voucherAmount === null){
+            return Feng.error('抵扣金额不能为空');
+        }
+    }
+    if (prescription === '3'){
+        if (experienceName === undefined || experienceName === '' || experienceName === null){
+            return Feng.error('体验券名称不能为空');
+        }
+    }
+
+
     // 说明
     var illustrate = $('#illustrate').val();
+    if (illustrate === undefined || illustrate === '' || illustrate === null){
+        return Feng.error('优惠券说明不能为空');
+    }
     // 发放方式
-    var distributionMethod = $('#distributionMethod').val();
+    let distributionMethod = $(":radio[name='distributionMethod']:checked").val();
+    if (distributionMethod === undefined || distributionMethod === '' || distributionMethod === null){
+        return Feng.error('发放方式不能为空');
+    }
     // 所需积分
     var requiredPoints = $('#requiredPoints').val();
+    // 所需现金
+    var requiredCash = $('#requiredCash').val();
     // 用户人群
     let userGroup = $(':radio[name="userGroup"]:checked').val();
 
     // 发放数量
     var quantityIssued = $('#quantityIssued').val();
+    if (quantityIssued === undefined || quantityIssued === '' || quantityIssued === null){
+        return Feng.error('发放数量不能为空');
+    }
     // 限领数量
     var pickUpQuantity = $('#pickUpQuantity').val();
+    if (pickUpQuantity === undefined || pickUpQuantity === '' || pickUpQuantity === null){
+        return Feng.error('限领数量不能为空');
+    }
     // 有效期
     var periodOfValidity = $('#periodOfValidity').val();
-
-    if (userType === '1'){
-        // 平台管理员
-        // 兑换方式:积分+现金
-        let exchangeMethod = $(':radio[name="exchangeMethod"]:checked').val();
-
-        if (exchangeMethod === 1){
-
-        }
-        if (exchangeMethod === 2){
-            var requiredCash = $('#requiredCash').val;
-
-        }
-        if (exchangeMethod === 3){
-
-        }
-        var goodImg = this.goodsCover;
-        var goodImgs = this.goodsPicArray;
-        // 适用范围 全国+指定城市+指定门店
-        let company = $(':radio[name="company"]:checked').val()
-        if (company === 2){
-
-        }
-        if (company === 3){
-
-        }
-
-        commitAJAX(resultData);
+    if (periodOfValidity === undefined || periodOfValidity === '' || periodOfValidity === null){
+        return Feng.error('有效期不能为空');
     }
-    if (userType === '2'){
-        // 城市管理员
-
-
+    // 兑换方式
+    let exchangeMethod = $(':radio[name="exchangeMethod"]:checked').val();
+    if (exchangeMethod === '' || exchangeMethod === undefined || exchangeMethod === null){
+        return Feng.error('兑换方式不能为空');
+    }
+    if (exchangeMethod === '1'){
+        if (requiredPoints === undefined || requiredPoints === '' || requiredPoints === null){
+            return Feng.error('所需积分不能为空');
+        }
+    }
+    if (exchangeMethod === '2'){
+        if (requiredPoints === undefined || requiredPoints === '' || requiredPoints === null){
+            return Feng.error('所需积分不能为空');
+        }
+        if (requiredCash === undefined || requiredCash === '' || requiredCash === null){
+            return Feng.error('所需现金不能为空');
+        }
+    }
+    if (exchangeMethod === '3'){
+        if (requiredCash === undefined || requiredCash === '' || requiredCash === null){
+            return Feng.error('所需现金不能为空');
+        }
     }
 
+    let company = $(':radio[name="company"]:checked').val();
+    var cts = "";
+    if (company === '2'){
+        var myselect=document.getElementById('cityData');
+        var seCity = myselect.options[myselect.selectedIndex].value;
+        if (seCity === null || seCity === undefined || seCity === ''){
+            return Feng.error('请选中一个省市');
+        }
+        cityIds.push(seCity);
+        if (num > 0){
+            for (let i = 1; i <= num; i++) {
+                var insSelect=document.getElementById('cityData'+i);
+                var inData = insSelect.options[insSelect.selectedIndex].value;
+                if (inData !== undefined || inData !== null ||  inData !== ''){
+                    cityIds.push(inData);
+                }
+            }
+            cts = cityIds.join(',');
+        }
+    }
 
-}
+    const commaSeparatedString = this.goodsPicArray.join(',');
 
-function commitAJAX(obj){
-
+    var stores = "";
+    if (company === '3'){
+        console.log('3---this.storeIds',this.storeIds);
+        if (couponInfoDlg.storeIds.length === 0 ){
+            return Feng.error('请至少选择一个门店');
+        }
+        stores = this.storeIds.join(',');
+        console.log('stores--===--',stores)
+    }
     //提交信息
     var ajax = new $ax(Feng.ctxPath + "/tCouponManage/commitData", function (data) {
         Feng.success("添加成功!");
@@ -312,8 +454,30 @@
     }, function (data) {
         Feng.error("添加失败!" + data.responseJSON.message + "!");
     });
-    ajax.set("dataResult", JSON.parse(obj));
+    ajax.set("userType",1);
+    ajax.set("cityManagerId",1);
+    ajax.set("couponName",couponName);
+    ajax.set("prescription",prescription);
+    ajax.set("condition",conditionalAmount);
+    ajax.set("subtraction",deductionAmount);
+    ajax.set("discount",voucherAmount);
+    ajax.set("experience",experienceName);
+    ajax.set("illustrate",illustrate);
+    ajax.set("distributionMethod",distributionMethod);
+    ajax.set("requiredPoints",requiredPoints);
+    ajax.set("requiredCash",requiredCash);
+    ajax.set("userGroup",userGroup);
+    ajax.set("quantityIssued",quantityIssued);
+    ajax.set("pickUpQuantity",pickUpQuantity);
+    ajax.set("periodOfValidity",periodOfValidity);
+    ajax.set("exchangeMethod",exchangeMethod);
+    ajax.set("goodImg",this.goodsCover);
+    ajax.set("goodImgs",commaSeparatedString);
+    ajax.set("company",company);
+    ajax.set("cityIds",cts);
+    ajax.set("storeIds",stores);
     ajax.start();
+
 }
 
 /**
@@ -347,6 +511,57 @@
 $(function () {
     getProvince(null);
     radio1();
+    var OBJradio = document.getElementsByName("prescription")
+    for (i = 0; i < OBJradio.length; i++) {//循环查找这个radio
+        if ($("#t1").val() == OBJradio[i].value) {//判断是否与radio的值相同
+            OBJradio[i].checked = true//修改选中状态
+        }
+    }
+
+    var OBJradio = document.getElementsByName("distributionMethod")
+    for (i = 0; i < OBJradio.length; i++) {//循环查找这个radio
+        if ($("#t2").val() == OBJradio[i].value) {//判断是否与radio的值相同
+            OBJradio[i].checked = true//修改选中状态
+        }
+    }
+    var OBJradio = document.getElementsByName("exchangeMethod")
+    for (i = 0; i < OBJradio.length; i++) {//循环查找这个radio
+        if ($("#t3").val() == OBJradio[i].value) {//判断是否与radio的值相同
+            OBJradio[i].checked = true//修改选中状态
+        }
+    }
+    var OBJradio = document.getElementsByName("userGroup")
+    for (i = 0; i < OBJradio.length; i++) {//循环查找这个radio
+        if ($("#t4").val() == OBJradio[i].value) {//判断是否与radio的值相同
+            OBJradio[i].checked = true//修改选中状态
+        }
+    }
+    var OBJradio = document.getElementsByName("company")
+    for (i = 0; i < OBJradio.length; i++) {//循环查找这个radio
+        if ($("#t5").val() == OBJradio[i].value) {//判断是否与radio的值相同
+            OBJradio[i].checked = true//修改选中状态
+        }
+    }
+    if($("#t5").val() ==2){
+        $("#citySelect").show();
+    }
+    if($("#t5").val() ==3){
+        $("#storeSelect").show();
+    }
+    if($("#t1").val()==1){
+        console.log(1)
+        $("#conditionalAmount").val($("#one").val())
+        $("#deductionAmount").val($("#two").val())
+    }
+    if($("#t1").val()==2){
+        radio2()
+        $("#voucherAmount").val($("#one").val())
+    }
+    if($("#t1").val()==3){
+        console.log(3)
+        $("#experienceName").val($("#three").val())
+    }
+
     var userType = $('#userType').val();
     if (userType === '1'){
         // 兑换方式

--
Gitblit v1.7.1