<template>
  <page-meta :page-style="themeColor"></page-meta>
  <view class="order">
    <!--搜索-->
    <view class="cate-search">
      <view class="search-box">
        <input class="uni-input" maxlength="50" v-model="searchText" confirm-type="search" placeholder="请输入订单编号" @confirm="search()"/>
        <text class="iconfont icon-sousuo3" @click="search()"></text>
      </view>
    </view>
    <!--选项卡-->
    <view v-if="true" class="tabs">
      <view
          v-for="(item,index) in tabs" :key="index"
          :class="['tabs-item',{'tabs-item-active': (item.status === tabs_active)}]"
          @click="tabs_active = item.status">
        {{ item.title }}
      </view>
    </view>
    <!--订单列表-->
    <mescroll-uni ref="mescroll" @getData="getList" top="170">
      <block slot="list">
		<view class="orderNum">总订单: {{orderCount}} 单</view>  
        <view class="list" v-if="list.length > 0">
          <view class="list-block" v-for="(item,index) in list" :key="index">
            <view class="block-top">
              <view class="left">订单号：{{ item.order_no || 'NO00000'}}</view>
              <view class="right">{{statusText(item)}}</view>
            </view>
            <view class="block-content">
              <view class="left">
                <image class="top-image" :src="$util.img(item.goods_image)" mode="widthFix"></image>
              </view>
              <view class="right">
                <view class="goods-name">{{ item.goods_name }}</view>
				<!-- <view class="goods-name" v-if="tabs_active!='myorderpay'">销售商：{{item.seller_nickname || '' }}</view> -->
				<view class="goods-name">销售商：{{tabs_active=='myorderpay'?item.buyer_name:item.seller_nickname || ''}}</view>
                <view class="goods-num">数量：{{ item.total }}</view>
				<view v-if="pageType=='release'">
					<view class="goods-info">
					   采购价：<view class="goods-info-price"><text class="goods-info-unit">￥</text>{{item.unit_price}}</view>
					</view>
					<view class="goods-info" > 
					    售卖价：<view class="goods-info-price"><text class="goods-info-unit">￥</text>{{ item.price }}</view>
					</view>
				</view>
				<view class="goods-info" v-if="pageType =='stock' || pageType=='all'">
				   采购价：<view class="goods-info-price">
					   
					         <text class="goods-info-unit" v-if="tabs_active=='myorderpay'&&pageType=='all'">￥{{item.price}}</text>
					         <text class="goods-info-unit" v-else>￥{{item.unit_price}}</text>
					         <!-- <text class="goods-info-unit" v-if="pageType =='stock' && tabs_active=='myorderend'">￥{{item.unit_price}}</text> -->
					         <!-- <text class="goods-info-unit" v-if="pageType=='all' && (tabs_active=='myorderend' || tabs_active=='myorderpay')">￥{{item.price}}</text> -->
					   </view>
				</view>
              </view>
            </view>
            <view class="buttons">
              <view v-if="item.status=='6' && tabs_active=='myorderpay'" class="button-item color-base-text color-base-border" @click="quickPay(item)">支付</view>
              <view v-else class="button-item" @click="$util.redirectTo('/pages_rush/futures/order_details',{futures_id: item.id,'pagetype':pageType })">查看详情</view>
            </view>
          </view>
        </view>
        <view v-else>
          <ns-empty :isIndex="false" text="无订单信息！"></ns-empty>
        </view>
      </block>
    </mescroll-uni>
	<pay-pop txt="支付密码" :pwdlength="6" ref="payPop" @pwd_e="pwdEvend" />
	<ns-payment ref="choosePaymentPopup"></ns-payment>
    <!--登录弹框-->
    <ns-login ref="login"></ns-login>
    <!--加载动画-->
    <loading-cover ref="loadingCover"></loading-cover>
  </view>
