| | |
| | | <!--[if lt IE 9]> |
| | | <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script> |
| | | <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script> |
| | | <script src="js/http.js"></script> |
| | | |
| | | <![endif]--> |
| | | |
| | | <style> |
| | |
| | | |
| | | </div> |
| | | </div> |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal" |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal hidden" |
| | | id="saveActivityInfo" lay-submit="">保存 |
| | | </button> |
| | | |
| | |
| | | </div> |
| | | </div> |
| | | </div> |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal" id="saveAwardInfo" lay-submit="">保存 |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal hidden" id="saveAwardInfo" lay-submit="">保存 |
| | | </button> |
| | | |
| | | |
| | |
| | | autocomplete="off" class="layui-textarea" maxlength="256"></textarea></div> |
| | | </div> |
| | | |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal" id="saveJoinInfo" |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal hidden" id="saveJoinInfo" |
| | | lay-filter="save-activity" lay-submit="">保存 |
| | | </button> |
| | | </form> |
| | |
| | | </div> |
| | | </div> |
| | | |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal" id="saveOpenInfo" |
| | | lay-filter="save-activity" lay-submit="">保存 |
| | | <button class="layui-btn layui-btn-radius layui-btn-normal hidden" id="saveOpenInfo" lay-submit="">保存 |
| | | </button> |
| | | </form> |
| | | </div> |
| | |
| | | |
| | | <button class="layui-btn layui-btn-warm layui-btn-lg" v-on:click="submit">立即提交</button> |
| | | </div> |
| | | |
| | | |
| | | </div> |
| | | |
| | | <script src="js/lodash.js"></script> |
| | | <script src="js/common.js"></script> |
| | | |
| | | <script> |
| | | //验证管理器 |
| | | var validManager = { |
| | | //验证抽奖信息 |
| | | verifyActivityInfo() { |
| | | const field = common.layuiForm.val('form-activity-info'); |
| | | if (!$("#poster").attr("src")) { |
| | | common.notify.error("请选择封面图片"); |
| | | return false; |
| | | } |
| | | |
| | | //判断条件 |
| | | if (field.showBanner == 1 && $(".banner").find("img").length == 0) { |
| | | common.notify.error("请选择banner图片"); |
| | | return false; |
| | | } |
| | | |
| | | if (field.showBanner == 1 && $(".banner").find("img").length > 3) { |
| | | common.notify.error("banner图最多3张"); |
| | | return false; |
| | | } |
| | | return true; |
| | | }, |
| | | //验证奖品信息 |
| | | verifyAwardInfo() { |
| | | console.log("verifyAwardInfo"); |
| | | if (app.tempAwardsList == null || app.tempAwardsList.length == 0) { |
| | | common.notify.error("请添加奖项"); |
| | | return false; |
| | | } |
| | | var hasAward = false; |
| | | for (var i = 0; i < app.tempAwardsList.length; i++) { |
| | | if (app.tempAwardsList[i].data && app.tempAwardsList[i].data.type) { |
| | | hasAward = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!hasAward) { |
| | | common.notify.error("请选择奖项类型"); |
| | | return false; |
| | | } |
| | | |
| | | const field = common.layuiForm.val('form-award-info'); |
| | | |
| | | return true; |
| | | }, |
| | | //验证参与信息 |
| | | verifyJoinInfo() { |
| | | const field = common.layuiForm.val('form-join-info'); |
| | | console.log(field); |
| | | if (!app.joinInfo.adInfo.data) { |
| | | common.notify.error("请选择参与条件-跳转链路"); |
| | | return false; |
| | | } |
| | | |
| | | |
| | | return true; |
| | | }, |
| | | //验证开奖条件 |
| | | verifyOpenInfo() { |
| | | const field = common.layuiForm.val('form-open-info'); |
| | | console.log(field); |
| | | if (parseInt(field.minPersonCount) < 1000 || parseInt(field.minPersonCount) > 10000) { |
| | | common.notify.error("至少参与人数的范围为:1000-10000"); |
| | | return false; |
| | | } |
| | | |
| | | if (parseInt(field.day) < 1 || parseInt(field.day) > 7) { |
| | | common.notify.error("活动有效期的范围为:1-7"); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | }, |
| | | verify(es) { |
| | | |
| | | for (var i = 0; i < es.length; i++) { |
| | | if (!es[i]()) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | }, |
| | | verifyAll() { |
| | | return this.verify([this.verifyActivityInfo, this.verifyAwardInfo, this.verifyJoinInfo, this.verifyOpenInfo]); |
| | | } |
| | | }; |
| | | |
| | | var formManager = { |
| | | |
| | | //保存到临时变量 |
| | | saveActivityInfoToTemp() { |
| | | app.temp.activity = app.activity; |
| | | }, |
| | | saveAwardInfoToTemp() { |
| | | app.temp.awardInfo = app.tempAwardsList; |
| | | }, |
| | | saveJoinInfoToTemp() { |
| | | //赋值 |
| | | const field = common.layuiForm.val('form-join-info'); |
| | | var joinInfo = app.joinInfo; |
| | | joinInfo.must = field.must; |
| | | joinInfo.desc = field.desc; |
| | | app.temp.joinInfo = joinInfo; |
| | | }, |
| | | saveOpenInfoToTemp() { |
| | | const field = common.layuiForm.val('form-open-info'); |
| | | var openInfo = app.openInfo; |
| | | for (key in field) { |
| | | openInfo[key] = field[key]; |
| | | } |
| | | app.temp.openInfo = openInfo; |
| | | }, |
| | | saveToTemp() { |
| | | this.saveActivityInfoToTemp(); |
| | | this.saveAwardInfoToTemp(); |
| | | this.saveJoinInfoToTemp(); |
| | | this.saveOpenInfoToTemp(); |
| | | <script>; |
| | | //验证管理器 |
| | | var validManager = { |
| | | //验证抽奖信息 |
| | | verifyActivityInfo() { |
| | | console.log("验证抽奖信息"); |
| | | const field = common.layuiForm.val('form-activity-info'); |
| | | if (!$("#poster").attr("src")) { |
| | | common.notify.error("请选择封面图片"); |
| | | return false; |
| | | } |
| | | |
| | | }; |
| | | //判断条件 |
| | | if (field.showBanner == 1 && $(".banner").find("img").length == 0) { |
| | | common.notify.error("请选择banner图片"); |
| | | return false; |
| | | } |
| | | |
| | | if (field.showBanner == 1 && $(".banner").find("img").length > 3) { |
| | | common.notify.error("banner图最多3张"); |
| | | return false; |
| | | } |
| | | return true; |
| | | }, |
| | | //验证奖品信息 |
| | | verifyAwardInfo() { |
| | | console.log("验证奖品信息"); |
| | | if (app.tempAwardsList == null || app.tempAwardsList.length == 0) { |
| | | common.notify.error("请添加奖项"); |
| | | return false; |
| | | } |
| | | var hasAward = false; |
| | | for (var i = 0; i < app.tempAwardsList.length; i++) { |
| | | if (app.tempAwardsList[i].data && app.tempAwardsList[i].data.type) { |
| | | hasAward = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!hasAward) { |
| | | common.notify.error("请选择奖项类型"); |
| | | return false; |
| | | } |
| | | |
| | | const field = common.layuiForm.val('form-award-info'); |
| | | |
| | | return true; |
| | | }, |
| | | //验证参与信息 |
| | | verifyJoinInfo() { |
| | | console.log("验证参与条件"); |
| | | const field = common.layuiForm.val('form-join-info'); |
| | | console.log(field); |
| | | if (!app.joinInfo.adInfo.data) { |
| | | common.notify.error("请选择参与条件-跳转链路"); |
| | | return false; |
| | | } |
| | | |
| | | |
| | | return true; |
| | | }, |
| | | //验证开奖条件 |
| | | verifyOpenInfo() { |
| | | console.log("验证开奖条件"); |
| | | const field = common.layuiForm.val('form-open-info'); |
| | | console.log(field); |
| | | alert(parseInt(field.minPersonCount)); |
| | | alert(parseInt(field.day)); |
| | | |
| | | if (!parseInt(field.minPersonCount)) { |
| | | common.notify.error("请填写正确的参与人数"); |
| | | return false; |
| | | } |
| | | |
| | | if (!parseInt(field.day)) { |
| | | common.notify.error("请填写正确的天数"); |
| | | return false; |
| | | } |
| | | |
| | | if (parseInt(field.minPersonCount) < 1000 || parseInt(field.minPersonCount) > 10000) { |
| | | common.notify.error("至少参与人数的范围为:1000-10000"); |
| | | return false; |
| | | } |
| | | |
| | | if (parseInt(field.day) < 1 || parseInt(field.day) > 7) { |
| | | common.notify.error("活动有效期的范围为:1-7"); |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | }, |
| | | verify(es) { |
| | | |
| | | for (var i = 0; i < es.length; i++) { |
| | | if (!es[i]()) { |
| | | return false; |
| | | } |
| | | } |
| | | return true; |
| | | }, |
| | | verifyAll() { |
| | | return this.verify([this.verifyActivityInfo, this.verifyAwardInfo, this.verifyJoinInfo, this.verifyOpenInfo]); |
| | | } |
| | | }; |
| | | |
| | | var formManager = { |
| | | |
| | | //保存到临时变量 |
| | | saveActivityInfoToTemp() { |
| | | app.temp.activity = app.activity; |
| | | }, |
| | | saveAwardInfoToTemp() { |
| | | app.temp.awardInfo = app.tempAwardsList; |
| | | }, |
| | | saveJoinInfoToTemp() { |
| | | //赋值 |
| | | const field = common.layuiForm.val('form-join-info'); |
| | | var joinInfo = app.joinInfo; |
| | | joinInfo.must = field.must; |
| | | joinInfo.desc = field.desc; |
| | | app.temp.joinInfo = joinInfo; |
| | | }, |
| | | saveOpenInfoToTemp() { |
| | | const field = common.layuiForm.val('form-open-info'); |
| | | var openInfo = app.openInfo; |
| | | for (key in field) { |
| | | openInfo[key] = field[key]; |
| | | } |
| | | app.temp.openInfo = openInfo; |
| | | }, |
| | | saveToTemp() { |
| | | this.saveActivityInfoToTemp(); |
| | | this.saveAwardInfoToTemp(); |
| | | this.saveJoinInfoToTemp(); |
| | | this.saveOpenInfoToTemp(); |
| | | } |
| | | }; |
| | | |
| | | </script> |
| | | |
| | |
| | | //文件上传初始化 |
| | | var uploadPoster; |
| | | var uploadBanner; |
| | | var posterFileList; |
| | | var bannerFileList; |
| | | common.initLayui(function () { |
| | | //layui相关初始化成功 |
| | | app.initData(); |
| | | |
| | | uploadPoster = common.initUploadImagePlugin({ |
| | | |
| | | const uploadPosterParams = { |
| | | elem: "#choicePoster", |
| | | showElem: "#poster", |
| | | uploadUrl: "/admin/upload/image?from=activity", |
| | | dir: 'poster', |
| | | field: "image", |
| | | choose(obj) { |
| | | var files = posterFileList = obj.pushFile(); |
| | | obj.preview(function (index, file, result) { |
| | | $("#poster").attr("src", result); |
| | | }); |
| | | }, |
| | | uploadSuccess: function (res) { |
| | | app.posterUploadSuccess(res.data); |
| | | //重置文件传输 |
| | | for (key in posterFileList) { |
| | | delete posterFileList[key]; |
| | | } |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | |
| | | uploadPoster = common.initUploadImagePlugin(uploadPosterParams); |
| | | |
| | | var bannerUrlList = new Array(); |
| | | |
| | | uploadBanner = common.initUploadImagePlugin({ |
| | | var uploadBannerParams = { |
| | | elem: "#choiceBanner", |
| | | uploadUrl: "/admin/upload/image?from=activity", |
| | | dir: 'banner', |
| | |
| | | count++; |
| | | } |
| | | bannerUrlList.push(res.data); |
| | | }, |
| | | allDone: function (res) { |
| | | //文件上传完毕 |
| | | if (bannerUrlList.length == count) { |
| | | app.bannerUploadSuccess(bannerUrlList); |
| | | app.bannerUploadSuccess(bannerUrlList); |
| | | for (key in bannerFileList) { |
| | | delete bannerFileList[key]; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | uploadBanner = common.initUploadImagePlugin(uploadBannerParams); |
| | | console.log(uploadBanner); |
| | | |
| | | }); |
| | | |
| | |
| | | data: { |
| | | activity: {}, |
| | | tempAwardsList: [], |
| | | openInfo: {}, |
| | | joinInfo: {adInfo: {}}, |
| | | openInfo: { |
| | | }, |
| | | joinInfo: { |
| | | adInfo: {}}, |
| | | temp: {//临时数据,用于提交到服务端 |
| | | |
| | | }, |
| | |
| | | this.addAward(); |
| | | }, |
| | | methods: { |
| | | //设置数据 |
| | | setTempData(temp) { |
| | | //活动信息赋值(深拷贝) |
| | | this.activity = _.cloneDeep(temp.activity); |
| | | this.tempAwardsList = _.cloneDeep(temp.awardInfo); |
| | | this.openInfo = _.cloneDeep(temp.openInfo); |
| | | this.joinInfo = _.cloneDeep(temp.joinInfo); |
| | | }, |
| | | //初始化数据 |
| | | initData() { |
| | | $this = this; |
| | | /**************初始化抽奖信息************/ |
| | | if (this.activity.poster) |
| | | $("#poster").attr("src", this.activity.poster); |
| | | if (this.activity.banner && this.activity.banner.length > 0) { |
| | | for (var i = 0; i < this.activity.banner.length; i++) { |
| | | var url = this.activity.banner[i].img; |
| | | var item = getBannerItemHtml(url); |
| | | item.find("i").on('click', function () { |
| | | //删除当前数据 |
| | | app.activity.banner.splice(i, 1); |
| | | item.remove(); |
| | | }); |
| | | $(".banner").append(item); |
| | | } |
| | | |
| | | //删除所有选择的文件 |
| | | for (key in posterFileList) { |
| | | delete posterFileList[key]; |
| | | } |
| | | |
| | | //选择banner |
| | | for (key in bannerFileList) { |
| | | delete bannerFileList[key]; |
| | | } |
| | | |
| | | |
| | | $(".banner").empty(); |
| | | if (this.activity.poster) |
| | | $("#poster").attr("src", this.activity.poster); |
| | | |
| | | |
| | | //选择banner监听 |
| | | common.layuiForm.on('radio(banner)', function (data) { |
| | | if (data.value == 1) { |
| | | $(".banner-container").css("display", "block"); |
| | |
| | | } |
| | | }); |
| | | |
| | | if (this.activity.bannerList && this.activity.bannerList.length > 0) { |
| | | for (var i = 0; i < this.activity.bannerList.length; i++) { |
| | | var url = this.activity.bannerList[i].url; |
| | | var item = getBannerItemHtml(url); |
| | | item.find("i").on('click', function () { |
| | | //删除当前数据 |
| | | app.activity.bannerList.splice(i, 1); |
| | | item.remove(); |
| | | }); |
| | | $(".banner").append(item); |
| | | } |
| | | //设置选项 |
| | | $("input[name=showBanner][value=1]").prop("checked", "true"); |
| | | } else { |
| | | console.log("选择banner"); |
| | | $("input[name=showBanner][value=0]").prop("checked", "true"); |
| | | } |
| | | |
| | | common.layuiForm.on('submit(form-activity-info)', |
| | | function (data) { |
| | | field = common.layuiForm.val('form-activity-info'); |
| | | if (!validManager.verifyActivityInfo()) |
| | | if (!validManager.verifyActivityInfo()) { |
| | | app.finishSubmit(); |
| | | return false; |
| | | } |
| | | // 数据暂存 |
| | | app.tempField.activity = field; |
| | | //有封面图 |
| | |
| | | common.layuiForm.on('submit(form-award-info)', |
| | | function (data) { |
| | | console.log("提交奖品信息"); |
| | | if (!validManager.verifyAwardInfo()) |
| | | if (!validManager.verifyAwardInfo()) { |
| | | app.finishSubmit(); |
| | | return false; |
| | | } |
| | | |
| | | //暂存 |
| | | formManager.saveAwardInfoToTemp() |
| | | |
| | | //赋值 |
| | | $("#saveJoinInfo").click(); |
| | | |
| | |
| | | common.layuiForm.on('submit(form-join-info)', |
| | | function (data) { |
| | | console.log("提交参与条件"); |
| | | if (!validManager.verifyJoinInfo()) |
| | | if (!validManager.verifyJoinInfo()) { |
| | | app.finishSubmit(); |
| | | return false; |
| | | $("#saveOpenInfo").click(); |
| | | } |
| | | //暂存 |
| | | formManager.saveJoinInfoToTemp(); |
| | | $("form[lay-filter=form-open-info]").submit() |
| | | return false; |
| | | }); |
| | | |
| | | //初始化表单的值 |
| | | common.layuiForm.val("form-join-info", this.joinInfo); |
| | | |
| | | |
| | | /**************初始化开奖条件************/ |
| | | common.layuiForm.on('submit(form-open-info)', |
| | | function (data) { |
| | | console.log("提交开奖条件"); |
| | | if (!validManager.verifyOpenInfo()) |
| | | if (!validManager.verifyOpenInfo()) { |
| | | app.finishSubmit(); |
| | | return false; |
| | | |
| | | |
| | | } |
| | | //暂存 |
| | | formManager.saveOpenInfoToTemp(); |
| | | app.finishSubmit(true); |
| | | return false; |
| | | }); |
| | | common.layuiForm.val("form-open-info", this.openInfo); |
| | | |
| | | common.layuiForm.render(); |
| | | }, |
| | | |
| | | //封面图上传成功 |
| | | posterUploadSuccess(res) { |
| | | console.log("封面图上传成功"); |
| | | console.log(res); |
| | | if (res) {//上传了文件 |
| | | $("#poster").attr("src", res); |
| | | this.activity.poster = res; |
| | | } |
| | | //上传文件 |
| | | var bannerEmpty = true; |
| | | for (key in bannerFileList) { |
| | |
| | | this.activity.bannerList.push(banner); |
| | | } |
| | | } |
| | | |
| | | //暂存活动信息 |
| | | formManager.saveActivityInfoToTemp(); |
| | | |
| | | //提交奖项 |
| | | $("#saveAwardInfo").click(); |
| | | |
| | | }, |
| | | |
| | | //添加 |
| | | requestAdd: function () { |
| | | //组装数据 |
| | | if (this.data.awardsList.length == 0) { |
| | | return; |
| | | } |
| | | if (this.data.poster == null || this.data.poster.length == 0) { |
| | | return; |
| | | } |
| | | |
| | | requestAdd: function (data) { |
| | | var params = { |
| | | activity: this.data.activity, |
| | | awardsList: this.data.awardsList, |
| | | openInfo: this.data.openInfo, |
| | | adInfo: this.data.adInfo, |
| | | data: data, |
| | | } |
| | | |
| | | |
| | | this.activity.poster = this.data.poster; |
| | | //发异步,把数据提交给php |
| | | ksapp.post('/admin/api/app/add', params, function (res) { |
| | | ksapp.post('/admin/activity/addActivity', params, function (res) { |
| | | if (res.code == 0) { |
| | | layer.alert("增加成功", { |
| | | icon: 6 |
| | |
| | | if (!validManager.verifyAll()) { |
| | | return; |
| | | } |
| | | var loading = layer.load(0, {shade: false}); |
| | | app.submitLoading = loading; |
| | | //触发表单提交 |
| | | $("#saveActivityInfo").click(); |
| | | //保存临时变量 |
| | | formManager.saveToTemp(); |
| | | console.log("临时变量") |
| | | //将数据提交到服务器 |
| | | var temp = this.temp; |
| | | |
| | | |
| | | |
| | | console.log(this.temp); |
| | | }, |
| | | finishSubmit: function (finish) { |
| | | console.log(JSON.stringify(this.temp)); |
| | | if (app.submitLoading) { |
| | | layer.close(app.submitLoading) |
| | | } |
| | | //所有数据已经取完 |
| | | if (finish) { |
| | | console.log("获取到的结果"); |
| | | console.log(this.temp); |
| | | app.setTempData(this.temp); |
| | | app.initData(); |
| | | //this.requestAdd(JSON.stringify(this.temp)); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | |
| | | title: params.title, |
| | | width: 500, |
| | | height: 400, |
| | | content: params.url + "?data=" + encodeURIComponent(JSON.stringify(award)), |
| | | content: params.url + "?data=" + escape(JSON.stringify(award)), |
| | | submit(res) { |
| | | var award = app.tempAwardsList[index]; |
| | | award.type = "alipayRedPackage"; |
| | | var data = award.data; |
| | | data.total = res.total; |
| | | data.count = res.count; |