<template>
  <view class="storemanagement">
    <view class="storemanagement-header">
      <view class="storemanagement-header-text"> 商品管理 </view>
    </view>
    <view class="card-list">
      <listCardInfo
        headerTitle="商品列表"
        class="mb-t1"
        :cardData="dataBuss"
        @custom-handle-click="businessHandleClick"
      ></listCardInfo>
      <listCardInfo
        headerTitle="供应链"
        class="mb-t1"
        :cardData="onlineData"
        @custom-handle-click="onGongyingliang"
      ></listCardInfo>
      <!-- <listCardInfo headerTitle="商品分类" class="mb-t1" :fullSreen="true" fullSreenTitle="商品分类列表" ></listCardInfo> -->
      <!-- <listCardInfo headerTitle="商品规格" class="mb-t1" :fullSreen="true" fullSreenTitle="商品规格列表"></listCardInfo> -->
      <listCardInfo
        headerTitle="商品评价"
        class="mb-t1"
        :fullSreen="true"
        fullSreenTitle="商品评价列表"
        @custom-handle-click="onHandlePingJia"
      ></listCardInfo>
      <listCardInfo
       headerTitle="在线选品"
       class="mb-t1" 
      :fullSreen="true"
        fullSreenTitle="在线选品列表"  @custom-handle-click="onHandleXuanPin"></listCardInfo>
    </view>
  </view>
</template>

