<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2023-10-16 13:59:22
-->
<template>
  <view class="content">
    <view class="header_a">
      <view class="header">
        <img @click="isTop = true" src="@/assets/images/search.png" alt="" />
        <!-- <img @click="isFont=true"
           src="@/assets/images/change.png"
           alt=""> -->
      </view>
    </view>
    <view class="zhan"></view>
    <!-- table -->
    <view class="kuang" v-for="(item, index) in tableData" :key="index">
      <table class="tftable" border="1">
        <tr>
          <td align="right">{{ '会员编号' }}</td>
          <td align="left">{{ item.memberCode }}</td>
        </tr>
        <tr>
          <td align="right">{{ '会员姓名' }}</td>
          <td align="left">{{ item.memberName }}</td>
        </tr>
        <tr>
          <td align="right">{{ '联系方式' }}</td>
          <td align="left">{{ item.phone }}</td>
        </tr>
        <tr>
          <td align="right">{{ '订单类型' }}</td>
          <td align="left">{{ item.orderTypeVal }}</td>
        </tr>
        <tr>
          <td align="right">{{ '荣誉奖衔' }}</td>
          <td align="left">{{ item.awardsName }}</td>
        </tr>
        <tr>
          <td align="right">{{ '隶属体系' }}</td>
          <td align="left">{{ item.vertexName }}</td>
        </tr>
        <tr>
          <td align="right">{{ '隶属团队' }}</td>
          <td align="left">{{ item.pkTeamCode }}</td>
        </tr>
        <tr>
          <td align="right">新增金额(￥)</td>
          <td align="left">{{ item.orderAmount }}</td>
        </tr>
        <tr>
          <td align="right">{{ '新增业绩' }}(PV)</td>
          <td align="left">{{ item.orderAchieve }}</td>
        </tr>
      </table>
    </view>
    <!-- 顶部搜索 -->
    <u-popup :show="isTop" mode="top" @close="isTop = false">
      <view class="tt">
        <u--form
          labelPosition="left"
          labelWidth="auto"
          :model="select"
          ref="uForm"
        >
          <u-row gutter="10" style="flex-wrap: wrap">
            <u-col span="6">
              <top-member-select
                label="系统编号"
                :borderBottom="false"
                @change="topMemberHandleChange"
              />
            </u-col>
            <u-col span="6">
              <u-form-item :label="'会员编号'">
                <u--input fontSize="12" v-model="select.memberCode"></u--input>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'会员姓名'">
                <u--input fontSize="12" v-model="select.memberName"></u--input>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'订单类型'">
                <picker
                  :range="orderTypeList"
                  range-key="label"
                  @change="bindPickerChange1"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.orderTypeVal"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'荣誉奖衔'">
                <picker
                  :range="awardsList"
                  range-key="awardsName"
                  @change="bindPickerChange3"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.pkAwardsVal"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'体系名称'">
                <picker
                  :range="vertexList"
                  range-key="vertexName"
                  @change="bindPickerChange4"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.vertexIdVal"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
            <u-col span="6">
              <u-form-item :label="'团队名称'">
                <picker
                  :range="memberteamList"
                  range-key="teamName"
                  @change="bindPickerChange5"
                >
                  <u--input
                    disabled
                    fontSize="12"
                    disabledColor="#ffffff"
                    v-model="select.teamIdVal"
                    suffixIcon="arrow-down"
                    suffixIconStyle="font-size: 12px;"
                  ></u--input>
                </picker>
              </u-form-item>
            </u-col>
            <u-col span="12">
              <u-form-item :label="'订单日期'" @click="isData = true">
                <u--input
                  disabled
                  fontSize="12"
                  disabledColor="#ffffff"
                  v-model="select.operationTimeVal"
                  suffixIcon="arrow-down"
                  suffixIconStyle="font-size: 12px;"
                ></u--input>
              </u-form-item>
            </u-col>
          </u-row>
        </u--form>
        <view class="footer">
          <u-button
            @click="getList1"
            color="#C8161D"
            text="搜索"
            class="btnn"
          ></u-button>
          <u-button @click="reset" text="重置"></u-button>
        </view>
      </view>
    </u-popup>
    <u-calendar
      @close="isData = false"
      :closeOnClickOverlay="true"
      :show="isData"
      :allowSameDay="true"
      mode="range"
      :maxDate="calendar.maxDate"
      :minDate="calendar.minDate"
      :monthNum="calendar.monthNum"
      @confirm="confirm"
    ></u-calendar>
    <!-- 悬浮球 -->
    <drag-button />
    <export-ball ref="exportBall" @handleExport="handleExport" />
  </view>
