<style>
  .pintuanSet .custom_Header {
    padding: 0 20px;
    height: 56px;
    line-height: 56px;
    background-color: #fff;
    margin-bottom: 15px;
    width: 100%;
  }

  .pintuan_Cont {
    padding: 20px 0 10px 0;
  }

  .pintuanSet .red {
    padding: 0 25px;
    display: inline-block;
    color: red;
  }

  .pintuanSet .block-box {
    color: #ffffff;
    cursor: pointer;
    display: inline-block;
    margin-right: 25px;
    height: 280px;
    width: 300px;
    border: 1px solid #D4D4D4;
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    position: relative;
  }

  .block-box .Cubeselect {
    display: none;
  }

  .imgCube_chooseBtn {
    position: absolute;
    height: 30px;
    width: 80px;
    padding: 0 !important;
    text-align: center;
    background-color: #409EFF;
    top: 50%;
    left: 0;
    right: 0;
    margin: -15px auto 0 !important;
    z-index: 10;
    display: none;
  }

  .block-box:hover .imgCube_chooseBtn {
    display: block;
  }

  .active .imgCube_chooseBtn {
    display: none !important;
  }

  .active .opacity {
    display: none !important;
  }

  .block-box:hover .opacity {
    display: block;
  }

  .pintuanSet .opacity {
    position: absolute;
    height: 250px;
    width: 280px;
    bottom: 0;
    left: 10px;
    z-index: 5;
    background-color: rgba(0, 0, 0, .3);
    display: none;
  }

  .cube_blockImg {
    width: 280px;
    height: 250px;
    position: absolute;
    bottom: 0px;
    left: 10px;
  }

  .active .Cubeselect {
    position: absolute;
    top: 0;
    left: 0;
    height: 80px;
    width: 80px;
    display: block;
    z-index: 10;
  }

  .pintuanSet .content {
    background: #fff;
    padding: 20px 0;
    box-sizing: border-box;
    margin-top: 10px;
    min-height: 400px;
  }

  .pintuanSet .app-banner-list {
    display: inline-block;
    padding-right: 5px;
    height: 280px;
    width: 250px;
    margin: 0 20px;
    cursor: pointer;
  }

  .pintuanSet .app-banner-list-item {
    height: 280px;
    width: 250px;
  }

  .pintuanSet .app-banner-add-icon {
    font-size: 62px;
    color: #C0C4CC;
    margin-top: 90px;
    margin-bottom: 20px;
  }

  .pintuanSet .shuff_add {
    color: rgb(192, 196, 204);
    font-size: 16px;
  }

  .pintuanSet .app-banner-list-item:hover {
    border: 1px solid #409EFF;
  }

  .pintuanSet .app-banner-list {
    display: inline-block;
    padding-right: 5px;
    height: 280px;
    width: 250px;
    margin-right: 20px;
    cursor: pointer;
  }

  .pintuanSet .app-banner-text {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 10px;
  }

  .pintuanSet .editImg {
    display: none;
    position: absolute;
    bottom: 30px;
    right: 80px;
    padding: 0px;
  }

  .pintuanSet .delImg {
    display: none;
    position: absolute;
    bottom: 30px;
    right: 20px;
    padding: 0px;
  }

  .pintuanSet .app-banner-list:hover .delImg {
    display: block;
  }

  .pintuanSet .app-banner-list:hover .editImg {
    display: block;
  }

  .pintuanSet .banner_btmDiv {
    height: 90px;
    padding: 10px;
    font-size: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.125);
  }

  .pintuanSet .banner_topImg {
    height: 190px;
    width: 250px;
    display: block;
  }

