<style>
    .magiContact{
        width:1000px;
        height:auto!important;
        background-color: #efefef;
        margin:0 auto;
        color:#555;
    }
    .magiTitle{
        width:100%;
        text-align: center;
        font-size:30px;
        margin:70px 0 120px 0;
    }
    .magiSignContent{
        width:580px;
        height:300px;    
        margin:0 auto;
        font-size:20px;
    }
    .magiSignPlace{
        display: flex;
        flex-direction: row;
        margin-bottom:40px;
    }
    .magijiafang{
        width:80px;
        text-align-last: justify    
    }
    .magibtnLine{
        border-bottom:1px solid #666666 !important;
        color:#666666;
        margin-top:-9px;
    }
    .magiSignPlace input{
        border:none!important;
        background-color:transparent;
        padding:0 2px !important;
        font-size:20px;
    }
    .magiSignPlace .el-input{
        border-radius: 0;
        height:34px;
        border: none !important;
        background-color: transparent !important;
        padding: 0 2px !important;
        text-align: center!important;
    }
    .w465{
        width:465px!important;
    }
    .w133{
        width:133px!important;
    }
    .magiNYR{
        display: flex;
        justify-content: space-between;
    }
    .magiBtmContent{
        width:800px;
        margin:0 auto;
        font-size:20px;
    }
    .jiayisf{
        width:100%;
        display: flex;
        justify-content: space-between;
    }
    .w195{
        width:195px!important;
    }
    .w212{
        width:212px!important;
    }
    .magiRule{
        margin-top:30px;
        text-indent: 40px;
        line-height: 40px;
    }
    .magiComTitle{
        font-size:25px;
        margin:30px 0;
    }
    .magiComSecond{
        font-size:22px;
        margin:20px 0;
    }
    .magiDingyi{
        margin-left:20px;
        line-height: 40px;
    }
    .magiDingyi>div{
        margin-bottom:20px;
    }
    .magiDingyi input {
        border: none!important;
        background-color: transparent;
        padding: 0 2px !important;
    }
    .magiLastNYR{
        display: flex;
        flex-direction: row;
    }
    .w60{
        width:60px!important;
    }
    .magiLastNYR input{
        border: none!important;
        background-color: transparent;
        padding: 0 2px !important;
        text-align: center;
        font-size:20px;
    }
    .saveMagiBtn{
        color: #fff;
        padding: 0 20px;
        height: 30px;
        background: #E95252;
        border: 1px solid #E95252;
        cursor: pointer;
        border-radius: 15px;
        margin-left: 10px;
    }
    .saveMagDiv{
        margin:30px 0;
        text-align: center;
    }
    .magiContact .zindex{
        z-index: 9999!important;
        opacity: 1!important;
    }

    .magiContact .signature{
        width:600px;
        background: #fff;
        padding:15px;
        border-radius: 20px;
        cursor: pointer;
    }
    .magiContact .Sign{
        position: fixed;
        width:100%;
        height:100%;
        top:0;
        left:0;
        background: rgba(0,0,0,.4);
        z-index: -500;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0;
    }
    .magiContact .Sign .signatureBox {
        width: 100%;
        height: 300px;
        box-sizing: border-box;
        overflow: hidden;
        background: #fff;
        z-index: 100;
        display: flex;
        flex-direction: column;
        margin-top:20px;
        padding:0 20px;
        box-sizing: border-box;
    }
    .magiContact .Sign .canvasBox {
        box-sizing: border-box;
        flex: 1;
    }
    .magiContact .Sign canvas {
        border: 1px solid #7d7d7d;
    }
    .magiContact .Sign .btnBox {
        padding: 10px;
        text-align: center;
    }
    .magiContact .Sign .btnBox button:first-of-type {
        background: transparent;
        border-radius: 4px;
        height: 40px;
        width: 80px;
        font-size: 14px;
    }
    .magiContact .Sign .btnBox button:last-of-type {
        background: #71b900;
        color: #fff;
        border-radius: 4px;
        height: 40px;
        width: 80px;
        font-size: 14px;
    }
    .MagiSign{
        width:100px;
    }
