<template>
  <div class="good-page">
    <div class="good-search" v-if="!isShowGoods">
      <div>
        <a-button danger class="ml10">全部</a-button>
        <a-button danger class="ml10">正常</a-button>
        <a-button danger class="ml10">已下架</a-button>
        <a-input-search v-model:value="value" placeholder="input search text" style="width: 200px; margin-left: 10px"
          @search="onSearch" />
      </div>
      <div class="good-cad">
        <a-button type="primary" class="mr10" @click="onGoods(0)">新建商品</a-button>
        <a-button type="primary" @click="onGoods(1)">新建商品包</a-button>
      </div>
    </div>
    <div class="goods-list" v-if="!isShowGoods">
      <a-table :columns="columns" :data-source="list">
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'tags'">
            <a-button type="primary">编辑</a-button>
            <a-button type="primary" style="margin-left:20px;">统计</a-button>
            <a-button type="primary" style="margin-left:20px;">下架</a-button>
            <a-button type="primary" style="margin-left:20px;">删除</a-button>
          </template>
        </template>
      </a-table>
    </div>
    <div v-if="isShowGoods">
      <div style="display: flex; align-items: center; justify-content: space-between" v-if="isShowGoods">
        <a-button class="small left" @click="onBack">
          <template #icon>
            <LeftOutlined />
          </template>
        </a-button>
      </div>
      <GoodsBags :props="{ propsData }" v-if="propsData.isCad == 0"></GoodsBags>
      <GoodsBagSubs :props="{ propsData }" v-else> </GoodsBagSubs>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { ref, reactive, defineExpose, onMounted } from "vue";
import { LeftOutlined } from "@ant-design/icons-vue";
import GoodsBags from "./components/goods/index.vue";
import GoodsBagSubs from "./components/goodsubs/index.vue";
import { onSelectGoods } from '@/api/index'
import { getUid } from "@/utils/userInfo";
const columns = [
  {
    title: "商品编号",
    dataIndex: "goodsid",
    key: "goodsid",
  },
  {
    title: "商品名称",
    dataIndex: "shortname",
    key: "shortname",
  },
  {
    title: "商品类型",
    dataIndex: "sellingmodel",
    key: "sellingmodel",
  },
  {
    title: "商品售卖数",
    key: "markingprice",
    dataIndex: "markingprice",
  },
  {
    title: "默认金额售卖数",
    key: "price",
    dataIndex: "price",
  },
  {
    title: "已售金额",
    key: "price",
    dataIndex: "price",
  },
  {
    title: "商品状态",
    key: "status",
    dataIndex: "status",
  },
  {
    title: "操作",
    key: "tags",
    dataIndex: "tags",
  },
];
interface props {
  isCad: Number;
}
const list = ref<Array<Object>>([])
const value = ref<string>("");
const propsData = reactive<props>({
  isCad: 0,
});
const isShowGoods = ref<Boolean>(false);
const onSearch = (searchValue: string) => {
  console.log("use value", searchValue);
  console.log("or use this.value", value.value);
};
const onGoods = (e: Number) => {
  propsData.isCad = e;
  isShowGoods.value = true;
};
const onBack = (e: Number) => {
  isShowGoods.value = false;
};
onMounted(async () => {
  const uid = getUid()
  const data = await onSelectGoods(uid)
  list.value = data.data
  console.log(list, 'list');

  return list
})
defineExpose({
  value,
  columns,
  isShowGoods,
  propsData,
  onBack,
  onSearch,
  onGoods,
});
</script>
<style lang="less" scoped>
.good-page {
  .good-search {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .ood-cad {
      width: 100%;
    }

    .ml10 {
      margin-left: 10px;
    }

    .mr10 {
      margin-right: 10px;
    }
  }

  .goods-list {
    margin-top: 10px;
  }

  .small {
    border: none;
    height: 30px;
    width: 50px;
  }

  .left {
    border-left: 1px solid rgb(236, 236, 236);
    border-top: 1px solid rgb(236, 236, 236);
    border-bottom: 1px solid rgb(236, 236, 236);
    border-right-width: 80%;
    border-right: 1px solid rgb(236, 236, 236);
    border-bottom-left-radius: 25px;
    border-top-left-radius: 25px;
  }
}
</style>
<style lang="less">
.ant-layout-content{
  overflow-y: scroll;
}
</style>
