<template>
<view>
<!--components/seckill/seckill.wxml-->
<!-- 秒杀 -->
<template name="seckill">
	<view class="pdlr20">
		<!-- 秒杀 -->
		<view class="mt20 bgfff  r10" v-if="seckillList.products.length > 0">
			<navigator class="head" hover-class="none" :url="'/activity/seckill/seckill' + url">
				<view class="titleNav pdlr20 dflex" v-if="seckillTemplate.titleType==1">
					{{seckillTemplate.titleCon}}
					<image src="/static/pages/images/more.png" class="more"></image>
				</view>
				<image lazy-load="true" v-if="seckillTemplate.titleType==2" :src="seckillTemplate.titleCon + '?x-oss-process=style/w750-auto'" mode="widthFix" class="imgtit"></image>
			</navigator>
			<goodsList :pageList="seckillList" :about="about" :merchant="web" :type="'2'" :typeName="'秒杀'"></goodsList>
<!-- 			<view class="tabcon dflex">
				<block v-for="(item, index) in seckillList" :key="index">
					<view class="li">
						<view class="jsdimgs" @tap="toSeckillList" :data-index="index" :data-url="web">
							<image lazy-load="true" :src="item.pic + '?x-oss-process=style/w375'" mode="aspectFit" class="jsdpro" :data-index="index">
							</image>
						</view>
						<view class="jsdinfo">
							<view class="proname" @tap="toSeckillList" :data-url="web" :data-index="index">{{item.productName}}</view>
							<view class="operate dflex">

								<view class="price proprice" @tap="toSeckillList" :data-url="web" :data-index="index">
									￥<text>{{item.money}}</text><text class="del" v-if="item.marketPrice!=0&&item.marketPrice>item.money">￥{{item.marketPrice}}</text></view>
								<view class="qiang mbglinear" v-if="item.start" @tap="toSeckillList" :data-url="web" :data-index="index">购买
								</view>
								<block v-else>
									<view class="qiang mbggreen" @tap="cancelActivityRemind" :data-index="index" :data-id="item.id" v-if="item.isRemind" data-type="3">已预约</view>
									<view class="qiang mbggreen" @tap="addActivityRemind" :data-index="index" :data-id="item.id" data-type="3" v-else>预约</view>
								</block>
							</view>
						</view>
					</view>
				</block>
			</view> -->
			<!-- 
		<view class="msinfos bgfff r10" wx:for="{{seckillList}}" wx:key="item">
			<image src="{{item.pic + '?x-oss-process=style/w750-auto'}}" mode="aspectFit" bindtap="toSeckillList"
				data-index="{{index}}"></image>
			<view class="msinfo">
				<view class="msname" bindtap="toSeckillList" data-index="{{index}}">{{item.productName}}</view>
				<view class="qgsta dflex">
					<view class="price proprice" bindtap="toSeckillList" data-index="{{index}}">￥<text>{{item.money}}</text><text
							class="del">￥{{item.marketPrice}}</text></view>
					<view class="qiang mbgcolor" wx:if="{{item.start}}" bindtap="toSeckillList" data-index="{{index}}">立即抢购</view>
					<block wx:else>
						<view class="qiang mbggreen" bindtap="cancelActivityRemind" data-index="{{index}}" data-id="{{item.id}}"
							wx:if="{{item.isRemind}}" data-type="3">取消提醒</view>
						<view class="qiang mbggreen" bindtap="addActivityRemind" data-index="{{index}}" data-id="{{item.id}}"
							data-type="3" wx:else>预约提醒</view>
					</block>
				</view>
			</view>
		</view> -->
		</view>
	</view>
</template>
</view>
</template>

<script>
// components/seckill/seckill.js
const route = require("../../utils/route.js");
const utils = require("../../utils/util.js");
const mes = require("../../utils/requestmessage.js");
const req = require("../../utils/request.js");
const app = getApp();
import goodsList from "../../components/goodsList/goodsList";
export default {
  data() {
    return {

    };
  },

  components: {goodsList},
  props: {
	seckillList:Object,
	seckillTemplate:Object,
	web:String,
	url:String,
	about:Object
  },
  watch: {

  },
  methods: {
    getRqeDatas() {
      let that = this; //秒杀

      let seckill = that.homeTemplate.filter(it => it.module == that.templateType.module_seckill);

      if (seckill && seckill.length > 0 && seckill[0].state == 0) {
        that.setData({
          seckillTemplate: seckill[0]
        });
        this.seckillListFun(seckill[0]);
      }
    },

    //秒杀商品
    seckillListFun(seckillTemplate) {
      let _ts = this;

      if (this.merchant && this.merchant.type == 5 || this.shopId && this.merchantId) {
        let from = {
          page: this.page,
          limit: seckillTemplate.number,
          type: 3,
          merchantId: this.merchant.merchantDTO.id,
          sid: this.merchant.id
        };
        if (this.shopId && this.merchantId) from.merchantId = this.merchantId, from.sid = this.shopId;
        route.getShopeList(from, res => {
          res = res.list.map(it => {
            it.isRemind = it.remindId;
            return it;
          });
          let arrObjFilter = res.filter(ele => ele.end == false);
          this.setData({
            seckillList: arrObjFilter
          });
        });
      }

      if (this.merchant && this.merchant.type != 5) {
        route.getAcitve({
          page: 1,
          limit: seckillTemplate.number,
          type: 2,
          tag: 'home'
        }, res => {
          data = res.map(it => {
            it.num = it.sellStock / it.quantity * 100;
            it.isRemind = it.remindId;
            return it;
          });
          data.sort(function (a, b) {
            return Date.parse(a.startTime) - Date.parse(b.startTime);
          });

          _ts.setData({
            seckillList: data
          });
        });
      }
    },

	  toSeckillList(event) {
	    const index = event.currentTarget.dataset.index;
	    const activity = this.seckillList[index];
	    const url = event.currentTarget.dataset.url
	    app.globalData.openPage('activity/seckillDetails/seckillDetails?acid=' + activity.id + "&id=" + activity.productId + url);
	    // app.openPage('activity/seckillDetails/seckillDetails?acid=' + activity.id + "&id=" + activity.productId);
	  },

    cancelActivityRemind(event) {
      const index = event.currentTarget.dataset.index;
      const id = event.currentTarget.dataset.id;
      const type = event.currentTarget.dataset.type;
	  if(req.header.appId=='ZQ1VK5oc17I387E'){
		  
	  }else{
		route.cancelActivityRemind({
		  id: id
		}, res => {
		  req.msg('取消提醒成功');
		  let data = {};
		  if (type == 3) data['seckillList[' + index + '].isRemind'] = false;
		  this.setData(data);
		});  
	  }
    },

    addActivityRemind(event) {
      const index = event.currentTarget.dataset.index;
      const id = event.currentTarget.dataset.id;
      const type = event.currentTarget.dataset.type;
      
      route.addActivityRemind({
        activityId: id
      }, res => {
		  mes.remind().then(res => res);
        // mes.remind().then(res=>res)
        // mes.requsetmessage()
        req.msg('订阅提醒成功');
        let data = {};
        if (type == 3) data['seckillList[' + index + '].isRemind'] = true;
        this.setData(data);
      });
    }

  }
};
</script>
<style>
@import "./seckill.css";
</style>