index.vue 4.54 KB
Newer Older
程智春 committed
1 2 3
<!-- 文字上下滚动 -->
<template>
  <div
程智春 committed
4
    class="marquee-wrap"
程智春 committed
5
    v-if="targetShow"
程智春 committed
6
    :style="{'top':(datas.componentData.yPosition * 16) +'px'}"
程智春 committed
7 8 9
  >
    <div class="marquee_box">
      <div class="evaluate" :class="animate?'animation_in':'animation_out'">
程智春 committed
10
        <img :src="selectImg" alt />
程智春 committed
11 12 13 14 15 16 17
        <span>{{subName}}刚刚购买了一单</span>
      </div>
    </div>
  </div>
</template>

<script>
程智春 committed
18
import { DFSImg} from '../../../utils/index.js'
程智春 committed
19
let api;
程智春 committed
20

程智春 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
const app = getApp()
export default {
  name: "shop-popup",
  props: {
    render: {
      type: Boolean,
      default: false
    },
    datas: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      targetShow: false,
      selectIndex: 0,
      animate: true,
      selectImg: "",
      selectname: "小工蚁",
      marqueeList: [],
      setTime1: null,
      setTime2: null,
      subName : ''
    };
  },
  created() {},
  mounted() {
      this.init()
  },
  watch : {
    // 'datas.componentData._tempData' : function(newVal){
    //   this.marqueeList = newVal;
    //   this.targetShow = true;
    //   this.play()
    // }
    
  },
  methods: {
    init() {


        clearTimeout(this.setTime1);
        clearTimeout(this.setTime2);
        try {
          // api = require("~/api/orderinfo").default;
          this.ordercustomerinfo();
        } catch (error) {}
    //   if (this.render) {
    //     clearTimeout(this.setTime1);
    //     clearTimeout(this.setTime2);
    //     try {
    //       // api = require("~/api/orderinfo").default;
    //       this.ordercustomerinfo();
    //     } catch (error) {}
    //   } else {
    //     this.targetShow = true;
    //   }
    },
    subName() {
      if (this.selectname.length > 1) {
        return `${this.selectname.substr(0, 1)}****${this.selectname.charAt(
          this.selectname.length - 1
        )}`;
      } else if (this.selectname.length == 1) {
        return `${this.selectname.substr(0, 1)}****`;
      } else {
        return `****`;
      }
    },
    ordercustomerinfo() {
      app.orderApi.ordercustomerinfo({
          page: 1,
          rows: 100
        })
        .then(res => {
          if (res.data.code == 200 && res.data.data.length > 0) {
            this.targetShow = true;
            this.marqueeList = res.data.data;
            this.play();
          }
        });
    },
    play() {
      //赋值
      this.selectname = this.marqueeList[this.selectIndex].customerNickname;
      this.selectImg = this.marqueeList[this.selectIndex].customerHeadImage;

程智春 committed
111 112
      this.selectImg = DFSImg(this.selectImg,300,300)

程智春 committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
        if (this.selectname.length > 1) {
        this.subName =  `${this.selectname.substr(0, 1)}****${this.selectname.charAt(
          this.selectname.length - 1
        )}`;
      } else if (this.selectname.length == 1) {
        this.subName = `${this.selectname.substr(0, 1)}****`;
      } else {
        this.subName = `****`;
      }
    
      this.animate = true;
      clearTimeout(this.setTime1);
      clearTimeout(this.setTime2);
      this.setTime1 = setTimeout(() => {
        this.animate = false;
        this.setTime2 = setTimeout(() => {
          this.selectImg = "";

          //递增
          this.selectIndex++;
          if (this.selectIndex >= this.marqueeList.length) {
            this.selectIndex = 0;
          }
          this.play();
        }, 2000);
      }, 5000);
    }
  },
  deactivated() {
    clearTimeout(this.setTime1);
    clearTimeout(this.setTime2);
  }
};
</script>
<style scoped lang="scss">
程智春 committed
148
.marquee-wrap {
程智春 committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
  font-size: 16px;
  width: 100%;
  align-items: center;
  color: #3a3a3a;
  display: flex;
  box-sizing: border-box;
  overflow: hidden;
  position: fixed;
  left: 0px;
  z-index: 1999;
}
.marquee_box {
  display: block;
  position: relative;
  // height: 30px;
  .evaluate {
    height: 23px;
    line-height: 23px;
    font-size: 14px;
    padding: 0 3px;
    text-decoration: none;
    list-style: none;
    background: rgba(0, 0, 0, 0.3);
    margin-left: 12px;
    color: #ffffff;
    display: flex;
    align-items: center;
    border-radius: 23px;
    img {
      width: 17px;
      height: 17px;
      margin-right: 5px;
      border-radius: 50%;
    }

    opacity: 0;
  }
  .animation_in {
    opacity: 1;
    animation: warn 2s ease;
  }
  .animation_out {
    opacity: 0;
    animation: warn_out 1s ease;
  }
}

@keyframes warn {
  0% {
    opacity: 0;
    margin-top: 30px;
  }
  100% {
    opacity: 1;
    margin-top: 0px;
  }
}
@keyframes warn_out {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
</style>