<template>
  <view class="mch-mine-container">
    <view class="mch-mine-bg">
      <image class="mch-mine-bg-img" src="https://api.ccttiot.com/mine-bg-1745765736909.png" mode="widthFix" />
    </view>
    <HeaderBar title="我的" text-align="center" />
    <!-- 商户信息区 -->
    <view class="mch-user-info">
      <image class="avatar" :src="parseLocalUrl(mch.avatar)" mode="aspectFill" />
      <view class="user-meta">
        <view class="nickname">{{ mch.name | dv}}</view>
        <view class="user-tag">商户</view>
      </view>
      <button class="share-btn" open-type="share">
        <image src="https://api.ccttiot.com/share-icon-1748442777724.png" class="share-icon" />
        <text>分享</text>
      </button>
    </view>
    <!-- 四宫格入口 -->
    <view class="mch-grid-row">
      <view class="mch-grid-item" v-for="item in gridList" :key="item.key" @click="onGridClick(item)">
        <image :src="item.icon" class="grid-icon" />
        <view class="grid-label">{{ item.label }}</view>
      </view>
    </view>

    <!-- 会员开通提示 -->
    <VipCard :mch="mch"/>

    <!-- 菜单列表 -->
    <view class="menu-list">
      <view class="menu-item" v-for="item in menuList" :key="item.key" @click="onMenuClick(item)">
        <image :src="item.icon" class="menu-icon" />
        <view class="menu-label">{{ item.label }}</view>
      </view>
    </view>
    <FooterTabBar :active="'/pages/mch/mine'" mode="mch"/>
  </view>
</template>

<script>
import HeaderBar from '@/components/HeaderBar.vue'
import { getMchDetail } from '@/api/app/mch'
import FooterTabBar from '@/components/FooterTabBar.vue'
import { mapGetters } from 'vuex'
import { parseLocalUrl } from '@/utils/index';
import { BalanceLogType } from '@/utils/enums'
import VipCard from './components/VipCard.vue'

export default {
  components: {
    HeaderBar,
    FooterTabBar,
    VipCard
  },
  data() {
    return {
      BalanceLogType,
      mch: {},
      defaultAvatar: '/static/images/profile.jpg',
      gridList: [
        { key: 'wallet', label: '我的钱包', icon: 'https://api.ccttiot.com/Frame%2025-1746435521889.png', path: '/pages/mch/balance' },
        { key: 'score', label: '我的积分', icon: 'https://api.ccttiot.com/Frame%2026-1746435560674.png', path: `/pages/score/index?type=${BalanceLogType.MCH_SCORE}`  },
        { key: 'order', label: '我的订单量', icon: 'https://api.ccttiot.com/2c837183f4b597de52fb735fd07046c7ca82b616593b6-wXiyya_fw1200-1746435587733.png', path: '/pages/dashboard/index' },
        { key: 'service', label: '客服', icon: 'https://api.ccttiot.com/608e7fd6c28e9ec3befb377c02bde858a9844b1f40197-BUsNfM_fw1200-1746435617651.png', path: '/pages/mchCustom/index' }
      ],
      menuList: [
        { key: 'mch', label: '修改信息', icon: 'https://api.ccttiot.com/%E5%95%86%E5%AE%B6%20(3)-1748442480183.png', path: '/pages/mch/edit' },
        { key: 'staff', label: '员工管理', icon: 'https://api.ccttiot.com/%E5%91%98%E5%B7%A5%E7%AE%A1%E7%90%86%20(2)-1749561103567.png', path: '/pages/mchStaff/index' },
        { key: 'help', label: '帮助中心', icon: 'https://api.ccttiot.com/Frame-1748442074654.png', path: '/pages/article/index?type=3' },
        // { key: 'intro', label: '商家简介', icon: 'https://api.ccttiot.com/Frame-1745765656714.png', path: '/pages/mch/intro/index' },
        { key: 'feedback', label: '意见反馈', icon: 'https://api.ccttiot.com/Frame%20(2)-1748442074341.png', path: '/pages/complaint/edit' },
        { key: 'privacy', label: '隐私协议', icon: 'https://api.ccttiot.com/Frame%20(3)-1748442074366.png', path: '/pages/article/detail?type=4' },
        { key: 'back', label: '返回用户端', icon: 'https://api.ccttiot.com/%E8%BF%94%E5%9B%9E%20(3)-1748442777724.png', path: '/pages/index/index' }
      ]
    }
  },
  computed: {
    ...mapGetters(['mchId', 'userId'])
  },
  onShow() {
    this.getMchInfo()
  },
  methods: {
    parseLocalUrl,
    getMchInfo() {
      getMchDetail(this.mchId).then(res => {
        this.mch = res.data
      })
    },
    onGridClick(item) {
      if (item.path) {
        uni.navigateTo({ url: item.path })
      }
    },
    onMenuClick(item) {
      if (item.key === 'back') {
        uni.switchTab({ url: '/pages/index/index' })
      }
      if (item.key === 'mch') {
        uni.navigateTo({ url: '/pages/mch/edit?id=' + this.mchId })
      }
      if (item.path) {
        uni.navigateTo({ url: item.path })
      }
    },
    onShareAppMessage() {
      return {
        title: `驰捷修-派单快速度快安全倒计时阶段`,
        path: `/pages/index/index?invitorId=${this.userId}`,
        imageUrl: 'https://api.ccttiot.com/64024b0ec02392312a95d75c369308143f64f6cd15b0e9-1KT9Qi_fw1200%201-1747228539523.png'
      }
    },
  }
}
</script>

