<template>
  <div>
    <el-dialog v-model="dialogVisible" :close-on-click-modal="false" custom-class="custom-inquiry-dialog" width="450px">
      <div class="info-section">
        <div class="info-item">
          <span class="label">首选商家：</span>
          <span class="value">{{ diodescription }}</span>
        </div>
        <div class="info-item">
          <span class="label">选择服务：</span>
          <span class="value">{{ diotext }}</span>
        </div>
      </div>

      <el-form ref="formRef" :model="form" label-position="top">
        <el-form-item label="需求量：" prop="quantity" :rules="[{ required: true, message: '请输入重量' }]">
          <el-input v-model="form.quantity" placeholder="请输入重量（kg）">
            <template #suffix>kg</template>
          </el-input>
        </el-form-item>

        <el-form-item label="您的称呼：" prop="name" :rules="[{ required: true, message: '请输入您的称呼' }]">
          <el-input v-model="form.name" placeholder="请输入您的称呼" />
        </el-form-item>

        <el-form-item
          label="您的电话："
          prop="phone"
          :rules="[
            { required: true, message: '请输入电话' },
            { pattern: /^1[3-9]\d{9}$/, message: '手机号格式错误' },
          ]"
        >
          <el-input v-model="form.phone" placeholder="请输入电话号码" />
        </el-form-item>
      </el-form>

      <template #footer>
        <div class="dialog-footer">
          <el-button class="cancel-btn" @click="dialogVisible = false">取消</el-button>
          <el-button class="submit-btn" type="primary" @click="handleSubmit">发送询价</el-button>
        </div>
      </template>
    </el-dialog>
    <!--  <page-layout :menus="state.menus"> </page-layout>-->
    <section>
      <common>
        <template #main>
          <el-card shadow="none" style="border-radius: 14px; position: relative">
            <div class="tabs tabs0">
              <div class="tab cursor">
                <div
                  v-for="(item, index) in tab0"
                  :key="index"
                  class="tab_list_li"
                  style="margin-left: 20px; margin-bottom: 10px"
                  :class="{ active: currentTab0 === index, tab_list_li0: currentTab0 === index }"
                  @click.stop="
                    currentTab0 = index;
                    currentTab1 = 0;
                    currentTab2 = 0;
                  "
                >
                  {{ item }}
                </div>
              </div>
            </div>
            <div class="tabs">
              <div class="tab cursor">
                <div
                  v-for="(item, index) in tab1"
                  :key="index"
                  class="tab_list_li"
                  :class="{ active: currentTab1 === index }"
                  @click.stop="switchTab(item, index)"
                >
                  {{ item }}
                </div>
              </div>
            </div>
            <div v-if="currentTab0 === 1" class="tabs">
              <div class="tab cursor">
                <div
                  v-for="(item, index) in tab2"
                  :key="index"
                  class="tab_list_li"
                  :class="{ active: currentTab2 === index }"
                  @click.stop="currentTab2 = index"
                >
                  {{ item }}
                </div>
              </div>
            </div>
            <div style="position: absolute; right: 3%; top: 27%">
              <el-button style="padding: 10px 50px" size="large" type="primary" @click="handleApply">发布需求</el-button>
            </div>
          </el-card>
          <el-row v-if="currentTab0 === 0" :gutter="20" style="margin-top: 10px">
            <el-col v-for="(item, index) in state.data0" :key="index" :span="12">
              <el-card class="storage-card" shadow="hover">
                <div class="storage-content">
                  <div class="storage-content-top" @click="toLink(item)">
                    <img :src="getAssetsFile(`${item.imageUrl}`)" fit="cover" class="storage-image" />
                    <div class="storage-info">
                      <h2 class="storage-title">
                        <span class="span">{{ item.title }}</span>
                        <span><img :src="getAssetsFile('images/warehouseLogistics/认证.png')" alt="" style="width: 20px" /></span>
                      </h2>
                      <div class="storage-desc">
                        <span>{{ item.description }}</span>
                        <!-- <img :src="getAssetsFile('images/warehouseLogistics/认证.png')" alt="" style="width: 20px" />
                        <img :src="getAssetsFile('images/warehouseLogistics/优先级.png')" alt="" style="width: 20px" /> -->
                      </div>
                      <div class="storage-tags">
                        <el-tag effect="plain" round style="background-color: rgba(37, 191, 130, 0.2); color: #25bf82">{{ item.type }}</el-tag>
                        <el-tag effect="plain" round style="background-color: rgba(37, 191, 130, 0.2); color: #25bf82">{{ item.monitor }}</el-tag>
                        <!-- <el-tag effect="plain" round style="background-color: rgba(37, 191, 130, 0.2); color: #25bf82">绿色</el-tag> -->
                      </div>
                      <div class="storage-location">
                        <el-icon><Location /></el-icon>
                        {{ item.location }}
                      </div>
                    </div>
                  </div>
                  <div class="storage-price">
                    <div class="storage-price-left">
                      <!-- <span class="price-label">报价</span> -->
                      <span class="price-amount">参考价：¥{{ item.price }}/小时</span>
                    </div>
                    <el-button type="success" class="contact-btn" @click="goDei(item)">
                      <!-- <img :src="getAssetsFile('images/warehouseLogistics/messageBox.png')" alt="" style="height: 30px; margin-right: 5px" /> -->
                      <span>预约</span>
                    </el-button>
                  </div>
                  <!-- <div v-if="item.rank" class="rank-badge">
                    <img :src="getAssetsFile('images/warehouseLogistics/top' + item.rank + '.png')" alt="" style="width: 80px" />
                  </div> -->
                </div>
              </el-card>
            </el-col>
          </el-row>
          <el-row v-if="currentTab0 === 1" :gutter="20" style="margin-top: 10px">
            <el-col :span="24">
              <el-card class="storage-card" shadow="hover" body-style="padding: 0">
                <div class="storage-content">
                  <div class="storage-content-top">
                    <img src="@/assets/images/warehouseLogistics/img3.png" fit="cover" class="storage-image storage-image1" />
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>

          <page-pagination :total="5" @current-change="currentChange" />
        </template>
      </common>
    </section>
  </div>
