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

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

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

  .wexinappconfig .el-button--small {
    padding: 9px 25px;
  }

</style>
<template>
  <div class="wexinappconfig">
    <div class="CommonHeader">微信小程序配置</div>
    <div class="mimitBody">
      <div class="el-col el-col-12">
        <el-form :model="appConfig" :rules="rules" ref="appConfig" label-width="150px">
          <el-form-item label="小程序AppId" prop="MiniAppId" size="small">
            <el-input type="text" size="small" maxlength="200" v-model="appConfig.MiniAppId">
            </el-input>
          </el-form-item>
          <el-form-item label="小程序appSecret" prop="MiniAppSecret" size="small">
            <el-input v-if="isShowAppSecret" type="text" @focus="isShowAppSecret=false" size="small" placeholder="已隐藏内容，点击查看或编辑">
            </el-input>
            <el-input v-else type="text" size="small" maxlength="200" v-model="appConfig.MiniAppSecret">
            </el-input>
          </el-form-item>
          <el-form-item label="微信支付商户号" prop="WeChatPayMerchants" size="small">
            <el-input type="text" size="small" maxlength="200" v-model="appConfig.WeChatPayMerchants">
            </el-input>
          </el-form-item>
          <el-form-item label="微信支付Api密钥" prop="WeChatApiSecret" size="small">
            <el-input v-if="isShowApi" type="text" @focus="isShowApi=false" size="small" placeholder="已隐藏内容，点击查看或编辑">
            </el-input>
            <el-input v-else type="text" size="small" maxlength="200" v-model="appConfig.WeChatApiSecret">
            </el-input>
          </el-form-item>
          <el-form-item label="微信支付apiclient_cert.pem" size="small">
            <el-input v-if="isShowClientOne" type="textarea" @focus="isShowClientOne=false" :rows="5" size="small" placeholder="已隐藏内容，点击查看或编辑">
            </el-input>
            <el-input v-else type="textarea" :rows="5" size="small" maxlength="1000"
              v-model="appConfig.WeChatPayCertificate">
            </el-input>
          </el-form-item>
          <el-form-item label="微信支付apiclient_key.pem" size="small">
            <el-input v-if="isShowClientTwo" type="textarea" @focus="isShowClientTwo=false" :rows="5" size="small" placeholder="已隐藏内容，点击查看或编辑">
            </el-input>
            <el-input v-else type="textarea" :rows="5" size="small" maxlength="1000"
              v-model="appConfig.WeChatPayPrivateKey">
            </el-input>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <el-button size="small" type="primary" @click="submitForm('appConfig')">保存</el-button>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        //是否显示小程序appSecret
        isShowAppSecret:true,
        //是否显示微信支付Api密钥
        isShowApi:true,
        //是否显示微信支付
        isShowClientOne:true,
        isShowClientTwo:true,

        //修改配置MSG
        appConfig: {
          MallBaseId: 0, //小程序Id
          MiniAppId: "", //小程序AppId
          MiniAppSecret: "", //小程序AppSecret
          WeChatPayMerchants: "", //微信支付商户号
          WeChatApiSecret: "", //微信支付Api密钥
          WeChatPayCertificate: "", //微信支付证书
          WeChatPayPrivateKey: "", //微信支付私钥
        },
        rules: {
          MiniAppId: [{
            required: true,
            message: "请输入appid",
            trigger: "blur"
          }],
          MiniAppSecret: [{
            required: true,
            message: "请输入appsecret",
            trigger: "blur"
          }],
          WeChatPayMerchants: [{
            required: true,
            message: "请输入mchid",
            trigger: "blur"
          }],
          WeChatApiSecret: [{
            required: true,
            message: "请输入key",
            trigger: "blur"
          }]
        }
      };
    },
    created() {

    },
    methods: {
      //版权信息
      GetWeiXinAppConfig() {
        this.appConfig.MallBaseId = this.getLocalStorage().MallBaseId;
        this.apipost("/api/Tenant/GetMiniPrograme", {
          MallBaseId: this.appConfig.MallBaseId,
        }, res => {
          if (res.data.resultCode == 1) {
            this.appConfig.MiniAppId = res.data.data.MiniAppId;
            this.appConfig.MiniAppId = res.data.data.MiniAppId;
            this.appConfig.MiniAppSecret = res.data.data.MiniAppSecret;
            this.appConfig.WeChatPayMerchants = res.data.data.WeChatPayMerchants;
            this.appConfig.WeChatApiSecret = res.data.data.WeChatApiSecret;
            this.appConfig.WeChatPayCertificate = res.data.data.WeChatPayCertificate;
            this.appConfig.WeChatPayPrivateKey = res.data.data.WeChatPayPrivateKey;
          } else {
            this.Info(res.data.message);
          }
        })
      },
      submitForm(msg) {
        //提交创建、修改表单
        this.$refs[msg].validate(valid => {
          if (valid) {
            this.UpdateAppConfig();
          } else {
            return false;
          }
        });
      },
      //修改版权
      UpdateAppConfig() {
        this.apipost("/api/Tenant/SetMiniProgramAppConfig", this.appConfig, res => {
          if (res.data.resultCode == 1) {
            this.GetWeiXinAppConfig();
            this.Success("操作成功!");
          } else {
            this.Info(res.data.message);
          }
        })
      },
    },
    mounted() {
      this.GetWeiXinAppConfig();
    }
  };

</script>
