<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-upload class="avatar-uploader" action="" accept="image/jpeg,image/gif,image/png,image/bmp"
                :show-file-list="false" :http-request="UploadImage">
                <el-button size="small">选择图片</el-button>
              </el-upload>
            </el-tooltip>
          </div>
          <div class="indexApp_image">
            <img v-if="copyRightMsg.CopyRightImg" :src="copyRightMsg.CopyRightImg" alt="" />
          </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>
  </div>
</template>
<script>
  import chooseMenu from "../common/chooseMenu.vue";
  export default {
    data() {
      return {
        //是否线下链接弹窗
        isShowLink: false,
        //修改版权MSG
        copyRightMsg: {
          MallBaseId: 0, //小程序Id
          CopyRightWord: '', //版权文字
          CopyRightImg: '', //版权图片
          CopyRightLink: '', //版权链接
          IsOpenCopyRight: 0, //是否开启版权设置(0-开启,1-关闭)
        },
      };
    },
    components: {
      chooseMenu
    },
    created() {

    },
    methods: {
      getMenu() {
        //调用子组件方法
        var obj = this.$refs.chooseMenu.getChooseMenu();
        this.copyRightMsg.CopyRightLink = obj.PageUrl;
        this.isShowLink = false;
      },
      //选择图片
      UploadImage(file) {
        this.UploadFileToTencent(this.FileType().UserImg, file.file, res => {
          if (res.resultCode == 1) {
            this.copyRightMsg.CopyRightImg = res.FileUrl;
          }
        })
      },
      //版权信息
      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>
