<template>
  <div class="worklist" v-loading="loading">
    <el-card>
      <div class="searchDiv">
        <div class="searchValue">
          <input type="text" placeholder="搜索关键字" v-model="searchKey">
          <div class="searchBtn" @click="initData">
            <img src="/kczy/searchIcon.png" alt="">
          </div>
        </div>
      </div>
      <div class="resultDiv">
        <el-empty v-if="resultData.length==0" image-size="100" description="无数据" style="padding: 10px 0;" />
        <div class="recordDiv" v-for="(item, index) in resultData" :key="index">
          <div class="record-list">
            <div class="left">
              <div>
                <span style="color: #171721;">{{item.yzzx_student_realname || item.yzkx_student_realname}}</span>
                <span style="font-size: 12px;color: #8083a3;margin-left: 10px;">{{item.create_time}} 提交</span>
              </div>
              <div style="margin: 10px 0 0 15px;">{{item.yzz_name || item.yzk_name}}</div>
            </div>
            <div class="right">
              <el-button size="mini" type="primary" plain @click="lookDetail(item.yzzx_id || item.yzkx_id)">查看</el-button>
            </div>
          </div>
          <el-divider border-style="dashed" />
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loading: false,
      workType: "",
      operateId: "",
      parentId: "",
      searchKey: "",
      resultData: [
        {
          yzzx_student_realname: "余枫",
          create_dateline: "2021-01-23 11:15",
          yzz_name: "数学作业",
        },
        {
          yzzx_student_realname: "余枫",
          create_dateline: "2021-01-23 11:15",
          yzz_name: "英语作业",
        }
      ],
    }
  },
  methods: {
    initData() {
      this.loading = true;
      if (this.workType == 1) {
        request({
          url: '/yzy/zy_zbkc_xfjl/index',
          data: {
            keyword: this.searchKey,
            kz_id: this.operateId,
            yzzx_status: 1,
          }
        }).then(res => {
          if (res.code == 1) {
            this.resultData = res.data.page_data;
            this.loading = false;
          }
        })
      } else if (this.workType == 2) {
        request({
          url: '/yzy/zy_kczy_xsdt/index',
          data: {
            keyword: this.searchKey,
            kf_id: this.operateId,
            kk_id: this.parentId,
          }
        }).then(res => {
          if (res.code == 1) {
            this.resultData = res.data.page_data;
            this.loading = false;
          }
        })
      }
    },
    lookDetail(id) {
      this.$router.push({ name: "personal_homework_wlzb_workdetail", params: { workType: this.workType, id } });
    },
  },
  created() {
    this.workType = this.$route.params.workType;
    this.operateId = this.$route.params.id || "";
    this.parentId = this.$route.query.kkID;
    if (this.operateId != "") {
      this.initData();
    }
  }
}
</script>

<style lang="scss" scoped>
.worklist {
  .searchDiv {
    display: flex;
    justify-content: flex-end;
    .searchValue {
      width: 350px;
      height: 50px;
      background: #ffffff;
      border-radius: 8px;
      overflow: hidden;
      position: relative;
      input {
        width: 100%;
        height: 100%;
        outline: 0;
        box-sizing: border-box;
        padding-left: 10px;
        background: #f6f8fa;
      }
      .searchBtn {
        width: 26px;
        height: 26px;
        background: #00a3ff;
        border-radius: 6px;
        position: absolute;
        right: 5px;
        top: 50%;
        transform: translate(-50%, -50%);
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        img {
          display: block;
          text-align: center;
          margin: 6px auto 0;
        }
      }
    }
  }
  .resultDiv {
    .recordDiv {
      .record-list {
        padding: 0 30px;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        font-size: 14px;
        .right {
          .el-button--primary.is-plain {
            padding: 0 16px;
            height: 24px;
            line-height: 24px;
            color: #019ff9;
            border: 1px solid #00a3ff;
            border-radius: 12px;
            background: transparent;
            font-size: 12px;
          }
        }
      }
      .el-divider--horizontal {
        margin: 15px 0;
      }
    }
  }
}
</style>