<template>
  <view class="finance">
    <view class="tabs_box flex_a_c">
      <u-subsection :list="subsList" :current="curNow" activeColor="#20A162" @change="subsChange"></u-subsection>
    </view>
    <block v-for="(item,i) in goodsList" :key="item.order_id">
      <view class="list_item">
        <view class="item_header flex_a_c_j_sb">
          <view class="title_left">
            <view class="name">采购人:{{item.real_name}}</view>
            <view class="name">电 话:{{item.user_phone}}</view>
            <view class="time">{{item.pay_time}}</view>
          </view>
          <view class="btn_right" @click="setInfo(item.mer_id,item.order_id)" v-if="item.status=='0'">去发货</view>
          <view class="btn_right" v-else="item.status=='2'">已完成</view>
        </view>
        <view class="item_cont">
          <view class="item_cell">采购商家：{{item.merchant.mer_name}}</view>
          <view class="item_cell flex">
            <view class="">采购详情：</view>
            <view style="width: 100%;flex: 1;">
              <!-- v-for="(item,index) in 3" :key="index" -->
              <view class="flex_a_c_j_sb"  v-for="list in item.orderProduct" :key="list.order_product_id">
              	<view class="">{{list.cart_info.product.store_name}}</view>
              	<view class="pro_num">X{{list.product_num}} </view>
              </view>
            </view>
          </view>
          <view class="item_cell">收货地址：{{item.user_address}}</view>
          <view class="item_cell">订单编号：{{item.order_sn}}</view>
        </view>
      </view>
    </block>
  </view>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { getOrderList, setAdminOrderDelivery } from '@/api/admin.js'
  import { Toast } from '../../../libs/uniApi'
  export default {
    data() {
      return {
        curNow: '0',
        serObj: {
          status: '0',
          page: '1',
          limit: '20',
		  product_type:98,
        },
        subsList: ['未发货', '已发货', '全部订单'],
        goodsList: [],
        merId: ''
      }
    },
    onLoad(options) {
		// console.log(options.merid,'123');
      this.merId = options.merid
    },
    onShow() {
      this.getDefaultData()
    },
    computed: mapGetters(['userInfo']),
    methods: {
      subsChange(index) {
        this.curNow = index
        //未发货
        if (index == '0') {
          this.serObj.status = '0'
          this.getDefaultData()
        }
        //index=='2'已发货
        if (index == '1') {
          this.serObj.status = '1'
          this.getDefaultData()
        }
        //全部订单---暂时无接口
        if (index == '2') {
          delete this.serObj.status
          this.getDefaultData()
        }
      },
      //默认是未发货查询
      async getDefaultData() {
        const res = await getOrderList(this.serObj, this.merId)
        // console.log(res);
        this.goodsList = res.data.list
      },
      //去发货---
      goDeliver_goods(order_id) {},
      setInfo(merId, orderId) {
        let that = this;
        const data = {
          delivery_id: this.userInfo.phone,
          delivery_name: this.userInfo.service.nickname,
          delivery_type: 2,
          is_split: 0,
          split: []
        }
        setAdminOrderDelivery(merId, orderId, data).then(
          res => {
            this.getDefaultData()
            Toast('提交成功')
          },
          error => {
            that.$util.Tips({
              title: error
            })
          }
        );
      },
    },
    onPullDownRefresh() {
      uni.stopPullDownRefresh()
    }
  }
</script>

<style lang="scss">
  .finance {}

  ::v-deep .u-subsection {
    height: 94.74rpx !important;
    padding: 10.53rpx !important;
  }

  ::v-deep .u-subsection__bar {
    height: 73.68rpx !important;
  }

  .tabs_box {
    padding: 0 28.07rpx;
    height: 136.84rpx;
    background-color: #fff;


  }
  .pro_num{
	  	color: #20A162;
  }
  .title_left {
    width: 548rpx;
  }

  .list_item {
    background-color: #fff;
    width: 694.74rpx;
    margin: 0 auto;
    margin-top: 31.58rpx;
    padding: 28.07rpx;
    border-radius: 8px;

    .item_header {
      width: 100%;
      padding-bottom: 17.54rpx;
      border-bottom: 1px dashed #20A162;

      .name {
        font-size: 31.58rpx;
        color: #333;
        font-weight: bold;
        margin-bottom: 21.05rpx;
      }

      .time {
        color: #999;
        font-size: 24.56rpx;
      }

      .btn_right {
        color: #20A162;
        text-align: center;
        line-height: 49.12rpx;
        width: 138.6rpx;
        height: 49.12rpx;
        border-radius: 4px;
        border: 1px solid #20A162;
      }
    }

    .item_cell {
      margin-top: 24.56rpx;
    }
  }
</style>