</template>

<script>
  import * as api from '@/api/information';
  import * as fin from '@/api/financial';
  import * as settle from '@/api/settle';
  import * as sta from '@/api/statistics';
  import topMemberSelect from '@/components/top-member-select/index.vue';
  import { isLocals, isLocalSymbol } from '@/util/numberToCurrency';
  export default {
    components: {
      topMemberSelect,
    },
    data() {
      return {
        select: {
          orderTypeVal: '全部',
          orderType: 1,
        },
        isTop: false,
        setTime: 0,
        total: 0,
        queryParams: {
          pageNum: 1,
          pageSize: 20,
        },
        tableData: [],
        vertexList: [],
        memberteamList: [],
        userCountry: {},

        orderTypeList: [],
        countryList: [],
        awardsList: [],
        calendar: {
          minDate: '',
          maxDate: '',
          monthNum: 25,
        },
        isData: false,
      };
    },
    onLoad(options) {
      if (uni.getStorageSync('userAll')) {
        this.userCountry = JSON.parse(uni.getStorageSync('userAll')).country;
      }
      this.getData();
      this.getSearch();
      this.chooseTimed();
      var s1 = this.getStartTime();
      var s2 = this.getEndTime();
      this.$set(this.select, 'startPayTime', s1);
      this.$set(this.select, 'endPayTime', s2);
      this.$set(this.select, 'operationTimeVal', s1 + ' 至 ' + s2);
    },
    onPullDownRefresh() {
      this.getList1();
    },
    methods: {
      isLocalSymbol,
      isLocals,
      topMemberHandleChange(value) {
        this.$set(this.select, 'memberCode', value);
      },
      getStartTime() {
        let date = new Date();
        let year = date.getFullYear(); // 得到当前年份
        let month =
          date.getDate() === 1 ? date.getMonth() : date.getMonth() + 1; // 得到当前月份（0-11月份，+1是当前月份）
        date.setDate(1); // 将当前时间的日期设置成第一天
        month = month >= 10 ? month : '0' + month; // 补零
        let day = date.getDate(); // 得到当前天数，实际是本月第一天，因为前面setDate(1) 设置过了
        day = day >= 10 ? day : '0' + day; // 补零
        return year + '-' + month + '-' + day;
      },
      getEndTime() {
        var date = new Date();
        var year = date.getFullYear(); // 年
        let month =
          date.getDate() === 1 ? date.getMonth() : date.getMonth() + 1; // 得到当前月份（0-11月份，+1是当前月份）
        var day = date.getDate() > 1 ? date.getDate() - 1 : date.getDate(); // 日
        let day1 = date.getDate();
        // 给一位数的数据前面加 "0"
        if (month >= 1 && month <= 9) {
          month = '0' + month;
        }
        if (day >= 0 && day <= 9) {
          day = '0' + day;
        }
        if (day1 == 1) {
          var date2 = new Date();
          var year2 = date2.getFullYear();
          var month2 = date2.getMonth();
          var dates = new Date(year2, month2, 0).getDate();
          day = dates;
        }
        return year + '-' + month + '-' + day;
      },
      // 设置默认日期，最大值为今天，最小值为去年今天
      chooseTimed() {
        let date = new Date();
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        if (month <= 9) {
          month = '0' + month;
        }
        if (day <= 9) {
          day = '0' + day;
        }
        let minyear = year - 1;
        let maxyear = year + 1;
        this.calendar.minDate = minyear + '-' + month + '-' + day;
        this.calendar.maxDate = maxyear + '-' + month + '-' + day;
      },
      handleExport() {
        let url = '/report/manager/member-report/export-direct-push-new';
        let obj = Object.assign({}, this.select, this.queryParams);
        this.$refs.exportBall.handleExport(url, obj, `伞下直推新增业绩`);
      },
      getData() {
        // 隶属体系下拉选
        api.getvertexValue().then((res) => {
          this.vertexList = res.data;
        });
        //隶属团队下拉选
        api.getmemberTeamList().then((res) => {
          this.memberteamList = res.rows;
        });
        // 订单类型
        api.getOrderBusiness().then((res) => {
          this.orderTypeList = res.data;
        });
        // 荣誉奖衔下拉选
        api.getAwardsListChiose().then((res) => {
          this.awardsList = res.rows;
        });
        // 获取国家
        settle.getcountryAllList().then((res) => {
          this.countryList = res.data;
        });
      },
      bindPickerChange1(e) {
        console.log(e);
        this.$set(
          this.select,
          'orderTypeVal',
          this.orderTypeList[e.detail.value].label
        );
        this.$set(
          this.select,
          'orderType',
          this.orderTypeList[e.detail.value].value
        );
      },
      bindPickerChange2(e) {
        this.$set(
          this.select,
          'pkSettleCountryVal',
          this.countryList[e.detail.value].name
        );
        this.$set(
          this.select,
          'pkCountry',
          this.countryList[e.detail.value].pkId
        );
      },
      bindPickerChange3(e) {
        this.$set(
          this.select,
          'pkAwardsVal',
          this.awardsList[e.detail.value].awardsName
        );
        this.$set(
          this.select,
          'pkAwards',
          this.awardsList[e.detail.value].pkId
        );
      },
      bindPickerChange4(e) {
        this.$set(
          this.select,
          'vertexIdVal',
          this.vertexList[e.detail.value].vertexName
        );
        this.$set(
          this.select,
          'pkVertex',
          this.vertexList[e.detail.value].pkId
        );
      },
      bindPickerChange5(e) {
        this.$set(
          this.select,
          'teamIdVal',
          this.memberteamList[e.detail.value].teamName
        );
        this.$set(
          this.select,
          'pkTeamCode',
          this.memberteamList[e.detail.value].pkId
        );
      },
      onReachBottom() {
        this.queryParams.pageNum++;
        this.getSearch();
      },
      //查询会员信息
      getSearch() {
        sta
          .directAddList(Object.assign({}, this.queryParams, this.select))
          .then((res) => {
            uni.stopPullDownRefresh();
            this.total = res.total;
            this.tableData = this.tableData.concat(res.rows);
          });
      },
      getList1() {
        this.tableData = [];
        this.queryParams.pageNum = 1;
        this.isTop = false;
        this.tableData = [];
        this.getSearch();
      },
      reset() {
        this.select = {};
      },
      confirm(e) {
        this.$set(this.select, 'startPayTime', e[0]);
        this.$set(this.select, 'endPayTime', e[e.length - 1]);
        this.$set(
          this.select,
          'operationTimeVal',
          e[0] + ' 至 ' + e[e.length - 1]
        );
        this.isData = false;
      },
    },
  };
