<!--
 * @Descripttion: 
 * @version: 
 * @Author: 王三华
 * @Date: 2024-02-26 14:33:49
-->
<!--
 * @Descripttion:
 * @version:
 * @Author: kBank
 * @Date: 2022-10-24 15:45:01
-->
<template>
  <div class="page">
    <topBar v-if="topList.length > 0"
            :topList="topList"
            :moren="moren"></topBar>
    <div class="main">
      <div class="form_all">
        <el-form ref="select"
                 :model="select"
                 label-width="auto">
          <el-row :gutter="40">
            <!-- 一层 -->
            <el-col :span="4">
              <el-form-item :label="'会员编号'">
                <el-input clearable
                          v-model="select.memberCode"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'产品编号'">
                <el-input v-model="select.productCode"
                          clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'产品名称'">
                <el-input v-model="select.productName"
                          clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'订单类型'">
                <el-select clearable
                           :placeholder="'请选择'"
                           v-model="select.orderType">
                  <el-option v-for="item in orderStatusList"
                             :key="item.value"
                             :label="item.label"
                             :value="item.value"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'订单日期'">
                <el-date-picker v-model="creationTime"
                                @change="changeTime"
                                value-format="yyyy-MM-dd"
                                type="daterange"
                                :range-separator="'至'"
                                :start-placeholder="'开始日期'"
                                :end-placeholder="'结束日期'">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary"
                         size="small"
                         @click="getDataList"> {{ '搜索' }}</el-button>
              <el-button size="small"
                         class="resetBtn"
                         @click="reset"> {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="main_a">
        <div class="mainbtn">
          <el-button size="small"
                     @click="handleExport"
                     v-hasButtons="['underProductExport']"
                     class="exportBtn"> {{ '导出' }}</el-button>
        </div>
        <div class="maintable">
          <el-table :data="tableData"
                    style="width: 100%"
                    v-loading="loading"
                    height="710px"
                    :header-cell-style="{ background: '#EEEEEE' }"
                    :row-class-name="tableRowClassName"
                    @selection-change="handleSelectionChange">
            <el-table-column type="selection"
                             width="55"> </el-table-column>
            <el-table-column align="center"
                             prop="memberCode"
                             :label="'会员编号'">
            </el-table-column>
            <el-table-column align="center"
                             prop="memberName"
                             :label="'会员姓名'">
            </el-table-column>
            <el-table-column align="center"
                             prop="orderTypeVal"
                             :label="'订单类型'">
            </el-table-column>
            <el-table-column align="center"
                             prop="pkRegisterGradeVal"
                             :label="'注册等级'">
            </el-table-column>
            <el-table-column align="center"
                             prop="pkAwardsVal"
                             :label="'真实奖衔'">
            </el-table-column>
            <el-table-column align="center"
                             prop="orderAmount"
                             :label="'累计金额'+'(￥)'">
            </el-table-column>
            <el-table-column align="center"
                             prop="orderAchieve"
                             :label="'累计业绩'+'(￥)'">
            </el-table-column>
            <el-table-column align="center"
                             prop="time"
                             :label="'操作'"
                             fixed="right">
              <template slot-scope="scope">
                <el-button @click="addData(scope.row)"
                v-hasButtons="['underProductDel']"
                           type="text"
                           style="color: #48B2FD;"
                           size="small">
                  去重
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <el-dialog title="去重"
               :close-on-click-modal="false"
               :visible.sync="dialogVisible"
               width="40%"
               center
               :before-close="handleClose">
      <el-form ref="form"
               :model="form"
               label-width="auto">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="'会员编号'">
              <el-input clearable
                        disabled
                        v-model="form.memberCode"
                        :placeholder="'请输入'"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'会员姓名'">
              <el-input clearable
                        disabled
                        v-model="form.memberName"
                        :placeholder="'请输入'"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="flex_div">
          <div class="flexs1 flex_left">
            <div class="left_top">
              <div>
                <el-form-item :label="'会员编号'">
                  <el-input clearable
                            v-model="form.addmemberCode"
                            :placeholder="'请输入'"></el-input>
                </el-form-item>
                <el-form-item :label="'会员姓名'">
                  <el-input clearable
                            v-model="form.addmemberName"
                            disabled></el-input>
                </el-form-item>
              </div>
              <div style="margin-left: 20px">
                <el-button @click.native.prevent="addLeftTag"
                           type="text"
                           size="small"
                           style="background: #c8161d; color: #ffffff">
                  {{ '添加' }}
                </el-button>
              </div>
            </div>
            <div class="flex_main">
              <div v-for="(aitem, aindex) in addList"
                   :key="aindex"
                   class="kuang">
                <div class="kuang_i">
                  <div>
                    <div> {{ aitem.memberCode }}</div>
                    <div> {{ aitem.memberName }}</div>
                  </div>
                  <img src="@/assets/images/iconpop.png"
                       @click="closeLeftTag(aitem)"
                       alt="">
                </div>
              </div>
              <!-- <el-tag
                v-for="(aitem, aindex) in addList"
                :key="aindex"
                style="margin-right: 10px; margin-bottom: 15px"
                effect="plain"
                closable
                @close="closeLeftTag(aitem)"
              >
             {{ aitem.memberCode }}
              </el-tag> -->
            </div>
          </div>
        </div>
      </el-form>
      <span slot="footer"
            class="dialog-footer">
        <el-button @click="handleClose">{{ '取消' }}</el-button>
        <el-button type="primary"
                   @click="onSubmit('form')">{{
          '确认'
        }}</el-button>
      </span>
    </el-dialog>
    <pagination v-show="total > 0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getDataList" />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/statistics.js'
import * as log from '@/api/logistics'
import { gettheMemberInfo } from '@/api/affiliatedteam'

export default {
  name: 'Bzpz',
  components: {
    topBar,
  },
  data() {
    return {
      creationTime: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading:false,
      moren: 'underDirectProductList',
      topList: [
        {
          name: '伞下直推产品查询',
          path: 'underDirectProductList',
        },
      ],

      orderStatusList: [],
      form: {},
      addList: [],
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
  },
  methods: {
    //重置
    reset() {
      this.select = {}
      this.creationTime = []
      this.getDataList()
    },
    //添加
    addData(item) {
      this.form = item
      this.dialogVisible = true
    },
    getData() {
      //订单状态
      log.getUnderAddOrderType().then((res) => {
        this.orderStatusList = res.data
      })
    },
    changeTime(val) {
      this.select.startDate = val ? val[0] : ''
      this.select.endDate = val ? val[1] : ''
    },
    addLeftTag() {
      gettheMemberInfo(this.form.addmemberCode).then((res) => {
        this.form.addmemberName = res.data.memberName
        if (res.code == 200) {
          const tag1 = { memberCode: '', memberName: '', pkMember: '' }
          tag1.memberCode = res.data.memberCode
          tag1.memberName = res.data.memberName
          tag1.pkMember = res.data.pkId
          let a = this.addList.some((item) => {
            return item.pkMember == tag1.pkMember
          })
         if(!a){
          this.addList.push(tag1)
         }
        }
      })
    },
    //加区减掉tag
    closeLeftTag(row) {
      for (let i = this.addList.length - 1; i >= 0; i--) {
        if (this.addList[i].memberCode === row.memberCode) {
          this.addList.splice(i, 1)
        }
      }
    },
    onSubmit() {
      let list = this.addList.map(item=>{
        return item.pkMember
      })
      let obj = Object.assign({pkMemberStr:list.join(',')},this.select)
      
      this.$router.push({
        path: 'underDirectProductDetails',
        query: {
          data: JSON.stringify(obj)
        },
      })
    },
    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },

    // 获取列表
    getDataList() {
      this.loading = true
      api
        .umbrellaList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.tableData = res.rows
          this.total = res.total
          this.loading = false
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then((_) => {
        this.download(
          '/report/manager/member-awards/umbrella-below-product-excel',
          Object.assign({}, { actType: 21 }, this.queryParams, this.select),
          `伞下直推产品查询${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    },
  },
}
</script>
<style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    // background: #ffffff;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    .main_a {
      background: #fff;
      border-radius: 8px;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    }
    .mainbtn {
      padding: 0;
    }
    .maintable {
      flex: 1;
    }
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
.form_all {
  padding: 0 20px;
  margin-bottom: 10px;
  background: #fff;
}
.flex_div {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  border-top: 4px solid rgba(0, 0, 0, 0.1);
  // .flex_left {
  //   border-right: 4px solid rgba(0, 0, 0, 0.1);
  // }
  .flexs1 {
    flex: 1;
    padding: 10px;

    .left_top {
      display: flex;
      align-items: center;
    }
  }
}
.flex_main {
  border: 1px solid #cccccc;
  padding: 10px;
  border-radius: 10px 10px 10px 10px;
  min-height: 300px;
  margin: 10px 0;
}
.atext {
  text-align: center;
  font-size: 18px;
  font-family: PingFang SC-Semibold, PingFang SC;
  font-weight: 600;
  color: #000000;
}
.kuang {
  border: 1px solid #cccccc;
  border-radius: 8px;
  display: inline-block;
  padding: 5px 10px;
  margin: 0 10px 10px 0;
  .kuang_i {
    display: flex;
    align-items: center;
    text-align: center;
  }
  img {
    width: 19px;
    height: 19px;
    margin-left: 10px;
  }
}
</style>
