<template>
  <div class="app-container" style="margin-top: 40px">
    <el-form :model="form" style="width: 500px" label-width="80px">
      <el-form-item label="商户号">
        <el-input v-model="form.mchId"></el-input>
      </el-form-item>
      <el-form-item label="MD5密钥">
        <el-input v-model="form.md5Key"></el-input>
      </el-form-item>
      <el-form-item label="支付网关">
        <el-input v-model="form.payReqUrl"></el-input>
      </el-form-item>
      <el-form-item label="通知地址">
        <el-input v-model="form.payNotifyUrl"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getUnionPayItem,saveUnionPayItem } from '@/api/financial/unionPay'

export default {
  name: 'unionPay',
  data() {
    return {
      form: {
        mchId: '',
        md5Key: '',
        payReqUrl: '',
        payNotifyUrl: ''
      }
    }
  },
  mounted() {
    this.getInfo();
  },
  methods: {
    getInfo(){
      const _that = this;
      var data = {}
      getUnionPayItem(data).then(response => {
        // console.log(response.data);
        var data  = response.data;
        _that.form.mchId = data.mchId;
        _that.form.md5Key = data.md5Key;
        _that.form.payReqUrl = data.payReqUrl;
        _that.form.payNotifyUrl = data.payNotifyUrl;
      }).catch(err => {
        _that.$message.error(err);
      })
    },
    onSubmit(){
      const _that = this;
      var data = {
        payConfigItem:{
          mchId: _that.form.mchId,
          md5Key: _that.form.md5Key,
          payReqUrl: _that.form.payReqUrl,
          payNotifyUrl: _that.form.payNotifyUrl
        }
      }
      // console.log(data);
      saveUnionPayItem(data).then(response => {
        _that.$message.success("保存成功");
      }).catch(err => {
        _that.$message.error(err);
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.filter-container {
  margin-bottom: 15px;
  margin-top: 40px;
}
</style>
