<template>
  <div
    :style="styleData[keyData.helpBargainDiv]"
    v-show="num != 0"
    ref="helpBargain"
    @click="styleClick('click', 'helpBargain')"
    @mousemove="styleClick('mousemove', 'helpBargain')"
    @mouseout="styleClick('mouseout')"
  >
    <div class="helpBargainDiv" :style="styleData[keyData.helpDiv]">
      <div :style="styleData[keyData.helpNum]">已有{{ num }}人帮忙砍价</div>
      <ul :style="styleData[keyData.listDiv]">
        <li
          v-for="(item, index) in firendList"
          :key="index"
          :style="styleData[keyData.itemDiv]"
        >
          <img :src="item.userImg" alt="" :style="styleData[keyData.userImg]" />
          <div :style="styleData[keyData.nickName]">{{ item.nickName }}</div>
          <div :style="styleData[keyData.createTime]">
            {{ item.createTime }}
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import apis1 from "../../../util/apis1.js";
import dateUtil from "../../../util/dateUtil.js";
import { goToShopPage } from "../../../util/tools";
let { bargainFriends } = apis1;
import store from "../../../store/store.js";
export default {
  components: {
    goToShopPage,
  },
  props: ["datas", "styleData", "keyData", "isTemplate", "isWebClick", "modifyContent"],
  data() {
    return {
      isHelper: false, //是否是助力者进入
      dataAll: {},
      num: "",
      helpShow: false,
      firendList: [],
      isCustomSwitching: 1,
      styleDataOld:{}
    };
  },
  mounted() {
    this.isHelper = store.state.shareUserId ? true : false;
    if (!this.isHelper) {
      if (this.isTemplate) {
        this.num = 1;
        this.firendList = [
           {
              nickName: "j**e",
              userImg:
                "http://storage.360buyimg.com/i.imageUpload/6a645f3534626631333762663830656531363030393234393630303432_mid.jpg",
              createTime: 1628835536000,
            },
        ];
        if (this.firendList.length > 0) {
          for (var i = 0; i < this.firendList.length; i++) {
            this.firendList[i].createTime = dateUtil.dateChangeYYYY(
              this.firendList[i].createTime,
              1
            );
          }
        }
        this.publicData.$emit("friendNotifRecord", this.num);
      } else {
        bargainFriends((data) => {
          this.num = data.data.num;
          this.firendList = data.data.friends;

          if (this.firendList.length > 0) {
            for (var i = 0; i < this.firendList.length; i++) {
              this.firendList[i].createTime = dateUtil.dateChangeYYYY(
                this.firendList[i].createTime,
                1
              );
            }
          }

          this.publicData.$emit("friendNotifRecord", this.num);
        });
      }
    }
  },

  methods: {
    initData(data) {
      console.log(data);
      let activityType = sessionStorage.getItem("activityType");
      this.dataAll = data;
    },
     styleClick(type, refName) {
      if (this.isWebClick) {
        //传值给B端
        let byValue = {
          modifyContent: this.modifyContent,
          refName: refName,
          styleData: this.styleData,
          c_this: this,
          isCustomSwitching: this.isCustomSwitching,
          styleDataOld: this.styleDataOld,
        };
        this.$emit("opertaionCom", type, byValue);
      }
    },
  },
  created(){
    //深拷贝重置需要
    this.styleDataOld = JSON.parse(JSON.stringify(this.styleData));
     this.publicData.$on("kanSwitchValue", (isCustomSwitching, refName) => {
        this.isCustomSwitching = isCustomSwitching;
      if(isCustomSwitching == '1') {
        this.num = 1;
      }else if(isCustomSwitching == "2"){
        this.num = 0;
      }else if(isCustomSwitching == "3"){
        this.num = 0;
      }
    });
  }
};
</script>

<style scoped>

ul {
  /*组合选择器*/
  list-style: none; /*清除列表默认样式*/
  padding: 0; /*清除padding*/
  margin: 0;
}
</style>