<style lang="scss" scoped>
.mch-mine-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #eaf2ff 0%, #f7faff 100%);
  padding-bottom: 80rpx;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
}
.mch-mine-bg {
  width: 100%;
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  .mch-mine-bg-img {
    width: 100%;
    display: block;
    pointer-events: none;
    user-select: none;
  }
}
.mch-user-info {
  display: flex;
  align-items: center;
  padding: 40rpx 32rpx 24rpx 32rpx;
  position: relative;
  .avatar {
    width: 104rpx;
    height: 104rpx;
    border-radius: 50%;
    border: 4rpx solid #fff;
    box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
    margin-right: 24rpx;
    background: #f5f5f5;
  }
  .user-meta {
    flex: 1;
    .nickname {
      font-size: 36rpx;
      font-weight: 600;
      color: #222;
      margin-bottom: 8rpx;
    }
    .user-tag {
      display: inline-block;
      font-size: 22rpx;
      color: #6a8cff;
      background: #f0f5ff;
      border-radius: 20rpx;
      padding: 4rpx 18rpx;
      margin-bottom: 6rpx;
    }
    .user-phone {
      font-size: 24rpx;
      color: #888;
    }
  }
  .share-btn {
    display: flex;
    align-items: center;
    color: #6a8cff;
    font-size: 24rpx;
    cursor: pointer;
    margin-left: 16rpx;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
    &::after {
      border: none;
    }
    .share-icon {
      width: 40rpx;
      height: 40rpx;
      margin-right: 4rpx;
    }
    text {
      margin-left: 4rpx;
    }
  }
}
.mch-grid-row {
  display: flex;
  justify-content: space-between;
  margin: 0 32rpx 32rpx 32rpx;
  .mch-grid-item {
    flex: 1;
    background: linear-gradient(180deg, #FFFFFF 0%, #D0E3FF 100%);
    border: 1px solid #fff;
    border-radius: 24rpx;
    box-shadow: 0 4rpx 24rpx rgba(106, 140, 255, 0.08);
    padding: 24rpx 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-right: 24rpx;
    &:last-child {
      margin-right: 0;
    }
    .grid-icon {
      width: 60rpx;
      height: 60rpx;
      margin-bottom: 8rpx;
    }
    .grid-label {
      font-size: 26rpx;
      color: #3a3a3a;
    }
  }
}
.menu-list {
  background: #fff;
  border-radius: 24rpx;
  margin: 0 32rpx 32rpx 32rpx;
  box-shadow: 0 4rpx 24rpx rgba(106, 140, 255, 0.06);
  padding: 8rpx 0;
  .menu-item {
    display: flex;
    align-items: center;
    padding: 28rpx 32rpx;
    border-bottom: 1rpx solid #f0f0f0;
    &:last-child {
      border-bottom: none;
    }
    .menu-icon {
      width: 40rpx;
      height: 40rpx;
      margin-right: 24rpx;
    }
    .menu-label {
      font-size: 28rpx;
      color: #222;
    }
  }
}
::v-deep .footer-tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
}
</style>