<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <TopMemberSelect
              ref="topMemberSelect"
              @change="topMemberHandleChange"
            />
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员编号'" prop="memberCode">
              <el-input v-model="queryParams.memberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员姓名'" prop="memberName">
              <el-input v-model="queryParams.memberName" clearable />
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item :label="'订单类型'" prop="orderType">
              <el-select
                v-model="queryParams.orderType"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in orderTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item :label="'真实奖衔'" prop="pkAwards">
              <el-select
                v-model="queryParams.pkAwards"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in awardsList"
                  :key="item.pkId"
                  :label="item.awardsName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'隶属体系'" prop="pkVertex">
              <el-select
                v-model="queryParams.pkVertex"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in vertexList"
                  :key="item.pkId"
                  :label="item.vertexName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'隶属团队'" prop="pkTeamCode">
              <el-select
                v-model="queryParams.pkTeamCode"
                clearable
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in memberTeamList"
                  :key="item.pkId"
                  :label="item.teamName"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="4">
            <el-form-item :label="'国家'" prop="orderType">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="queryParams.orderType"
              >
                <el-option
                  v-for="item in countryList"
                  :key="item.pkId"
                  :label="item.name"
                  :value="item.pkId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item :label="'订单日期'" prop="thetimes">
              <el-date-picker
                v-model="queryParams.thetimes"
                value-format="yyyy-MM-dd"
                type="daterange"
                :clearable="false"
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                @change="changeTime"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button
                class="my_search"
                @click="
                  () => {
                    getSearch();
                    getCzNum();
                  }
                "
              >
                {{ '搜索' }}</el-button>
              <el-button class="my_reset" @click="reChongzhi">
                {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button size="small" class="thebtn1" @click="handleExport">
            {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          v-loading="loading"
          :data="tableData"
          height="680px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column prop="colsele" type="selection" width="55" />

          <el-table-column
            align="center"
            prop="nationalFlag"
            :label="'国旗（圆形）'"
          >
            <template scope="scope">
              <img
                style="width: 44px; height: 44px; border-radius: 50%"
                :src="scope.row.nationalFlag"
                alt=""
              >
            </template>
          </el-table-column>

          <el-table-column
            align="center"
            prop="shortName"
            :label="'国家'"
            min-width="120px"
          />
          <el-table-column
            align="center"
            prop="memberCode"
            :label="'会员编号'"
            min-width="120px"
          />
          <el-table-column
            align="center"
            prop="memberName"
            :label="'会员姓名'"
            min-width="120px"
          />

          <el-table-column
            align="center"
            prop="phone"
            :label="'联系方式'"
            min-width="120px"
          />
          <el-table-column
            align="center"
            prop="awardsName"
            :label="'真实奖衔'"
          />
          <el-table-column
            align="center"
            prop="vertexName"
            :label="'隶属体系'"
          />
          <el-table-column
            align="center"
            prop="teamCodeName"
            :label="'隶属团队'"
          />
          <el-table-column
            align="center"
            prop="leftNewAddAmount"
            :label="'左区新增金额'"
          />
          <el-table-column
            align="center"
            prop="rightNewAddAmount"
            :label="'右区新增金额'"
          />
          <el-table-column
            align="center"
            prop="leftNewAddAchieve"
            min-width="100px"
            :label="'左区新增业绩' + `(PV)`"
          />
          <el-table-column
            align="center"
            prop="rightNewAddAchieve"
            min-width="100px"
            :label="'右区新增业绩' + `(PV)`"
          />
          <!-- <el-table-column
            min-width="120px"
            align="center"
            prop="orderTime"
            :label="'订单日期'"
          >
          </el-table-column> -->
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as sta from '@/api/statistics'
import * as log from '@/api/logistics'
import { getAwardsListChiose } from '@/api/level'
import { getcountryAllList } from '@/api/exchangerate'
import { getvertexValue, getmemberTeamList } from '@/api/financialCase'
import { isLocals, isLocalSymbol } from '@/utils/numberToCurrency'
import TopMemberSelect from '@/components/top-member-select/index.vue'
export default {
  name: 'UnderPlacementPer',
  components: {
    topBar,
    TopMemberSelect
  },
  data() {
    return {
      moren: 'underPlacementPer',
      topList: [
        {
          name: '伞下新增安置业绩',
          path: 'underPlacementPer'
        }
      ],
      tableData: [],
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        thetimes: [],
        memberCode: ''
      },
      total: 0,
      multipleSelection: [],
      awardsList: [],
      memberTeamList: [],
      vertexList: [],
      countryList: [],
      orderTypeList: []
    }
  },
  created() {
    this.getSearch()
    this.getOthers()
    var s1 = this.getStartTime()
    var s2 = this.getEndTime()
    this.queryParams.startPayTime = s1
    this.queryParams.endPayTime = s2
    this.queryParams.thetimes = [s1, s2]
  },
  methods: {
    isLocalSymbol,
    isLocals,
    topMemberHandleChange(val) {
      if (val) {
        this.queryParams.memberCode = val
        this.getSearch()
      }
    },
    getStartTime() {
      const date = new Date()
      date.setDate(1) // 将当前时间的日期设置成第一天
      const year = date.getFullYear() // 得到当前年份
      let month = date.getMonth() + 1 // 得到当前月份（0-11月份，+1是当前月份）
      month = month >= 10 ? month : '0' + month // 补零
      let day = date.getDate() // 得到当前天数，实际是本月第一天，因为前面setDate(1) 设置过了
      day = day >= 10 ? day : '0' + day // 补零
      return year + '-' + month + '-' + day
    },
    getEndTime() {
      const date = new Date()
      const year = date.getFullYear() // 得到当前年份
      let month = date.getMonth() + 1 // 得到当前月份（0-11月份，+1是当前月份）
      month = month >= 10 ? month : '0' + month // 补零
      let day = date.getDate() // 得到当前天数，实际是本月第一天，因为前面setDate(1) 设置过了
      day = day >= 10 ? day : '0' + day // 补零
      return year + '-' + month + '-' + day + ' '
    },
    changeTime(val) {
      this.queryParams.startPayTime = val[0]
      this.queryParams.endPayTime = val[1]
    },
    getOthers() {
      getAwardsListChiose().then((res) => {
        this.awardsList = res.rows
      })
      getmemberTeamList().then((res) => {
        this.memberTeamList = res.rows
      })
      getvertexValue().then((res) => {
        this.vertexList = res.data
      })
      getcountryAllList().then((res) => {
        this.countryList = res.data
      })
      // 获取订单类型
      log.getUnderAddOrderType().then((res) => {
        this.orderTypeList = res.data
      })
    },
    // 导出
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/report/manager/member-report/member-resettle-achieve-export',
          { ...this.queryParams },
          `${'伞下新增安置业绩'}${new Date().getTime()}.xlsx`
        )
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    reChongzhi() {
      this.$refs.topMemberSelect.reset()
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
        thetimes: []
      }
      this.getSearch()
    },
    getSearch() {
      this.loading = true
      sta.getResettleAchieve(this.queryParams).then((res) => {
        this.loading = false
        if (res.code == 200) {
          this.tableData = res.rows
          this.total = res.total
        }
      })
    },
    getCzNum() {
      this.queryParams.pageNum = 1
    }
  }
}
</script>

    <style lang="scss" scoped>
::v-deep .el-image-viewer__close {
  right: 500px;
}
::v-deep .dizhi .el-cascader {
  width: 100%;
}
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #ffad41;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          color: #ffffff;
          background: #009b58;
          width: 68px;
          height: 32px;
        }
        .thebtn3 {
          color: #ffffff;
          background: #c8161d;
          width: 68px;
          height: 32px;
        }
      }
    }
  }
}
</style>
