<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-02-17 14:46:41
 * @Description: file content
 * @FilePath: \oms\pages\project\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="queryForm.nboName"
              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-tabs
        :list="list"
        @change="changeTabs"
        :current="curTabIndex"
        :activeStyle="{
          color: '#323232',
          fontWeight: 'bold',
        }"
        :inactiveStyle="{
          color: '#969696',
        }"></u-tabs>
      <u-empty v-if="projectData.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 projectData" :key="i" @click="toDetails(v)">
            <view class="customer-name flex">
              <text class="name">{{ v.nboName }}</text>
              <view class="user-code">
                <text>{{ v.nboCode }}</text>
              </view>
            </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.saleName"></u-text>
                </view>
                <view class="info-row flex_l">
                  <text class="info-label">客户名称：</text>
                  <u-text color="#323232" size="24rpx" :text="v.custName"></u-text>
                </view>
                <view class="info-row flex_l">
                  <text class="info-label">项目来源：</text>
                  <u-text
                    color="#323232"
                    size="24rpx"
                    :text="selectDictLabel(sourceOptions, v.nboSource) || '-'"></u-text>
                </view>
                <view class="info-row flex_l">
                  <text class="info-label">销售模式：</text>
                  <u-text
                    color="#323232"
                    size="24rpx"
                    :text="selectDictLabel(salesModelOptions, v.salesModel) || '-'"></u-text>
                </view>
                <view class="info-row flex_l">
                  <text class="info-label">产品线：</text>
                  <u-text
                    color="#323232"
                    size="24rpx"
                    :text="selectDictLabel(productLineOptions, v.productLine) || '-'"></u-text>
                </view>
                <view class="info-row flex_l">
                  <text class="info-label">项目预算（万元）：</text>
                  <u-text color="#323232" size="24rpx" mode="price" :text="v.nboBudget"></u-text>
                </view>
                <view class="flex_l">
                  <view class="transfer-btn mr20" @click.stop="linkToTransfer(v.id)">
                    <u-button type="primary" size="small" text="转移项目"></u-button>
                  </view>
                  <!-- <view class="transfer-btn mr20" @click.stop="$refs.moveCust.open(v.id)">
                    <u-button type="primary" size="small" text="移入公海"></u-button>
                  </view> -->
                </view>
              </view>
              <view class="info-right flex_l flex-column">
                <!-- <image class="user-img" src="@/static/images/user.jpg" mode="scaleToFill" /> -->
                <u-text color="#646464" size="20rpx" :text="v.salesName"></u-text>
              </view>
            </view>
          </view>
          <u-loadmore :status="loadStatus" />
        </view>
      </scroll-view>
    </view>
  </view>
</template>
<script>
  import projectApi from '../../api/project'
  import to from 'await-to-js'
  export default {
    name: 'omsIndex',
    components: {},
    data() {
      return {
        list: [
          {
            name: '全部项目',
            status: 0,
            nboType: null,
          },
          {
            name: 'C类项目',
            status: 1,
            nboType: '30',
          },
          {
            name: 'B类项目',
            status: 2,
            nboType: '20',
          },
          {
            name: 'A类项目',
            status: 3,
            nboType: '10',
          },
          {
            name: '成交项目',
            status: 4,
            nboType: '40',
          },
          {
            name: '储备项目',
            status: 5,
            nboType: '50',
          },
        ],
        curTabIndex: 0, //tabs状态
        height: '',
        paddingTop: '',
        queryForm: {
          pageNum: 0,
          pageSize: 10,
          nboName: '', //项目名称
        },
        projectData: [], //项目列表
        projectDataTotal: 0, //列表元素数量
        loadStatus: '', //加载状态
        salesModelOptions: [], //销售模式列表
        productLineOptions: [], //产品线列表
        sourceOptions: [], //来源列表
      }
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    onShow() {
      this.getOptions()
      this.searchList()
    },
    methods: {
      getOptions() {
        Promise.all([
          this.getDicts('proj_sales_model'),
          this.getDicts('sys_product_line'),
          this.getDicts('proj_nbo_source'),
        ])
          .then(([model, line, source]) => {
            this.salesModelOptions = model.data.values || []
            this.productLineOptions = line.data.values || []
            this.sourceOptions = source.data.values || []
          })
          .catch((err) => console.log(err))
      },
      // 改变tab
      changeTabs(data) {
        console.log(data)
        this.curTabIndex = data.status
        this.searchList()
      },
      // 上拉滚动
      lower() {
        if (this.projectData.length < this.projectDataTotal && this.loadStatus != 'loading') {
          this.$u.throttle(this.getProjectData(), 2000, false)
        }
      },
      // 查询列表
      searchList() {
        this.queryForm.pageNum = 0
        this.getProjectData(true)
      },
      async getProjectData(reset) {
        this.loadStatus = 'loading'
        this.queryForm.pageNum++
        let params = {
          nboType: this.list[this.curTabIndex].nboType,
          nboName: this.queryForm.nboName,
          pageNum: this.queryForm.pageNum,
          pageSize: this.queryForm.pageSize,
        }
        const [err, res] = await to(projectApi.getList(params))
        if (err) {
          this.loadStatus = 'nomore'
          return
        }
        if (res && res.code == 200) {
          if (reset) {
            this.projectData = res.data.list || []
          } else {
            this.projectData = [...this.projectData, ...(res.data.list || [])]
          }
          this.projectDataTotal = res.data.total
          console.log(
            'this.projectData.length == this.projectDataTotal',
            this.projectData.length == this.projectDataTotal
          )
          this.loadStatus = this.projectData.length == this.projectDataTotal ? 'nomore' : 'loadmore'
        } else {
          this.loadStatus = 'nomore'
        }
      },
      // 跳转到转移客户
      linkToTransfer(id) {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/project/transfer?id=' + id,
        })
      },
      goBack() {
        uni.navigateBack({
          //关闭当前页面，返回上一页面或多级页面。
          delta: 1,
        })
      },
      toDetails(v) {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/project/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;
      overflow: hidden;
      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 - 422rpx);
        overflow: auto;
        .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;
        }
      }
    }
  }
</style>