</template>
<script setup name="page-menu">
import { onMounted, ref, reactive, watch } from 'vue';
import { getAssetsFile } from '@/utils';
import { useRoute, useRouter } from 'vue-router';
import warehouseLogisticsRoutes from '@/router/modules/warehouseLogistics';
import Common from './components/common.vue';

const route = useRoute();
const router = useRouter();

// const tab0 = reactive(['分拣服务', '分拣需求']);
const tab0 = reactive(['分拣服务']);
const tab1 = reactive(['全部', '人工分拣', '自动化分拣']);
const tab2 = reactive(['全部', '已完成', '分拣中', '已接单', '待接单']);
const tab3 = reactive(['水产', '其他类']);
const state = reactive({
  menus: warehouseLogisticsRoutes[0].children,
  query: {
    current: 1,
  },
  data0: [],
  data: [
    {
      title: '云南绿源生态农业有限公司',
      description: '根茎类 ',
      location: '临沧市·耿马县',
      locationUrl: 'images/dz.png',
      //分拣
      type: '自动化分拣',
      //监控方式
      monitor: '全程实时监控',
      price: '23',
      rank: '1',
      imageUrl: 'images/5.png',
      //联系人
      contact: '李志强',
      phone: '13988324687',
      //介绍
      introduce:
        '云南绿源生态农业有限公司专注耿马高原根茎类作物，拥有5000㎡无尘车间，自动滚轴分选线可精准区分大小、糖度；全程冷链+云端监控，客户手机即可查看货位温湿度；3-5元/kg为当季地头价，量大可议价，支持京东冷链直发、边贸自提。',
    },
    {
      title: '云南丰瑞农业发展有限公司',
      description: '豆类 ',
      location: '临沧市·耿马县',
      locationUrl: 'images/dz.png',
      //分拣
      type: '人工分拣',
      //监控方式
      monitor: '全程实时监控',
      price: '15',
      rank: '1',
      imageUrl: 'images/6.png',
      //联系人
      contact: '张 莉',
      phone: '13888013256',
      //介绍
      introduce:
        '云南丰瑞农业发展主打滇西蚕豆、芸豆，人工手选保证完整无破损，200㎡恒温库+24h摄像监控，价格2.5-4元/kg含简易真空小袋；可提供出口级质检报告，孟定口岸当天装车，适合电商小包及边贸批量。',
    },
    {
      title: '云南田园牧歌农业科技有限公司',
      description: '菌菇类 ',
      location: '临沧市·耿马县',
      locationUrl: 'images/dz.png',
      //分拣
      type: '自动化分拣',
      //监控方式
      monitor: '全程实时监控',
      price: '18',
      rank: '1',
      imageUrl: 'images/7.png',
      contact: '王 磊',
      phone: '15987925518',
      //介绍
      introduce:
        '云南田园牧歌农业科技依托耿马原始松林，年产野生菌鲜货800吨；自动光学分拣机剔除虫蛀、畸形，4-6元/kg为产地批发价，全程-2℃冷藏车直达昆明机场；支持顺丰冷运、泡沫箱+冰袋包装，24小时温湿度云端可查。',
    },
    {
      title: '云南金土地农业有限公司',
      description: '坚果类 ',
      location: '临沧市·耿马县',
      locationUrl: 'images/dz.png',
      //分拣
      type: '人工分拣',
      //监控方式
      monitor: '全程实时监控',
      price: '19',
      rank: '1',
      imageUrl: 'images/4.png',
      contact: '陈 刚',
      phone: '13759347102',
      //介绍
      introduce:
        '云南金土地农业专注澳洲坚果、薄壳核桃，人工色选+比重筛选，碎仁率＜2%；500㎡充氮保鲜库全程可视监控，5-7元/kg含麻袋或礼盒包装；提供有机认证，可代发全国，边贸客户可孟定口岸自提，散称或整柜均可。',
    },
  ],
});