</script>
<style lang="scss" scoped>
  .content {
    background: #f9f9f9;
    // padding: 20rpx;
  }
  .header_a {
    position: fixed;
    width: 100%;
    z-index: 1;
  }
  .header {
    margin: 20rpx;
    background: #ffffff;
    box-shadow: 0px 2px 10px 0px rgba(204, 204, 204, 0.4);
    border-radius: 10px 10px 10px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 30rpx 40rpx;
    img {
      width: 24px;
      height: 24px;
    }
  }
  .zhan {
    height: 130rpx;
  }
  .kuang {
    margin: 20rpx;
    background: #f9f9f9;
    border-radius: 10px 10px 10px 10px;
  }
  .table_f {
    display: flex;
    uni-button {
      margin: 20rpx 10rpx;
    }
  }
  .tftable {
    font-size: 12px;
    border-collapse: collapse;
    border-radius: 10px;
    width: 100%;
    background: #fff;
    border: 1px solid #f9f9f9;
    margin-top: 20rpx;
    td {
      font-size: 11px;
      font-family:
        PingFang SC-Medium,
        PingFang SC;
      font-weight: 500;
      color: #999;
      padding: 20rpx 40rpx;
      width: 50%;
      // height: 60px;
      border-left: 1px solid #333;
      border-bottom: 1px solid #333;
    }
    td:nth-child(odd) {
      border-left: 1px solid #f9f9f9;
    }
    tr :nth-child(2) {
      color: #333333;
    }
  }
  .tt {
    padding: 20rpx;
    margin-top: 20rpx;
  }
  ::v-deep .u-transition {
    z-index: 998 !important;
  }
  .footer {
    display: flex;
    align-items: center;
    padding: 20rpx 60rpx;
    .btnn {
      margin-right: 40rpx;
    }
  }
  ::v-deep .u-input {
    padding: 0 9px !important;
  }
  ::v-deep .u-form-item__body__left__content__label {
    font-size: 12px;
  }
  ::v-deep .u-form-item__body {
    padding: 5px 0;
  }
  .theflex {
    display: flex;
    align-items: center;
  }
</style>