</style>
<template>
    <div class="magiContact">
        <div class="magiTitle">麦子ERP使用协议书</div>
        <div class="magiSignContent">
            <div class="magiSignPlace">
                <div class="magijiafang">甲方</div>:
                <div class="magibtnLine">
                    <el-input type="text" class="w465" value="成都微途科技有限公司"></el-input>
                </div>
            </div>
            <div class="magiSignPlace">
                <div class="magijiafang">乙方</div>:
                <div class="magibtnLine">
                    <el-input type="text" class="w465" v-model="msg.CustomerName"></el-input>
                </div>
            </div>
            <div class="magiSignPlace">
                <div class="magijiafang">签订日期</div>:
                <div class="magiNYR">
                    <div class="magibtnLine">
                        <el-input type="text" class="w133" v-model="SignYear"></el-input>
                    </div>
                    年
                    <div class="magibtnLine">
                        <el-input type="text" class="w133" v-model="SignMonth"></el-input>
                    </div>
                    月
                    <div class="magibtnLine">
                        <el-input type="text" class="w133" v-model="SignDate"></el-input>
                    </div>
                    日
                </div>
            </div>
        </div>
        <div class="magiBtmContent">
            <div class="jiayisf">
                <div>
                    甲方:成都微途科技有限公司
                </div>
                <div>
                    营业执照:915101060776915321
                </div> 
            </div>
            <div class="jiayisf" style="margin-top:30px;">
                <div class="magiSignPlace">
                    <div>乙方:</div>
                    <div class="magibtnLine">
                        <el-input type="text" class="w195" v-model="msg.CustomerName"></el-input>
                    </div>
                </div>
                <div class="magiSignPlace">
                    <div>营业执照:</div>
                    <div class="magibtnLine">
                        <el-input type="text" class="w212" v-model="msg.BusinessLicense"></el-input>
                    </div>
                </div>
            </div>
            <div class="magiRule">
                根据《中华人民共和国合同法》以及其它相关法律、法规的规定,本着平等互利的原则, 甲、乙双方就合作开展_麦子ERP系统_软件的免费应用,特订立本合同,并共同遵守下列条款:
            </div>
            <div class="magiComTitle">一、定义</div>
            <div class="magiDingyi">
                <div>除非本合同的条款或者内容中另有规定,下列名词具有如下意义:</div>
                <div>1、软件产品:指甲方提供的《麦子ERP系统》的SaaS版本</div>
                <div>2、知识产权:指依据中国有关法律和国际条约规定权利人所享有的专利权、版权(著作权)、商标权、商业信誉和商业秘密权。</div>
                <div>3、技术支持:应软件用户的要求,为用户解决软件应用过程中产生的各种技术问题。</div>
                <div>4、售后服务:指为乙方及乙方用户提供软件维护、升级等其它服务。</div>
                <div>5、补充协议及附件:指主合同的补救条款或从合同等,与主合同具有同样的效力。</div>
            </div>
            <div class="magiComTitle" style="margin-top:50px;">二、合同期限</div>
            <div class="magiDingyi">
                <div>本合同规定“麦子ERP系统”软件基础版免费使用期限为:</div>
                <div class="magiLastNYR">
                    <div class="magibtnLine" style="margin-top:0;">
                        <el-input type="text" class="w60" v-model="SYear"></el-input>
                    </div>
                    年
                    <div class="magibtnLine" style="margin-top:0;">
                        <el-input type="text" class="w60" v-model="SMonth"></el-input>
                    </div>
                    月
                    <div class="magibtnLine" style="margin-top:0;">
                        <el-input type="text" class="w60" v-model="SDate"></el-input>
                    </div>
                    日
                    <div style="margin-left:20px;">至</div>
                    <div class="magibtnLine" style="margin-top:0;">
                        <el-input type="text" class="w60" v-model="EYear"></el-input>
                    </div>
                    年
                    <div class="magibtnLine" style="margin-top:0;">
                        <el-input type="text" class="w60" v-model="EMonth"></el-input>
                    </div>
                    月
                    <div class="magibtnLine" style="margin-top:0;">
                        <el-input type="text" class="w60" v-model="EDate"></el-input>
                    </div>
                    日
                </div>
            </div>
            <div class="magiComTitle">三、费用及结算模式</div>
            <div class="magiRule">
                经甲乙双方协商一致,乙方使用软件产品的基础功能为免费使用,若乙方需要使用其他增值功能,需要和甲方另行签订协议。
            </div>
            <div class="magiComTitle" style="margin-bottom:0;">四、双方的权利和责任</div>
            <div class="magiComSecond" style="margin-top:0;">(一)甲方的权利和责任</div>
            <div class="magiDingyi">
                <div>1、甲方向乙方提供软件产品和运行环境。</div>
                <div>2、甲方保障系统的稳定运行和BUG的及时修复。</div>
                <div>3、甲方可以向乙方提供单独付费的定制化开发或服务内容。</div>
                <div>4、甲方有权要求乙方保证系统的知识产权。乙方不得将系统转借非乙方企业成员使用</div>
                <div>5、甲方可以为乙方提供全方位技术支持。由此产生的甲方工作人员的交通住宿费用由乙方承担。</div>
                <div>6、 甲方需保障乙方的数据安全,不可泄露任何乙方数据为给非乙方工作人员。</div>
            </div>
            <div class="magiComSecond">(二)乙方的权利和责任</div>
            <div class="magiDingyi">
                <div>1、乙方使用本系统,必须遵守国家互联网信息管理相关法律、法规、条例。乙方对其经营行为和信息发布时因违反上述规定而引起的任何政治、经济、法律责任承担全部责任。</div>
                <div>2、乙方须对系统使用账号严格保存,禁止非乙方公司员工拥有该系统账户,员工离职后,及时禁用其账户,如因乙方泄露账号密码,造成的数据安全问题,甲方概不负责。</div>
                <div>3、乙方可以在周一至周五(9:30-18:00)联系甲方技术支持代表解决系统问题。若乙方升级至定制化用户可以调整为周一至周日(9:30-21:30)</div>
            </div>
            <div class="magiComTitle">五、合同的解除与终止</div>
            <div class="magiRule">
                双方协商一致可以解除本合同。另外,本合同在下列情形下也可以解除,但提出解除的一方应提前一个月以书面形式通知对方:            
            </div>
            <div style="line-height:40px;">
                <div>
                    1、因合同一方经营状况出现重大困难,濒临破产进入法定整顿期间或被清算,另一方可以解除本协议。
                </div>
                <div>
                    2、因合同一方未履行合同义务或违约,另一方经书面告知给予一定期限仍不履行或不予采取补救措施,致使另一方合同预期利益无法实现或无继续履行必要,另一方有权解除本合同。
                </div>
                <div>
                    3、本合同期限届满,双方未续签的,合同解除或合同到期自然终止,双方仍应履行未完毕之合同义务,安排售出产品的售后服务事项。同等条件下,乙方有优先续约权利。
                </div>
            </div>
            <div class="magiComTitle">六、违约责任</div>
            <div class="magiDingyi">
                <div>1、乙方若违反协议约定,侵犯甲方知识产权,需承担不低于贰拾万元整的经济损失。</div>
                <div>2、若一方违约给另一方造成损失的,除赔偿损失外,另需承担其它违约责任。</div>
                <div>3、因一方履约不当给第三方造成损失的,应自行承担赔偿责任。</div>
            </div>
            <div class="magiComTitle">七、争议解决</div>
            <div class="magiDingyi">
                <div>甲、乙双方之间因履行本合同或因本合同任何条款的解释与适用而发生任何争议,甲、乙双方应通过友好协商解决。如协商不能解决,任何一方有权向有管辖权的人民法院起诉。</div>
            </div>
            <div class="magiComTitle">八、其它</div>
            <div class="magiDingyi">
                <div>1、凡涉及本代理合同补充、变更、解除等事宜,双方均可进行协商并签署补充协议作为合同附件。合同附件与本合同具有同等法律效力。</div>
                <div>2、本合同一式贰份,双方各执壹份,签字盖章后生效,具有同等法律效力。</div>
            </div>
            <div style="margin:60px 0;">本公司尚有"选配功能"."增值功能"."附加服务"三项优质产品,欢迎选购</div>
            <div class="jiayisf">
                <div>
                    甲方授权代表(签章):
                </div>
                <div style="display:flex">
                    乙方授权代表(签章):<img class="MagiSign" :src="msg.CustomerSignImg" v-if="msg.CustomerSignImg!=''"/>
                    <a style="text-decoration:none;" v-else href="javascript:void(0);" @click="SetPic()">签名</a>
                </div> 
            </div>
            <div class="jiayisf" style="margin:30px 0">
                <div class="magiLastNYR">
                    <div class="magibtnLine">
                        <el-input type="text" class="w60" v-model="JYear"></el-input>
                    </div>
                    年
                    <div class="magibtnLine">
                        <el-input type="text" class="w60" v-model="JMonth"></el-input>
                    </div>
                    月
                    <div class="magibtnLine">
                        <el-input type="text" class="w60" v-model="JDate"></el-input>
                    </div>
                    日
                </div>
                <div class="magiLastNYR">
                    <div class="magibtnLine">
                        <el-input type="text" class="w60" v-model="YYear"></el-input>
                    </div>
                    年
                    <div class="magibtnLine">
                        <el-input type="text" class="w60" v-model="YMonth"></el-input>
                    </div>
                    月
                    <div class="magibtnLine">
                        <el-input type="text" class="w60" v-model="YDate"></el-input>
                    </div>
                    日
                </div>
            </div>
            <div class="saveMagDiv">
                <input type="button" class="saveMagiBtn" value="保存" @click="SaveInfo()"/>
            </div>
        </div>

                <!-- 签名 -->
        <div class="Sign" :class="signState?'zindex':''">
            <div class="signature">
                <p class="f14" style="padding:10px 10px 10px 0">签名
                    <span @click="CloseSign" style="float:right" class="el-icon-close"></span>
                </p>
                <div class="signatureBox">
                    <div class="canvasBox" ref="canvasHW">
                        <canvas ref="canvasF" @mousedown="mouseDown" @mousemove="mouseMove" @mouseup="mouseUp"></canvas>
                        <div class="button" style="text-align:center;margin-top:20px">
                            <el-button size="small"  @click="overwrite">重写</el-button>
                            <el-button size="small" type="danger" @click="commit">提交</el-button>
                        </div>   
                    </div>
                </div>
            </div>   
        </div>

    </div>
