
import { ModuleTypes } from './../types/sceneTypes';
import { Buried } from './../../libs/tw/util/Buried';
import { VisitDetailData } from './../../libs/tw/data/pets/VisitDetailData';
import { PlugWinModel } from './../../libs/tw/model/plug/PlugWinModel';
import { GCache } from './../../libs/tc/util/GCache';
import { WinnersData } from './../../libs/tw/data/common/winners/WinnersData';
import { NetManager } from './../../libs/tw/manager/NetManager';
import { DataManager } from './../../libs/tw/manager/DataManager';
import Scene from "../views/Scene";
import layers from "../../src/views/layers";
import showAlertPanel from "../ctrls/showAlertPanel";
import MovieClipManager from "../ctrls/MovieClipManager";
import Panel from "../views/Panel";
import PanelCtrl from "../ctrls/panelCtrl";
import SceneTransitionAni from '../SceneTransitionAni';
import SceneCtrl from '../ctrls/sceneCtrl';
import GameConst from '../GameConst';
export default class PlayScene extends Scene {
    protected get skinKey() { return 'Play' }

    /**
     * 签到进度条
     */
    private signBar: egret.Sprite;

    //三个交互
    private washBtn: eui.Button;
    private touchBtn: eui.Button;
    private feedBtn: eui.Button;

    public recordBtn: eui.Button;
    public shareBtn: eui.Button;
    public dateBtn: eui.Button;
    public drawGiftTips: eui.Image;

    //添加过的图片池  避免换装时一直new
    private pool = {};

    private propBarHead: eui.Scroller;
    private propBarBody: eui.Scroller;

    private propBarGroupHead: eui.Group;
    private propBarGroupBody: eui.Group;

    private designBtn: eui.Button;

    private vip: eui.Image;

    public bg: eui.Image;

    private signDays = 0;

    //猪当前头部和身体装扮的序号
    private currentHeadNum = null;     //初始无头部
    private currentBodyNum = null;     //初始身体按vip定
    private headArr = [];   //记录当前头部装扮的image    添加到舞台时判断其是否空，移除存在的image，再push进
    private bodyArr = [];   //记录当前身体装扮的image
    private vipLevel = 0;
    private currentPigNum = 0;
    private currentPigStr = "yd";
    private chooseHeadTips;
    private chooseBodyTips;

    private headBtn;
    private bodyBtn;
    private loveValue;
    private loveContainer;

    private bodyPartStrs = ["head", "body", "leftHand", "rightHand", "out", "leftHandExt", "rightHandExt"];
    //运动猪0  臭美猪1  社会猪2
    private dataAll: any = [
        //运动猪
        {
            //头部就一部分，已名称路径标记，不需记录，与body格式区别
            head: [
                { x: -103, y: -278, z: 999, unlockDay: 1 },
                { x: -103, y: -278, z: 999, unlockDay: 3 },
                { x: -88, y: -220, z: 999, unlockDay: 6 },
                { x: -155, y: -270, z: 2, unlockDay: 8 },
                { x: -115, y: -185, z: 2, unlockDay: 11 },
            ],
            //身体部分，，，多部位添加,无字段的表示没有，各部位记录图片路径（保证唯一） group套装     字段  head body leftHand rightHand out
            body: [
                {
                    leftHand: { x: -90, y: 85, z: 999, source: "ydLeftHandOn0_png" },
                    unlockDay: 2
                },
                {
                    body: { x: -76, y: -5, z: 999, source: "ydBodyOn1_png" },
                    head: { x: -85, y: -215, z: 999, source: "ydHeadExtOn1_png" },
                    unlockDay: 4,
                    group: true
                },
                {
                    leftHand: { x: -125, y: -43, z: 999, source: "ydLeftHandOn2_png" },
                    rightHand: { x: 80, y: 100, z: 999, source: "ydRightHandOn2_png" },
                    unlockDay: 5
                },
                {
                    body: { x: -76, y: -10, z: 999, source: "ydBodyOn3_png" },
                    head: { x: -85, y: -215, z: 999, source: "ydHeadExtOn3_png" },
                    unlockDay: 7,
                    group: true
                },
                {
                    leftHand: { x: -180, y: -28, z: 999, source: "ydLeftHandOn4_png" },
                    rightHand: { x: 80, y: 100, z: 999, source: "ydRightHandOn4_png" },
                    unlockDay: 9
                },
                {
                    rightHand: { x: 60, y: 75, z: 999, source: "ydRightHandOn5_png" },
                    out: { x: -200, y: -130, z: 999, source: "ydOutOn5_png" },
                    unlockDay: 10
                },
                {
                    body: { x: -65, y: -40, z: 999, source: "ydBodyOn6_png" },
                    unlockDay: 12
                },
                {
                    leftHand: { x: -140, y: 50, z: 999, source: "ydLeftHandOn7_png" },
                    rightHand: { x: 85, y: 98, z: 999, source: "ydRightHandOn7_png" },
                    unlockDay: 13
                },
                {
                    leftHand: { x: -80, y: 50, z: 999, source: "ydLeftHandOn8_png" },
                    rightHand: { x: 58, y: 58, z: 999, source: "ydRightHandOn8_png" },
                    unlockDay: 14
                },
            ]
        },
        //臭美猪
        {
            head: [

            ],
            body: [

            ],
        },
        //社会猪
        {
            head: [

            ],
            body: [

            ],
        }
    ]

    private petData;
    private isBack: boolean;
    start(data?) {
        //造数据
        // window["currentPigData"] = {
        //     "identifier": "wastonB",     //用来判断vip等级和猪的类型
        //     "alredyReward": false,
        //     "loveValue": 100,
        //     "petLevel": 14,
        //     "usingToys": [        //用来确定头部和身体装扮
        //         "1",
        //         "0"
        //     ]
        // }

        this.isBack = data ? data.isBack : false;

        this.petData = window["currentPigData"];

        //更新数据   根据宠物信息数据
        this.vipLevel = 2;
        this.currentPigNum = 0;

        //猪类型
        switch (this.currentPigNum) {
            case 0:
                this.currentPigStr = "yd"
                break
            case 1:
                this.currentPigStr = "cm"
                break
            case 2:
                this.currentPigStr = "sh"
                break
        }

        this.loveValue = this.petData.loveValue;
        this.signDays = this.petData.petLevel;

        if (this.petData.usingToys && this.petData.usingToys.length) {
            if (this.petData.usingToys[0] != "null") {
                this.currentHeadNum = this.petData.usingToys[0];
            }
            if (this.petData.usingToys[1] != "null") {
                this.currentBodyNum = this.petData.usingToys[1];
            }
        } else {
            this.petData.usingToys = [];
        }
        //根据vip等级给dataAll加入初始数据   
        // unshift
        if (this.vipLevel == 0) {
            // this.dataAll[0].body.shift()
        }
        else if (this.vipLevel == 1) {
            this.dataAll[0].body.push({
                leftHand: { x: -52, y: 0, z: 999, source: "ydLeftHandVip1_png" },
                rightHand: { x: 22, y: 5, z: 999, source: "ydRightHandVip1_png" },
                body: { x: -77, y: -10, z: 999, source: "ydBodyVip1_png" },
                unlockDay: 0
            });
            this.dataAll[1].body.push({ body: { x: 0, y: 0, z: 999 }, unlockDay: 0 });
            this.dataAll[2].body.push({ body: { x: 0, y: 0, z: 999 }, unlockDay: 0 });
            if (!this.petData.usingToys.length) {
                this.currentBodyNum = this.dataAll[this.currentPigNum].body.length - 1;
                this.petData.usingToys[1] = "" + this.currentBodyNum;
            }
        }
        else if (this.vipLevel == 2) {
            this.dataAll[0].body.push({
                leftHand: { x: -55, y: 7, z: 999, source: "ydLeftHandVip2_png" },
                rightHand: { x: 35, y: 10, z: 999, source: "ydRightHandVip2_png" },
                body: { x: -78, y: -8, z: 999, source: "ydBodyVip2_png" },
                // head: { x: -78, y: -20, z: 999, source: "ydHeadVip2_png" },
                unlockDay: 0
            });
            this.dataAll[1].body.push({ body: { x: 0, y: 0, z: 999 }, unlockDay: 0 });
            this.dataAll[2].body.push({ body: { x: 0, y: 0, z: 999 }, unlockDay: 0 });
            if (!this.petData.usingToys.length) {
                this.currentBodyNum = this.dataAll[this.currentPigNum].body.length - 1;
                this.petData.usingToys[1] = "" + this.currentBodyNum;
            }
        }


        egret.Tween.removeAllTweens();

        this.initBuired();

        this.initScene();

        setTimeout(() => {
            //先判断猪等级
            if (!this.isBack) {
                if (this.signDays >= 14) {
                    //猪已14天则出切换弹框
                    PanelCtrl.instance.show(ModuleTypes.SWITCHPIG_PANEL);
                } else {
                    //发签到接口，
                    if (!DataManager.ins.signInfoData.signInfoVO.todaySigned) {
                        NetManager.ins.doSign((s) => {
                            if (s) {
                                this.signComplete();
                                //打卡成功弹框   传this和解锁道具名称

                                let data = { scene: this, unlockToy: '' }
                                PanelCtrl.instance.show(ModuleTypes.PUNCHCARDSUC_PANEL, data);
                            } else {
                                //打卡失败弹框   传入this参数
                                let data = { scene: this }
                                PanelCtrl.instance.show(ModuleTypes.PUNCHCARDFAIL_PANEL, data);
                            }
                        },
                            1111,               //签到活动ID
                            DataManager.ins.gameCfgData.gameInfo.oaId)   //活动ID
                    }
                }
            }

        }, 20)

    }