</style>
<template>
  <div class="pintuanSet">
    <div class="custom_Header">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="基本设置" name="1"></el-tab-pane>
        <el-tab-pane label="轮播图" name="2"></el-tab-pane>
        <el-tab-pane label="拼团广告" name="3"></el-tab-pane>
      </el-tabs>
    </div>
    <div class="pintuan_Cont">
      <!-- 基本设置 -->
      <template v-if="checkIndex==1">
        <div class="app-setting">
          <el-form label-width="180px">
            <el-card class="box-card" style="margin-bottom:10px;">
              <div slot="header" class="clearfix">
                <span>购买设置</span>
              </div>
              <el-form-item label="是否开启分销" size="mini">
                <el-switch v-model="msg.Is_Share" active-color="#409EFF" :active-value="1" :inactive-value="0">
                </el-switch>
                <span class="red">注：必须在“<el-button type="text" @click="openNewUrl('baseSet')">分销中心=>基础设置</el-button>
                  ”中开启，才能使用</span>
              </el-form-item>
              <el-form-item label="是否开启区域允许购买" size="mini">
                <el-switch v-model="msg.Is_Territorial_Limitation" active-color="#409EFF" :active-value="1"
                  :inactive-value="0">
                </el-switch>
                <span class="red">注：必须在“<el-button type="text" @click="openNewUrl('regionBuy')">系统管理=>区域允许购买</el-button>
                  ”中开启，才能使用</span>
              </el-form-item>
              <el-form-item label="支付方式" size="mini">
                <el-tooltip class="item" effect="dark" content="默认支持线上支付；若三个都不勾选，则视为勾选线上支付" placement="top">
                  <i class="topelzk elzk el-tooltip el-icon-info"></i>
                </el-tooltip>
                <el-checkbox-group v-model="msg.Payment_TypeList" :min="1"
                  style="display:inline-block;margin-left:10px;">
                  <el-checkbox label="online_pay">线上支付</el-checkbox>
                  <el-checkbox label="huodao">货到付款</el-checkbox>
                  <el-checkbox label="balance">余额支付</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
              <el-form-item label="发货方式" size="mini">
                <el-tooltip class="item" effect="dark" content="自提需要设置门店，如果您还未设置门店请保存本页后设置门店" placement="top">
                  <i class="topelzk elzk el-tooltip el-icon-info"></i>
                </el-tooltip>
                <el-checkbox-group v-model="msg.Send_TypeList" :min="1" style="display:inline-block;margin-left:10px;">
                  <el-checkbox label="express">快递配送</el-checkbox>
                  <el-checkbox label="offline">到店自提</el-checkbox>
                  <el-checkbox label="city">同城配送</el-checkbox>
                </el-checkbox-group>
                <div style="color: rgb(204, 204, 204);">
                  注：手机端显示排序（1.快递配送 2.到店自提 3.同城配送）
                </div>
              </el-form-item>

            </el-card>
            <el-card class="box-card" style="margin-bottom:10px;">
              <div slot="header" class="clearfix">
                <span>优惠叠加设置</span>
              </div>
              <el-form-item label="优惠券" size="mini">
                <el-switch v-model="msg.Is_Coupon" active-color="#409EFF" :active-value="1" :inactive-value="0">
                </el-switch>
              </el-form-item>
              <el-form-item label="超级会员卡" size="mini">
                <el-switch v-model="msg.SVIP_Status" active-color="#409EFF" :active-value="1" :inactive-value="0">
                </el-switch>
                <span class="red">注：必须在“<el-button type="text">插件中心=>超级会员卡</el-button>”中开启，才能使用</span>
              </el-form-item>
              <el-form-item label="会员价" size="mini">
                <el-switch v-model="msg.Is_Member_Price" active-color="#409EFF" :active-value="1" :inactive-value="0">
                </el-switch>
              </el-form-item>
              <el-form-item label="积分抵扣" size="mini">
                <el-switch v-model="msg.Is_Integral" active-color="#409EFF" :active-value="1" :inactive-value="0">
                </el-switch>
              </el-form-item>

            </el-card>
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>拼团规则设置</span>
              </div>
              <el-form-item label="活动规则" size="mini">
                <UE style="width:750px;" :defaultMsg="msg.RuleText" ref="ue"></UE>
              </el-form-item>
            </el-card>
          </el-form>
        </div>
      </template>
      <!-- 轮播图 -->
      <template v-if="checkIndex==2">
        <div class="head-title">
          轮播图管理
        </div>
        <div class="content clearfix">
          <div class="app-banner-list" style="float:left;"
            @click="isShowLunbo=true,clearMsg(),ischoiceLunbo=true,isEditLunbo=false">
            <div class="el-card app-banner-list-item" style="text-align:center;">
              <div class="el-card__body" style="padding: 0px;">
                <i class="el-icon-plus app-banner-add-icon"></i>
                <div class="shuff_add">添加轮播图</div>
              </div>
            </div>
          </div>
          <div>
            <div class="app-banner-list" v-for="(item,index) in msg.BannerList" :key="index">
              <div class="el-card app-banner-list-item">
                <div style="padding:0">
                  <div style="position: relative;">
                    <img class="banner_topImg" :src="getIconLink(item.NavImg)" alt="">
                    <el-tooltip slot="label" class="item" effect="dark" content="修改" placement="top">
                      <img class="editImg" src="../../assets/img/userman/edit.png" alt="" @click="EditRole(item,index)">
                    </el-tooltip>
                    <el-tooltip slot="label" class="item" effect="dark" content="删除" placement="top">
                      <img class="delImg" src="../../assets/img/userman/del.png" alt="" @click="RemmoveRole(index)">
                    </el-tooltip>
                  </div>
                </div>
                <div class="banner_btmDiv">
                  <div class="app-banner-text">标题：{{item.NavName}}</div>
                  <div class="app-banner-text">路径：{{item.NavLink}}</div>
                </div>
              </div>
            </div>
          </div>
        </div>

      </template>
      <!-- 拼团广告 -->
      <template v-if="checkIndex==3">
        <el-form label-width="150px">
          <el-form-item label="拼团广告状态" size="mini">
            <el-switch v-model="msg.Is_Advertisement" active-color="#409EFF" :active-value="1" :inactive-value="0">
            </el-switch>
          </el-form-item>
          <el-form-item label="样式选择" size="mini">
            <div class="block-box" v-for="(item,index) in styleList" :key="index"
              :class="item.Style==msg.Style?'active':''" @click="getStyleType(item)">
              <img src="../../assets/img/storeDesign/select.png" class="Cubeselect" alt="" />
              <div class="opacity"></div>
              <el-button class="imgCube_chooseBtn" type="primary">启用该样式</el-button>
              <img :src="item.ImgUrl" class="cube_blockImg" alt="">
            </div>
          </el-form-item>
          <el-form-item label="板块设置">
            <template v-if="msg.MagicDataList.length==0">
              <el-tag type="danger">请先选择样式</el-tag>
            </template>
            <template v-else>
              <el-row style="margin-bottom:15px;" v-for="(subItem,subIndex) in msg.MagicDataList" :key="subIndex">
                <el-col :span="2">
                  <el-tooltip class="item" effect="dark" :content="'建议尺寸：'+subItem.size" placement="top">
                    <el-button size="mini" @click="choicImg=true,commonIndex=subIndex,ischoiceLunbo=false">选择图片
                    </el-button>
                  </el-tooltip>
                  <div class="customize-share-title">
                    <div class="zk_pic_box" style="width:80px;height:80px;" flex="main:center cross:center"
                      :style="{backgroundImage:'url(' + getIconLink(subItem.ImgUrl) + ')'}">
                      <i v-if="subItem.ImgUrl==''" class="el-icon-picture-outline"></i>
                    </div>
                  </div>
                </el-col>
                <el-col :span="12">
                  <div style="display:flex;" flex="box:last">
                    <el-input type="text" v-model="subItem.Link" :disabled="true" size="small">
                    </el-input>
                    <div>
                      <el-button size="mini" @click="isShowLink=true,commonIndex=subIndex,ischoiceLunbo=false">选择链接
                      </el-button>
                    </div>
                  </div>
                </el-col>
              </el-row>
            </template>
          </el-form-item>
        </el-form>
      </template>
      <el-button size="small" style="margin:30px 0 150px 0;padding:9px 25px;" type="primary"
        @click="saveGroupBuyConfig">保 存</el-button>
    </div>
    <!-- 选择图片文件 -->
    <el-dialog :title="commonTitle" :visible.sync="isShowLunbo" width="960px">
      <el-form label-width="100px" :model="addMsg" :rules="rules" ref="addMsg">
        <el-form-item label="标题" prop="NavName">
          <el-input type="text" v-model="addMsg.NavName" size="small" maxlength="50"></el-input>
        </el-form-item>
        <el-form-item label="跳转链接">
          <el-input type="text" v-model="addMsg.NavLink" size="small" :disabled="true" maxlength="200">
            <el-button slot="append" @click="isShowLink=true">选择链接</el-button>
          </el-input>
        </el-form-item>
        <el-form-item label="图片" prop="NavImg">
          <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 350" placement="top">
            <el-button size="mini" @click="choicImg=true">选择图片</el-button>
          </el-tooltip>
          <div class="zk_pic_box" flex="main:center cross:center" style="width:80px;height:80px;"
            :style="{backgroundImage:'url(' + getIconLink(addMsg.NavImg) + ')'}">
            <i v-if="addMsg.NavImg==''" class="el-icon-picture-outline"></i>
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowLunbo = false" size="small">取消</el-button>
        <el-button type="primary" @click="submitform('addMsg')" size="small">提交</el-button>
      </span>
    </el-dialog>

    <!-- 选择图片文件 -->
    <el-dialog title="选择文件" :visible.sync="choicImg" width="1240px">
      <ChooseImg @SelectId="SelectId"></ChooseImg>
    </el-dialog>
    <!-- 选择链接 -->
    <el-dialog title="选择链接" :visible.sync="isShowLink" width="800px">
      <chooseMenu ref="chooseMenu"></chooseMenu>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="isShowLink=false">取 消</el-button>
        <el-button size="small" type="danger" @click="getChoiceLink()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import UE from '@/components/global/UE.vue'
  import ChooseImg from "@/components/global/ChooseImg.vue";
  import chooseMenu from "../common/chooseMenu.vue";

  export default {
    data() {
      return {
        ischoiceLunbo: false,
        commonTitle: '',
        commonIndex: -1,
        choicImg: false,
        isShowLink: false,
        isShowLunbo: false,
        isEditLunbo: false,
        commonImgIndex: -1,

        activeName: '1',
        checkIndex: 1,
        config: {
          initialFrameWidth: null,
          initialFrameHeight: 350,
        },
        msg: {
          GroupByConfigId: 0, //配置编号
          Is_Share: 0, //是否开启分销
          Is_Territorial_Limitation: 0, //是否开启区域允许购买
          Payment_TypeList: ["online_pay", "balance", "huodao"], //支付方式
          Send_TypeList: ["express", "offline", "city"], //发货方式
          Is_Coupon: 1, //优惠券
          SVIP_Status: 1, //超级会员卡
          Is_Member_Price: 1, //会员价
          Is_Integral: 1, //积分抵扣
          RuleText: '', //活动规则
          Is_Advertisement: 1, //拼团广告状态
          Goods_Poster: "",
          Style: 0, //魔方样式
          MagicDataList: [], //广告列表
          BannerList: [], //轮播图
        },
        //样式选择枚举
        styleList: [{
          Id: 1,
          size: ['750*360'],
          Style: 1,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube1-1.png'
        }, {
          Id: 2,
          size: ['300*360', '450*360'],
          Style: 2,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube1-2.png'
        }, {
          Id: 3,
          size: ['300*360', '450*180', '450*180'],
          Style: 3,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube1-3.png'
        }, {
          Id: 4,
          size: ['300*360', '450*180', '225*180', '225*180'],
          Style: 4,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube1-4.png'
        }, {
          Id: 5,
          size: ['375*240', '375*240'],
          Style: 5,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube2-1.png'
        }, {
          Id: 6,
          size: ['250*240', '250*240', '250*240'],
          Style: 6,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube2-2.png'
        }, {
          Id: 7,
          size: ['188*188', '188*188', '188*188', '188*188'],
          Style: 7,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube2-3.png'
        }, {
          Id: 8,
          size: ['375*186', '375*186', '375*186', '375*186'],
          Style: 8,
          ImgUrl: this.domainManager().ImageUrl + '/Static/cube3-1.png'
        }],
        defaultMsg: [{
          ImgUrl: '',
          Link: ''
        }, {
          ImgUrl: '',
          Link: ''
        }, {
          ImgUrl: '',
          Link: ''
        }, {
          ImgUrl: '',
          Link: ''
        }],
        //添加轮播图obj
        addMsg: {
          NavName: '', //标题
          NavLink: '', //跳转链接
          NavImg: '' //图片链接
        },
        rules: {
          NavName: [{
            required: true,
            message: "标题不能为空",
            trigger: "change"
          }],
          NavImg: [{
            required: true,
            message: "图片不能为空",
            trigger: "change"
          }]
        },
      };
    },
    created() {},
    components: {
      UE,
      ChooseImg,
      chooseMenu
    },
    methods: {
      //切换
      handleClick(tab) {
        this.checkIndex = tab.name;
      },
      //点击选择广告
      getStyleType(item) {
        this.msg.Style = item.Style;
        this.msg.MagicDataList = [];
        for (var i = 0; i < item.size.length; i++) {
          this.msg.MagicDataList.push(this.defaultMsg[i]);
        }
        this.msg.MagicDataList.forEach((x, index) => {
          x.size = this.styleList[(item.Id-1)].size[index]
        })
      },
      //保存拼团配置
      saveGroupBuyConfig() {
        if (this.checkIndex == 1) {
          let content = this.$refs.ue.getUEContent();
          this.msg.RuleText = content;
        }
        this.apipost("/api/GroupBuy/SetGroupBuyConfig", this.msg, res => {
          if (res.data.resultCode == 1) {
            this.getGroupBuyConfig();
            this.Success(res.data.message);
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //获取拼团配置
      getGroupBuyConfig() {
        this.apipost("/api/GroupBuy/GetGroupBuyConfig", {}, res => {
          if (res.data.resultCode == 1) {
            var dataObj = res.data.data;
            if (dataObj) {
              this.msg.GroupByConfigId = dataObj.GroupByConfigId;
              this.msg.Is_Share = dataObj.Is_Share;
              this.msg.Is_Territorial_Limitation = dataObj.Is_Territorial_Limitation;
              this.msg.Payment_TypeList = dataObj.Payment_TypeList;
              this.msg.Send_TypeList = dataObj.Send_TypeList;
              this.msg.Is_Coupon = dataObj.Is_Coupon;
              this.msg.SVIP_Status = dataObj.SVIP_Status;
              this.msg.Is_Member_Price = dataObj.Is_Member_Price;
              this.msg.Is_Integral = dataObj.Is_Integral;
              this.msg.Is_Advertisement = dataObj.Is_Advertisement;
              this.msg.Goods_Poster = dataObj.Goods_Poster;
              if (dataObj.RuleText && dataObj.RuleText != "") {
                this.msg.RuleText = dataObj.RuleText;
              }
              this.msg.Style = dataObj.Style;
              if (dataObj.BannerList) {
                this.msg.BannerList = dataObj.BannerList;
              }
              if (dataObj.MagicDataList) {
                this.msg.MagicDataList = dataObj.MagicDataList;
              }
            }
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //清空消息
      clearMsg() {
        this.commonTitle = '添加轮播图';
        this.addMsg.NavName = '';
        this.addMsg.NavLink = '';
        this.addMsg.NavImg = '';
      },
      //选择图片
      SelectId(msg) {
        if (this.ischoiceLunbo) {
          this.addMsg.NavImg = msg.url;
        } else {
          if (this.commonIndex > -1) {
            this.defaultMsg[this.commonIndex].ImgUrl = msg.url;
          }
        }
        this.choicImg = false;
      },
      //获取选择链接
      getChoiceLink() {
        //调用子组件方法
        var obj = this.$refs.chooseMenu.getChooseMenu();
        if (this.ischoiceLunbo) {
          this.addMsg.NavLink = obj.PageUrl;
        } else {
          if (this.commonIndex > -1) {
            this.defaultMsg[this.commonIndex].Link = obj.PageUrl;
          }
        }
        this.isShowLink = false;
      },
      submitform(addMsg) {
        //提交创建、修改表单
        this.$refs[addMsg].validate(valid => {
          if (valid) {
            this.addShuffImg();
          } else {
            return false;
          }
        });
      },
      addShuffImg() {
        this.commonTitle = '添加轮播图';
        var obj = JSON.parse(JSON.stringify(this.addMsg))
        if (!this.isEditLunbo) {
          this.msg.BannerList.push(obj);
        } else {
          this.msg.BannerList[this.commonImgIndex].NavName = obj.NavName;
          this.msg.BannerList[this.commonImgIndex].NavLink = obj.NavLink;
          this.msg.BannerList[this.commonImgIndex].NavImg = obj.NavImg;
        }
        this.isShowLunbo = false;
      },
      //修改
      EditRole(item, index) {
        this.commonTitle = '轮播图编辑';
        this.isShowLunbo = true;
        this.isEditLunbo = true;
        this.commonImgIndex = index;
        this.addMsg.NavName = item.NavName;
        this.addMsg.NavLink = item.NavLink;
        this.addMsg.NavImg = item.NavImg;
      },
      //删除
      RemmoveRole(index) {
        let that = this;
        that.Confirm("确认要退出系统吗?", function () {
          that.msg.BannerList.splice(index, 1);
        });
      },
      //新窗口打开链接
      openNewUrl(path) {
        let routeData = this.$router.resolve({
          name: path
        });
        window.open(routeData.href, '_blank');
      }
    },
    mounted() {
      this.getGroupBuyConfig();
    }
  };

</script>
