<template>
  <div>
    <i-page-header class="product_tabs" title="用户条款"></i-page-header>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <el-tabs>
        <el-tab-pane label="用户条款" style="background: #fff;">
          <el-form ref="form" :model="form" label-width="150px" >
            <el-divider content-position="left">用户协议</el-divider>
			<el-form-item label="" prop="user_agreement" :rules="[{ required: true, message: '请输入用户协议'}]">
			  <vue-ueditor-wrap v-model="form.user_agreement"  :config="myConfig"  style="width: 95%;"></vue-ueditor-wrap>
			</el-form-item>
            <el-divider content-position="left">用户隐私声明</el-divider>
			<el-form-item label="" prop="privacy_policy" :rules="[{ required: true, message: '请输入用户隐私声明'}]">
              <vue-ueditor-wrap v-model="form.privacy_policy"  :config="myConfig"  style="width: 95%;"></vue-ueditor-wrap>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">立即修改</el-button>
              <el-button>取消</el-button>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
    </Card>
  </div>

</template>
<script>
	import VueUeditorWrap from 'vue-ueditor-wrap'
    import Setting from "../../../../setting";
    import {SystemAgreeSave, SystemSys} from "../../../../api/system/sys";
    import util from "../../../../libs/util";
    import IPageHeader from "../../../../layouts/system/page-header/index";
    export default {
        name: "index",
        components: {IPageHeader, VueUeditorWrap},
        computed: {},
        data() {
            return {
                form  : {
                    privacy_policy:"",
					user_agreement:"",
                },
				myConfig: {
					toolbars: [
					    ['fullscreen', 'source', 'undo', 'redo', 'bold','italic', 'underline','strikethrough','paragraph', 'justifyleft','justifyright',
						'justifycenter','touppercase', 'lineheight','rowspacingtop', 'indent','rowspacingbottom','tolowercase',]
					],
					fontsize:[12,14,16,18,20,22,24],
				    autoHeightEnabled: false, // 编辑器不自动被内容撑高
				    initialFrameHeight: 300, // 初始容器高度
				    initialFrameWidth: '100%', // 初始容器宽度
				    UEDITOR_HOME_URL: Setting.apiBaseURL + '/sadminx/UEditor/',
				    serverUrl: ''
				},
            }
        },

        created() {
        },

        mounted(){
            this.$utils.loading(this,"loading..");
            SystemSys()
                .then(res=>{
                    this.$utils.loadingClose();
                    if(res.code == 200) {
                        this.form = res.data;
                    } else {
                        this.$alert(res.msg);
                    }
                })
                .catch(err=>{
                    this.$utils.loadingClose();
                    this.$alert("网络繁忙，加载失败，请稍等片刻在尝试!", '系统提示');
                });
        },

        methods: {
            /**
             * 提交数据
             */
            onSubmit:function () {
				var that = this;
				 this.$refs['form'].validate((valid) => {
					if (valid) {
					    that.$utils.loading(that,"加载中...");
					    var data = {};
					    for(var i in that.form) {
					        data[i] = that.form[i];
					    }
					    SystemAgreeSave(data).then(res => {
					        that.$utils.loadingClose();
					        if(res.code == 200) {
					            that.$message({
					                message: '恭喜你，修改成功',
					                type: 'success'
					            });
					        } else {
					            that.$alert(res.msg);
					        }
					    }).catch(err => {
					        that.$utils.loadingClose();
					        that.$alert("网络繁忙，加载失败，请稍等片刻在尝试!", '系统提示');
					    });
					}
				 })
            }
        }
    }
</script>
<style scoped>

</style>