<script>
import readAppInfo, { getPhpToken } from "@/utils/readAppInfo.js";
import listCardInfo from "./components/listCardInfo.vue";
import { toQueryString } from "@/utils/index.js";
import { getGoodsTab, getSupplyChainTab } from "@/commit/product.js";
export default {
  components: { listCardInfo },
  data() {
    return {
      dataBuss: [
        {
          type: 1,
          name: "出售中商品",
          count: 0,
          img: "/static/images/new_ui/yijingchushou.png",
        },
        {
          type: 2,
          name: "仓库中商品",
          count: 0,
          img: "/static/images/new_ui/cangku.png",
        },
        {
          type: 3,
          name: "已售罄商品",
          count: 0,
          img: "/static/images/new_ui/yijingshouqing.png",
        },
        {
          type: 4,
          name: "警戒库存",
          count: 0,
          img: "/static/images/new_ui/jingjiekucun.png",
        },
      ],
      onlineData: [
        {
          type: 1,
          name: "出售中商品",
          count: 0,
          img: "/static/images/new_ui/yijingchushou.png",
        },
        {
          type: 2,
          name: "仓库中商品",
          count:0,
          img: "/static/images/new_ui/cangku.png",
        },
      ],

      // mnu: [
      // 	{
      // 		name: "在线选品",
      // 		url: "https://cdn.bjtdba.com/vod/image/2022-08-12/20220812161733260.png",
      // 		pages:"/pages/onlineproductselection/onlineproductselection",
      // 		show:true,
      // 		id: "0",
      // 	},
      // 	{
      // 		name: "商品列表",
      // 		url: "https://cdn.bjtdba.com/vod/image/2022-08-12/20220812161733260.png",
      // 		pages:"/shop/productManagementModule/productManagement",
      // 		show:true,
      // 		id: "0",
      // 	},
      // 	{
      // 		name: "供应链列表",
      // 		url: "https://cdn.bjtdba.com/vod/image/2022-08-12/20220812161733260.png",
      // 		pages:"/pages/supplychainon/supplychainon",
      // 		show:true,
      // 		id: "0",
      // 	}
      // ],
      uid: "",
      authorization: "",
    };
  },
  async onLoad() {
    console.log("进了我的页面了");
    // uni.showLoading({
    // 	title: '加载中',
    // 	mask: true
    // });

    await readAppInfo();
    await getPhpToken();
    return;
    let jurisdiction = uni.getStorageSync("jurisdiction") || [];
    console.log("jurisdiction", jurisdiction);
    let mnuList = this.mnu;
    if (jurisdiction) {
      jurisdiction.forEach((res, index) => {
        mnuList.forEach((result, i) => {
          if (res == result.id) {
            result.show = true;
          }
          return result;
        });
        return res;
      });
      this.mnu = mnuList;
    }

    console.log(this.mnu);

    setTimeout(function () {
      uni.hideLoading();
    }, 700);

    console.log("我的show===>>>>>>");

    this.authorization = uni.getStorageSync("authorization");
    let userinfo = uni.getStorageSync("userinfo");
    this.uid = userinfo.uid;
    console.log("onshow");
    return;

    let authorization = uni.getStorageSync("authorization");
    // let userinfo = uni.getStorageSync('userinfo')
    let selectmerchant = uni.getStorageSync("selectmerchant");
    let uid = userinfo.uid;
    console.log(selectmerchant, authorization, userinfo);
    if (authorization && uid) {
      if (selectmerchant.merId >= 0 && selectmerchant.status == -1) {
        uni.redirectTo({
          url: "/openmerchant/guide/index", //有或者没有商户 没有金额支付and激活码支付
        });
        return;
      } else if (
        selectmerchant.merId > 0 &&
        (selectmerchant.status == 1 || selectmerchant.status == 5)
      ) {
        return;
      } else if (
        selectmerchant.merId >= 0 &&
        (selectmerchant.status == 3 || selectmerchant.status == 4)
      ) {
        uni.redirectTo({
          url: "/openmerchant/shopentry/process?mer_id=" + selectmerchant.merId, //已开通商户未填写资料
        });
        return;
      } else if (selectmerchant.merId > 0 && selectmerchant.status == 0) {
        uni.redirectTo({
          url: "/openmerchant/shopentry/processaudit?submitCode=" + 3, //已开通商户待审核
        });
        return;
      } else if (selectmerchant.merId > 0 && selectmerchant.status == 2) {
        uni.redirectTo({
          url: "/openmerchant/shopentry/processaudit?submitCode=" + 2, //已开通商户审核拒绝
        });
        return;
      }
    }
  },
  async onShow() {
    uni.showLoading({
      title: "加载中",
    });
    try {
      await this.getGoodsTabNum();
      await this.getSupplyChainTabData();
    } finally {
      uni.hideLoading();
      uni.hideToast();
    }
  },
  methods: {
    async getGoodsTabNum() {
      try {
        const res = await getGoodsTab();
        if (res.data.status === 200) {
          let data = JSON.parse(JSON.stringify(this.dataBuss));
          this.dataBuss = data.map((item, index) => {
            return {
              ...item,
              count: res.data.data[index] ? res.data.data[index].count : 0,
            };
          });
        }
      } catch (error) {}
    },

    async getSupplyChainTabData() {
      try {
        const res = await getSupplyChainTab();
        if(res.data.status === 200) {
          let data = JSON.parse(JSON.stringify(this.onlineData));
          this.onlineData = data.map((item, index) => {
            return {
              ...item,
              count: res.data.data[index] ? res.data.data[index].count : 0,
            };
          });
        
        }
      } catch (error) {}
    },

    //点击事件
    businessHandleClick(item, index) {
      const obj = {
        tabIndex: index,
        type: item.type,
      };
      uni.redirectTo({
        url: `./productManagement?${toQueryString(obj)}`,
      });
    },

    //商品列表
    businessHandleClick(item, index) {
      const obj = {
        tabIndex: index,
        type: item.type,
      };
      uni.redirectTo({
        url: `./productManagement?${toQueryString(obj)}`,
      });
    },
    getUrlAuthorization() {
       let authorization = uni.getStorageSync("authorization");
        let userinfo = uni.getStorageSync("userinfo");
        let selectmerchant = uni.getStorageSync("selectmerchant");
        let uid = userinfo.uid;
          if (authorization && uid) {
          if (selectmerchant.merId >= 0 && selectmerchant.status == -1) {
            uni.redirectTo({
              url: "/openmerchant/guide/index", //有或者没有商户 没有金额支付and激活码支付
            });
            return;
          } else if (
            selectmerchant.merId > 0 &&
            (selectmerchant.status == 1 || selectmerchant.status == 5)
          ) {
            uni.redirectTo({
              url: page,
            });
            return;
          } else if (
            selectmerchant.merId >= 0 &&
            (selectmerchant.status == 3 || selectmerchant.status == 4)
          ) {
            uni.redirectTo({
              url:
                "/openmerchant/shopentry/process?mer_id=" +
                selectmerchant.merId, //已开通商户未填写资料
            });
            return;
          } else if (selectmerchant.merId > 0 && selectmerchant.status == 0) {
            uni.redirectTo({
              url: "/openmerchant/shopentry/processaudit?submitCode=" + 3, //已开通商户待审核
            });
            return;
          } else if (selectmerchant.merId > 0 && selectmerchant.status == 2) {
            uni.redirectTo({
              url: "/openmerchant/shopentry/processaudit?submitCode=" + 2, //已开通商户审核拒绝
            });
            return;
          }
        } else {
          uni.navigateTo({
            url: "/pages/user/login/index?type=1",
          });
          return;
        }
    },
    onHandleXuanPin(){
      uni.redirectTo({
        url:"/pages/onlineproductselection/onlineproductselection"
      })
    },
    // jinru(n, p) {
    //   let name = p;
    //   let page = n;
    //   if (name == "分润设置") {
       
      
    //   } else if (name == "锁定用户") {
    //     uni.redirectTo({
    //       url: page,
    //     });
    //   } else {
    //     uni.redirectTo({
    //       url: page,
    //     });
    //   }
    // },
    //商品评价
    onHandlePingJia() {
      console.log("商品评价");
      uni.redirectTo({
        url: "/shop/productManagementModule/productevaluation",
      });
    },
    //供应链
    onGongyingliang(item, index) {
      // console.log('供应链',item,index)
       const obj = {
        tabIndex: index,
        indexs:index,
        type: item.type,
      };
      uni.redirectTo({
        url: `/pages/supplychainon/supplychainon?${toQueryString(obj)}`,
      });
    },
  },
};
</script>
<style>
page {
  background-color: #f7f8fc;
}
</style>
<style lang="scss" scoped>
.storemanagement {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 40rpx;
  box-sizing: border-box;

  .storemanagement-header {
    width: 100%;
    height: 328rpx;
    background: linear-gradient(
      180deg,
      rgba(31, 124, 255, 0.22) 0%,
      rgba(255, 255, 255, 0.15) 100%
    );
    position: relative;
    display: flex;
    justify-content: center;

    .storemanagement-header-text {
      position: absolute;
      font-size: 46rpx;
      font-weight: 500;
      color: #333333;
      top: 60rpx;
      left: 64rpx;
    }
  }
  .card-list {
    position: relative;
    top: -160rpx;
    width: calc(100% - 52px);
    padding: 0 26px;
  }
  .mb-t {
    margin-bottom: 26rpx;
  }
}
</style>
