<template>
  <div class="page">
    <topBar v-if="topList.length > 0" :top-list="topList" :moren="moren" />
    <div class="thetopbox">
      <el-form ref="form" :model="queryParams" label-width="auto">
        <el-row :gutter="20">
          <el-col :span="4">
            <el-form-item :label="'会员编号'">
              <el-input v-model="queryParams.memberCode" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员姓名'">
              <el-input v-model="queryParams.memberName" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'隶属体系'" prop="pkVertex">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="queryParams.pkVertex"
              >
                <el-option
                  v-for="item in vertexList"
                  :key="item.pkId"
                  :label="item.vertexName"
                  :value="item.pkId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'隶属团队'" prop="pkTeamCode">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="queryParams.pkTeamCode"
              >
                <el-option
                  v-for="item in memberteamList"
                  :key="item.pkId"
                  :label="item.teamName"
                  :value="item.pkId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="补贴状态" prop="status">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="queryParams.status"
              >
                <el-option
                  v-for="item in pekStatusList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开始时间" prop="creationTime">
              <el-date-picker
                v-model="queryParams.creationTime"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="--"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button class="my_search" @click="research">
                {{ '搜索' }}</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="addBtn"
            v-hasButtons="['memberSubsidyConfigAdd']"
            @click="addRules"
            >{{ '添加' }}</el-button
          >
          <el-button
            size="small"
            style="background-color: #c73030; color: #fff"
            @click="delRole"
            :disabled="multipleSelection.length == 0"
            v-hasButtons="['memberSubsidyConfigDel']"
          >
            {{ '删除' }}
          </el-button>
          <el-button
            size="small"
            @click="handleExport"
            class="thebtn1"
            style="background: rgba(243, 169, 0, 1)"
            v-hasButtons="['memberSubsidyConfigExport']"
          >
            {{ '导出' }}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          height="670px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column
            min-width="130px"
            align="center"
            prop="memberCode"
            label="会员编号"
          />
          <el-table-column align="center" prop="memberName" label="会员姓名" />
          <el-table-column
            min-width="130px"
            align="center"
            prop="vertexName"
            label="体系"
          />
          <el-table-column
            min-width="130px"
            align="center"
            prop="teamName"
            label="团队"
          />
          <el-table-column
            align="center"
            prop="checkAmountVal"
            label="考核金额"
          />
          <el-table-column
            align="center"
            prop="checkAchieveVal"
            label="考核业绩"
          />
          <el-table-column
            align="center"
            prop="checkTypeVal"
            label="考核类型"
          />
          <el-table-column
            align="center"
            prop="containCabinVal"
            label="是否含舱"
          />
          <el-table-column
            align="center"
            prop="deductionPolicyVal"
            label="扣除政策币"
          />
          <el-table-column
            align="center"
            prop="deductionRepurchaseVal"
            label="扣除复购券"
          />
          <el-table-column
            align="center"
            prop="deduplicationVal"
            label="是否去重"
          />
          <el-table-column
            min-width="130px"
            align="center"
            prop="startDate"
            label="开始时间"
          />
          <el-table-column
            min-width="130px"
            align="center"
            prop="endDate"
            label="结束时间"
          />
          <el-table-column
            align="center"
            prop="realAmount"
            min-width="130px"
            label="实际金额"
          />
          <el-table-column
            align="center"
            prop="realAchieve"
            min-width="130px"
            label="实际业绩"
          />
          <el-table-column
            align="center"
            prop="distinctAmount"
            label="去重金额"
          >
            <template slot-scope="scope">
              <span
                @click="goOrder(scope.row)"
                style="color: #48b2fd; cursor: pointer"
                >{{ scope.row.distinctAmount }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="distinctAchieve"
            label="去重业绩"
          >
            <template slot-scope="scope">
              <span
                @click="goOrder(scope.row)"
                style="color: #48b2fd; cursor: pointer"
                >{{ scope.row.distinctAchieve }}</span
              >
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="usedPolicy"
            min-width="130px"
            label="使用政策币"
          />
          <el-table-column
            align="center"
            prop="usedRepurchase"
            min-width="130px"
            label="使用复购券"
          />
          <el-table-column
            min-width="130px"
            align="center"
            prop="finalAmount"
            label="最终金额"
          />
          <el-table-column
            align="center"
            prop="finalAchieve"
            min-width="130px"
            label="最终业绩"
          />
          <el-table-column align="center" prop="statusVal" label="补贴状态" />
          <el-table-column
            align="center"
            fixed="right"
            :label="'操作'"
            width="150"
          >
            <template slot-scope="scope">
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #ffad41"
                @click.native.prevent="goDetail(scope.row)"
                v-hasButtons="['memberSubsidyConfigDetail']"
              >
                {{ '明细' }}
              </el-button>
              <el-button
                size="small"
                type="text"
                @click="toCopy(scope.row)"
                style="color: #6962f6"
                v-hasButtons="['memberSubsidyConfigCopy']"
                class="colors"
                >{{ '复制' }}</el-button
              >
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #48b2fd"
                v-if="scope.row.status == 1"
                @click.native.prevent="updateShow(scope.row)"
                v-hasButtons="['memberSubsidyConfigUpdate']"
              >
                {{ '修改' }}
              </el-button>
              <el-button
                class="colors"
                type="text"
                size="small"
                style="color: #ffad41"
                v-if="scope.row.status == 3"
                @click.native.prevent="returnedMemberPerk(scope.row)"
                v-hasButtons="['memberSubsidyConfigReturn']"
              >
                反补
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="research"
    />
    <el-dialog
      :title="title"
      :visible.sync="ruleShow"
      width="70%"
      center
      :close-on-click-modal="false"
      :before-close="handleClose"
    >
      <el-table
        :data="dialogTable"
        style="width: 100%"
        :header-cell-style="{ background: '#EEEEEE' }"
        :row-class-name="tableRowClassName"
      >
        <el-table-column
          min-width="100px"
          align="center"
          prop="memberCode"
          label="会员编号"
        >
          <template slot-scope="scope">
            <el-input
              @blur="checkName(scope.row)"
              v-model="scope.row.memberCode"
            ></el-input>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="checkAmount" label="考核金额">
          <template slot-scope="scope">
            <el-select
              clearable
              :placeholder="'请选择'"
              v-model="scope.row.checkAmount"
            >
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="checkAchieve" label="考核业绩">
          <template slot-scope="scope">
            <el-select
              clearable
              :placeholder="'请选择'"
              v-model="scope.row.checkAchieve"
            >
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="checkType" label="考核类型">
          <template slot-scope="scope">
            <el-select
              clearable
              :placeholder="'请选择'"
              v-model="scope.row.checkType"
            >
              <el-option
                v-for="item in achievementTypeList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="containCabin" label="是否含舱">
          <template slot-scope="scope">
            <el-select
              clearable
              :placeholder="'请选择'"
              v-model="scope.row.containCabin"
            >
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="deductionPolicy"
          label="扣除政策币"
        >
          <template slot-scope="scope">
            <el-select
              clearable
              :placeholder="'请选择'"
              v-model="scope.row.deductionPolicy"
            >
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="deductionRepurchase"
          label="扣除复购券"
        >
          <template slot-scope="scope">
            <el-select
              clearable
              :placeholder="'请选择'"
              v-model="scope.row.deductionRepurchase"
            >
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="deduplication" label="是否去重">
          <template slot-scope="scope">
            <el-select
              clearable
              :placeholder="'请选择'"
              v-model="scope.row.deduplication"
            >
              <el-option
                v-for="item in yesNoList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column
          min-width="130px"
          align="center"
          prop="startDate"
          label="开始时间"
        >
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.startDate"
              value-format="yyyy-MM-dd"
              type="date"
            >
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column
          min-width="130px"
          align="center"
          prop="endDate"
          label="结束时间"
        >
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.endDate"
              value-format="yyyy-MM-dd"
              type="date"
            >
            </el-date-picker>
          </template>
        </el-table-column>
      </el-table>
      <div
        style="margin: 10px 5px 5px 0; text-align: center"
        v-show="addOrEdit == 1 || addOrEdit == 3"
      >
        <i
          class="el-icon-remove-outline"
          v-show="dialogTable.length > 1"
          style="font-size: 28px; margin-right: 5px"
          @click="delDialogrow"
        ></i>
        <i
          class="el-icon-circle-plus-outline"
          style="font-size: 28px"
          @click="addDialogrow"
        ></i>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button class="cancels" @click="handleClose">{{
          '取消'
        }}</el-button>
        <el-button
          class="submit"
          style="margin-left: 40px"
          @click="ruleSubmit"
          >{{ '确认' }}</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
  
  <script>
import topBar from "@/components/topBar";
import * as api from "@/api/specialBusiness.js";
import * as mem from "@/api/member";
import * as sys from "@/api/systemconfiguration.js";
import * as sta from "@/api/statistics.js";
import { Message } from "element-ui";
export default {
  name: "MemberSubsidyConfig",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "memberSubsidyConfig",
      topList: [
        {
          name: "会员补贴配置",
          path: "memberSubsidyConfig",
        },
      ],
      title: '添加',
      addOrEdit: "",
      ruleShow: false,
      multipleSelection: [],

      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      tableData: [],
      loading: false,
      total: 0,
      vertexList: [], //隶属体系
      memberteamList: [], //隶属团队
      pekStatusList: [], //补贴状态
      dialogTable: [
        {
          checkAmount: "",
          checkAchieve: "",
          checkType: "",
        },
      ],
      yesNoList: [],
      achievementTypeList: [],
    };
  },
  created() {
    this.research();
    this.getOthers();
  },
  methods: {
    getOthers() {
      mem.getmemberTeamList().then((res) => {
        this.memberteamList = res.rows;
      });
      mem.getvertexValue().then((res) => {
        this.vertexList = res.data;
      });
      api.getPekStatus().then((res) => {
        this.pekStatusList = res.data;
      });
      sys.getYseNoList().then((res) => {
        this.yesNoList = res.data;
      });
      sta.getAchievementType().then((res) => {
        this.achievementTypeList = res.data;
      });
    },
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/report/manager/member-perk/export",
          { ...this.queryParams },
          `会员补贴配置${new Date().getTime()}.xlsx`
        );
      });
    },
    goDetail(row) {
      //补贴明细
      this.$router.push({
        path: "memberSubsidyConfigDetail",
        query: { pkId: row.pkId },
      });
    },
    goOrder(row) {
      //补贴订单
      this.$router.push({
        path: "memberSubsidyConfigOrder",
        query: { pkId: row.pkId },
      });
    },
    checkName(row) {
      api.queryMember({ memberCode: row.memberCode }).then((res) => {
        row.pkMember = res.data.pkId;
      });
    },
    delDialogrow() {
      this.dialogTable.pop();
      this.$forceUpdate();
    },
    addDialogrow() {
      this.dialogTable.push({
        mmeberCode: "",
      });
      this.$forceUpdate();
    },
    //反补
    returnedMemberPerk(row) {
      this.$confirm("是否确定反补？", '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        api.returnedMemberPerk(row.pkId).then((res) => {
          if (res.code == 200) {
            Message({
              message: res.msg,
              type: "success",
            });
            this.research();
          }
        });
      });
    },
    addRules() {
      this.addOrEdit = 1;
      this.ruleShow = true;
      this.title = '添加';
    },
    toCopy(row) {
      this.addOrEdit = 3;
      this.title = '添加';
      api.getMemberPerkRowDetail({ pkId: row.pkId }).then((res) => {
        if (res.code === 200) {
          delete res.data.pkId;
          this.dialogTable = [res.data];
          this.ruleShow = true;
        }
      });
    },
    updateShow(row) {
      this.addOrEdit = 2;
      this.title = '修改';
      api.getMemberPerkRowDetail({ pkId: row.pkId }).then((res) => {
        if (res.code === 200) {
          this.ruleShow = true;
          this.dialogTable = [res.data];
        }
      });
    },
    delRole() {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        let idList = this.multipleSelection.map((item) => {
          return item.pkId;
        });
        api
          .deleteMemberPerk({
            pkIdList: idList.join(),
          })
          .then((res) => {
            if (res.code === 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.research();
            }
          });
      });
    },
    ruleSubmit() {
      let url = "";
      if (this.addOrEdit == 1 || this.addOrEdit == 3) {
        url = api.saveMemberPerk;
        url(this.dialogTable).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.ruleShow = false;
            this.research();
          }
        });
      } else {
        url = api.updateMemberPerk;
        url(this.dialogTable[0]).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.ruleShow = false;
            this.research();
          }
        });
      }
    },
    handleClose() {
      this.ruleShow = false;
    },
    research() {
      this.loading = true;
      api.getMemberPekList(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.tableData = res.rows;
          this.total = res.total;
        }
        this.loading = false;
      });
    },
    reChongzhi() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
      };
      this.modifiedTime = [];
      this.research();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>
  <style lang="scss" scoped>
