<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-05-22 15:31:58
 * @Description: file content
 * @FilePath: \oms\pages\distributor\index.vue
-->
<template>
  <view class="home">
    <view class="nav">
      <view :style="{ paddingTop }">
        <view class="title" :style="[{ height }, { lineHeight: height }]">
          <view class="back" @click="goBack()">
            <u-icon name="arrow-left" color="#ffffff" size="22"></u-icon>
          </view>
          <text>招标信息</text>
        </view>
      </view>
    </view>
    <view class="main">
      <!-- 搜索 -->
      <view class="query-wrap">
        <view class="search-container">
          <view class="search-input">
            <u-input
              clearable
              placeholderStyle="font-size:26rpx"
              :customStyle="{ height: '66rpx' }"
              v-model="title"
              prefixIcon="search"
              prefixIconStyle="font-size: 22px;color: #909399"
              placeholder="请输入招标信息标题"
              shape="circle"
              border="surround"></u-input>
          </view>
          <view class="search-btn" @click="searchList">搜索</view>
        </view>
      </view>
      <u-empty v-if="bidData.length == 0" mode="list" text="暂无数据"></u-empty>
      <scroll-view :scroll-y="true" class="data-list" @scrolltolower="lower" v-else>
        <view>
          <view class="data-item" v-for="(v, i) in bidData" :key="i" @click="toDetails(v)">
            <view class="customer-name flex">
              <text class="name">{{ v.title }}</text>
            </view>
            <view class="customer-info flex">
              <view class="info-left flex_1">
                <view class="info-row flex_l">
                  <text class="info-label">客户名称：</text>
                  <u-text color="#323232" size="24rpx" :text="v.cuctName || '-'"></u-text>
                </view>
                <view class="info-row flex_l">
                  <text class="info-label">招标产品名称：</text>
                  <u-text color="#323232" size="24rpx" :text="v.productName || '-'"></u-text>
                </view>
                <view class="info-row flex_l">
                  <text class="info-label">发布招标日期：</text>
                  <u-text
                    color="#323232"
                    size="24rpx"
                    :text="parseTime(v.publishedTime, '{y}-{m}-{d}') || '-'"></u-text>
                </view>
              </view>
            </view>
          </view>
          <u-loadmore :status="loadStatus" />
        </view>
      </scroll-view>
    </view>
    <!-- 消息提示 -->
    <u-toast ref="uToast"></u-toast>
  </view>
</template>
<script>
  import bidApi from '../../api/bid'
  import to from 'await-to-js'
  export default {
    name: 'omsIndex',
    components: {},
    data() {
      return {
        openBtnWidth: false,
        lineBg: require('@/static/images/up.png'),
        curTabIndex: 0,
        height: '',
        paddingTop: '',
        pageNum: 0,
        pageSize: 10,
        bidData: [], //客户列表
        bidDataTotal: 0, //列表元素数量
        loadStatus: '', //加载状态
        title: '', //经销商名称
      }
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    onShow() {
      this.searchList()
    },
    methods: {
      // 上拉滚动
      lower() {
        if (this.bidData.length < this.bidDataTotal && this.loadStatus != 'loading') {
          this.$u.throttle(this.getBidList(), 2000, false)
        }
      },
      // 查询列表
      searchList() {
        this.pageNum = 0
        this.getBidList(true)
      },
      async getBidList(reset) {
        this.loadStatus = 'loading'
        this.pageNum++
        let params = {
          title: this.title,
          pageNum: this.pageNum,
          pageSize: this.pageSize,
        }
        const [err, res] = await to(bidApi.list(params))
        if (err) {
          this.loadStatus = 'nomore'
          return
        }
        if (res && res.code == 200) {
          if (reset) {
            this.bidData = res.data.list || []
          } else {
            this.bidData = [...this.bidData, ...(res.data.list || [])]
          }
          this.bidDataTotal = res.data.total
          this.loadStatus = this.bidData.length == this.bidDataTotal ? 'nomore' : 'loadmore'
        } else {
          this.loadStatus = 'nomore'
        }
      },
      goBack() {
        uni.navigateBack({
          //关闭当前页面，返回上一页面或多级页面。
          delta: 1,
        })
      },
      toDetails(v) {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/inviteTenders/details?id=' + v.id,
        })
      },
    },
  }
