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';

import { YdPig } from "./YdPig";
import { CmPig } from "./CmPig";
import { ShPig } from "./ShPig";
export default class PlayScene extends Scene {
    protected get skinKey() { return 'Play' }

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

    //三个交互
    private interactionBg: eui.Rect;
    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;

    public iTips: eui.Group;
    public iTipsBg: eui.Image;
    public iTipsTxt: eui.Image;

    public propTips: eui.Group;

    //添加过的图片池  避免换装时一直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 newObjIcon: 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 shareBottomBg;
    private ewm;

    private headBtn;
    private bodyBtn;
    private loveValue;
    private loveContainer;
    private tipsCount: number = 0; // 提示计数

    private bodyPartStrs = ["head", "body", "leftHand", "rightHand", "out", "leftHandDown", "rightHandDown", "leftHandUp", "rightHandUp"];
    //运动猪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: [
                { x: -98, y: -263, z: 999, unlockDay: 1 },
                { x: -93, y: -230, z: 3, unlockDay: 3 },
                { x: -70, y: -295, z: 999, unlockDay: 5 },
                { //定制数据 ，手上有口红，添加进嘴巴0    点击切换和初始化
                    custom: "kouhong",
                    mouth0: { x: 28, y: 37, z: 999, source: "cmHeadOn3_png" },
                    leftHand: { x: -20, y: 40, z: 999, source: "kouhong_png" },
                    leftHandUp: { x: -8, y: -45, z: 0, source: "kouhong0_png" },
                    unlockDay: 6
                },
                { x: -110, y: -220, z: 5, unlockDay: 8 },
                { x: -110, y: -220, z: 5, unlockDay: 10 },
                { x: -58, y: -290, z: 999, unlockDay: 11 },
                { x: -120, y: -96, z: 5, unlockDay: 12 },
                { x: -83, y: -255, z: 999, unlockDay: 13 },
            ],
            body: [
                {
                    body: { x: 25, y: 50, z: 999, source: "cmBodyOn0_png" },
                    unlockDay: 2
                },
                {
                    body: { x: -5, y: 40, z: 999, source: "cmBodyOn1_png" },
                    head: { x: -85, y: -299, z: 999, source: "cmHeadExtOn1_png" },
                    leftHand: { x: 12, y: 0, z: 999, source: "cmLeftHandOn1_png" },
                    rightHand: { x: -12, y: 0, z: 999, source: "cmRightHandOn1_png" },
                    leftHandDown: { x: 34, y: 23, z: 999, source: "cmLeftHandDownOn1_png" },
                    rightHandDown: { x: 0, y: 23, z: 999, source: "cmRightHandDownOn1_png" },
                    group: true,
                    unlockDay: 4
                },
                {
                    body: { x: -2, y: 29, z: 999, source: "cmBodyOn2_png" },
                    leftHand: { x: 3, y: 0, z: 999, source: "cmLeftHandOn2_png" },
                    rightHand: { x: 3, y: 0, z: 999, source: "cmRightHandOn2_png" },
                    leftHandDown: { x: 30, y: 23, z: 999, source: "cmLeftHandDownOn2_png" },
                    rightHandDown: { x: 0, y: 25, z: 999, source: "cmRightHandDownOn2_png" },
                    group: true,
                    unlockDay: 7
                },
                {
                    body: { x: -20, y: 50, z: 999, source: "cmBodyOn3_png" },
                    unlockDay: 9
                },
                {
                    body: { x: -5, y: 50, z: 999, source: "cmBodyOn4_png" },
                    unlockDay: 14
                },
            ],
        },
        //社会猪
        {
            head: [
                { x: -110, y: -265, z: 999, unlockDay: 1 },
                { //定制数据 ，头部两张图片
                    custom: "blackHair",
                    hairUp: { x: -140, y: -290, z: 11, source: "shHeadOn1_png" },
                    hairDown: { x: 26, y: -248, z: 0, source: "shHeadOnDown1_png" },
                    unlockDay: 3
                },
                { x: -118, y: -132, z: 9, unlockDay: 5, isGlasses: true },
                { x: -118, y: -303, z: 999, unlockDay: 6 },
                { x: -30, y: -350, z: 999, unlockDay: 8 },
                { x: -130, y: -125, z: 9, unlockDay: 10, isGlasses: true },
                { x: -118, y: -303, z: 999, unlockDay: 11 },
            ],
            body: [
                {
                    body: { x: 31, y: 52, z: 999, source: "shBodyOn0_png" },
                    unlockDay: 2
                },
                {
                    body: { x: -5, y: 100, z: 1, source: "shBodyOn11_png" },
                    head: { x: -86, y: -225, z: 999, source: "shHeadExtOn11_png" },
                    group: true,
                    unlockDay: 4
                },
                {
                    body: { x: -3, y: 100, z: 1, source: "shBodyOn2_png" },
                    head: { x: -70, y: -225, z: 999, source: "shHeadExtOn2_png" },
                    leftHand: { x: -85, y: 5, z: 999, source: "shHandOn2_png" },
                    group: true,
                    unlockDay: 7
                },
                {
                    out: { x: -190, y: -317, z: 999, source: "shOutOn3_png" },
                    unlockDay: 9
                },
                {
                    body: { x: 15, y: 108, z: 1, source: "shBodyOn4_png" },
                    unlockDay: 12
                },
                {
                    leftHand: { x: -133, y: -15, z: 999, source: "shHandOn5_png" },
                    unlockDay: 13
                },
                {
                    out: { x: -200, y: -55, z: 999, source: "shOutOn6_png" },
                    unlockDay: 14
                },
            ],
        }
    ]


    //埋点
    private exposures;
    private headPropsExposureIndex;
    private bodyPropsExposureIndex;

    private petData;
    private isBack: boolean;
    start(data?) {
        //造数据
        // window["currentPigData"] = {
        //     "petId": 11111,
        //     "vipLevel": 3,
        //     "identifier": "wastonB",
        //     "alredyReward": false,         //爱心值抽奖后更新
        //     "loveValue": 80,           //交互后更新
        //     "petLevel": 13,         //签到打卡成功更新
        //     "usingToys": [        //用来确定头部和身体装扮   更新装扮时更新
        //         "3",
        //         "0",
        //     ]
        // }
        // window["currentPigData"].petLevel=13
        this.isBack = data ? data.isBack : false;

        this.petData = window["currentPigData"];

        //更新数据   vip等级
        this.vipLevel = this.petData.vipLevel - 1;

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

        this.loveValue = this.petData.alredyReward ? 100 : this.petData.loveValue || 0;

        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()
            if (!this.petData.usingToys.length) {
                this.petData.usingToys[0] = "null";
                this.petData.usingToys[1] = "null"
            }
        }
        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: -2, y: 35, z: 999, source: "cmBodyVip1_png" },
                leftHand: { x: 9, y: 0, z: 999, source: "cmLeftHandVip1_png" },
                rightHand: { x: -13, y: 0, z: 999, source: "cmRightHandVip1_png" },
                leftHandDown: { x: 30, y: 20, z: 999, source: "cmLeftHandDownVip1_png" },
                rightHandDown: { x: 0, y: 20, z: 999, source: "cmRightHandDownVip1_png" },
                unlockDay: 0
            });
            this.dataAll[2].body.push({
                body: { x: -4, y: 95, z: 1, source: "shBodyVip1_png" },
                leftHand: { x: -83, y: 5, z: 999, source: "shHandVip1_png" },
                unlockDay: 0
            });
            if (!this.petData.usingToys.length) {
                this.currentBodyNum = this.dataAll[this.currentPigNum].body.length - 1;
                this.petData.usingToys[1] = "" + this.currentBodyNum;
                this.petData.usingToys[0] = "null"
            }
        }
        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" },
                unlockDay: 0
            });
            this.dataAll[1].body.push({
                body: { x: -5, y: 40, z: 999, source: "cmBodyVip2_png" },
                leftHand: { x: 10, y: 2, z: 999, source: "cmLeftHandVip2_png" },
                rightHand: { x: 5, y: 0, z: 999, source: "cmRightHandVip2_png" },
                leftHandDown: { x: 32, y: 28, z: 999, source: "cmLeftHandDownVip2_png" },
                rightHandDown: { x: 12, y: 28, z: 999, source: "cmRightHandDownVip2_png" },
                unlockDay: 0
            });
            this.dataAll[2].body.push({
                head: { x: -87, y: -20, z: 999, source: "shMainVip2_png" },
                body: { x: -5, y: 53, z: 1, source: "shBodyVip2_png" },
                unlockDay: 0
            });
            if (!this.petData.usingToys.length) {
                this.currentBodyNum = this.dataAll[this.currentPigNum].body.length - 1;
                this.petData.usingToys[1] = "" + this.currentBodyNum;
                this.petData.usingToys[0] = "null"
            }
        }


        egret.Tween.removeAllTweens();

        this.initBuired();

        this.initScene();

        //先判断猪等级
        if (!this.isBack) {
            if (this.signDays >= 14) {
                if (DataManager.ins.getData('getAllPetsInfo').data.length >= 3) {
                    //都已养成，展示

                } else {
                    //猪已14天则出切换弹框   且单天未签到，则弹出切换
                    if (!DataManager.ins.signInfoData.signInfoVO.todaySigned) {
                        PanelCtrl.instance.show(ModuleTypes.SWITCHPIG_PANEL);
                    }
                }
            } else {
                //发签到接口，
                if (!DataManager.ins.signInfoData || !DataManager.ins.signInfoData.signInfoVO.todaySigned) {
                    this.doSign();
                }
            }
        }

    }

    doSign() {
        NetManager.ins.doSign((s) => {
            if (s) {
                let signInfoVo = DataManager.ins.signInfoData.signInfoVO;
                //签到天数取余14
                // var signDays=signInfoVo.acmDay%14;
                var signDays = signInfoVo.acmDay ? signInfoVo.acmDay % 14 || 14 : 0;
                //如果4，7，14天时掉插件抽奖
                if (signDays == 4 || signDays == 7 || signDays == 14) {
                    NetManager.ins.doJoinPlugDraw((s) => {
                        if (s) {
                            NetManager.ins.getPlugOrderStatus((suc) => {
                                this.signComplete();
                                if (suc) {
                                    //奖品按钮上加红点,如果原先有红点则不加
                                    if (this.recordBtn.$children.length <= 1) this.addRedPoint(this.recordBtn, 65, -5)
                                }
                            },
                                DataManager.ins.doJoinPlugDrawData.orderId,
                                () => { return DataManager.ins.getPlugOrderStatusData.result == 0; }
                            );
                        }
                        //失败
                        else {
                            this.signComplete();
                        }
                    }, window["pluginIds"]["" + signDays])
                }
                //其他天数
                else {
                    this.signComplete();
                }
            } else {
                //打卡失败弹框   传入this参数
                let data = { scene: this }
                PanelCtrl.instance.show(ModuleTypes.PUNCHCARDFAIL_PANEL, data);
            }
        },
            window['signActivityId'],      //签到活动ID
        )   //插件ID，增加抽奖次数用
    }

    // 初始化埋点信息
    initBuired() {

        this.exposures = {};
        var dpmRecordBtn = Buried.connectDpm(40, 4, 1);
        var dpmDateBtn = Buried.connectDpm(40, 4, 2);
        var dpmShareBtn = Buried.connectDpm(40, 4, 3);
        var dpmDesignBtn = Buried.connectDpm(40, 4, 4);

        var dpmWashBtn = Buried.connectDpm(40, 5, 1);
        var dpmTouchBtn = Buried.connectDpm(40, 5, 2);
        var dpmFeedBtn = Buried.connectDpm(40, 5, 3);

        //爱心值抽奖 
        var dpmDrawGiftTips = Buried.connectDpm(40, 7, 1);

        var dcm = Buried.connectDcm(230, window['skinID'], this.currentPigNum + 1);

        this.exposures["recordBtn"] = Buried.createExposure(dpmRecordBtn, dcm);
        this.exposures["dateBtn"] = Buried.createExposure(dpmDateBtn, dcm);
        this.exposures["shareBtn"] = Buried.createExposure(dpmShareBtn, dcm);
        this.exposures["designBtn"] = Buried.createExposure(dpmDesignBtn, dcm);
        this.exposures["washBtn"] = Buried.createExposure(dpmWashBtn, dcm);
        this.exposures["touchBtn"] = Buried.createExposure(dpmTouchBtn, dcm);
        this.exposures["feedBtn"] = Buried.createExposure(dpmFeedBtn, dcm);

        this.exposures["drawGiftTips"] = Buried.createExposure(dpmDrawGiftTips, dcm);

        this.exposures["props"] = [];
        this.headPropsExposureIndex = [];  //记录的索引值num对应上面的下标
        this.bodyPropsExposureIndex = [];
        //所有道具的埋点1到14根据unlockDay， 0也根据unlockDay。表示初始衣服  注意签到完成时需push一组数据
        var dataPig = this.dataAll[this.currentPigNum]
        //头部
        for (var i = 0; i < dataPig.head.length; i++) {
            //已解锁的道具
            var num = dataPig.head[i].unlockDay
            if (num <= this.signDays) {
                var dpmPropHead = Buried.connectDpm(40, 11, num);
                this.exposures["props"][num] = Buried.createExposure(dpmPropHead, dcm);
                this.headPropsExposureIndex.push(num)
            }
        }
        //身体
        for (var i = 0; i < dataPig.body.length; i++) {
            //已解锁的道具
            var num = dataPig.body[i].unlockDay
            if (num <= this.signDays) {
                var dpmPropBody = Buried.connectDpm(40, 11, num || 15);
                this.exposures["props"][num] = Buried.createExposure(dpmPropBody, dcm);
                this.bodyPropsExposureIndex.push(num)
            }
        }



        //发送曝光埋点
        NetManager.ins.showLog(this.exposures["recordBtn"]);
        NetManager.ins.showLog(this.exposures["dateBtn"]);
        NetManager.ins.showLog(this.exposures["shareBtn"]);
        NetManager.ins.showLog(this.exposures["designBtn"]);

    }

    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等级图片  取cookie
        var str = GameConst.getCookie('dcustom') + "";
        var strs = str.split("&")
        var aaa = "null";
        for (var i = 0; i < strs.length; i++) {
            if (strs[i].indexOf("vip") >= 0) {
                aaa = strs[i]
            }
        }
        let vip = aaa.replace(/[^0-9]/ig, "");
        var userLevel = 1
        if (vip) {
            switch (parseInt(vip)) {
                case 4:
                    userLevel = 1
                    break
                case 8:
                    userLevel = 2
                    break
                case 7:
                    userLevel = 3
                    break
                default:
                    userLevel = 1
                    break
            }
        }
        this.vip.source = "vip" + (userLevel - 1) + "_png";
        // this.vip.source = "vip" + this.vipLevel + "_png";

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


        //爱心条
        this.setLove();

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

        //新物品图标
        this.newObjIcon = new eui.Image();
        this.newObjIcon.source = "newpTips_png";
        this.newObjIcon.x = 660;
        this.newObjIcon.bottom = 408
        this.addChildAt(this.newObjIcon, 5)
        this.newObjIcon.visible = false;

        //更新进度条，礼盒，
        this.updateSignUI();

        //头部身体切换按钮
        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.addChildAt(headBtn, 9);
        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.addChildAt(bodyBtn, 9);
        console.log(bodyBtn)
        //默认初始先隐藏身体栏，显示头部栏
        this.propBarBody.visible = false;

        //背景图片更换
        this.bg.source = this.currentPigStr + "Bg_jpg";

        //根据传入猪参数更新两个滚动栏
        //头部
        //滚动条背景
        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.addChildAt(this.propBarHead, 0)
                //发头部装扮曝光埋点
                for (var m = 0; m < this.headPropsExposureIndex.length; m++) {
                    var index = this.headPropsExposureIndex[m];
                    if (this.exposures["props"][index]) NetManager.ins.showLog(this.exposures["props"][index])
                }
            }
        }, 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.addChildAt(this.propBarBody, 0)
                //发身体装扮曝光埋点
                for (var m = 0; m < this.bodyPropsExposureIndex.length; m++) {
                    var index = this.bodyPropsExposureIndex[m];
                    if (this.exposures["props"][index]) NetManager.ins.showLog(this.exposures["props"][index])
                }
            }
        }, this);

        this.bodyBtn = bodyBtn
        this.headBtn = headBtn

        this.addChild(this.washBtn);
        this.addChild(this.touchBtn);
        this.addChild(this.feedBtn)
        //根据猪的类型显示
        this.setPigStatus();
        //绑定事件
        this.pig.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_pig, this);

        this.shareBottomBg = new eui.Image();
        this.shareBottomBg.source = `shareTips_png`;
        this.shareBottomBg.x = -375;
        this.shareBottomBg.y = 140;
        this.shareBottomBg.visible = false;
        this.pig.addChildAt(this.shareBottomBg, 1);

        this.ewm = new eui.Image();
        this.ewm.source = window['ewmSource'] ? window['ewmSource'] : `ewm_png`;
        this.ewm.width = 120;
        this.ewm.height = 120;
        this.ewm.x = 140;
        this.ewm.y = 110;
        this.pig.addChild(this.ewm);
        this.ewm.visible = false;


    }

    //打卡成功后逻辑
    public signComplete() {
        //更新签到天数
        this.signDays++;
        //更新宠物等级
        this.petData.petLevel++;
        //显示新物品图标
        this.newObjIcon.visible = true

        //更新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) {
                //打卡成功弹框   传this和解锁道具名称
                let data = { scene: this, unlockToy: prop.$children[0]["source"] }
                PanelCtrl.instance.show(ModuleTypes.PUNCHCARDSUC_PANEL, data);
                //新道具埋点
                var dcm = Buried.connectDcm(230, window['skinID'], this.currentPigNum + 1);
                var dpmPropHead = Buried.connectDpm(40, 11, prop['unlockDay']);
                this.exposures["props"][prop['unlockDay']] = Buried.createExposure(dpmPropHead, dcm);
                this.headPropsExposureIndex.push(prop['unlockDay'])
                if (prop.$children.length > 1) {
                    // GameConst.removeEle(prop.$children[1], prop.$children);
                    prop['removeChild'](prop.$children[1])
                    this.addRedPoint(prop, 100, -5);
                }
            }
        })
        this.propBarGroupBody.$children.forEach(prop => {
            if (prop['unlockDay'] == this.petData.petLevel) {
                //打卡成功弹框   传this和解锁道具名称
                let data = { scene: this, unlockToy: prop.$children[0]["source"] }
                PanelCtrl.instance.show(ModuleTypes.PUNCHCARDSUC_PANEL, data);
                //新道具埋点
                var dcm = Buried.connectDcm(230, window['skinID'], this.currentPigNum + 1);
                var dpmPropBody = Buried.connectDpm(40, 11, prop['unlockDay']);
                this.exposures["props"][prop['unlockDay']] = Buried.createExposure(dpmPropBody, dcm);
                this.bodyPropsExposureIndex.push(prop['unlockDay'])
                if (prop.$children.length > 1) {
                    prop['removeChild'](prop.$children[1])
                    this.addRedPoint(prop, 100, -5);
                }
            }
        });
    }

    //新奖品及新道具增加红点逻辑
    addRedPoint(parent, x, y) {
        let redPoint = new eui.Image();
        redPoint.source = "redPoint_png";
        redPoint.x = x;
        redPoint.y = y;
        parent.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.addChildAt(this.signBar, 8);
        //打卡文案背景
        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;
    }

    //重置猪
    private pig: egret.Sprite;

    setPigStatus() {
        this.vipLevel;
        this.currentPigNum;

        switch (this.currentPigNum) {
            case 0:
                // this.threeActionBtnShow.bind(this)
                this.pig = new YdPig();
                break;
            case 1:
                this.pig = new CmPig();
                break;
            case 2:
                this.pig = new ShPig();
                break;
        }
        this.pig["updateFeet"](this.vipLevel)
        this.addChild(this.pig);
        //初始化衣服
        this.pigClothInit();

    }

    //设置爱心值动画
    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 = "wave99_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 + "%";

        //如果用户爱心值满，但是未抽奖，则出现抽奖按钮
        if (this.loveValue >= 100 && !this.petData.alredyReward) {
            this.drawGiftTips.visible = true;
            let tw2 = egret.Tween.get(this.drawGiftTips).to({ x: 560 }, 500);
            //爱心值抽奖按钮曝光埋点
            NetManager.ins.showLog(this.exposures["drawGiftTips"])
        }


        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.recordBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_recordBtn, 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.pig.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_pig, 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.recordBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_recordBtn, 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.pig.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_pig, this);
        // this.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ele, this);
        this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);

        egret.Tween.removeAllTweens();

        //三个交互按钮
        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_recordBtn() {
        //去掉红点逻辑
        if (this.recordBtn.$children[1]) {
            this.recordBtn.removeChild(this.recordBtn.$children[1])
        }
        //路径，四个插件的路径
        var recordUrl = window['recordUrl'];
        var type = "01";
        var ids = [
            window["pluginIds"]["4"],
            window["pluginIds"]["7"],
            window["pluginIds"]["14"],
            window["pluginIds"]["loveValue"]
        ];
        var strPram = recordUrl.match('[\?]') ? '&origins=' : '?origins=';
        let i = 0;
        const len = ids.length;
        recordUrl += strPram;
        for (i; i < len; i++) {
            recordUrl += ids[i] + type;
            //如果不是最后一个id要加,隔开
            if (i != len - 1) {
                recordUrl += ","
            }
        }
        //点击埋点
        NetManager.ins.clickLog(this.exposures["recordBtn"]);
        setTimeout(() => {
            window.location.href = recordUrl;
        }, 1500)

    }

    onTap_dateBtn() {
        //点击埋点
        NetManager.ins.clickLog(this.exposures["dateBtn"]);
        SceneCtrl.instance.change(ModuleTypes.CALENDAR_SCENE);
    }

    onTap_shareBtn() {
        //点击埋点
        NetManager.ins.clickLog(this.exposures["shareBtn"]);
        PanelCtrl.instance.show(ModuleTypes.SHARE_PANEL)

        let nbg = new eui.Image();
        switch (this.petData.identifier) {
            case "wastonA":
                nbg.source = `ydShareBg_png`;
                break
            case "wastonB":
                nbg.source = `cmShareBg_png`;
                break
            case "wastonC":
                nbg.source = `shShareBg_png`;
                break
        }
        nbg.x = -549 / 2;
        nbg.y = 355 - 950;
        this.pig.addChildAt(nbg, 0);

        this.pig.addChildAt(this.shareBottomBg, 1)
        this.shareBottomBg.visible = true;

        // let circleMask = new egret.Graphics();
        // circleMask.drawCircle(125, 35, 70)

        this.ewm.source = window['ewmSource'] ? window['ewmSource'] : `ewm_png`;
        this.ewm.width = 120;
        this.ewm.height = 120;
        this.ewm.x = 125;
        this.ewm.y = 95;
        // this.ewm.mask = circleMask;
        this.pig.addChild(this.ewm);
        this.ewm.visible = true;



        let shareTxt = new eui.Label();
        let randomTxtIdx = '' + Math.min(8, Math.floor(Math.random() * 9));
        switch (randomTxtIdx) {
            default:
            case '0':
                shareTxt.text = `坚持运动 为酷瘦打call`;
                break;
            case '1':
                shareTxt.text = `每天变美一点点 你就是猪角`;
                break;
            case '2':
                shareTxt.text = `社会我潮猪 不狠就是潮`;
                break;
            case '3':
                shareTxt.text = `来呀，和我组成猪队友`;
                break;
            case '4':
                shareTxt.text = `外面风大，跟我回家`;
                break;
            case '5':
                shareTxt.text = `近猪者赤，近你者甜`;
                break;
            case '6':
                shareTxt.text = `你像一头猪，我的掌上明猪`;
                break;
            case '7':
                shareTxt.text = `一看就是养猪人，来包养我`;
                break;
            case '8':
                shareTxt.text = `做猪呢，最重要是开心`;
                break;
        }

        shareTxt.x = -250;
        shareTxt.y = 180;
        shareTxt.size = 30;
        shareTxt.textColor = 0x2a2a2a;
        this.pig.addChildAt(shareTxt, 2);

        let saveTips = new eui.Label();
        saveTips.text = `—`;
        saveTips.alpha = 0.7;
        saveTips.x = -250;
        saveTips.y = 240;
        saveTips.size = 24;
        saveTips.textColor = 0x2a2a2a;
        this.pig.addChildAt(saveTips, 2);

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


        let img = document.getElementById('shareImg');
        img.style.display = 'block';
        img.style.borderRadius = '20px';
        // img.style.border = '3px solid #ffffff';
        let imgData = GameConst.getPrintScreenData(this.pig, -375 + 100, -600, 550, 900);
        GameConst.showImgByImgData(img, imgData, 100, GameConst.stage.stageHeight / 2 - 480, 550, () => {
            this.pig.removeChild(nbg);
            // this.pig.removeChild(this.shareBottomBg);
            this.shareBottomBg.visible = false;
            // this.pig.removeChild(ewm);
            this.ewm.visible = false;
            this.pig.removeChild(shareTxt);
            this.pig.removeChild(saveTips);
            this.pig.removeChild(scanTips);
        })
    }

    onTap_drawGiftTipsBtn() {

        //点击埋点
        NetManager.ins.clickLog(this.exposures["drawGiftTips"]);

        // 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)
                            //奖品按钮加红点
                            if (this.recordBtn.$children.length <= 1) this.addRedPoint(this.recordBtn, 65, -5)
                        } else {
                            // 已经抽过奖
                            PanelCtrl.instance.show(ModuleTypes.NOPRIZE_PANEL);
                        }
                    } else {
                        //爱心值抽奖失败容错
                        let msgData = { msg: '啊哦，网络开了小差~', time: 1500, isHideMask: true }
                        PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, msgData);
                    }
                }, orderId, () => {
                    return (DataManager.ins.getPlugOrderStatusData.result == 0)
                }, 10)
            } else {
                //爱心值抽奖失败容错
                let msgData = { msg: '啊哦，网络开了小差~', time: 1500, isHideMask: true }
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, msgData);
            }
        }, window['pluginIds']["loveValue"])
    }

    //头部切换
    onTap_propBarGroupHead(e) {
        //根据target.source区分handle
        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提示未解锁？
            this.propTips.visible = true;
            this.addChild(this.propTips);
            egret.Tween.get(this.propTips).set({ visible: true, alpha: 0 }).to({ alpha: 1 }, 300).wait(1500).call(() => {
                this.propTips.visible = false;
            })
            return
        }
        //发送点击埋点
        var index = e.target.parent.unlockDay;
        if (this.exposures["props"][index]) NetManager.ins.clickLog(this.exposures["props"][index])
        //原先头部穿戴相同则取消穿戴
        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++) {
                if (this.headArr[i].parent) {
                    this.headArr[i].parent.removeChild(this.headArr[i])
                }
            }
            this.headArr = [];
        } else {
            this.currentHeadNum = num;
            if (e.target.parent.$children[1]) {
                e.target.parent.removeChild(e.target.parent.$children[1])
            }
            e.target.parent.addChild(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 = [];
            //再添加现在的
            if (!data.custom) {
                //常规
                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])
                //社会猪专用眼镜处理
                if (this.currentPigStr == "sh") {
                    head["glasses"].visible = data.isGlasses ? false : true;
                }
                console.log(this.pool[url])
            }
            //口红
            else if (data.custom == "kouhong") {
                //添加进头部的嘴巴
                var url1 = data.mouth0.source;
                if (!this.pool[url1]) {
                    this.pool[url1] = new eui.Image();
                    this.pool[url1].source = url1;
                    this.pool[url1].x = data.mouth0.x;
                    this.pool[url1].y = data.mouth0.y;
                }
                head["mouth0"].addChildAt(this.pool[url1], data.mouth0.z);
                this.headArr.push(this.pool[url1])
                //左手  添加进leftHand和Up
                var url2 = data.leftHand.source;
                if (!this.pool[url2]) {
                    this.pool[url2] = new eui.Image();
                    this.pool[url2].source = url2;
                    this.pool[url2].x = data.leftHand.x;
                    this.pool[url2].y = data.leftHand.y;
                }
                this.pig["main"]["leftHand"].addChildAt(this.pool[url2], data.leftHand.z);
                this.headArr.push(this.pool[url2])
                //
                var url3 = data.leftHandUp.source;
                if (!this.pool[url3]) {
                    this.pool[url3] = new eui.Image();
                    this.pool[url3].source = url3;
                    this.pool[url3].x = data.leftHandUp.x;
                    this.pool[url3].y = data.leftHandUp.y;
                }
                this.pig["main"]["leftHandUp"].addChildAt(this.pool[url3], data.leftHandUp.z)
                this.headArr.push(this.pool[url3])
            }
            //杀马特头发
            else if (data.custom = "blackHair") {
                //头发上
                var url11 = data.hairUp.source;
                if (!this.pool[url11]) {
                    this.pool[url11] = new eui.Image();
                    this.pool[url11].source = url11;
                    this.pool[url11].x = data.hairUp.x;
                    this.pool[url11].y = data.hairUp.y;
                }
                head.addChildAt(this.pool[url11], data.hairUp.z);
                this.headArr.push(this.pool[url11])
                //头发下
                var url22 = data.hairDown.source;
                if (!this.pool[url22]) {
                    this.pool[url22] = new eui.Image();
                    this.pool[url22].source = url22;
                    this.pool[url22].x = data.hairDown.x;
                    this.pool[url22].y = data.hairDown.y;
                }
                head.addChildAt(this.pool[url22], data.hairDown.z);
                this.headArr.push(this.pool[url22])
            }
        }
        //记录进全局变量
        this.petData.usingToys[0] = "" + this.currentHeadNum;

        //原先身体是套装的要把套装去掉  并且头部有装扮
        if (this.currentBodyNum != null
            && this.dataAll[this.currentPigNum].body[this.currentBodyNum].group
            && this.dataAll[this.currentPigNum].body[this.currentBodyNum].head) {
            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提示未解锁？
            this.propTips.visible = true;
            this.addChild(this.propTips);
            egret.Tween.get(this.propTips).set({ visible: true, alpha: 0 }).to({ alpha: 1 }, 300).wait(1500).call(() => {
                this.propTips.visible = false;
            })
            return
        }
        //发送点击埋点
        var index = e.target.parent.unlockDay;
        if (this.exposures["props"][index]) NetManager.ins.clickLog(this.exposures["props"][index])
        //原先穿戴相同则取消穿戴
        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;
            if (e.target.parent.$children[1]) {
                e.target.parent.removeChild(e.target.parent.$children[1])
            }
            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.dataAll[this.currentPigNum].body[this.currentBodyNum].head) {
            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])
                }
            }
            //还原默认眼镜
            if (this.currentPigStr == "sh") {
                this.pig["main"]["head"]["glasses"].visible = true;
            }
            this.headArr = [];
        }
    }

    //装扮按钮
    onTap_designBtn() {
        this.designBtn.touchEnabled = false;
        //隐藏新物品图标
        this.newObjIcon.visible = 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;
            });

            //发曝光埋点
            if (this.headBtn.source == this.headBtn["sourceOpen"]) {
                //发头部装扮曝光埋点
                for (var m = 0; m < this.headPropsExposureIndex.length; m++) {
                    var index = this.headPropsExposureIndex[m];
                    if (this.exposures["props"][index]) NetManager.ins.showLog(this.exposures["props"][index])
                }
            }
            //发身体装扮曝光埋点
            else {
                for (var m = 0; m < this.bodyPropsExposureIndex.length; m++) {
                    var index = this.bodyPropsExposureIndex[m];
                    if (this.exposures["props"][index]) NetManager.ins.showLog(this.exposures["props"][index])
                }
            }
        } 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;
            });
            //发送同步信息接口
            var str = this.petData.usingToys[0] + "," + this.petData.usingToys[1];
            GameConst.updateUsingToys(str, this.petData.petId, (s) => {
                //同步失败出toast
                if (!s) {
                    let msgData = { msg: '啊哦，保存失败，请尝试重新保存~', time: 1500, isHideMask: true }
                    PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, msgData);
                }

            })
        }
    }

    //点击猪
    onTap_pig() {
        console.log(this.pig["aniComplete"])
        this.iTips.visible = false;
        this.isInteracting = !this.isInteracting;
        //pigAniComplete只在复原到usual状态时为true
        if (!this.pig["aniComplete"]) return;
        //显示交互栏
        // setTimeout(()=>{
        //     this.threeActionBtnShow()
        // },1500)
        this.pig["aniComplete"] = false;
        //点完进入可交互站立状态

        if (!this.pig["isStand"]) {
            this.pig["usualToStand"]()
            this.threeActionBtnShow();
        } else {
            this.pig["standToUsual"]()
            this.threeActionBtnHide();
        }

    }

    onTap_washBtn() {
        const scope = this;
        this.pig["aniComplete"] = false;
        //点击埋点
        NetManager.ins.clickLog(this.exposures["washBtn"])
        this.washBtn.touchEnabled = false;
        this.threeActionBtnHide();
        //执行动效
        setTimeout(() => {
            scope.addEventListener(egret.Event.ENTER_FRAME, scope.onEnterFrame, scope);
            scope.isInteracting = false;
        }, 3000)
        this.washAni();
        this.addLoveValue();
    }
    onTap_touchBtn() {
        const scope = this;
        this.pig["aniComplete"] = false;
        //点击埋点
        NetManager.ins.clickLog(this.exposures["touchBtn"])
        this.touchBtn.touchEnabled = false;
        this.threeActionBtnHide();
        //执行动效
        setTimeout(() => {
            scope.addEventListener(egret.Event.ENTER_FRAME, scope.onEnterFrame, scope);
            scope.isInteracting = false;
        }, 3000)
        this.touchAni();
        this.addLoveValue();
    }
    onTap_feedBtn() {
        const scope = this;
        this.pig["aniComplete"] = false;
        //点击埋点
        NetManager.ins.clickLog(this.exposures["feedBtn"])
        this.feedBtn.touchEnabled = false;
        this.threeActionBtnHide();
        //执行动效  喂食操作有区分
        setTimeout(() => {
            scope.addEventListener(egret.Event.ENTER_FRAME, scope.onEnterFrame, scope);
            scope.isInteracting = false;
        }, 3000)
        this.pig["feedAni"]();
        this.addLoveValue();
    }

    addLoveValue() {
        if (this.loveValue >= 100 || window['currentPigData'].alredyReward) return
        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);
            }
        })
    }

    // 更新爱心值
    updateLoveValue() {
        let scope = this;
        let targetValue = Number(DataManager.ins.getData('addValue').data);
        this.loveValue = targetValue;
        // targetValue
        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame2, this);
        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(() => {
            this.loveContainer["blood"].source = `wave99_png`;
            this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame2, this);
            if (targetValue >= 100 && !window['currentPigData'].alredyReward) {
                scope.drawGiftTips.visible = true;
                let tw2 = egret.Tween.get(scope.drawGiftTips).to({ x: 560 }, 500);
                //爱心值抽奖按钮曝光埋点
                NetManager.ins.showLog(this.exposures["drawGiftTips"])
            }
        });
    }

    private clouds = []
    private washAni() {
        if (!this.clouds.length) {
            //初始化7多云
            this.createCloud(390, 700, 0);
            this.createCloud(240, 520, 1);
            this.createCloud(370, 460, 2);
            this.createCloud(200, 400, 2);
            this.createCloud(300, 320, 2);
            this.createCloud(340, 460, 0);
            this.createCloud(430, 380, 1);
        }
        let count = 0;
        for (var i = 0; i < this.clouds.length; i++) {
            let cloud = this.clouds[i];
            this.addChild(cloud);
            var x = cloud["initX"];
            var deta = this.randomT(10, 20) * this.randomT([1, -1]);
            var t = 300
            cloud.x = x - deta
            egret.Tween.get(cloud, { loop: true })
                .to({ x: x + deta }, t)
                .to({ x: x - deta }, t)
            egret.Tween.get(cloud)
                .wait(this.randomT(0, 300))
                .to({ alpha: 1 }, this.randomT(400, 800))
                .wait(this.randomT(2000, 2500))
                .to({ alpha: 0 }, this.randomT(300, 700))
                .call(() => {
                    this.removeChild(cloud)
                    egret.Tween.removeTweens(cloud);
                    count++;
                    //都执行后
                    if (count == this.clouds.length) {
                        this.pig["standToUsual"]()
                    }

                }, this)
        }
    }

    private touchAni() {
        var bool = true;
        let count = 0;
        for (var i = 0; i < 9; i++) {
            let heart = this.takeOut("heart");
            if (!heart) {
                heart = new eui.Image();
                heart.source = "heart1_png";
                heart.anchorOffsetX = 81 / 2;
                heart.anchorOffsetY = 72 / 2;
            }
            bool = !bool
            this.addChild(heart);
            heart.bottom = 350;
            var direction = bool ? 1 : -1;
            heart.x = 375 + direction * this.randomT(0, 50) + 10
            heart.scaleX = heart.scaleY = 0; //先打后小
            heart.alpha = 1;
            egret.Tween.get(heart)
                .wait(i * 70)
                .to({ scaleX: 1.2, scaleY: 1.2 }, 150)
                .to({ scaleX: 1, scaleY: 1 }, 40)
                .to({ bottom: 650 + this.randomT(0, 150) }, 1500 + this.randomT(0, 500), egret.Ease.quadIn)

            egret.Tween.get(heart)
                .wait(i * 100)
                .to({ x: heart.x + direction * this.randomT(100, 230) }, 1500)
                .to({ alpha: 0 }, 500)
                .call(() => {
                    egret.Tween.removeTweens(heart)
                    this.removeChild(heart);
                    this.recover("heart", heart);
                    count++
                    if (count == 9) {
                        this.pig["standToUsual"]()
                    }
                }, this)
        }
    }

    private createCloud(x, bottom, type) {
        var cloud = new eui.Image();
        cloud.alpha = 0;
        cloud.source = "bubble" + type + "_png";
        cloud.bottom = bottom
        cloud.x = x;
        cloud["initX"] = x;
        this.clouds.push(cloud)
    }



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

    //显示三个交互按钮    
    private threeActionBtnShow() {
        //发送交互按钮曝光埋点
        NetManager.ins.showLog(this.exposures["washBtn"]);
        NetManager.ins.showLog(this.exposures["touchBtn"]);
        NetManager.ins.showLog(this.exposures["feedBtn"]);

        var waitTime = 1;
        //初始bottom  862
        var b = 875;
        if (this.currentPigNum == 0) {
            b = 832;
            waitTime = 90
        }
        else if (this.currentPigNum == 1) {
            b = 832;
            waitTime = 370
        }
        this.washBtn.visible = true;
        this.washBtn.alpha = 0;
        this.washBtn.x = 247.44 + 10
        this.washBtn.bottom = b - 200;
        egret.Tween.get(this.washBtn)
            .to({ alpha: 1 }, 10)
            .to({ bottom: b + 40 }, 300)
            .to({ bottom: b }, 50)
            .wait(waitTime)
            .call(() => {
                this.washBtn.touchEnabled = true;
            }, this)
        this.touchBtn.visible = true;
        this.touchBtn.alpha = 0;
        this.touchBtn.x = 373.37 + 10
        this.touchBtn.bottom = b - 200;
        egret.Tween.get(this.touchBtn)
            .wait(30)
            .to({ alpha: 1 }, 10)
            .to({ bottom: b + 40 }, 300)
            .to({ bottom: b }, 50)
            .wait(waitTime)
            .call(() => {
                this.touchBtn.touchEnabled = true;
            }, this)
        console.log(this.touchBtn)
        this.feedBtn.visible = true;
        this.feedBtn.alpha = 0;
        this.feedBtn.x = 498.96 + 10
        this.feedBtn.bottom = b - 200;
        egret.Tween.get(this.feedBtn)
            .wait(60)
            .to({ alpha: 1 }, 10)
            .to({ bottom: b + 40 }, 300)
            .to({ bottom: b }, 50)
            .wait(waitTime)
            .call(() => {
                this.feedBtn.touchEnabled = true;
            }, this)

        this.interactionBg.visible = true;

    }
    //隐藏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)

        this.interactionBg.visible = false;
    }

    private count = 0;
    onEnterFrame2() {
        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 isInteracting = false;
    onEnterFrame() {
        if (!this.isInteracting) {
            this.count++;
            if (this.count % (60 * 6) == 0) {
                console.log(this.count);
                this.removeEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
                this.iTipsTxt.source = `iTips${this.tipsCount}_png`;
                if (this.tipsCount < 5) {
                    this.tipsCount++;
                } else {
                    this.tipsCount = 0;
                }
                this.iTips.visible = true;
                this.iTips.y = this.pig.y - this.pig.height / 2 - 210;
                setTimeout(() => {
                    this.iTips.visible = false;
                    this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this);
                }, 6000)
            }
        }
    }

    //猪装扮初始  通用
    private pigClothInit() {
        //头部
        if (this.currentHeadNum != null) {
            var data = this.dataAll[this.currentPigNum].head[this.currentHeadNum];
            if (!data.custom) {
                //常规
                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.currentPigStr == "sh") {
                    this.pig["main"]["head"]["glasses"].visible = data.isGlasses ? false : true;
                }
            }
            //口红
            else if (data.custom == "kouhong") {
                //添加进头部的嘴巴
                var url1 = data.mouth0.source;
                if (!this.pool[url1]) {
                    this.pool[url1] = new eui.Image();
                    this.pool[url1].source = url1;
                    this.pool[url1].x = data.mouth0.x;
                    this.pool[url1].y = data.mouth0.y;
                }
                this.pig["main"].head["mouth0"].addChildAt(this.pool[url1], data.mouth0.z);
                this.headArr.push(this.pool[url1])
                //左手  添加进leftHand和Up
                var url2 = data.leftHand.source;
                if (!this.pool[url2]) {
                    this.pool[url2] = new eui.Image();
                    this.pool[url2].source = url2;
                    this.pool[url2].x = data.leftHand.x;
                    this.pool[url2].y = data.leftHand.y;
                }
                this.pig["main"]["leftHand"].addChildAt(this.pool[url2], data.leftHand.z);
                this.headArr.push(this.pool[url2])
                //
                var url3 = data.leftHandUp.source;
                if (!this.pool[url3]) {
                    this.pool[url3] = new eui.Image();
                    this.pool[url3].source = url3;
                    this.pool[url3].x = data.leftHandUp.x;
                    this.pool[url3].y = data.leftHandUp.y;
                }
                this.pig["main"]["leftHandUp"].addChildAt(this.pool[url3], data.leftHandUp.z)
                this.headArr.push(this.pool[url3])
            }
            //杀马特头发
            else if (data.custom = "blackHair") {
                //头发上
                var url11 = data.hairUp.source;
                if (!this.pool[url11]) {
                    this.pool[url11] = new eui.Image();
                    this.pool[url11].source = url11;
                    this.pool[url11].x = data.hairUp.x;
                    this.pool[url11].y = data.hairUp.y;
                }
                this.pig["main"].head.addChildAt(this.pool[url11], data.hairUp.z);
                this.headArr.push(this.pool[url11])
                //头发下
                var url22 = data.hairDown.source;
                if (!this.pool[url22]) {
                    this.pool[url22] = new eui.Image();
                    this.pool[url22].source = url22;
                    this.pool[url22].x = data.hairDown.x;
                    this.pool[url22].y = data.hairDown.y;
                }
                this.pig["main"].head.addChildAt(this.pool[url22], data.hairDown.z);
                this.headArr.push(this.pool[url22])
            }
        }
        //身体
        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;
                    }
                    //out额外区分，根据需求，
                    if (str == "out") {
                        this.pig.addChildAt(this.pool[source], data[str].z);
                    }
                    else {
                        this.pig["main"][str].addChildAt(this.pool[source], data[str].z);
                    }
                    this.bodyArr.push(this.pool[source])
                    console.log(this.pool[source])
                }
            }

        }

    }

    //获取数组里的随机值或区间随机值
    private randomT(e, n?) {
        return e && "number" == typeof e.length && e.length ? e[Math.floor(Math.random() * e.length)] : ("number" != typeof n && (n = e || 1, e = 0), e + Math.random() * (n - e))
    }
    //四舍五入取整
    private roundT(n) {
        return (n + 0.5) >> 0
    }

    private takeOut(name) {
        if (this.pool[name] && this.pool[name].length) {
            return this.pool[name].shift();
        }
        return false;
    }
    private recover(name, obj) {
        if (!this.pool[name]) {
            this.pool[name] = [];
        }
        this.pool[name].push(obj);
    }
}