<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <div style="margin: 20px 10px 10px 10px">
        <el-radio-group v-model="type" @change="changeRadio">
          <el-radio-button label="1">自动续约</el-radio-button>
          <el-radio-button label="2">休止期使用钱包</el-radio-button>
          <el-radio-button label="3">续约免实名</el-radio-button>
        </el-radio-group>
        <!-- <el-radio-group v-model="type" @change="changeRadio">
          <el-radio label="1" border>自动续约</el-radio>
          <el-radio label="2" border>休止期使用钱包</el-radio>
        </el-radio-group> -->
      </div>
      <div class="form_all">
        <el-form ref="select" :model="select" label-width="auto">
          <el-row :gutter="10">
            <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="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" @click="getDataList">
                {{ '搜索' }}</el-button
              >
              <el-button type="" @click="reset"> {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            v-hasButtons="['agreenmentWhiteAdd']"
            size="small"
            @click="openDig"
            class="addBtn"
            >{{ '添加' }}</el-button
          >
          <el-button
            @click="handleDelete"
            type="text"
            v-hasButtons="['agreenmentWhiteDel']"
            size="small"
            style="background: #c8161d; color: #fff"
            :disabled="multipleSelection.length == 0"
          >
            {{ '删除' }}
          </el-button>
          <el-button
            size="small"
            v-hasButtons="['agreenmentWhiteExport']"
            @click="handleExport"
            style="background: #ffad41; color: #fff"
            >{{ '导出' }}</el-button
          >
          <el-button
            size="small"
            class="thebtn1"
            @click="handleImport"
            style="background: #ff6723"
            v-if="type == 1"
            v-hasButtons="['agreenmentWhiteImport']"
          >
            {{ '导入' }}</el-button
          >
          <el-button
            size="small"
            class="thebtn2"
            @click="importTemplate"
            style="background: #009b58"
            v-hasButtons="['agreenmentWhiteTemplate']"
            v-if="type == 1"
          >
            {{ '下载模板' }}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          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>

          <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="pkAwardsVal"
            :label="'真实奖衔'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="vertexName"
            :label="'隶属体系'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="creationTime"
            :label="'创建日期'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="time"
            :label="'操作'"
            fixed="right"
          >
            <template slot-scope="scope">
              <!-- <el-button
                @click="toFixed(scope.row.pkId)"
                type="text"
                style="color: #f3a900"
                v-hasButtons="['dealFix']"
                size="small"
              >
                {{ '修改' }}
              </el-button> -->
              <el-button
                @click="handleDelete(scope.row)"
                type="text"
                size="small"
                v-hasButtons="['agreenmentWhiteDel']"
                style="color: #c8161d"
              >
                {{ '删除' }}
              </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="getDataList"
    />
    <el-dialog
      :title="dialogTitle"
      :close-on-click-modal="false"
      :visible.sync="dialogVisible"
      width="40%"
      center
      :before-close="handleClose"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="80px">
        <el-row
          style="
            border-bottom: 1px solid rgba(0, 0, 0, 0.1);
            margin-bottom: 10px;
          "
        >
          <el-col :span="12">
            <el-form-item :label="'会员编号'" prop="memberCode">
              <el-input v-model="form.memberCode"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </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>
    <el-dialog
      :title="upload.title"
      :close-on-click-modal="false"
      :visible.sync="upload.open"
      width="600px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :on-exceed="handleExceed"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          {{ '将文件拖到此处，或' }}
          <em>{{ '点击上传' }}</em>
        </div>
        <div class="el-upload__tip" style="color: red" slot="tip">
          {{ '提示：仅允许导入“xls”或“xlsx”格式文件！' }}
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">{{
          '确认'
        }}</el-button>
        <el-button @click="upload.open = false">{{
          '取消'
        }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import topBar from "@/components/topBar";
import * as api from "@/api/configManage.js";
import { getToken } from "@/utils/auth";
export default {
  name: "AgreementWhitelist",
  components: {
    topBar,
  },
  data() {
    return {
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      total: 0,
      tableData: [],
      multipleSelection: [],
      moren: "agreementWhitelist",
      topList: [
        {
          name: "交易配置",
          path: "dealSetList",
          url: "DealSetList",
        },
        {
          name: "白名单",
          path: "whiteList",
          url: "WhiteList",
        },
        {
          name: "续约白名单",
          path: "agreementWhitelist",
          url: "AgreementWhitelist",
        },
        {
          name: "转账账户白名单",
          path: "transferWhite",
          url: "TransferWhite",
        },
      ],
      form: {},
      dialogVisible: false,
      dialogTitle: "",
      ifadd: "",
      rules: {
        memberCode: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        // contacts: [
        //   { required: true, message: '请输入', trigger: 'blur' },
        // ],
      },
      deleteId: "",
      creationTime: [],
      upload: {
        // 是否显示弹出层（物流导入）
        open: false,
        // 弹出层标题（物流导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的物流数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url:
          process.env.VUE_APP_BASE_API +
          "/system/manage/renewal-white/import-agreement",
      },
      type: "1",
    };
  },
  mounted() {
    // 获取列表
    this.getDataList();
  },
  methods: {
    changeRadio() {
      this.getDataList();
    },
    //下载模板
    importTemplate() {
      this.download(
        "/system/manage/renewal-white/download-agreement-template",
        {},
        `自动续约${new Date().getTime()}.xlsx`
      );
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = '安置架构';
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      var fileName = response.fileName;
      if (fileName != undefined && fileName != "") {
      }
      if (response.code == 200) {
        this.getDataList();
      }

      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, '导入结果', {
        dangerouslyUseHTMLString: true,
      });
      // this.getList();
    },
    // 上传文件数量超出后的动作
    handleExceed() {
      this.upload.isUploading = false;
      this.msgInfo('仅可上传一个文件哦');
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    onSubmit(formName) {
      this.form.type = this.type;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = "";
          if (this.ifadd == 1) {
            //添加
            url = api.addArenewalWhite;
          } else {
            // url = sys.updateStoreHouse
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.dialogVisible = false;
              this.getDataList();
            }
          });
        }
      });
    },
    getDataList() {
      api
        .getRenewalWhiteList(
          Object.assign({}, this.queryParams, this.select, { type: this.type })
        )
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
        });
    },
    getEYesNoList() {
      api.getEYesNoList().then((res) => {
        this.yesNoList = res.data;
      });
    },
    reset() {
      this.select = {};
      this.queryParams = {
        pageNum: 1,
        pageSize: 50,
      };
      this.creationTime = [];
      this.getDataList();
    },
    changeTime(val) {
      this.select.startDate = val ? val[0] : "";
      this.select.endDate = val ? val[1] : "";
    },

    // 点击修改
    toFixed(id) {
      this.ifadd = 2;
    },
    // 删除
    handleDelete(row) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        if (row.pkId) {
          this.deleteId = row.pkId;
        } else {
          const ids = this.multipleSelection.map((obj) => obj.pkId);
          this.deleteId = ids.join(",");
        }
        api
          .deleteRenewalWhite({
            pkId: this.deleteId,
          })
          .then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.getDataList();
            }
          });
      });
    },
    openDig() {
      this.dialogTitle = '添加';
      this.form = {};
      this.ifadd = 1;
      this.dialogVisible = true;
    },
    handleClose() {
      this.dialogVisible = false;
      this.$refs["form"].clearValidate();
      this.$refs["form"].resetFields();
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then((_) => {
        this.download(
          "/system/manage/renewal-white/export",
          Object.assign({}, this.queryParams, this.select, { type: this.type }),
          `续约白名单${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%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .form_all {
      padding: 0px 20px 0 20px;
      // margin-bottom: 20px;
      background: #fff;
      border-radius: 8px;
    }
    .maintop {
      display: flex;
      padding: 0px 0px;
      justify-content: space-between;
      align-items: center;

      background: #f8f8f8;
      .mainbtn {
        .thebtn1 {
          background: rgba(0, 155, 88, 1);
          color: #ffffff;
        }
        .thebtn2 {
          background: rgba(243, 169, 0, 1);
          color: #ffffff;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .tem {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}
.dizhi {
  ::v-deep .el-cascader {
    width: 100%;
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
</style>
  