</template>
<script>
import nsPayment from '@/components/payment/payment.vue';
import orderMethod from '../order/public/js/orderMethod.js';
import payPop from '@/pages_rush/components/pay-pop/pay-pop.vue';
export default {
  data() {
    return {
      orderData: '',
	  payMoney: 0,
	  payMoneyMerge: 0,
      searchText: '',
	  pageType: 'release',
      tabs_active: 'all',
      tabs: [],
      page_titles: {
        6: '我的订单',
		all: '采购订单',
        stock: '我的库存',
        release: '销售中订单',
        sold: '已售卖订单',
      },
      list: [],
	  orderCount:0,
      status_text: {
        1 : '库存',
        2 : '正在销售',
        3 : '已售出',
        4 : '提货中',
        5 : '提货完成',
        6 : '待支付',
        7 : '捡漏',
      }
    };
  },
 components: {
	payPop, 
 	nsPayment
 },
  mixins: [orderMethod],
  onLoad(option) {
    // 获取需要显示的订单类型
	this.pageType=option.status || 'release';
	console.log(this.pageType);
    if(option.status == 'release'){
      this.tabs_active = 6;
      this.tabs = [
        {title: '未付款订单', status: 6},
        {title: '订单已完成',  status: 3},
      ]
    }
    if(option.status == 'all'){
      this.tabs_active = 'myorderpay';
      this.tabs = [
        {title: '采购未付款', status: 'myorderpay'},
        {title: '成功完成订单', status: 'myorderend'},
      ]
    }
    if(option.status == 'stock'){
      this.tabs_active = 'stock';
      this.tabs = [
        {title: '库存订单', status: 'stock'},
        {title: '提货订单', status: 'pickup'},
        {title: '审核出售', status: 'time'},
      ]
    }
    // 获取页面标题
    let pageTitle = this.page_titles[this.tabs_active];
    uni.setNavigationBarTitle({
      title: pageTitle
    });
  },
  onShow() {},
  onReady(){
    // 判断是否登录
    if (!uni.getStorageSync('token')) this.$refs.login.open('/pages_rush/futures/list');
  },
  watch:{
    tabs_active: {
      handler(newStatus) {
        if(this.$refs.mescroll) this.$refs.mescroll.refresh();
      },
      immediate: true
    }
  },
  methods: {
	quickPay(orderData){
		this.orderData = orderData;
		this.payMoney = parseFloat(orderData.pay_money);
		// this.isBalance
		this.$refs.choosePaymentPopup.useBalance(1,false);
		this.orderPay(orderData);
		
		 // this.$refs.payPop.Open();
	},
	pwdEvend(){
		
	},
    statusText(item){
      switch (item.status){
        case 1:
          return '库存'
        case 2:
          if (item.release_time <= (new Date().getTime() / 1000) ){
            return '正在销售'
          }
          if (item.release_time > (new Date().getTime() / 1000) ){
            return '审核中'
          }
          break
        case 3:
          return '已完成'
        case 4:
          return '提货中'
        case 5:
          return '已提货'
        case 6:
          return '待付款'
        case 7:
          return '正在销售'
        case 8:
          return '已拆单'
      }
    },
    // 订单搜索
    search(){
      this.$refs.mescroll.refresh();
    },
    // 获取订单列表
    getList(mescroll) {
      this.$api.sendRequest({
        url: '/futures/api/futures/myList',
        data: {
          page: mescroll.num || 1,
          page_size: mescroll.size || 10,
          status: this.tabs_active,
          search_text: this.searchText, // 搜索内容
        },
        success: res => {
          if(parseInt(res.code) === 0){
			this.orderCount=res.data.count||0;
            mescroll.endSuccess(Object.keys(res.data.list).length);
            //设置列表数据
            if (parseInt(mescroll.num) === 1){
              this.list = []; //如果是第一页需手动制空列表
            }
            this.list = this.list.concat(res.data.list); //追加新数据
          }else {
            this.msg = res.message;
          }
          if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
        },
        fail: res => {
          mescroll.endErr();
          if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
        }
      });
    },
  },
  onBackPress(options) {
    if (options.from === 'navigateBack') return false;
    this.$util.redirectTo('/pages/member/index');
    return true;
  }
};
</script>