::v-deep .el-upload--picture-card {
  min-width: 80px !important;
  min-height: 80px !important;
  border: 1px solid #ccc;
  border-radius: 4px;
}

::v-deep .el-select {
  width: 100%;
}

::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}

::v-deep .colors {
  padding: 5px !important;
}

::v-deep .banner .el-form-item__error {
  left: 100px;
  margin-top: 10px;
}

.avatar-uploader {
  width: 68px !important;
  height: 68px !important;
}

::v-deep .input-s .el-input {
  //width:637px;
}

.button-style {
  width: 209px;
  height: 48px;
  background: #cccccc;
  border-radius: 5px 5px 5px 5px;
  opacity: 1;
  line-height: 48px;
  padding: 0 !important;
  color: #fff;
  font-size: 18px;
}

::v-deep .el-dialog__title {
  font-weight: bold;
}

::v-deep .el-dialog__header {
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.button-s {
  padding: 0 2px !important;
}

::v-deep .el-button {
  padding: 10px 20px;
}

::v-deep .el-date-editor .el-range__close-icon {
  margin-top: -10px;
}

::v-deep .el-date-editor .el-range-separator {
  margin-top: -10px;
}

::v-deep .el-date-editor .el-range__icon {
  margin-top: -10px;
}

::v-deep .el-input__inner {
  //height:28px;
  //line-height: 28px;
}

::v-deep .el-form-item {
  margin-bottom: 15px;
}

::v-deep .el-form-item__label {
  color: #333;
  font-weight: inherit;
}

::v-deep .el-row {
  //margin-top: 20px;
}

::v-deep .el-date-editor {
  width: 100% !important;
}

::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}

::v-deep .el-table thead {
  color: #000000;
}
.submit {
  background: #c8161d;
  border-radius: 5px;
  color: #fff;
  border-color: #c8161d;
  margin-left: 20px;
}
.cancels {
  background: #cccccc;
  border-radius: 5px;
  color: #fff;
  border-color: #ccc;
}

.openClose {
  margin-top: 10px;
  margin-right: 10px;
  color: #666666;
  text-align: center;
}

.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;

  .thetopbox {
    background: #ffffff;
    border-radius: 8px;
    padding-bottom: 10px;

    .searchbox {
      display: flex;
      align-items: center;

      .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: 0px 0;
      justify-content: space-between;
      align-items: center;

      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #3181e5;
          width: 68px;
          //height: 32px;
        }
      }
    }
  }
}
</style>
  