<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>详情-我的商户-创业帮</title>
    <meta name="keywords" content="详情-我的商户-创业帮">
    <meta name="description" content="详情-我的商户-创业帮">
    <meta content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,shrink-to-fit=no,user-scalable=no" name="viewport" viewport="cover">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta content="telephone=no" name="format-detection">
    <meta content="email=no" name="format-detection">
    <meta name="apple-mobile-web-app-title" content="详情-我的商户-创业帮">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <link rel="stylesheet" href="./static/css/main.css">
  </head>
  <body class="bgcfff pb0 ovh vh100" style="box-sizing:border-box;">
    <div class="iphonetitle"></div>
    <div class="merchant_current detail-pos" id="app">
      <van-sticky>
        <van-nav-bar class="camp_title user_title_normal f16" title="商户信息" @click-left="goback" v-if="toptitleisshow" left-arrow v-cloak>
          <template #left>
            <van-icon name="arrow-left" color="#333" size="20"></van-icon>
          </template>
        </van-nav-bar>
      </van-sticky>
      <div class="merchant-header merchant-header-back"></div>
      <div class="merchant-info ml16 mr16 bgcfff" v-cloak>
        <div class="pt16 pb16 pl16 pr16">
          <van-cell :title="merchant.Name" center :border="false">
            <template #label><span class="mr16">{{merchant.MerRealName}}</span><span>{{merchant.Mobile}}</span></template>
            <template #icon>
              <van-image src="./static/images/merchant-header.png" fit="cover" lazy-load></van-image>
            </template>
            <template #right-icon>
              <div class="merchant-phone" @click="takephone"><img src="./static/images/icon-phone.png" alt="" width="100%"></div>
            </template>
          </van-cell>
          <div class="merchant-info-content mt16" v-cloak>
            <div class="merchant-info-desc ovh" :class="active ? '' : 'merchant-info-close'">
              <van-cell-group class="pb8" :border="false">
                <van-cell title="商户名称" :value="merchant.Name" :border="false"></van-cell>
                <van-cell title="企业法人" :value="merchant.LegalName" :border="false"></van-cell>
                <van-cell title="创建时间" :value="merchant.CreateDate" :border="false"></van-cell>
              </van-cell-group>
            </div>
            <div class="merchant-info-content-title tc pt16 van-hairline--top" @click="toggleMerchantInfo()"><img class="vm pl6 pr6" src="./static/images/icon-arrow-down@3x.png" alt="" :class="active ? 'toUp' : ''"><span class="f12 c999 vm">{{active ? '收起' : '商户详情'}}</span></div>
          </div>
        </div>
      </div>
      <div class="merchant-info-statistics mt16" ref="wrapper2">
        <div class="ml16 mr16 pt8 pb8 bgcfff">
          <van-cell class="merchant-info-statistics-cell mt8 mb20" title="总交易额" :value="merchant.TradeTotal + '元'" center :border="false"></van-cell>
        </div>
        <van-tabs v-model="merchantactive" color="#FFD500">
          <van-tab title="交易记录"></van-tab>
          <van-tab disabled></van-tab>
          <van-tab disabled></van-tab>
        </van-tabs>
        <div class="ml16 mr16 pt8 pb8 bgcfff">
          <div class="mt8 merchant_detail_list" ref="wrapper2">
            <van-pull-refresh v-model="refreshing" @refresh="onRefresh" style="min-height: 60vh;" :class="transactions.length === 0 ? 'isnodata':''">
              <van-list v-model="loading" :finished="finished" finished-text="没有更多数据了" @load="onLoad" :immediate-check="false">
                <van-empty class="custom-image" image="./static/images/empty-img.png" description="暂无数据" v-if="isnodata"></van-empty>
                <van-cell-group :border="false">
                  <van-cell v-for="item,index in transactions" center :title="item.TradeDate" :value="item.TradeAmt + '元'"></van-cell>
                </van-cell-group>
              </van-list>
            </van-pull-refresh>
          </div>
        </div>
      </div>
      <van-popup v-model="showDate" position="bottom" :style="{ height: '50%' }">
        <van-datetime-picker v-model="currentDate" type="year-month" title="选择年月" :min-date="minDate" :max-date="maxDate" :formatter="formatter" @confirm="onConfirmDate"></van-datetime-picker>
      </van-popup>
    </div> 
    <script src="./static/js/klm-vv.min.js"></script>
    <script src="./static/js/appfunc.min.js"></script>
    <script src="./static/js/klm-axios-config.js"></script>
    <script src="./static/js/publicfn.js"></script>
    <script>
      // 通过 CDN 引入时不会自动注册 Lazyload 组件
      // 可以通过下面的方式手动注册
      Vue.use(vant.Lazyload);
      //--- PublicLib.SetStatusBarStyle({type:'light', isShow:1});
      // 在 #app 标签下渲染一个按钮组件
      let app = new Vue({
        el: '#app',
        data() {
          return {
            isnodata:false,
            toptitleisshow:true,
            active: false,
            merchantactive:0,
            merchant:{
              TradeTotal:0,
            },
            realMerchantMobile:'',
            showDate: false,
            minDate: new Date(2020, 0, 1),
            maxDate: new Date(2025, 10, 1),
            currentDate:  new Date(),
            formatime:'',
            dateName: '本月',
            transactions: [
            ],
            pageinfo:{
              PageSize:10,
              PageNum:1
            },
            loading: false,
            finished: false,
            refreshing: false,
            allcount:{}
          };
        },
        created() {
          this.formatime = formatDate(this.currentDate.getFullYear(),this.currentDate.getMonth() + 1);
          this.getmerchantinfo();
          this.getmerchantdetail();
        },
        mounted(){
            this.$refs.wrapper2.style.height = `${document.documentElement.clientHeight - 450}px`;
        },
        methods: {
          toggleMerchantInfo(){
            this.active = !this.active;
          },
          onShowDate(){
            this.showDate = !this.showDate;
          },
          formatter(type, val) {
            if (type === 'year') {
              return `${val}年`;
            } else if (type === 'month') {
              return `${val}月`;
            }
            return val;
          },
          onConfirmDate() {
            this.transactions = [];
            this.showDate = false;
            this.dateName = this.currentDate.getFullYear() + '年' + (this.currentDate.getMonth() + 1) + '月';
            this.formatime = formatDate(this.currentDate.getFullYear(),this.currentDate.getMonth() + 1);
            this.getmerchantdetail();
          },
          onLoad() {
              if (this.refreshing) {
                this.transactions = [];
                this.refreshing = false;
                this.pageinfo.PageNum = 0;
              }
              this.pageinfo.PageNum++;
              this.getmerchantdetail();
          },
          onRefresh() {
            // 清空列表数据
            this.finished = false;
            // 重新加载数据
            // 将 loading 设置为 true,表示处于加载状态
            this.loading = true;
            this.onLoad();
          },
          async getmerchantinfo(){
            //- PublicLib.ShowLoading({Message:''});
            const Id = PublicLib.getCookieInfo('merchantId');
            const res = await getRequest('api/v1/merchantinfo/detail?t='+Math.random(6),JSON.stringify({Id}));
            if(res.status !== '1') return tips('获取商户信息失败,请重试!');
            //- PublicLib.HideLoading();
            res.data.TradeTotal = res.data.TradeTotal.toFixed(2);
            this.merchant = res.data;
            this.realMerchantMobile = res.data.Mobile;
            //- this.merchant.Mobile = hidemiddlenum(res.data.Mobile,3,4);
          },
          async getmerchantdetail(){
            const MerchantId = PublicLib.getCookieInfo('merchantId');
            const res = await getRequest('api/v1/usertradedaysummary/merchanttradelist?t='+Math.random(6),JSON.stringify({...this.pageinfo,TradeMonth:this.formatime,MerchantId}));
            if(res.status !== '1') return tips('获取交易记录失败,请重试!');
            if(res.data.length < this.pageinfo.PageSize) {
              this.finished = true;
            };
            if(this.pageinfo.PageNum === 1){
              res.data.splice(0,1);
            };
            res.data.forEach(item=>{
              item.TradeAmt = item.TradeAmt.toFixed(2)
            });
            this.allcount = res;
            this.transactions.push(...res.data);
            this.loading = false;
            if(this.transactions.length === 0) {this.isnodata = true}else{this.isnodata = false};
          },
          goback(){
            PublicLib.GoBack({Level:1});
          },
          takephone(){
            PublicLib.PhoneCall(this.realMerchantMobile);
          }
        }
      });
    </script>
  </body>
</html>