const currentTab0 = ref(0);
const currentTab1 = ref(0);
const currentTab2 = ref(0);
const currentTab3 = ref(0);
const dialogVisible = ref(false);
const formRef = ref(null);

const form = reactive({
  quantity: '',
  title: '',
  phone: '',
  name: '',
});

const diotext = ref('');
const diodescription = ref('');

//切换
const switchTab = (item, index) => {
  console.log(item);
  if (item === '全部') {
    state.data0 = state.data;
  } else if (item === '人工分拣') {
    state.data0 = state.data.filter((item) => item.type === '人工分拣');
  } else {
    state.data0 = state.data.filter((item) => item.type === '自动化分拣');
  }

  currentTab1.value = index;
};

const goDei = (data) => {
  // diodescription.value = data.description;
  // diotext.value = data.title;
  // dialogVisible.value = true;
};

const handleSubmit = () => {
  formRef.value.validate((valid) => {
    if (valid) {
      console.log('提交数据:', form);
      dialogVisible.value = false;
    }
  });
};

const currentChange = (current) => {
  state.query.current = current;
};

const toLink = (row) => {
  row.data = ['高品质', '杀菌灭毒', '绿色'];
  router.push({
    path: '/sub-operation-service/packaging/details',
    query: row,
  });
};
const handleApply = () => {
  router.push({
    path: '/sub-operation-service/packaging/apply',
  });
};
onMounted(() => {
  console.log('state.data', state.data);
  state.data0 = state.data;
});
</script>
<style lang="scss" scoped>
// 基础颜色配置
$primary-color: #25bf82; // 主色调
$text-dark: #25bf82; // 深色文字
$text-regular: #606266; // 常规文字
$border-color: #dcdfe6; // 边框颜色

// 弹窗整体样式
:deep(.custom-inquiry-dialog) {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);

  .el-dialog__header {
    padding: 20px;
    border-bottom: 1px solid #f2f6fc;
    .el-dialog__title {
      font-size: 18px;
      color: $text-dark;
      font-weight: 600;
    }
  }

  .el-dialog__body {
    padding: 20px 28px;
  }

  .el-form-item__label {
    color: $text-regular;
    font-size: 14px;
    padding-bottom: 6px;
  }
}

.info-section {
  padding: 0px 50px;
  margin-bottom: 24px;
  .info-item {
    margin-bottom: 12px;
    .label {
      color: $text-regular;
      margin-right: 8px;
      font-size: 20px;
    }
    .value {
      color: $text-dark;
      font-weight: 500;
      font-size: 20px;
    }
  }
}

