<template>
  <view class="c-card">
    <view class="search">
      <u-search
        placeholder="请输入出货产品名称"
        v-model="state.name"
        :showAction="false"
        :bgColor="'#fff'"
        :borderColor="'rgba(0, 0, 0, 0.1)'"
        :placeholderColor="'#C1C1C1'"
        @search="handleSearch()"
      ></u-search>
      <view class="btn" @click="add"> 新增 </view>
    </view>

    <view class="box" v-for="(item, index) in pageList.list" :key="index">
      <view>
        <view>
          <view>{{ item.shmProductsName }}</view>
          <view>分类：{{ item.parentName }} / {{ item.shmCategoryName }} </view>
        </view>
        <view class="op-box">
          <view class="btn" @click="edit(item)"> 编辑 </view>
          <view class="btn" @click="update(item)"> 删除 </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script setup lang="ts">
import { GoodsApi } from "@/services";
import { UsersType } from "@/utils/enum";
const state = reactive<any>({
  name: "",
  supplierTypeId: -1,
  isShowType: false,
  typeList: [],
});
const pageList: PageResult<{
  shmProductsName: string;
  parentName: string;
  shmCategoryName: string;
}> = reactive({
  total: 0,
  list: [],
  pageNum: 1,
  pageSize: 10,
});

const handleSearch = () => {
  getList();
};

const update = (item: any) => {
  GoodsApi.EditReceiveProduct({ isDeleted: true, id: item.id }).then(
    (res) => {
      if (res.code === 200) {
        getList();
      }
    }
  );
};

const edit = (item: any) => {
  uni.navigateTo({
    url:
      "/pagesApp/components/addShipmentProduct?title=编辑收货产品&item=" +
      JSON.stringify(item), // 要跳转到的页面路径
  });
};
const getList = () => {
  let params: any = {
    pageSize: 10,
    pageNum: 1,
    name: state.name,
  };
  GoodsApi.getShipmentProductByPage(params).then((res) => {
    if (res.code === 200) {
      if (res.code === 200) {
        (pageList as any).list = (res.data as any).list;
      }
    }
  });
};
const add = () => {
  uni.navigateTo({
    url: "/pagesApp/components/addShipmentProduct", // 要跳转到的页面路径
  });
};
onMounted(() => {
  getList();
});
</script>
<style lang="scss" scoped>
.c-card {
  margin: 30rpx 25rpx;
  .search {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .type {
      display: flex;
      margin-right: 20rpx;
      font-size: 28rpx;
      color: #000000;
    }
    .btn {
      background: #00dcee;
      border-radius: 24rpx;
      border: 1px solid #00dcee;
      font-weight: 500;
      font-size: 28rpx;
      color: #ffffff;
      margin-left: 50rpx;
      padding: 6rpx 30rpx;
    }
  }
  .box {
    background: #ffffff;
    box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(5, 68, 37, 0.12);
    border-radius: 13rpx;
    padding: 0rpx 20rpx;
    font-weight: 400;
    font-size: 28rpx;
    color: #000000;
    line-height: 41rpx;
    margin-top: 30rpx;
    > view {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 20rpx 0rpx;

      .op-box {
        display: flex;
        .btn + .btn {
          margin-left: 20rpx;
        }
        .btn {
          background: #ff9d55;
          border-radius: 24rpx;
          font-weight: 500;
          font-size: 28rpx;
          color: #ffffff;
          padding: 6rpx 30rpx;
        }
        .btn_text {
          font-weight: 500;
          font-size: 24rpx;
          color: #00dcee;
        }
      }
    }
    > view + view {
      border-top: 1px solid rgba(233, 233, 233, 0.76);
    }
  }
}
</style>