<style lang="scss" scoped>
.order{
  background-color: #f8f8f8;// #f8f8f8
  min-height: 100vh;
  .cate-search {
    width: calc(100% - 48rpx);
    background: #ffffff;
    padding: 10rpx 24rpx 10rpx 24rpx;
    /* #ifdef H5 */
    padding-top: 30rpx;
    /* #endif */
    position: relative;
    z-index: 998;

    input {
      font-size: $font-size-base;
      height: 76rpx;
      padding: 0 25rpx 0 30rpx;
      line-height: 60rpx;
      width: calc(100% - 120rpx);
    }

    text {
      font-size: 32rpx;
      color: $color-tip;
      width: 120rpx;
      text-align: center;
    }

    .search-box {
      width: 100%;
      background: $color-bg;
      display: flex;
      justify-content: center;
      align-items: center;
      border-radius: 100rpx;
    }
  }
  .tabs{
    width: 100vw;
    height: 70rpx;
    background-color: #FFFFFF;
    display: inline-flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-content: center;
    justify-content: space-around;
    align-items: center;

    .tabs-item{
      max-width: max-content;
      height: 70rpx;
      line-height: 70rpx;
      font-size: 30rpx;
      color: #000000;
    }
    .tabs-item-active{
      color: #d86351;
      position: relative;
    }
    .tabs-item-active:after{
      content: "";
      position: absolute;
      left: 0;
      bottom: 0;
      height: 6rpx;
      width: 100%;
      background-color: #d86351;
    }
  }
  .orderNum{
	  height: 20px;
	  padding: 30rpx;
	  background: #fff;
	  margin: 15px 15px 0;
	  border-radius: 10px;
  }
  .list{
    width: calc(100vw - (30rpx * 2));
    padding: 30rpx;
    .list-block{
      padding: 20rpx;
      margin-bottom: 30rpx;
      background-color: #FFFFFF;
      border-radius: 20rpx;

      .block-top{
        width: 100%;
        display: inline-flex;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: flex-start;
        height: 50rpx;
        .left{
          line-height: 50rpx;
          font-size: 26rpx;
          color: #000000;
        }
        .right{
          line-height: 40rpx;
          font-size: 26rpx;
          //color: #de6758;
          //border: 2rpx solid #de6758;
          height: 40rpx;
          padding: 0 10rpx;
          border-radius: 10rpx;
          background: #ff0000;
          color: #ffffff;
          margin-left: 20rpx;
        }
      }
      .block-content{
        --content-height--: 240rpx;
        height: var(--content-height--);
        width: 100%;
        padding: 10rpx 0;
        display: inline-flex;
        flex-direction: row;
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: center;
        .left{
          height: var(--content-height--);
          width: var(--content-height--);
          border-radius: 10rpx;
          overflow: hidden;
          .top-image{
            width: 100% !important;
            height: 100%!important;
          }
        }
        .right{
          height: var(--content-height--);
          width: calc(100% - var(--content-height--) - 20rpx);
          padding-left: 20rpx;

          .goods-name{
            font-size: 26rpx;
            font-weight: bold;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            height: 50rpx;
          }
          .goods-num{
            display: inline-flex;
            flex-direction: row;
            flex-wrap: nowrap;
            justify-content: flex-start;
            align-items: center;
            width: 100%;
            font-size: 26rpx;
            height: 50rpx;
          }
          .goods-info{
            display: inline-flex;
            flex-direction: row;
            flex-wrap: nowrap;
            justify-content: flex-start;
            align-items: baseline;
            width: 100%;
            font-size: 26rpx;
            height: 50rpx;
            .goods-info-price{
			  // margin-left: 5px;	
              color: #e05c3b;
              .goods-info-unit{
                font-size: 24rpx;
              }
            }
          }
        }
      }
      .buttons{
        display: inline-flex;
        justify-content: flex-end;
        width: 100%;
        .button-item{
          height: 50rpx;
          line-height: 50rpx;
          color: #d74a2c;
          border: 1rpx solid #d74a2c;
          width: 160rpx;
          text-align: center;
          font-size: 26rpx;
          border-radius: 10rpx;
        }
		.action-btn {
			line-height: 1;
			padding: 20rpx 26rpx;
			color: #333;
			display: inline-block;
			border-radius: $border-radius;
			background: #fff;
			border: 2rpx solid #999;
			font-size: $font-size-tag;
			margin-left: 10rpx;
		}
      }
    }
  }
}
</style>
