
<template>
  <div class="app-container">
    <div class="app-container1 flex">
      <div v-for="(item, index) in list" :key="index" class="flex">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <div class="flex2">
              <span>{{ item.auditName }}</span>
              <i>{{ item.auditType == 1 ? "固定环节" : "自定义环节" }}</i>
            </div>

            <div class="btn">
              <el-button
                v-if="item.auditType == 2"
                type="danger"
                size="mini"
                @click="deleteFun(item.passAuditId)"
                >删除</el-button
              >
              <el-button
              v-if="item.auditMarkStep!=9"
                type="primary"
                size="mini"
                @click="create('编辑环节', item)"
                >编辑</el-button
              >
            </div>
          </div>
          <template v-if="[1,2,9].indexOf(item.auditMarkStep)>-1">
            <div
              class="content"
              v-for="(item2, index2) in item.documentVoList"
              :key="index2"
            >
              <div class="flex unit-name">
                <i class="text name1">{{ item2.username }}</i>
                <i class="text">审核员列表</i>
              </div>
              <div class="user flex">
                <div
                  class="flex1"
                  v-for="(item1, index1) in item2.documentList"
                  :key="index1"
                >
                  <el-image
                    v-if="item1.avatar"
                    class="photo"
                    :src="item1.avatar"
                    :preview-src-list="[item1.avatar]"
                  ></el-image>
                  <span class="photo" v-else>暂无</span>
                  <span class="name">{{ item1.name }}</span>
                </div>
              </div>
            </div>
          </template>
          <template v-else>
            <div class="content">
              <i class="text">审核员列表</i>
              <div class="user flex">
                <div>
                  <i class="el-icon-plus photo" @click="adduserFun(item)"></i>
                </div>
                <div
                  class="flex1"
                  v-for="(item1, index1) in item.userList"
                  :key="index1"
                >
                  <el-image
                  v-if="item1.avatar"
                  class="photo"
                  :src="item1.avatar"
                  :preview-src-list="[item1.avatar]"
                ></el-image>
                <span class="photo" v-else>暂无</span>
                  <span class="name">{{ item1.name }}</span>
                </div>
              </div>
            </div>
          </template>
        </el-card>
        <img class="arrow" src="../../assets/arrow.png" alt="" />
        <el-button
        v-if="item.auditMarkStep!=9"
          class="add-link"
          type="primary"
          size="mini"
          @click="create('增加环节', index)"
          >增加环节</el-button
        >
      </div>
      <!--对话框-->
      <addUser
        v-if="userDialogVisible"
        :form1="form"
        :dialogVisible="userDialogVisible"
        @close="userDialogVisible = false"
        @getform="getform"
      />
      <!--对话框-->
      <handleLink
        v-if="dialogVisible"
        :form1="form"
        :dialogTitle="dialogTitle"
        :dialogVisible="dialogVisible"
        @close="dialogVisible = false"
        @getform="getform"
      />
    </div>
  </div>
</template>

<script>
import handleLink from "./compoment/handleLink.vue";
import addUser from "./compoment/addUser.vue";
import { passList, passEdit, passDelete } from "@/api/audit";
export default {
  components: { handleLink, addUser },
  filters: {},
  computed: {},
  data() {
    return {
      // 主表格&主表格加载状态
      list: [],
      listLoading: true,
      // 是否显示对话框
      dialogVisible: false,
      userDialogVisible: false,
      dialogTitle: null,
      form_copy: null,
      form: {
        personAdminType: 1,
        personAdminId: null,
        userIdList: [],
        isExtra: false,
        auditType: 2,
        auditName: null,
        //自定义字段
        checkContent: null,
        rectificationContent: null,
        rejectContent: null,
      },
    };
  },
  created() {
    this.fetchData();
    this.form_copy = JSON.parse(JSON.stringify(this.form));
  },
  watch: {
    "form.aaaaa": {
      handler(n, o) {
        this.form.addCustomList = [];
      },
    },
  },
  methods: {
    // 获取列表数据
    fetchData() {
      this.listLoading = true;
      passList().then((res) => {
        this.list = res.data;
        this.total = res.data.total;
        this.listLoading = false;
      });
    },
    // 打开添加角色对话框
    create(type, row) {
      if (type === "增加环节") {
        this.form = JSON.parse(JSON.stringify(this.form_copy));
        if (this.list[row + 1]) {
          this.form.nextStepId = this.list[row + 1].passAuditId;
        }
      } else {
        this.form = Object.assign(this.form, row);
      }
      this.dialogTitle = type;
      this.dialogVisible = true;
    },
    adduserFun(row) {
      this.form = Object.assign(this.form, row);
      this.userDialogVisible = true;
    },
    getform(form, type) {
      passEdit(form).then((res) => {
        this.fetchData();
        if (type) {
          this.userDialogVisible = false;
        } else {
          this.dialogVisible = false;
        }
        this.$message({
          type: "success",
          message: "操作成功!",
        });
      });
    },
    // 删除角色
    deleteFun(id) {
      this.$confirm("确定要删除吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      }).then(() => {
        passDelete(id).then((res) => {
          this.fetchData();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        });
      });
    },
  },
};
</script>
<style scoped lang="scss">
.box-card {
  width: 370px;
  // height: 286px;
  border-radius: 8px;
  margin-bottom: 20px;
}
.clearfix {
  span {
    color: #333333;
    font-size: 20px;
  }
  i {
    display: inline-block;
    font-size: 14px;
    color: #5babfe;
    padding: 5px 10px;
    border: 1px solid #3e9dff;
    border-radius: 8px;
  }
}
.btn {
  width: 100%;
  margin-top: 21px;
  text-align: center;
  .el-button {
    display: inline-block;
  }
}
.content {
  border: 1px solid #ecf0fb;
  border-radius: 8px;
  margin-bottom: 12px;
  .text {
    color: #909399;
    float: right;
    font-size: 14px;
    margin: 15px 20px;
  }
}
.user {
  padding: 0 20px 12px;
  overflow-x: auto;
}
.photo {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  margin-right: 12px;
  color: #c0c4cc;
  text-align: left;
  font-size: 14px;
  background-color: #f5f7fa;
}
.el-icon-plus {
  line-height: 50px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  background: #f7f8fc;
  border: 1px solid rgba(196, 202, 215, 0.46);
  color: #909399;
}
.flex2 {
  display: flex;
  justify-content: space-between;
}
.flex1 {
  display: flex;
  flex-direction: column;
  justify-content: left;
  flex-wrap: wrap;
}
.table-img {
  width: 50px;
  height: 50px;
}
.name {
  width: 50px;
  display: inline-block;
  margin-top: 4px;
  font-size: 14px;
  text-align: center;
}
.arrow {
  width: 56px;
  height: 116px;
  margin: 85px 8px 0 16px;
}
.add-link {
  // width: 44px;
  height: 40px;
  margin-top: 120px;
  margin-right: 16px;
}
.flex {
  flex-wrap: nowrap;
}
.unit-name {
  justify-content: space-between;
  .name1 {
    font-weight: 500;
    font-size: 16px;
    color: #606266;
  }
}
</style>
