<template>
  <div class="record-warp">
    <div class="record-main">
      <el-row>
        <!-- <el-col :span="24">
              <div class="search-head">
                <span>公司名称：</span>
                <el-input v-model="name" clearable placeholder="请输入公司名称"></el-input>&nbsp;&nbsp;&nbsp;&nbsp;
                <el-button type="primary" icon="el-icon-search" @click="searchTarget">搜索</el-button>
                <el-button type="primary" icon="el-icon-delete-solid" @click="clearSearch">清空</el-button>
              </div>
            </el-col> -->
      </el-row>
      <el-row class="add_user_class">
        <el-col :span="24">
          <div class="search-head">
            <el-button type="success" round icon="el-icon-plus" @click="addPrice"
              >新增</el-button
            >
            <el-button
              type="delete"
              :disabled="multipleSelection.length == 0"
              round
              icon="el-icon-delete"
              @click="mulDeletePrice"
              >批量删除</el-button
            >
          </div>
        </el-col>
      </el-row>

      <div class="table-content">
        <el-table
          ref="multipleTable"
          :data="tableData"
          :row-style="{ height: '0px' }"
          :cell-style="{ padding: '5px' }"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" align="center" width="" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="productName" label="产品名" align="center" width="">
          </el-table-column>
          <el-table-column prop="reportName" label="报告名" align="center" width="">
          </el-table-column>
          <el-table-column prop="price" label="价格" align="center" width="">
          </el-table-column>
          <el-table-column prop="times" label="次数" align="center" width="">
           
        </el-table-column>
        <el-table-column
            prop="status"
            label="状态"
            align="center"
            :formatter="formatterState"
            width=""
          >
          </el-table-column>
        <el-table-column prop="type" label="接口类型" align="center" :formatter="formatterLevel" width="">
        </el-table-column>
        <el-table-column prop="description" label="接口描述" align="center"    width="">
        </el-table-column>
         
          <!-- <el-table-column prop="isDelete" label="删除状态" align="center" :formatter="formatterDelete" width="">
                        </el-table-column> -->
          <el-table-column label="操作" width="200px" align="center" fixed="right">
            <template slot-scope="scope">
              <el-button @click="viewUser(scope.row)" type="text" size="small"
                >查看</el-button
              >
              <el-button type="text" size="small" @click="editUser(scope.row)"
                >编辑</el-button
              >

              <el-popconfirm
                title="确定删除吗？"
                placement="top"
                @confirm="deletePrice([scope.row.id])"
              >
                <el-button
                  size="small"
                  style="margin-left: 10px"
                  type="text"
                  slot="reference"
                  >删除</el-button
                >
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <el-pagination
        small
        background
        @current-change="handleCurrentChange"
        :current-page.sync="pageNum"
        layout="total, prev, pager, next"
        :page-size="pageSize"
        :total="total"
      >
      </el-pagination>
      <!-- <el-pagination small background layout="total prev, pager, next" :total="36">
            </el-pagination> -->
    </div>
    <ProductRegister ref="register" @search="searchTarget" />
    <el-dialog title="查看" :visible.sync="centerDialogVisible" width="60%" center>
      <div>
        <el-row>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="user_out">
              <div class="user_out_sub">产品名</div>
              <div class="user_out_subNext">
                {{ detailObj.productName }}
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="user_out">
              <div class="user_out_sub">报告名</div>
              <div class="user_out_subNext">
                {{ detailObj.reportName  }}
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="user_out">
              <div class="user_out_sub">价格</div>
              <div class="user_out_subNext">
                {{ detailObj.price }}
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="user_out">
              <div class="user_out_sub">接口状态</div>
              <div class="user_out_subNext">
                {{ detailObj.status == "1" ? "生效中" : "未生效" }}
              </div>
            </div>
          </el-col>

          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="user_out">
              <div class="user_out_sub">次数</div>
              <div class="user_out_subNext">
                {{ detailObj.times }}
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="user_out">
              <div class="user_out_sub">接口类型</div>
              <div class="user_out_subNext">
                {{ detailObj.type == "1" ? "次卡" : "时效卡" }}
              </div>
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
            <div class="user_out">
              <div class="user_out_sub">描述</div>
              <div class="user_out_subNext">
                {{ detailObj.description }}
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { oSessionStorage } from "../../../utils/utils";
import productRegister from "../../../components/ProductRegister.vue";
export default {
  name: "channelManagement",
  components: {
    ProductRegister: productRegister,
  },
  data() {
    return {
      multipleSelection: [],
      centerDialogVisible: false,
      editUserFlag: false,
      startTime: "",
      endTime: "",
      value1: null,
      total: 0,
      pageSize: 10,
      pageNum: 1,
      keyword: "",
      tableData: [],
      userInfo: {}, //用户信息
      userId: "", //用户id
      name: "", //根据名称搜索
      userName: "", //根据昵称搜索
      hospitalOrDepartment: "", //医院科室

      invitationCode: "",
      roleType: "0",
      type: 0,
      view: {
        name: "",
        userName: "",
        channelId: "",
        role: "",
      },
      detailObj: {},
    };
  },
  created() {},
  mounted() {
    this.userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));

    this.view.channelId = this.$route.query.channelId;

    this.invitationCode = this.userInfo.invitationCode;
    //判断是超级管理员吗
    if (this.userInfo.roleType == "1") {
      this.type = 0;
    } else if (this.userInfo.roleType == "3") {
      //如果登录的是代理用户
      this.type = 4;
    } else if (this.userInfo.roleType == "2") {
      this.type = 5;
    }

    if (this.$route.query.invitationCode) {
      this.invitationCode = this.$route.query.invitationCode;
      this.type = this.$route.query.type;
    }
    if (!this.userInfo) {
      //如果用户信息不存在跳转登陆页
      this.$router.push({ path: "/" });
    }
    this.searchTarget();
  },
  methods: {
    mulDeletePrice() {
      let that = this;
      let ids = [];
      for (let i = 0; i < this.multipleSelection.length; i++) {
        ids.push(this.multipleSelection[i].id);
      }

      this.$confirm("此操作将永久删除该价格, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          that.deletePrice(ids);
        })
        .catch(() => {
          //   this.$message({
          //     type: 'info',
          //     message: '已取消删除'
          //   });
        });
      //获取id的集合
      //   let ids=[]
      //   for(let i){

      //   }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    formatterLevel(row) {
      if (row.type == "1") {
        return "次卡";
      } else if (row.type == "2") {
        return "时效卡";
      }
    },
    goBack() {
      this.$router.go(-1);
    },
    //格式化状态
    formatterIsDelete(row) {
      if (row.isDelete == "0") {
        return "正常";
      } else if (row.isDelete == "1") {
        return "已删除";
      } else {
        return "";
      }
    },
    //格式化状态
    formatterState(row) {
      if (row.status == "1") {
        return "生效中";
      } else if (row.status == "0") {
        return "未生效";
      }
    },
    formatterDelete(row) {
      if (row.isDelete == 0) {
        return "正常";
      } else {
        return "已删除";
      }
    },
    resetUser(index, val) {
      this.$http.get(`/user/reset/${val.id}`, {}, (res) => {
        //  this.$toast.success({message:'成功'});
        if (res && res.code == 200) {
          this.$message.success("重置成功");
          this.searchTarget();
        } else {
          this.$message.error(res.msg);
        }
      });
      //重置密码
    },
    editUser(row) {
      this.editRegisterUser(row);
    },
    viewUser(row) {
      this.detailObj = row;
      this.centerDialogVisible = true;
    },
    addPrice() {
      this.addRegisterPrice(true);
    },
    clearSearch() {
      this.name = "";
      this.userName = "";
      this.searchTarget();
    },
    formatterRole(val) {
      if (val.type == "1") {
        return "超级管理员";
      } else {
        return "渠道用户";
      }
    },

    forma(val) {
      if (val.gender == "0") {
        return "男";
      } else {
        return "女";
      }
    },
    addRegisterPrice(val) {
      this.$refs.register.open(val);
    },
    editRegisterUser(val) {
      this.$refs.register.edit(val);
    },
    deletePrice(ids) {
      this.$http.post(`/product/delete`, ids, (res) => {
        //  this.$toast.success({message:'成功'});
        if (res && res.code == 200) {
          this.$message.success("删除成功");
          this.searchTarget();
        } else {
          this.$message.error("删除失败");
        }
      });
    },

    handleCurrentChange(val) {
      this.pageNum = val;
      this.searchList();
    },
    //根据现有情况进行搜索
    searchList() {
      //  let url =``
      this.$http.get(`/product/find/${this.pageNum}/${this.pageSize}`, {}, (res) => {
        // console.log(res,'用户测试记录')
        if (res && res.code == 200) {
          this.tableData = res.data.content;
          this.total = res.data.totalElements;
        } else {
          // this.$toast.fail(res.msg);
          this.$message.error(res.msg);
        }
      });
    },
    searchTarget() {
      this.pageNum = 1;
      this.searchList();
    },
    //跳转首页
    goHome() {
      this.$router.push({ path: "/home" });
    },
    //跳转记录页
    goRecord() {
      this.$router.push({ path: "/record" });
    },
    //退出登陆
    logout() {
      oSessionStorage.removeItem("userInfo");
      oSessionStorage.removeItem("token");
      this.$router.push({ path: "/" });
    },
    //点击日历获取日期
    getDate(param) {
      // console.log(param,"日期。。。")
      this.userRecord(param.dateStr);
    },
    //点击获取月出勤次数
    getTimes(param) {
      this.monthTimes = param;
    },
    // 用户测试记录显示
    userRecord(date) {
      this.$http.get(
        `gameRecord/findListByUserIdAndDate/${this.userId}/${date}`,
        {},
        (res) => {
          // console.log(res,'用户测试记录')
          if (res && res.code == 200) {
            this.listData = res.data;
          } else {
            this.$toast.fail(res.msg);
          }
        }
      );
    },
  },
};
</script>

<style lang="less" scoped>
@import "../../../styles/theme.less";

.record-warp {
  width: 100%;
  height: 80vh;
  //background: url(../../assets/img/index/19.png) no-repeat center;
  //background-size: 100% 100%;
  position: relative;

  .record-main {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;

    .search-head {
      width: 100%;
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;

      .zc-title {
        color: #606266;
        font-size: 14px;
      }
    }

    .table-content {
      margin: 10px 0;
    }
  }
}

.add_user_class {
  margin-top: 10px;
  display: flex;
}

.user_out {
  display: flex;
  width: 100%;
  align-items: center;
  border: 1px solid #eeeeef;
  line-height: 50px;
  margin-top: 10px;
}

.user_out_sub {
  flex: 1;
  background-color: #fafafa;
  text-align: center;
  // color:#ffffff
}

.user_out_subNext {
  padding-left: 10px;
  flex: 3;
}
</style>