</script>
<style>
  page {
    background: #f2f3f5;
  }
</style>
<style lang="scss" scoped>
  .home {
    padding-top: 188rpx;

    .nav {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 284rpx;
      background: #3e7ef8;
      .title {
        position: relative;
        text-align: center;
        font-size: 32rpx;
        font-weight: bold;
        color: #ffffff;
        .back {
          position: absolute;
          top: 0;
          bottom: 0;
          margin: auto;
          left: 70rpx;
          display: flex;
        }
      }
    }

    .main {
      position: absolute;
      width: 100%;
      height: calc(100vh - 188rpx);
      background: #ffffff;
      box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
      border-radius: 31rpx 31rpx 0 0;
      padding: 0 32rpx;
      padding-bottom: 64rpx;
      .query-wrap {
        padding-top: 20rpx;
        .search-container {
          display: flex;
          align-items: center;
          .search-input {
            flex: 1;
          }
          .search-btn {
            text-align: center;
            line-height: 60rpx;
            border-radius: 12rpx;
            width: 100rpx;
            height: 60rpx;
            font-size: 26rpx;
            margin: 0 0 0 12rpx;
            background: $u-primary;
            color: #ffffff;
          }
        }
      }
      .data-list {
        width: 100%;
        height: calc(100vh - 372rpx);
        overflow-y: scroll;
        .data-item {
          background: rgba(242, 243, 245, 0.5);
          border-radius: 15rpx;
          padding: 28rpx 40rpx 28rpx 38rpx;
          margin-top: 32rpx;
          .customer-name {
            .name {
              flex: 1;
              color: #323232;
              font-weight: bold;
              font-size: 28rpx;
              margin-right: 12rpx;
            }
            .user-code {
              width: 180rpx;
              height: 32rpx;
              font-size: 24rpx;
              color: #323232;
              line-height: 32rpx;
            }
          }
          .customer-info {
            .info-left {
              .transfer-btn {
                margin-top: 20rpx;
                width: 150rpx;
              }
              .info-row {
                margin-top: 12rpx;
                .info-label {
                  color: #646464;
                  font-size: 24rpx;
                }
              }
            }
            .info-right {
              padding-top: 30rpx;
              .user-img {
                border-radius: 50%;
                width: 46rpx;
                height: 46rpx;
              }
            }
          }
        }
      }
    }

    .filter-popup {
      background: rgba(0, 0, 0, 0.8);
      position: fixed;
      width: 100%;
      height: 100%;
      left: 0;
      z-index: 1;
      .filter-wrap {
        width: 100%;
        padding: 20rpx;
        background: #ffffff;
        .filter-item {
          padding-bottom: 30rpx;
          .tit {
            font-size: 26rpx;
            color: #323232;
            font-weight: bold;
            padding-bottom: 20rpx;
          }
          .menu-list {
            display: flex;
            flex-wrap: wrap;
            .menu-item {
              margin-right: 40rpx;
              margin-bottom: 20rpx;
            }
          }
        }
      }
      .btn-box {
        width: 698rpx;
        height: 75px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        > view {
          width: 320rpx;
          height: 40px;
          border-radius: 40px;
          border: solid 1rpx #ec652b;
          align-items: center;
          justify-content: center;
          text-align: center;
          line-height: 40px;
        }
        .reset {
          color: #ec652b;
        }
        .submit {
          color: #fff;
          background-color: #ec652b;
        }
      }
    }

    .fixed-btn-group {
      position: fixed;
      display: flex;
      justify-content: space-around;
      align-items: center;
      width: 90rpx;
      height: 90rpx;
      bottom: 50rpx;
      right: 50rpx;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      border-radius: 20px;
      transition: all 0.2s;
      background: #fff;

      .btn {
        width: 60rpx;
        height: 60rpx;
        background: #3e7ef8;
        border-radius: 50%;
        margin: 10rpx;
        font-size: 26rpx;
        font-weight: bold;
        color: #ffffff;
      }
    }
  }
</style>