    // 初始化埋点信息
    initBuired() {
        Buried.init();

        // 炸弹埋点信息
        // let bombDpmOut = Buried.connectDpm(110, 2, 1); // 点击埋点   
        // let bombDcmOut = Buried.connectDcm(202, 0, 0); // 曝光埋点
        // this.bombExposure = Buried.createExposure(bombDpmOut, bombDcmOut);

        // NetManager.ins.showLog(this.addCountExposure);
    }

    initScene() {
        this.percentWidth = 100;
        this.percentHeight = 100;

        //初始化场景
        this.drawGiftTips.x = 900;
        this.drawGiftTips.visible = false;

        //两个选中框
        this.chooseHeadTips = new eui.Image();
        this.chooseHeadTips.source = "wearTips_png";
        this.chooseHeadTips.x = -3;
        this.chooseHeadTips.y = -3;
        this.chooseHeadTips.touchEnabled = false;
        this.chooseBodyTips = new eui.Image();
        this.chooseBodyTips.source = "wearTips_png";
        this.chooseBodyTips.x = -3;
        this.chooseBodyTips.y = -3;
        this.chooseBodyTips.touchEnabled = false;

        //装扮按钮处理
        // this.designBtn.icon="saveWear_png";
        this.designBtn["iconWear"] = "WearBtn_png";
        this.designBtn["iconSave"] = "saveWear_png";

        //vip等级图片
        this.vip.source = "vip" + this.vipLevel + "_png";

        //三个交互按钮隐藏
        this.washBtn.visible = false;
        this.touchBtn.visible = false;
        this.feedBtn.visible = false;

        //根据vip等级替换鞋子图片,根据猪的类型显示
        this.setPigStatus()
        //绑定事件
        this.pig.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_pig, this);

        //爱心条
        setTimeout(() => {
            this.setLove();
        }, 20)


        //顶部进度条
        this.upSignBar();

        //更新进度条，礼盒，


        //头部身体切换按钮
        var headBtn = new eui.Image();
        headBtn.x = 32;
        headBtn.bottom = 172 - 300;
        headBtn["bottomOri"] = 172;
        headBtn.source = "headBtn_png";
        headBtn["sourceOpen"] = "headBtn_png";
        headBtn["sourceClose"] = "headBtn0_png";
        this.addChild(headBtn);
        var bodyBtn = new eui.Image();
        bodyBtn.x = 187;
        bodyBtn.bottom = 172 - 300;
        bodyBtn["bottomOri"] = 172;
        bodyBtn.source = "bodyBtn0_png";
        bodyBtn["sourceOpen"] = "bodyBtn_png";
        bodyBtn["sourceClose"] = "bodyBtn0_png";
        this.addChild(bodyBtn);
        console.log(bodyBtn)
        //默认初始先隐藏身体栏，显示头部栏
        this.propBarBody.visible = false;
        //背景图片更换
        this.bg.source = this.currentPigStr + "Bg_jpg";

        // //猪类型
        // var pigType;
        // switch (this.currentPigNum) {
        //     case 0:
        //         pigType = "yd";
        //         break
        //     case 1:
        //         pigType = "cm";
        //         break
        //     case 2:
        //         pigType = "sh";
        //         break
        // }

        //根据传入猪参数更新两个滚动栏
        //头部
        //滚动条背景
        var bg = new egret.Sprite();
        bg.graphics.beginFill(0x000000, 0.5);
        bg.graphics.drawRoundRect(0, 0, 730, 176, 40);
        bg.graphics.endFill();
        bg.x = 0;
        bg.y = 0;
        this.propBarHead.addChildAt(bg, 0);
        this.propBarHead["bottomOri"] = this.propBarHead.bottom;
        this.propBarHead.bottom = this.propBarHead["bottomOri"] - 300;

        for (var i = 0; i < this.dataAll[this.currentPigNum].head.length; i++) {
            var sprite = new eui.Component();
            var image: eui.Image = new eui.Image();
            image.source = this.currentPigStr + "Head" + i + "_png";
            sprite.x = i * 159 + 30;
            sprite.y = 30;
            sprite.addChild(image);

            var head = this.dataAll[this.currentPigNum].head[i];
            //锁定
            sprite["unlockDay"] = head.unlockDay;
            if (head.unlockDay > this.signDays) {
                var lock: eui.Image = new eui.Image();
                lock.source = "lockMask_png";
                lock.touchEnabled = false;
                sprite.addChild(lock);

            }
            //选中
            else if (this.currentHeadNum == i) {
                sprite.addChild(this.chooseHeadTips);
            }
            this.propBarGroupHead.addChild(sprite)
        }

        //身体
        //滚动条背景
        var bg = new egret.Sprite();
        bg.graphics.beginFill(0x000000, 0.5);
        bg.graphics.drawRoundRect(0, 0, 730, 176, 40);
        bg.graphics.endFill();
        bg.x = 0;
        bg.y = 0;
        this.propBarBody.addChildAt(bg, 0);
        this.propBarBody["bottomOri"] = this.propBarBody.bottom;
        this.propBarBody.bottom = this.propBarBody["bottomOri"] - 300;
        for (var i = 0; i < this.dataAll[this.currentPigNum].body.length; i++) {
            var sprite = new eui.Component();
            var image: eui.Image = new eui.Image();
            if ((this.vipLevel == 1 || this.vipLevel == 2)) {
                if (i == this.dataAll[this.currentPigNum].body.length - 1) {
                    image.source = "vipBody" + this.vipLevel + "_png";
                    sprite.x = 30;
                } else {
                    image.source = this.currentPigStr + "Body" + i + "_png";
                    sprite.x = (i + 1) * 159 + 30;
                }
            } else {
                image.source = this.currentPigStr + "Body" + i + "_png";
                sprite.x = i * 159 + 30;
            }
            sprite.y = 30;
            sprite.addChild(image);
            var body = this.dataAll[this.currentPigNum].body[i];
            //锁定
            sprite["unlockDay"] = body.unlockDay;
            if (body.unlockDay > this.signDays) {
                var lock: eui.Image = new eui.Image();
                lock.source = "lockMask_png";
                lock.touchEnabled = false;
                sprite.addChild(lock);

            }
            //选中
            else if (this.currentBodyNum == i) {
                sprite.addChild(this.chooseBodyTips);
            }
            this.propBarGroupBody.addChild(sprite)
        }
        console.log(this.propBarGroupBody)

        headBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
            if (headBtn.source == headBtn["sourceClose"]) {
                headBtn.source = headBtn["sourceOpen"];
                bodyBtn.source = bodyBtn["sourceClose"];
                this.propBarBody.visible = false;
                this.propBarHead.visible = true;
            }
        }, this);
        bodyBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
            if (bodyBtn.source == bodyBtn["sourceClose"]) {
                bodyBtn.source = bodyBtn["sourceOpen"];
                headBtn.source = headBtn["sourceClose"];
                this.propBarBody.visible = true;
                this.propBarHead.visible = false;
            }
        }, this);

        this.bodyBtn = bodyBtn
        this.headBtn = headBtn
    }

    //打卡成功后逻辑
    public signComplete() {
        //更新签到天数
        this.signDays++;
        //更新宠物等级
        this.petData.petLevel++;
        //更新ui内容  签到完成后更新累计签到文案，进度条，礼盒状态，滚动条解锁情况（加红点），装扮按钮出新物品
        this.updateSignUI();
        //出现打卡成功弹框 传入解锁道具名称

    }

    updateSignUI() {
        console.log(this.petData)
        // 签到文案
        this.signBar["signMsgTxt"].text = `累计打卡${this.petData.petLevel}天`;
        // 进度条
        let mask = new egret.Rectangle(0, 0, 600 * this.petData.petLevel / 14, 10);     //宽度0到600  重新计算
        this.signBar["redline"].mask = mask;
        // 礼盒状态
        if (this.petData.petLevel >= 14) {
            this.signBar["box4"].source = this.signBar["box4"]['sourceOpen'];
            this.signBar["box7"].source = this.signBar["box7"]['sourceOpen'];
            this.signBar["box14"].source = this.signBar["box14"]['sourceOpen'];
        } else if (this.petData.petLevel >= 7) {
            this.signBar["box4"].source = this.signBar["box4"]['sourceOpen'];
            this.signBar["box7"].source = this.signBar["box7"]['sourceOpen'];
        } else if (this.petData.petLevel >= 4) {
            this.signBar["box4"].source = this.signBar["box4"]['sourceOpen'];
        }
        // 滚动条解锁情况（加红点）
        this.signBar["redlinePoint"].x = 0 + 28 - 6 + 600 * this.petData.petLevel / 14;
        // 装扮按钮出新物品
        this.propBarGroupHead.$children.forEach(prop => {
            if (prop['unlockDay'] == this.petData.petLevel) {
                if (prop.$children.length > 1) {
                    // GameConst.removeEle(prop.$children[1], prop.$children);
                    prop['removeChild'](prop.$children[1])
                    let redPoint = new eui.Image();
                    redPoint.source = "redPoint_png";
                    redPoint.x = 100;
                    redPoint.y = -5;
                    prop['addChild'](redPoint);
                }
            }
        })
        this.propBarGroupBody.$children.forEach(prop => {
            if (prop['unlockDay'] == this.petData.petLevel) {
                if (prop.$children.length > 1) {
                    prop['removeChild'](prop.$children[1])
                    let redPoint = new eui.Image();
                    redPoint.source = "redPoint_png";
                    redPoint.x = 100;
                    redPoint.y = -5;
                    console.log(prop)
                    prop['addChild'](redPoint);
                }
            }
        });
    }


    //顶部进度条
    upSignBar() {
        //顶部进度条
        this.signBar = new egret.Sprite();
        this.signBar.graphics.beginFill(0xffffff, 0.8);
        this.signBar.graphics.drawRoundRect(0, 0, 657, 130, 80);
        this.signBar.graphics.endFill();
        this.signBar.x = (750 - 657) / 2
        this.signBar.y = 28
        this.addChild(this.signBar);
        //打卡文案背景
        var signMsgBg = new egret.Sprite();
        signMsgBg.graphics.beginFill(0xffd9d9, 1);
        signMsgBg.graphics.drawRoundRect(0, 0, 170, 40, 50);
        signMsgBg.graphics.endFill();
        signMsgBg.x = 26
        signMsgBg.y = 12
        this.signBar.addChild(signMsgBg);
        //打卡文案
        var signMsgTxt = new egret.TextField();
        signMsgTxt.textColor = 0x212457;
        signMsgTxt.size = 24;
        signMsgTxt.text = "累计打卡0天";
        signMsgTxt.x = 11;
        signMsgTxt.y = 20;
        signMsgTxt.textAlign = egret.HorizontalAlign.CENTER;
        signMsgTxt.width = 200;
        this.signBar.addChild(signMsgTxt);
        this.signBar["signMsgTxt"] = signMsgTxt;
        //浅色进度条
        var redline0 = new eui.Image();
        redline0.x = 28;
        redline0.y = 70;
        redline0.source = `redline0_png`;
        this.signBar.addChild(redline0);
        //深色进度条
        var redline1 = new eui.Image();
        redline1.x = 28;
        redline1.y = 70;
        redline1.source = `redline1_png`;
        this.signBar.addChild(redline1);
        this.signBar["redline"] = redline1;
        var mask = new egret.Rectangle(0, 0, 0, 10);     //宽度0到600  重新计算
        redline1.mask = mask;
        //进度条小球
        var redlinePoint = new eui.Image();   //红点位置注意计算，前后有裁剪
        redlinePoint.x = 0 + 28 - 6;
        redlinePoint.y = 70 - 4;
        redlinePoint.source = `redlinePoint_png`;
        this.signBar.addChild(redlinePoint);
        this.signBar["redlinePoint"] = redlinePoint;
        //礼盒第四天
        var box4 = new eui.Image();
        box4.x = 28 + 600 / 14 * 4 - 30;
        box4.y = 50;
        box4.source = "signInBoxClose0_png";
        box4["sourceOpen"] = "signInBoxOpen0_png";
        box4["sourceClose"] = "signInBoxClose0_png";
        this.signBar.addChild(box4);
        this.signBar["box4"] = box4;
        //礼盒第7天
        var box9 = new eui.Image();
        box9.x = 28 + 600 / 14 * 7 - 20;
        box9.y = 50;
        box9.source = "signInBoxClose1_png";
        box9["sourceOpen"] = "signInBoxOpen1_png";
        box9["sourceClose"] = "signInBoxClose1_png";
        this.signBar.addChild(box9);
        this.signBar["box7"] = box9;
        //礼盒第14天
        var box14: eui.Image = new eui.Image();
        box14.x = 28 + 600 / 14 * 14 - 70;
        box14.y = 40;
        box14.source = "signInBoxClose2_png";
        box14["sourceOpen"] = "signInBoxOpen2_png";
        box14["sourceClose"] = "signInBoxClose2_png";
        this.signBar.addChild(box14);
        this.signBar["box14"] = box14;

        this.updateSignUI();
    }

    //重置猪
    private pig: egret.Sprite;
    private land;
    setPigStatus() {
        this.vipLevel;
        this.currentPigNum;

        switch (this.currentPigNum) {
            case 0:
                this.ydPig();
                break;
            case 1:

                break;
            case 2:

                break;
        }
    }

    // //运动猪
    // ydPig() {
    //     //pig分为主体main和land
    //     var pig = new egret.Sprite();
    //     pig.x = 375;
    //     this.pig = pig;
    //     this.addChild(pig);
    //     //底座
    //     var land = new eui.Image();
    //     land.source = "ydLand_png";
    //     land.anchorOffsetX = 271 / 2;
    //     land.anchorOffsetY = 43 / 2;
    //     pig["land"] = land;
    //     pig.addChild(land);
    //     //主体部分，还是以底座中心为原点
    //     var main = new egret.Sprite();
    //     pig["main"] = main;
    //     pig.addChild(main);
    //     //左手，有装扮，用commp，设置原点
    //     var leftHand = new eui.Component();
    //     leftHand.x = -42;
    //     leftHand.y = -203;
    //     var leftHandImage = new eui.Image();
    //     leftHandImage.source = "ydHandLeft_png";
    //     leftHandImage.x = -68;
    //     leftHand.addChild(leftHandImage)
    //     main["leftHand"] = leftHand;
    //     main.addChild(leftHand);
    //     //右手，有装扮，用com，设置原点
    //     var rightHand = new eui.Component();
    //     rightHand.x = 22;
    //     rightHand.y = -198;
    //     var rightHandImage = new eui.Image();
    //     rightHandImage.source = "ydHandRight_png";
    //     rightHand.addChild(rightHandImage)
    //     main["rightHand"] = rightHand;
    //     main.addChild(rightHand);

    //     //左腿，无装扮，用image，设置锚点
    //     var leftLeg = new eui.Image();
    //     leftLeg.source = "ydLegLeft_png";
    //     leftLeg.anchorOffsetX = 47;
    //     leftLeg.anchorOffsetY = 126;
    //     leftLeg.x = -34;
    //     leftLeg.y = -29;
    //     console.log(leftLeg)
    //     main["leftLeg"] = leftLeg;
    //     main.addChild(leftLeg);

    //     //左脚，不动用image；和vip等级有关
    //     var leftFoot = new eui.Image();
    //     leftFoot.source = "ydFootLeft" + this.vipLevel + "_png";
    //     leftFoot.x = -87;
    //     leftFoot.y = -56;
    //     main["leftFoot"] = leftFoot;
    //     main.addChild(leftFoot);



    //     setTimeout(() => {
    //         this.pig.y = GameConst.stage.stageHeight - 355;
    //     }, 1)



    // }

    //设置爱心值动画
    setLove() {
        this.loveContainer = new egret.Sprite();
        this.loveContainer.x = 510;
        this.loveContainer.touchEnabled = false;
        var bg = new eui.Image();
        bg.source = "loveBg_png";
        this.loveContainer.addChild(bg)
        this.addChild(this.loveContainer);
        //血条
        var blood = new eui.Image();
        blood.alpha = 0.7;
        blood.x = -35;
        blood.y = 0;       //25 dao -35
        // console.log(blood)
        blood.source = "wave0_png";
        blood["sourceAll"] = ["wave0_png", "wave1_png", "wave2_png", "wave3_png", "wave4_png", "wave5_png", "wave6_png", "wave7_png"];
        blood["currentFrame"] = 0;
        blood["allFrame"] = 7;
        this.loveContainer.addChild(blood);
        this.loveContainer["blood"] = blood;
        let mask = new egret.Shape();
        mask.graphics.beginFill(0xff0000, 1);
        mask.graphics.moveTo(41, 69);
        mask.graphics.lineTo(71, 37);
        mask.graphics.cubicCurveTo(79, 20, 58, 0, 41, 13);
        mask.graphics.cubicCurveTo(23, 0, 2, 20, 10, 37);
        mask.graphics.lineTo(41, 69);
        mask.graphics.endFill();
        blood.mask = mask;
        this.loveContainer.addChild(mask);
        //光点
        var light = new eui.Image();
        light.source = "lightPoint_png";
        light.x = 16;
        light.y = 16;
        this.loveContainer.addChild(light);
        //文字
        var text: egret.TextField = new egret.TextField();
        text.text = "0%";
        text.textColor = 0xf21c65;
        text.bold = true;
        text.size = 24;
        text.x = 2;
        text.y = 55;
        text.textAlign = egret.HorizontalAlign.CENTER;
        text.width = 80;
        text.stroke = 3;
        text.strokeColor = 0xffffff;
        this.loveContainer.addChild(text);
        this.loveContainer["cusTxt"] = text;
        // console.log(text)

        //根据数据更新
        blood.y = -(60 / 100) * this.loveValue + 25;
        text.text = this.loveValue + "%";

        setTimeout(() => {

            this.loveContainer.y = GameConst.stage.stageHeight - 550 - 76;
        }, 1)


    }

    initEvents() {
        super.initEvents();
        this.propBarGroupHead.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_propBarGroupHead, this);
        this.propBarGroupBody.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_propBarGroupBody, this);
        this.designBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_designBtn, this);
        this.dateBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_dateBtn, this);
        this.shareBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_shareBtn, this);
        this.drawGiftTips.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_drawGiftTipsBtn, this);
        // this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ele, this);
        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
        //三个交互按钮
        this.washBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_washBtn, this);
        this.touchBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_touchBtn, this);
        this.feedBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_feedBtn, this);

    }

    removeEvents() {
        super.removeEvents();
        this.propBarGroupHead.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_propBarGroupHead, this);
        this.propBarGroupBody.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_propBarGroupBody, this);
        this.designBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_designBtn, this);
        this.dateBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_dateBtn, this);
        this.shareBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_shareBtn, this);
        this.drawGiftTips.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_drawGiftTipsBtn, this);
        // this.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ele, this);
        this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
        //三个交互按钮
        this.washBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_washBtn, this);
        this.touchBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_touchBtn, this);
        this.feedBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_feedBtn, this);
    }

    onTap_dateBtn() {
        SceneCtrl.instance.change(ModuleTypes.CALENDAR_SCENE);
    }

    onTap_shareBtn() {
        PanelCtrl.instance.show(ModuleTypes.SHARE_PANEL)

        let nbg = new eui.Image();
        nbg.source = this.bg.source;
        nbg.x = -375;
        nbg.y = 355 - 1624;
        this.pig.addChildAt(nbg, 0);

        let bottomBg = new eui.Image();
        bottomBg.source = `shareTips_png`;
        bottomBg.x = -375;
        bottomBg.y = 80;
        this.pig.addChildAt(bottomBg, 1);

        let ewm = new eui.Image();
        ewm.source = `ewm_png`;
        ewm.x = 140;
        ewm.y = 110;
        this.pig.addChildAt(ewm, 2);

        let shareTxt = new eui.Label();
        switch (window['currentPigData'].identifier) {
            default:
            case 'wastonA':
                shareTxt.text = `坚持运动 为酷瘦打call`;
                break;
            case 'wastonB':
                shareTxt.text = `每天变美一点点 你就是猪角`;
                break;
            case 'wastonC':
                shareTxt.text = `社会我潮猪 不狠就是潮`;
                break;
        }
        shareTxt.x = -260;
        shareTxt.y = 100;
        shareTxt.size = 32;
        shareTxt.textColor = 0x224791;
        this.pig.addChildAt(shareTxt, 2);

        let saveTips = new eui.Label();
        saveTips.text = `长按保存图片`;
        saveTips.x = -260;
        saveTips.y = 150;
        saveTips.size = 24;
        saveTips.textColor = 0x224791;
        this.pig.addChildAt(saveTips, 2);

        let scanTips = new eui.Label();
        scanTips.text = `扫码马上领养`;
        scanTips.x = -10;
        scanTips.y = 200;
        scanTips.size = 24;
        scanTips.textColor = 0x224791;
        this.pig.addChildAt(scanTips, 2);


        let img = document.getElementById('shareImg');
        img.style.display = 'block';
        img.style.borderRadius = '15px';
        // img.style.border = '3px solid #ffffff';
        let imgData = GameConst.getPrintScreenData(this.pig, -375 + 100, -554, 550, 800);
        GameConst.showImgByImgData(img, imgData, 100, GameConst.stage.stageHeight / 2 - 350, 550, () => {
            this.pig.removeChild(nbg);
            this.pig.removeChild(bottomBg);
            this.pig.removeChild(ewm);
            this.pig.removeChild(shareTxt);
            this.pig.removeChild(saveTips);
            this.pig.removeChild(scanTips);
        })
    }

    onTap_drawGiftTipsBtn() {
        // window['giftId'] = 1234;
        let scope = this;
        this.drawGiftTips.touchEnabled = false;
        GameConst.clearValue(window['currentPigData'].petId);
        NetManager.ins.doJoinPlugDraw((isSuccess) => {
            let tw = egret.Tween.get(scope.drawGiftTips).to({ x: 800 }, 500);
            window['currentPigData'].alredyReward = true;
            if (isSuccess) { // 接口成功
                // 获取订单id，查询是否中奖
                let orderId = DataManager.ins.doJoinPlugDrawData.orderId;
                NetManager.ins.getPlugOrderStatus((success) => {
                    if (success) {
                        // NetManager.ins.getPrizeInfo((success) => {
                        //     if (success) {
                        //         this.lotteryCount = DataManager.ins.getPrizeInfoList[`${this.lotteryId}`].limitCount;
                        //     }
                        // }, this.lotteryId);
                        if (DataManager.ins.getPlugOrderStatusData.lottery) {
                            // 已抽中奖
                            PanelCtrl.instance.show(ModuleTypes.PRIZE_PANEL)
                        } else {
                            // 已经抽过奖
                            PanelCtrl.instance.show(ModuleTypes.NOPRIZE_PANEL);
                        }
                    }
                }, orderId, () => {
                    return (DataManager.ins.getPlugOrderStatusData.result == 0)
                }, 10)
            } else {

            }
        }, window['giftId'])
    }

    // 引导的确认按钮的点击事件
    onTap_propBarGroupHead(e) {
        //根据target.source区分handle
        // console.log(e.target.source);
        if (!e.target || !e.target.source) return
        //截取字符串中的数字  6开始   "ydHead"   注意截取时命名规则，修改注意   ydHead3_png
        var index = e.target.source.indexOf("_");//比如7
        var num = parseInt(e.target.source.substring(6, index))
        var data = this.dataAll[this.currentPigNum].head[num];
        if (data.unlockDay > this.signDays) {
            //锁定的图片，出toast提示未解锁？
            return
        }
        //原先头部穿戴相同则取消穿戴
        var head = this.pig["main"].head;
        if (this.currentHeadNum == num) {
            this.currentHeadNum = null;
            e.target.parent.removeChild(this.chooseHeadTips)
            for (var i = 0; i < this.headArr.length; i++) {
                head.removeChild(this.headArr[i])
            }
            this.headArr = [];
        } else {
            this.currentHeadNum = num;

            e.target.parent.addChild(this.chooseHeadTips);
            //先移除原来的
            for (var i = 0; i < this.headArr.length; i++) {
                head.removeChild(this.headArr[i])
            }
            this.headArr = [];
            //再添加现在的
            var url = this.currentPigStr + "HeadOn" + num + "_png";
            if (!this.pool[url]) {
                this.pool[url] = new eui.Image();
                this.pool[url].source = url;
                this.pool[url].x = data.x;
                this.pool[url].y = data.y;
            }
            head.addChildAt(this.pool[url], data.z);
            this.headArr.push(this.pool[url])
        }
        //记录进全局变量
        this.petData.usingToys[0] = "" + this.currentHeadNum;

        //原先身体是套装的要把套装去掉
        if (this.currentBodyNum != null && this.dataAll[this.currentPigNum].body[this.currentBodyNum].group) {
            this.currentBodyNum = null;
            this.petData.usingToys[1] = "" + this.currentBodyNum;
            if (this.chooseBodyTips.parent) {
                this.chooseBodyTips.parent.removeChild(this.chooseBodyTips)
            }
            for (var i = 0; i < this.bodyArr.length; i++) {
                if (this.bodyArr[i].parent) {
                    this.bodyArr[i].parent.removeChild(this.bodyArr[i])
                }
            }
            this.bodyArr = [];
        }
    }

    onTap_propBarGroupBody(e) {
        //根据target.source区分handle   有vip默认服装时额外区分
        console.log(e.target.source);
        if (!e.target || !e.target.source) return

        var num;
        //有vip默认服装时额外区分    "vipBody1_png"  "vipBody2_png"  num为最后一项
        if (e.target.source.indexOf("vip") >= 0) {
            num = this.dataAll[this.currentPigNum].body.length - 1
        } else {
            //截取字符串中的数字  6开始   "ydBody"   注意截取时命名规则，修改注意   ydBody3_png
            var index = e.target.source.indexOf("_");//比如7
            num = parseInt(e.target.source.substring(6, index))
        }
        var data = this.dataAll[this.currentPigNum].body[num];
        if (data.unlockDay > this.signDays) {
            //锁定的图片，出toast提示未解锁？
            return
        }
        //原先穿戴相同则取消穿戴
        if (this.currentBodyNum == num) {
            this.currentBodyNum = null;
            e.target.parent.removeChild(this.chooseBodyTips)
            for (var i = 0; i < this.bodyArr.length; i++) {
                if (this.bodyArr[i].parent) {
                    this.bodyArr[i].parent.removeChild(this.bodyArr[i])
                }
            }
            this.bodyArr = [];
        } else {
            this.currentBodyNum = num;
            e.target.parent.addChild(this.chooseBodyTips);
            //先移除原来的
            for (var i = 0; i < this.bodyArr.length; i++) {
                if (this.bodyArr[i].parent) {
                    this.bodyArr[i].parent.removeChild(this.bodyArr[i])
                }
            }
            this.bodyArr = [];
            //再添加现在的 所有部位
            for (var j = 0; j < this.bodyPartStrs.length; j++) {
                var str = this.bodyPartStrs[j];   //部位字段
                if (data[str]) {
                    var url = data[str].source;
                    if (!this.pool[url]) {
                        this.pool[url] = new eui.Image();
                        this.pool[url].source = url;
                        this.pool[url].x = data[str].x;
                        this.pool[url].y = data[str].y;
                    }
                    //out额外区分，根据需求，是否一起呼吸  暂不
                    if (str == "out") {
                        this.pig.addChildAt(this.pool[url], data[str].z);
                    } else {
                        this.pig["main"][str].addChildAt(this.pool[url], data[str].z);
                    }
                    this.bodyArr.push(this.pool[url])

                    console.log(this.pool[url])
                }
            }
        }
        //记录进全局变量
        this.petData.usingToys[1] = "" + this.currentBodyNum;

        //如果当前装扮是套装的，要把原先头部的去掉
        if (this.currentBodyNum != null && this.currentHeadNum != null && this.dataAll[this.currentPigNum].body[this.currentBodyNum].group) {
            this.currentHeadNum = null;
            this.petData.usingToys[0] = "" + this.currentHeadNum;
            if (this.chooseHeadTips.parent) {
                this.chooseHeadTips.parent.removeChild(this.chooseHeadTips)
            }
            for (var i = 0; i < this.headArr.length; i++) {
                if (this.headArr[i].parent) {
                    this.headArr[i].parent.removeChild(this.headArr[i])
                }
            }
            this.headArr = [];
        }
    }

    //装扮按钮
    onTap_designBtn() {
        this.designBtn.touchEnabled = false;
        if (this.designBtn.icon == this.designBtn["iconWear"]) {
            //按钮切换为保存
            this.designBtn.icon = this.designBtn["iconSave"];
            //显示操作栏
            this.downAni(this.headBtn, this.headBtn["bottomOri"]);
            this.downAni(this.bodyBtn, this.bodyBtn["bottomOri"]);
            this.downAni(this.propBarHead, this.propBarHead["bottomOri"]);
            this.downAni(this.propBarBody, this.propBarBody["bottomOri"], () => {
                this.designBtn.touchEnabled = true;
            });

        } else {
            //按钮切换为保存
            this.designBtn.icon = this.designBtn["iconWear"];
            //显示操作栏
            this.downAni(this.headBtn, this.headBtn["bottomOri"] - 300);
            this.downAni(this.bodyBtn, this.bodyBtn["bottomOri"] - 300);
            this.downAni(this.propBarHead, this.propBarHead["bottomOri"] - 300);
            this.downAni(this.propBarBody, this.propBarBody["bottomOri"] - 300, () => {
                this.designBtn.touchEnabled = true;
                //发送同步信息接口；并更改 this.petData


            });

        }
    }

    //点击猪
    onTap_pig() {

        //pigAniComplete只在复原到usual状态时为true
        if (!this.pigAniComplete) return;
        this.pigAniComplete = false;
        //点完进入可交互站立状态
        this.pigStatus = false;

    }

    onTap_washBtn() {
        this.washBtn.touchEnabled = false;
        this.threeActionBtnHide();
        //执行动效 回调里切换usual状态  this.pigStatus = true;
        GameConst.addValue(window['currentPigData'].petId, (success) => {
            if (success) {
                // 加爱心成功
                this.updateLoveValue();
            } else {
                // 加爱心不成功
                let msgData = { msg: '啊哦，网络开了小差，请重新尝试互动~', time: 1500, isHideMask: true }
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, msgData);
            }
        })
        this.washAni()
    }
    onTap_touchBtn() {
        this.touchBtn.touchEnabled = false;
        this.threeActionBtnHide();
        GameConst.addValue(window['currentPigData'].petId, (success) => {
            if (success) {
                // 加爱心成功
                this.updateLoveValue();
            } else {
                // 加爱心不成功
                let msgData = { msg: '啊哦，网络开了小差，请重新尝试互动~', time: 1500, isHideMask: true }
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, msgData);
            }
        })
        //执行动效
        this.touchAni()
    }
    onTap_feedBtn() {
        this.feedBtn.touchEnabled = false;
        this.threeActionBtnHide();
        GameConst.addValue(window['currentPigData'].petId, (success) => {
            if (success) {
                // 加爱心成功
                this.updateLoveValue();
            } else {
                // 加爱心不成功
                let msgData = { msg: '啊哦，网络开了小差，请重新尝试互动~', time: 1500, isHideMask: true }
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, msgData);
            }
        })
        //执行动效
        this.feedAni()
    }

    private washAni() {
        setTimeout(() => {

            this.pigStatus = true;
        }, 100)
    }

    private touchAni() {
        setTimeout(() => {


            this.pigStatus = true;
        }, 100)
    }

    private feedAni() {
        //需要替换嘴部，动效位置信息可能有区别
        setTimeout(() => {


            this.pigStatus = true;
        }, 100)
    }

    private downAni(obj, bottom, callback?) {
        let show = egret.Tween.get(obj);
        show.to({ bottom: bottom }, 500).call(() => {
            if (callback) {
                callback();
            }
        });
    }

    updateLoveValue() {
        let scope = this;
        let targetValue = Number(DataManager.ins.getData('addValue').data);
        this.loveValue = targetValue;
        // targetValue
        let value = { value: (this.loveContainer["blood"].y - 25) / -(60 / 100) };
        let tw = egret.Tween.get(value, {
            onChange: () => {
                this.loveContainer["blood"].y = -(60 / 100) * Math.floor(value.value) + 25;
                this.loveContainer["cusTxt"].text = Math.floor(value.value) + "%";
            }
        }).to({ value: targetValue }, 1000).call(() => {
            if (targetValue >= 100 && !window['currentPigData'].alredyReward) {
                scope.drawGiftTips.visible = true;
                let tw2 = egret.Tween.get(scope.drawGiftTips).to({ x: 560 }, 500);
            }
        });
    }

    //显示三个交互按钮    
    private threeActionBtnShow() {
        //初始bottom  812；
        this.washBtn.visible = true;
        this.washBtn.alpha = 0;
        this.washBtn.bottom = 612;
        egret.Tween.get(this.washBtn)
            .to({ alpha: 1 }, 10)
            .to({ bottom: 850 }, 300)
            .to({ bottom: 812 }, 50)
            .call(() => {
                this.washBtn.touchEnabled = true;
            }, this)
        this.touchBtn.visible = true;
        this.touchBtn.alpha = 0;
        this.touchBtn.bottom = 612;
        egret.Tween.get(this.touchBtn)
            .wait(30)
            .to({ alpha: 1 }, 10)
            .to({ bottom: 850 }, 300)
            .to({ bottom: 812 }, 50)
            .call(() => {
                this.touchBtn.touchEnabled = true;
            }, this)
        this.feedBtn.visible = true;
        this.feedBtn.alpha = 0;
        this.feedBtn.bottom = 612;
        egret.Tween.get(this.feedBtn)
            .wait(60)
            .to({ alpha: 1 }, 10)
            .to({ bottom: 850 }, 300)
            .to({ bottom: 812 }, 50)
            .call(() => {
                this.feedBtn.touchEnabled = true;
            }, this)
    }
    //隐藏3个交互按钮   点击任意按钮后就隐藏     执行完交互动效后就返回初始状态   
    private threeActionBtnHide() {
        //初始bottom  812；
        this.washBtn.visible = true;
        egret.Tween.get(this.washBtn)
            .to({ alpha: 0 }, 100)
            .call(() => {
                this.washBtn.visible = false;
            }, this)
        this.touchBtn.visible = true;
        egret.Tween.get(this.touchBtn)
            .to({ alpha: 0 }, 100)
            .call(() => {
                this.touchBtn.visible = false;
            }, this)
        this.feedBtn.visible = true;
        egret.Tween.get(this.feedBtn)
            .to({ alpha: 0 }, 100)
            .call(() => {
                this.feedBtn.visible = false;
            }, this)
    }

    private count = 0;
    onEnterFrame() {
        this.count++;
        if (this.count % 3 == 0) {
            var blood = this.loveContainer["blood"];
            if (blood.currentFrame == blood.allFrame) {
                blood.currentFrame = 0;
            } else {
                blood.currentFrame++;
            }
            blood.source = blood.sourceAll[blood.currentFrame];
        }
    }

    //猪装扮初始  通用
    private pigClothInit() {
        if (this.currentHeadNum != null) {
            var data = this.dataAll[this.currentPigNum].head[this.currentHeadNum];
            var url = this.currentPigStr + "HeadOn" + this.currentHeadNum + "_png";
            if (!this.pool[url]) {
                this.pool[url] = new eui.Image();
                this.pool[url].source = url;
                this.pool[url].x = data.x;
                this.pool[url].y = data.y;
            }
            this.pig["main"].head.addChildAt(this.pool[url], data.z);
            this.headArr.push(this.pool[url])
        }
        if (this.currentBodyNum != null) {
            var data = this.dataAll[this.currentPigNum].body[this.currentBodyNum];
            for (var j = 0; j < this.bodyPartStrs.length; j++) {
                var str = this.bodyPartStrs[j];   //部位字段
                if (data[str]) {
                    var source = data[str].source;
                    if (!this.pool[source]) {
                        this.pool[source] = new eui.Image();
                        this.pool[source].source = source;
                        this.pool[source].x = data[str].x;
                        this.pool[source].y = data[str].y;
                    }
                    this.pig["main"][str].addChildAt(this.pool[source], data[str].z);
                    this.bodyArr.push(this.pool[source])
                    console.log(this.pool[source])
                }
            }

        }

    }

    //状态，一般状态true，站立状态false   交互时都禁止点击
    private pigStatus = true;
    private pigAniComplete = true;


    //******************运动猪分割线*********************************运动猪***********
    ydPig() {
        //pig分为主体main和land
        var pig = new egret.Sprite();
        pig.x = 375;
        this.pig = pig;
        this.addChild(pig);
        //底座
        var land = new eui.Image();
        land.source = "ydLand_png";
        land.anchorOffsetX = 271 / 2;
        land.anchorOffsetY = 43 / 2;
        pig["land"] = land;
        pig.addChild(land);
        //主体部分，还是以底座中心为原点
        var main = new egret.Sprite();
        pig["main"] = main;
        pig.addChild(main);

        //左腿，无装扮，用image，设置锚点
        var leftLeg = new eui.Image();
        leftLeg.source = "ydLegLeft_png";
        leftLeg.anchorOffsetX = 47;
        leftLeg.anchorOffsetY = 126;
        leftLeg.x = -30;
        leftLeg.y = -29;
        main["leftLeg"] = leftLeg;
        main.addChild(leftLeg);

        //右腿，无装扮，用image，设置锚点
        var rightLeg = new eui.Image();
        rightLeg.source = "ydLegRight_png";
        rightLeg.anchorOffsetX = 25;
        rightLeg.anchorOffsetY = 126;
        rightLeg.x = 58;
        rightLeg.y = -45;
        main["rightLeg"] = rightLeg;
        main.addChild(rightLeg);

        //左脚，不动用image；和vip等级有关
        var leftFoot = new eui.Image();
        leftFoot.source = "ydFootLeft" + this.vipLevel + "_png";
        leftFoot.x = -83;
        leftFoot.y = -56;
        main["leftFoot"] = leftFoot;
        main.addChild(leftFoot);
        //右脚，无装扮，用image，设置锚点
        var rightFoot = new eui.Image();
        rightFoot.source = "ydFootRight" + this.vipLevel + "_png";
        rightFoot.anchorOffsetX = 32;
        rightFoot.anchorOffsetY = 35;
        rightFoot.x = 62;
        rightFoot.y = -29;
        main["rightFoot"] = rightFoot;
        main.addChild(rightFoot);

        //左手，有装扮，用commp，设置原点
        var leftHand = new eui.Component();
        leftHand.x = -42;
        leftHand.y = -190;
        var leftHandImage = new eui.Image();
        leftHandImage.source = "ydHandLeft_png";
        leftHandImage.x = -68;
        leftHand.addChild(leftHandImage)
        main["leftHand"] = leftHand;
        main.addChild(leftHand);
        //右手，有装扮，用com，设置原点
        var rightHand = new eui.Component();
        rightHand.x = 22;
        rightHand.y = -198;
        var rightHandImage = new eui.Image();
        rightHandImage.source = "ydHandRight_png";
        rightHand.addChild(rightHandImage)
        main["rightHand"] = rightHand;
        main.addChild(rightHand);

        //肚子，右装扮，用comp，设置原点
        var body = new eui.Component();
        body.x = -3;
        body.y = -189;
        var bodyImage = new eui.Image();
        bodyImage.x = -153 / 2;
        bodyImage.y = -45;
        bodyImage.source = "ydBody_png";
        body.addChild(bodyImage)
        main["body"] = body;
        main.addChild(body);

        //猪头，层级，用comp，设置原点,所有头部东西都加入，所以其他部件都用image
        var head = new egret.Sprite();
        head.x = -1;
        head.y = -177;
        main["head"] = head;
        main.addChild(head);
        //左耳
        var leftEar = new eui.Image();
        leftEar.source = "ydEarLeft_png";
        leftEar.anchorOffsetX = 114;
        leftEar.anchorOffsetY = 102;
        leftEar.x = -43;
        leftEar.y = -336 + 177;
        head["leftEar"] = leftEar;
        head.addChild(leftEar);
        //右耳
        var rightEar = new eui.Image();
        rightEar.source = "ydEarRight_png";
        // rightEar.anchorOffsetX = 114;
        rightEar.anchorOffsetY = 106;
        rightEar.x = 49;
        rightEar.y = -336 + 177;
        head["rightEar"] = rightEar;
        head.addChild(rightEar);
        //脸
        var face = new eui.Image();
        face.source = "ydFace_png";
        face.x = -243 / 2;
        face.y = -266;
        head.addChild(face);
        //眼睛2
        var eye2 = new eui.Image();
        eye2.source = "ydEye2_png";
        eye2.x = -133;
        eye2.y = -171;
        head["eye2"] = eye2;
        head.addChild(eye2);
        //眼睛1
        var eye1 = new eui.Image();
        eye1.source = "ydEye1_png";
        eye1.x = -133;
        eye1.y = -171;
        eye1.alpha = 0;
        head["eye1"] = eye1;
        head.addChild(eye1);
        //眼睛0
        var eye0 = new eui.Image();
        eye0.source = "ydEye0_png";
        eye0.x = -133;
        eye0.y = -171;
        eye0.alpha = 0;
        head["eye0"] = eye0;
        head.addChild(eye0);
        //嘴巴
        var mouth = new eui.Image();
        mouth.source = "ydMouth_png";
        mouth.anchorOffsetX = 56 / 2;
        mouth.anchorOffsetY = 31 / 2;
        mouth.x = 37;
        mouth.y = -68;
        head["mouth"] = mouth;
        head.addChild(mouth);
        //鼻子
        var nose = new eui.Image();
        nose.source = "ydNose_png";
        nose.x = -59;
        nose.y = -183;
        head["nose"] = nose;
        head.addChild(nose);

        //根据数据设置初始时装
        this.pigClothInit();

        //全程固定动效写这
        this.ydPigAniAlways();

        this.ydPigAniUsual();

        setTimeout(() => {
            this.pig.y = GameConst.stage.stageHeight - 355;
        }, 1)
    }

    //运动猪全程动效
    private ydPigAniAlways() {
        var pig = this.pig["main"];
        // 开眼全  初始alph1
        pig.head.eye2.alpha = 1;
        var eye2 = egret.Tween.get(pig.head.eye2, { loop: true });
        eye2.to({ alpha: 1 }, 100)
            .to({ alpha: 0 }, 30)
            .to({ alpha: 1 }, 270)
            .wait(1600);
        // 开眼半  初始alph0
        pig.head.eye1.alpha = 0;
        var eye1 = egret.Tween.get(pig.head.eye1, { loop: true });
        eye1.wait(100)
            .to({ alpha: 1 }, 30)
            .to({ alpha: 1 }, 100)
            .to({ alpha: 0 }, 30)
            .wait(1740);
        // 闭眼  初始alph0
        pig.head.eye0.alpha = 0;
        var eye0 = egret.Tween.get(pig.head.eye0, { loop: true });
        eye0.wait(230)
            .to({ alpha: 1 }, 30)
            .to({ alpha: 1 }, 100)
            .to({ alpha: 0 }, 40)
            .wait(1600);

        //整体
        var pigAllTween = egret.Tween.get(pig, { loop: true });
        pigAllTween.to({ scaleY: 0.99 }, 1000)
            .to({ scaleY: 1 }, 1000)
    }
    //运动猪普通状态动画
    private ydPigAniUsual() {
        var pig = this.pig["main"];
        //猪头
        var head = egret.Tween.get(pig.head, { loop: true });
        head.to({ rotation: -2 }, 160)
            .to({ rotation: 0 }, 170)
            .to({ rotation: -2 }, 170)
            .to({ rotation: 0 }, 160)
            .to({ rotation: -2 }, 170)
            .to({ rotation: 0 }, 170)
            .wait(1000)
            .call(() => {
                if (!this.pigStatus) {
                    this.ydPigUsualToStand();
                }
                //这里统一回调
                // console.log(111)
            }, this)
        //身体   初始位置-3   
        var body = egret.Tween.get(pig.body, { loop: true });
        body.to({ x: 0 }, 160)
            .to({ x: -3 }, 170)
            .to({ x: 0 }, 170)
            .to({ x: -3 }, 160)
            .to({ x: 0 }, 170)
            .to({ x: -3 }, 170)
            .wait(1000);
        //左手
        var leftHand = egret.Tween.get(pig.leftHand, { loop: true });
        leftHand.to({ rotation: 2 }, 160)
            .to({ rotation: 0 }, 170)
            .to({ rotation: 2 }, 170)
            .to({ rotation: 0 }, 160)
            .to({ rotation: 2 }, 170)
            .to({ rotation: 0 }, 170)
            .wait(1000)
        //右手
        var rightHand = egret.Tween.get(pig.rightHand, { loop: true });
        rightHand.to({ rotation: -2 }, 160)
            .to({ rotation: 0 }, 170)
            .to({ rotation: -2 }, 170)
            .to({ rotation: 0 }, 160)
            .to({ rotation: -2 }, 170)
            .to({ rotation: 0 }, 170)
            .wait(1000);
        //左腿
        var leftLeg = egret.Tween.get(pig.leftLeg, { loop: true });
        leftLeg.to({ rotation: 4 }, 160)
            .to({ rotation: 0 }, 170)
            .to({ rotation: 4 }, 170)
            .to({ rotation: 0 }, 160)
            .to({ rotation: 4 }, 170)
            .to({ rotation: 0 }, 170)
            .wait(1000)
        //右腿
        var rightLeg = egret.Tween.get(pig.rightLeg, { loop: true });
        rightLeg.to({ rotation: 2 }, 160)
            .to({ rotation: 0 }, 170)
            .to({ rotation: 2 }, 170)
            .to({ rotation: 0 }, 160)
            .to({ rotation: 2 }, 170)
            .to({ rotation: 0 }, 170)
            .wait(1000);
        //右脚
        var rightFoot = egret.Tween.get(pig.rightFoot, { loop: true });
        rightFoot.to({ rotation: 8 }, 160)
            .to({ rotation: 0 }, 170)
            .to({ rotation: 8 }, 170)
            .to({ rotation: 0 }, 160)
            .to({ rotation: 8 }, 170)
            .to({ rotation: 0 }, 170)
            .wait(1000);
        //嘴   初始位置x:37,y:-68,rotation:0
        pig.head.mouth.rotation = 10;
        pig.head.mouth.x = 37 - 5;
        pig.head.mouth.y = -68 + 2;
        var mouth = egret.Tween.get(pig.head.mouth, { loop: true });
        mouth.to({ rotation: 0, x: 37, y: -68 }, 230)
            // .to({ rotation: 0,x:37,y:-68 }, 1030)
            .wait(1030)
            .to({ rotation: 10, x: 32, y: -66 }, 200)
            .wait(540);
        //左耳
        var leftEar = egret.Tween.get(pig.head.leftEar, { loop: true });
        leftEar.wait(1300)
            .to({ rotation: -4 }, 200)
            .to({ rotation: 0 }, 160)
            .to({ rotation: -4 }, 170)
            .to({ rotation: 0 }, 170)
        //右耳
        var rightEar = egret.Tween.get(pig.head.rightEar, { loop: true });
        rightEar.wait(1300)
            .to({ rotation: 4 }, 200)
            .to({ rotation: 0 }, 160)
            .to({ rotation: 4 }, 170)
            .to({ rotation: 0 }, 170)
    }

    //运动猪从普通状态到站立状态
    private ydPigUsualToStand() {

        //显示交互栏
        this.threeActionBtnShow()

        var pig = this.pig["main"];
        //如果点击了身体，根据标志位，清除特定tween。执行切换动画，及站立时的循环动画
        egret.Tween.removeTweens(pig.head.leftEar);
        egret.Tween.removeTweens(pig.head.rightEar);
        egret.Tween.removeTweens(pig.head.mouth);
        egret.Tween.removeTweens(pig.head);
        egret.Tween.removeTweens(pig.body);
        egret.Tween.removeTweens(pig.leftHand);
        egret.Tween.removeTweens(pig.rightHand);
        egret.Tween.removeTweens(pig.leftLeg);
        egret.Tween.removeTweens(pig.rightLeg);
        egret.Tween.removeTweens(pig.rightFoot);
        //执行切换
        //躯体  初始位置x:-3 y:-189
        egret.Tween.get(pig.body)
            .to({ x: -3 + 17 }, 30)
            .to({ y: -189 + 12 }, 100)
            .to({ y: -189 + 12 - 84 }, 130)
            .to({ y: -189 + 12 }, 120)
            .to({ y: -189 }, 70);
        //左手，位移和躯体一致 -42;-190
        egret.Tween.get(pig.leftHand)
            .to({ x: -42 + 17, rotation: 8 }, 30)
            .to({ y: -190 + 12 }, 100)
            .to({ y: -190 + 12 - 84 }, 130)
            .to({ y: -190 + 12 }, 120)
            .to({ y: -190 }, 70);
        //右手，位移和躯体一致 22;-198
        egret.Tween.get(pig.rightHand)
            .to({ x: 22 + 17, rotation: 7 }, 30)
            .to({ y: -198 + 12, rotation: -4 }, 100)
            .to({ y: -198 + 12 - 84, rotation: 7 }, 130)
            .to({ y: -198 + 12, rotation: -4 }, 120)
            .to({ y: -198, rotation: 7 }, 70);
        //猪头 ，初始位置  -1   -177
        egret.Tween.get(pig.head)
            .to({ x: -1 + 17 }, 30)
            .to({ y: -177 + 7 + 12 }, 100)
            .to({ y: -177 - 84 }, 130)
            .to({ y: -177 + 4 }, 120)
            .to({ y: -177 }, 70);
        //左腿 初始位置 -30 -29
        egret.Tween.get(pig.leftLeg)
            .to({ rotation: 11 }, 30)
            .wait(100)
            .to({ y: -29 - 72 }, 130)
            .to({ y: -29 }, 120)
            .to({ y: -29 }, 70);
        //右腿 初始位置 58 -45
        egret.Tween.get(pig.rightLeg)
            .to({ rotation: 11 }, 30)
            .wait(100)
            .to({ y: -45 - 72 }, 130)
            .to({ y: -45 }, 120)
            .to({ y: -45 }, 70);
        //左脚  初始位置-83 -56
        egret.Tween.get(pig.leftFoot)
            // .to({ rotation: 18 }, 30)
            .wait(130)
            .to({ y: -56 - 72 }, 130)
            .to({ y: -56 }, 120)
            .to({ y: -56 }, 70);
        //右脚  初始位置 62 -29
        egret.Tween.get(pig.rightFoot)
            .to({ rotation: 18 }, 30)
            .wait(100)
            .to({ y: -29 - 72 }, 130)
            .to({ y: -29 }, 120)
            .to({ y: -29 }, 70);
        //地盘
        egret.Tween.get(this.pig["land"])
            .wait(30)
            .to({ scaleX: 1.2, scaleY: 1.2 }, 100)
            .to({ scaleX: 0.8, scaleY: 0.8 }, 130)
            .to({ scaleX: 1.1, scaleY: 1.1 }, 120)
            .to({ scaleX: 1, scaleY: 1 }, 70)
        //左耳
        egret.Tween.get(pig.head.leftEar, { loop: true })
            .wait(30)
            .to({ rotation: 10 }, 100)
            .to({ rotation: -4 }, 130)
            .to({ rotation: -1 }, 120)
            .to({ rotation: 0 }, 70)
            .wait(1300);
        //右耳
        egret.Tween.get(pig.head.rightEar, { loop: true })
            .wait(30)
            .to({ rotation: -10 }, 100)
            .to({ rotation: 4 }, 130)
            .to({ rotation: 1 }, 120)
            .to({ rotation: 0 }, 70)
            .wait(1300)
            .call(() => {
                if (this.pigStatus) {
                    this.ydPigStandToUsual();
                }
            }, this);
    }
    //运动猪从站立到普通状态  反向   在执行完交互后就执行
    private ydPigStandToUsual() {
        //如果点击其他地方，反向复原后执行usual动画
        var pig = this.pig["main"];
        egret.Tween.removeTweens(pig.head.leftEar);
        egret.Tween.removeTweens(pig.head.rightEar);
        //执行切换
        //躯体  初始位置x:-3 y:-189
        egret.Tween.get(pig.body)
            .to({ y: -189 + 12 }, 70)
            .to({ y: -189 + 12 - 84 }, 120)
            .to({ y: -189 + 12 }, 130)
            .to({ y: -189 }, 100)
            .to({ x: -3 }, 30)
        //左手，位移和躯体一致 -42;-190
        egret.Tween.get(pig.leftHand)
            .to({ y: -190 + 12 }, 70)
            .to({ y: -190 + 12 - 84 }, 120)
            .to({ y: -190 + 12 }, 130)
            .to({ y: -190 }, 100)
            .to({ x: -42, rotation: 0 }, 30)
        //右手，位移和躯体一致 22;-198
        egret.Tween.get(pig.rightHand)
            .to({ y: -198 + 12, rotation: -4 }, 70)
            .to({ y: -198 + 12 - 84, rotation: 7 }, 120)
            .to({ y: -198 + 12, rotation: -4 }, 130)
            .to({ y: -198, rotation: 7 }, 100)
            .to({ x: 22, rotation: 0 }, 30)
        //猪头 ，初始位置  -1   -177
        egret.Tween.get(pig.head)
            .to({ y: -177 + 4 }, 70)
            .to({ y: -177 - 84 }, 120)
            .to({ y: -177 + 7 + 12 }, 130)
            .to({ y: -177 }, 100)
            .to({ x: -1 }, 30)
        //左腿 初始位置 -30 -29
        egret.Tween.get(pig.leftLeg)
            .to({ y: -29 }, 70)
            .to({ y: -29 - 72 }, 120)
            .to({ y: -29 }, 130)
            .wait(100)
            .to({ rotation: 0 }, 30)
        //右腿 初始位置 58 -45
        egret.Tween.get(pig.rightLeg)
            .to({ y: -45 }, 70)
            .to({ y: -45 - 72 }, 120)
            .to({ y: -45 }, 130)
            .wait(100)
            .to({ rotation: 0 }, 30)
        //左脚  初始位置-83 -56
        egret.Tween.get(pig.leftFoot)
            .to({ y: -56 }, 70)
            .to({ y: -56 - 72 }, 120)
            .to({ y: -56 }, 130)
            .wait(130)
        //右脚  初始位置 62 -29
        egret.Tween.get(pig.rightFoot)
            .to({ y: -29 }, 70)
            .to({ y: -29 - 72 }, 120)
            .to({ y: -29 }, 130)
            .wait(100)
            .to({ rotation: 0 }, 30)

        //地盘
        egret.Tween.get(this.pig["land"])
            .to({ scaleX: 1.1, scaleY: 1.1 }, 70)
            .to({ scaleX: 0.8, scaleY: 0.8 }, 120)
            .to({ scaleX: 1.2, scaleY: 1.2 }, 130)
            .to({ scaleX: 1, scaleY: 1 }, 100)
            .wait(40)
            .call(() => {
                // this.pig.touchEnabled = true;
                this.pigAniComplete = true;
                this.ydPigAniUsual();
            }, this);
    }




    //******************臭美猪分割线*********************************臭美猪***********
    cmPig() {

    }



    //******************社会猪分割线*********************************社会猪***********
    shPig() {

    }
}