<style>
  .copyrightset .mimitBody {
    padding: 20px;
    background-color: #fff;
    margin: 10px 0 20px 0;
    display: table;
    width: 100%;
  }

  .copyrightset .mimitList {
    margin-bottom: 15px;
    display: flex;
    flex-direction: row;
  }

  .copyrightset .mimitBody .el-tag {
    min-width: 120px;
    padding-right: 50px;
  }

  .copyrightset .el-button--small {
    padding: 9px 25px;
  }
</style>
<template>
  <div class="copyrightset">
    <div class="CommonHeader">版权设置</div>
    <div class="mimitBody">
      <el-form :model="copyRightMsg" ref="copyRightMsg" label-width="150px">
        <el-form-item label="版权开关">
          <el-switch v-model="copyRightMsg.IsOpenCopyRight" :active-value="0" :inactive-value="1"></el-switch>
        </el-form-item>
        <el-form-item label="底部版权文字">
          <el-input type="text" style="width:250px" size="small" maxlength="100" v-model="copyRightMsg.CopyRightWord">
          </el-input>
        </el-form-item>
        <el-form-item label="底部版权图标">
          <div>
            <el-tooltip class="item" effect="dark" content="建议尺寸:160*50" placement="top-start">
              <el-button size="small" @click="choicImg=true">选择图片</el-button>
            </el-tooltip>
          </div>
          <div class="zk_pic_box" @click="choicImg=true" flex="main:center cross:center" style="width:100px;height:100px;margin-top:10px;"
            :style="{backgroundImage:'url(' + copyRightMsg.CopyRightImg + ')'}">
            <i v-if="copyRightMsg.CopyRightImg==''" class="el-icon-picture-outline"></i>
            <el-button type="danger" v-if="copyRightMsg.CopyRightImg!=''" class="image-delete" size="mini"
              icon="el-icon-close" @click.stop="copyRightMsg.CopyRightImg=''" circle></el-button>
          </div>
        </el-form-item>
        <el-form-item label="底部版权链接">
          <el-input style="width:250px" size="small" maxlength="200" :disabled="true"
            v-model="copyRightMsg.CopyRightLink" />
          <el-button plain size="small" @click="isShowLink=true">选择链接</el-button>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="UpdateCopyRight()">确 定</el-button>
      </span>
    </div>
    <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="getMenu()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 选择图片文件 -->
    <el-dialog title="选择文件" :visible.sync="choicImg" width="1240px">
      <ChooseImg @SelectId="SelectId"></ChooseImg>
    </el-dialog>
  </div>
</template>
<script>
  import chooseMenu from "../common/chooseMenu.vue";
  import ChooseImg from "@/components/global/ChooseImg.vue";
  export default {
    data() {
      return {
        //是否线下链接弹窗
        isShowLink: false,
        //选择图片弹窗
        choicImg:false,
        //修改版权MSG
        copyRightMsg: {
          MallBaseId: 0, //小程序Id
          CopyRightWord: '', //版权文字
          CopyRightImg: '', //版权图片
          CopyRightLink: '', //版权链接
          IsOpenCopyRight: 0, //是否开启版权设置(0-开启,1-关闭)
        },
      };
    },
    components: {
      chooseMenu,
      ChooseImg
    },
    created() {

    },
    methods: {
      getMenu() {
        //调用子组件方法
        var obj = this.$refs.chooseMenu.getChooseMenu();
        this.copyRightMsg.CopyRightLink = obj.PageUrl;
        this.isShowLink = false;
      },
      //选择图片
      SelectId(msg) {
        this.copyRightMsg.CopyRightImg = this.getIconLink(msg.url);
        this.choicImg = false;
      },
      //版权信息
      GetCopyRight() {
        this.copyRightMsg.MallBaseId = this.getLocalStorage().MallBaseId;
        this.apipost("/api/Tenant/GetMiniPrograme", {
          MallBaseId: this.copyRightMsg.MallBaseId,
        }, res => {
          if (res.data.resultCode == 1) {
            this.copyRightMsg.CopyRightWord = res.data.data.CopyRightWord;
            this.copyRightMsg.CopyRightImg = res.data.data.CopyRightImg;
            this.copyRightMsg.CopyRightLink = res.data.data.CopyRightLink;
            this.copyRightMsg.IsOpenCopyRight = res.data.data.IsOpenCopyRight;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //修改版权
      UpdateCopyRight() {
        this.apipost("/api/Tenant/SetMiniProgrameCopyRight", this.copyRightMsg, res => {
          if (res.data.resultCode == 1) {
            this.GetCopyRight();
            this.Success("操作成功!");
          } else {
            this.Info(res.data.message);
          }
        })
      },
    },
    mounted() {
      this.GetCopyRight();
    }
  };

</script>