</template>
<script>
import moment from 'moment'
export default {
    data() {
      return {
          msg:{
            Id:0,
            CustomerName:'', //乙方名称
            SignDate:'', //签订日期
            BusinessLicense:'',  //营业执照
            ContractStartDate:'',  // 合同开始日期
            ContractEndDate:'',  //合同结束日期
            ViittoSignImg:'',  //微途签章图片
            ViittoSignDate:'',  //微途签订日期
            CustomerSignImg:'',  //客户签章图片
            CustomerSignDate:'',  //客户签订日期
          },
          SignYear:'', //签约日期年
          SignMonth:'', //签约日期月
          SignDate:'', //签约日期日

          SYear:'', //使用开始年
          SMonth:'',  //使用开始月
          SDate:'',  //使用开始日

          EYear:'', //使用结束年
          EMonth:'', //使用结束月
          EDate:'',  //使用结束日

          JYear:'', //甲方签约年
          JMonth:'', //甲方签约月
          JDate:'',  //甲方签约日

          YYear:'', //乙方签约年
          YMonth:'',//乙方签约月
          YDate:'', //乙方签约日

          signState:false,
          startX: 0,
          startY: 0,
          moveY: 0,
          moveX: 0,
          endY: 0,
          endX: 0,
          w: null,
          h: null,
          isDown: false,

      }
    },
    mounted() {
        let canvas = this.$refs.canvasF
        canvas.height = this.$refs.canvasHW.offsetHeight - 100
        canvas.width = this.$refs.canvasHW.offsetWidth - 10
        this.canvasTxt = canvas.getContext('2d')
        this.stageInfo = canvas.getBoundingClientRect()

        if (this.$route.query.Id) {
            this.msg.Id = this.$route.query.Id;
            this.getContract();
        }

    },
    methods: {
        //初始化信息
        getContract(){
            let msg = {
                Id:this.$route.query.Id
            }
            this.apipost("viitto_get_GetEntityService",msg,res => {
                if (res.data.resultCode == 1) {
                    let myData = res.data.data;
                    this.msg.CustomerName = myData.CustomerName;
                    if(myData.SignDate!=null){
                        this.SignYear = moment(myData.SignDate).format("YYYY-MM-DD").split("-")[0];
                        this.SignMonth = moment(myData.SignDate).format("YYYY-MM-DD").split("-")[1];
                        this.SignDate = moment(myData.SignDate).format("YYYY-MM-DD").split("-")[2];
                    }
                    this.msg.BusinessLicense = myData.BusinessLicense;
                    if(myData.ContractStartDate!=null){
                        this.SYear = moment(myData.ContractStartDate).format("YYYY-MM-DD").split("-")[0];
                        this.SMonth = moment(myData.ContractStartDate).format("YYYY-MM-DD").split("-")[1];
                        this.SDate = moment(myData.ContractStartDate).format("YYYY-MM-DD").split("-")[2];
                    }
                    if(myData.ContractEndDate!=null){
                        this.EYear = moment(myData.ContractEndDate).format("YYYY-MM-DD").split("-")[0];
                        this.EMonth = moment(myData.ContractEndDate).format("YYYY-MM-DD").split("-")[1];
                        this.EDate = moment(myData.ContractEndDate).format("YYYY-MM-DD").split("-")[2];
                    }
                    if(myData.ViittoSignDate!=null){
                        this.JYear = moment(myData.ViittoSignDate).format("YYYY-MM-DD").split("-")[0];
                        this.JMonth = moment(myData.ViittoSignDate).format("YYYY-MM-DD").split("-")[1];
                        this.JDate = moment(myData.ViittoSignDate).format("YYYY-MM-DD").split("-")[2];
                    }
                    if(myData.CustomerSignDate!=null){
                        this.YYear = moment(myData.CustomerSignDate).format("YYYY-MM-DD").split("-")[0];
                        this.YMonth = moment(myData.CustomerSignDate).format("YYYY-MM-DD").split("-")[1];
                        this.YDate = moment(myData.CustomerSignDate).format("YYYY-MM-DD").split("-")[2];
                    }
                    this.msg.ViittoSignImg = myData.ViittoSignImg;
                    this.msg.CustomerSignImg = myData.CustomerSignImg;
                } else {
                    this.Error(res.data.message);
                }
            },
                err => {}
            );
        },
        //保存
        SaveInfo(){
            this.msg.SignDate = this.SignYear+"-"+this.SignMonth+"-"+this.SignDate;
            this.msg.ContractStartDate = this.SYear+"-"+this.SMonth+"-"+this.SDate;
            this.msg.ContractEndDate = this.EYear+"-"+this.EMonth+"-"+this.EDate;
            this.msg.ViittoSignDate = this.JYear+"-"+this.JMonth+"-"+this.JDate;
            this.msg.CustomerSignDate = this.YYear+"-"+this.YMonth+"-"+this.YDate;
            this.apipost("viitto_post_SetViittoContractService",this.msg,res => {
                if (res.data.resultCode == 1) {
                    this.Success('保存成功');
                } else {
                    this.Error(res.data.message);
                }
            },
                err => {}
            );
        },
        SetPic(){
            this.overwrite();
            this.signState=true
        },
        CloseSign(){
            this.signState=false;
        },
        // 签名
        //重写
        overwrite() {
            this.canvasTxt.clearRect(0, 0, this.$refs.canvasF.width, this.$refs.canvasF.height)
            this.points = []
        },
        //提交签名
        commit() {
            let that=this;
            let imgUrl =this.$refs.canvasF.toDataURL();
            let newArr = [];
            var fileName = `${that.uuid(10,10)}.png`;
            var path = `/RevenueFile/`;
            newArr.push(this.dataURLtoFile(imgUrl,fileName))
            this.UploadSelfFileT(path, newArr, x => {
                this.msg.CustomerSignImg=that.domainManager().ViittoFileUrl+x.data.FilePath;
            }, 1);
            this.signState=false;
        },

        mouseDown(ev) {
            ev = ev || event
            ev.preventDefault()
            if (1) {
            let obj = {
                x: ev.offsetX,
                y: ev.offsetY
            }
            this.startX = obj.x
            this.startY = obj.y
            this.canvasTxt.beginPath()
            this.canvasTxt.moveTo(this.startX, this.startY)
            this.canvasTxt.lineTo(obj.x, obj.y)
            this.canvasTxt.stroke()
            this.canvasTxt.closePath()
            this.points.push(obj)
            this.isDown = true
            }
        },
        mouseMove(ev) {
            ev = ev || event
            ev.preventDefault()
            if (this.isDown) {
            let obj = {
                x: ev.offsetX,
                y: ev.offsetY
            }
            this.moveY = obj.y
            this.moveX = obj.x
            this.canvasTxt.beginPath()
            this.canvasTxt.moveTo(this.startX, this.startY)
            this.canvasTxt.lineTo(obj.x, obj.y)
            this.canvasTxt.stroke()
            this.canvasTxt.closePath()
            this.startY = obj.y
            this.startX = obj.x
            this.points.push(obj)
            }
        },
        mouseUp(ev) {
            ev = ev || event
            ev.preventDefault()
            if (1) {
            let obj = {
                x: ev.offsetX,
                y: ev.offsetY
            }
            this.canvasTxt.beginPath()
            this.canvasTxt.moveTo(this.startX, this.startY)
            this.canvasTxt.lineTo(obj.x, obj.y)
            this.canvasTxt.stroke()
            this.canvasTxt.closePath()
            this.points.push(obj)
            this.points.push({x: -1, y: -1})
            this.isDown = false
            }
        },
        uuid(len, radix) {
            var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
            var uuid = [],
            i;
            radix = radix || chars.length;
            if (len) {
            // Compact form
            for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
            } else {
            var r;
            uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
            uuid[14] = '4';
            for (i = 0; i < 36; i++) {
                if (!uuid[i]) {
                r = 0 | Math.random() * 16;
                uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                }
            }
            }
            return uuid.join('');
        },
        dataURLtoFile(dataurl, filename) {//将base64转换为文件
            var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
                bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
            while(n--){
                u8arr[n] = bstr.charCodeAt(n);
            }
            return new File([u8arr], filename, {type:mime});
        },
    },
}
</script>