// 输入框样式覆盖
:deep(.el-input) {
  .el-input__inner {
    height: 40px;
    line-height: 40px;
    border-radius: 4px;
    &:focus {
      border-color: $primary-color;
    }
  }
  .el-input__suffix {
    color: $text-regular;
    right: 12px;
  }
}

// 下拉菜单样式
:deep(.custom-select-dropdown) {
  .el-select-dropdown__item {
    color: $text-regular;
    &.selected {
      color: $primary-color;
    }
  }
}

// 按钮组样式
.dialog-footer {
  text-align: right;
  .el-button {
    padding: 10px 24px;
    border-radius: 4px;
    font-size: 14px;
  }
  .cancel-btn {
    color: $text-regular;
    &:hover {
      color: $primary-color;
      border-color: $primary-color;
    }
  }
  .submit-btn {
    color: #fff;
    background: $primary-color;
    &:hover {
      background: mix($primary-color, #fff, 85%);
    }
  }
}
.tabs {
  //height: 160px;
  line-height: 50px;
  display: flex;
  flex-direction: column;
  font-size: 18px;
  align-items: flex-start;
  justify-content: space-between;
  // padding: 0 20px;
}
.tabs0 {
  padding: 0;
}
.tab {
  // height: 100px;
  width: 850px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
  overflow: auto; /* 启用滚动 */
  white-space: nowrap; /* 强制单行显示 */
  -ms-overflow-style: none; /* IE/Edge 兼容 */
  scrollbar-width: none; /* 隐藏滚动条 */
  .tab_list {
    color: #999999;
    font-size: 20px;
    font-weight: 400;
  }
  .tab_list_li {
    margin-left: 40px;
    color: #000000;
    font-size: 20px;
    font-weight: 400;
  }
  .tab_list_li:first-child {
    margin-left: 20px;
  }
  .tab_list_li.active {
    color: rgba(37, 191, 130, 1);
  }
  .tab_list_li0 {
    border-bottom: 2px solid rgba(37, 191, 130, 1);
  }
}
.cursor {
  cursor: pointer;
}
.active {
  color: rgba(37, 191, 130, 1);
}
.storage-card {
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
  border: 0;
  border-radius: 16px;
}
.storage-content {
  // @include flex-column;

  gap: 16px;
  &-top {
    @include flex-row;

    align-items: center;
  }
}
.storage-image {
  margin-right: 16px;
  width: 120px;
  height: 120px;
  border-radius: 8px;
  object-fit: cover;
}
.storage-image1 {
  margin-right: 0;
  width: 100%;
  height: auto;
  border-radius: 0;
  object-fit: cover;
  cursor: pointer;
}
.storage-info {
  // padding-right: 50px;
  flex: 1;
  cursor: pointer;
}
.storage-title,
.storage-desc,
.storage-tags,
.storage-location {
  overflow: hidden;
  margin: 10px 0;
  width: 100%;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}
.storage-title {
  margin-top: 0 !important;
  font-weight: 700;
  color: #000000;
  @include ellipsis;
  .span {
    width: 250px;
    //超出宽度显示省略号
    @include ellipsis;
    margin-right: 10px;
  }
}
.storage-desc {
  font-size: 16px;
  color: #999999;
  @include ellipsis;
  i {
    display: inline-block;
    width: 20px;
    height: 20px;
  }
}
.storage-tags {
  span {
    margin-right: 10px;
  }
}
.storage-location {
  display: flex;
  align-items: center;
  font-size: 16px;
  font-weight: 400;
  color: #000000;
}
.storage-price {
  display: flex;
  justify-content: space-between;
  align-items: center;
  &-left {
    color: #25bf82;
  }
}
.price-label {
  margin-right: 10px;
  font-size: 16px;
  color: #999999;
}
.price-amount {
  font-size: 20px;
  font-weight: 700;
  color: #25bf82;
}
.contact-btn {
  width: 152px;
  height: 48px;
  font-size: 20px;
  border-radius: 8px;
  background: #25bf82 !important;
  :deep(.el-icon) {
    margin-right: 10px;
  }
}
.rank-badge {
  position: absolute;
  top: 0;
  right: 20px;
  width: 80px;
  height: 80px;
}
</style>
