<style lang="scss">
.preview {
  .el-form-item {
    margin-bottom: 15px;
  }
  label,
  p {
    line-height: 25px !important;
  }
}
.el-cascader {
  width: 100%;
}
a {
  text-decoration: none;
  color: #409eff;
  cursor: pointer;
}
// 右边
.item-main {
  // margin:34px;
  // height:600px;
  // background: #FFFFFF;
  border: 1px solid #dddddd;
  box-shadow: 0px 5px 10px 0px rgba(0, 0, 0, 0.13);
  border-radius: 20px;
  .el-form.over_y {
    max-height: calc(100vh - 340px);
  }
  /deep/.el-form-item__label {
    float: none;
  }
}
// label样式
.edit_label {
  /deep/.el-input__inner {
    background: #f5faff;
    border: 0px;
    padding: 0px;
  }
}
/deep/.opicon {
  font-weight: bold;
  padding: 5px;
  color: #3895fe;
}
.tpl_title {
  font-size: 18px;
  margin: 20px 0;
}
.tpl_form {
  margin: 20px;
  border: 1px solid #ccc;
  border-radius: 20px;
  /deep/.el-form-item {
    background: none;
  }
  /deep/.el-form-item__content {
    width: 100%;
  }
}
.survey_logo {
  position: relative;
  top: 15px;
  left: 20px;
}
.result_dialog .el-dialog{
    width: 40%;
    margin-top:20vh!important;
}
.result-item{
    height: 35px;
    .label{
        font-weight: 600;
    }
}
  .desc{
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        white-space: normal;
    }
</style>
<template>
  <section>
    <p><span>信息管理></span>活动管理</p>
    <div class="content">
      <div class="filter">
        <el-form
          size="small"
          label-width="70px"
          :inline="true"
          label-position="left"
        >
          <el-form-item label="">
            <el-input
              clearable
              placeholder="请输入标题"
              v-model="form.name"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="search">搜索</el-button>
          </el-form-item>
          <el-form-item style="float: right">
            <el-button @click="addActivity" type="primary">发布活动</el-button>
          </el-form-item>
          <el-form-item style="float: right" v-if='form.journal_id'>
            <el-button @click="$router.go(-1)" type="info">返回</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table
        class="table"
        :data="list"
        height="57vh"
        border
        v-loading="loading"
        default-expand-all
        row-key="id"
        style="width: 100%"
      >
        <el-table-column prop="img" label="活动海报">
          <template slot-scope="scope">
              <img :src="scope.row.img" alt="" height="80" width="60">
          </template>
        </el-table-column>
        <el-table-column prop="name" label="活动名称" width="300px"></el-table-column>
        <el-table-column prop="journal_name" label="发布单位"  width="150"></el-table-column>
        <el-table-column prop="the_host" label="主办方" width="150"></el-table-column>
        <el-table-column prop="to_undertake" label="承办方" width="150"></el-table-column>
        <el-table-column prop="begin_time" label="活动时间"  width="170"></el-table-column>
        <el-table-column prop="address" label="活动地址"  width="200"></el-table-column>
        <el-table-column prop="desc" label="活动简介" width="500">
                    <template slot-scope="scope">
                        <div class="desc">{{scope.row.desc}}</div>
                    </template>
        </el-table-column>
        <el-table-column prop="zip" width="150" label="操作" fixed="right"  align="center">
          <template slot-scope="scope">
            <el-button class="edit" type="text" @click="edit(scope.row)"
              >编辑</el-button
            >
            <el-button class="del" @click="del(scope.row.id)" type="text"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <Page
        ref="pageButton"
        :current="form.page"
        :page_size="form.page_size"
        :total="total"
        @pageChange="gopage"
      />
    </div>
  </section>
</template>
<script>
import Page from "../../components/Page";
import fuEditor from '../../components/fuEditor'
export default {
  name:'oldact',
  components: {
    Page,
    fuEditor
  },
  data() {
    return {
      form: { name: "", page: 1, page_size: 20 },
      total: 1,
      list: [{ name: "2333" }],
      loading: false,
      rules: {
        name: [{ required: true, message: "请输入标题", trigger: "blur" }],
      },
    };
  },
  methods: {
    search() {
      let parm = this.form;
      this.getData();
    },
    openDiag() {
      this.form1 = {};
      this.dialogVisible = true;
      this.dialogTitle = "发送消息";
    },
    addActivity(){
          this.$router.push({path:'/learning/oldactivity/add',query:{type:1}})
    },
    gopage(size) {
      if (size) {
        this.form.page_size = size;
      }
      this.form.page = this.$refs.pageButton.page;
      this.getData();
    },
    getData() {
      var parm = this.form;
      this.loading = true;
      parm.type = 1
      this.$api.getActivityList(parm).then((res) => {
        this.list = res.data.data.list;
        this.total=res.data.data.total
        this.loading = false;
      });
    },
    del(id) {
      this.$confirm("确定删除吗", "提示", {
        type: "warning",
      }).then(() => {
        this.$api.delActivity({ id: id }).then((res) => {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.getData();
        });
      });
    },
    edit(row) {
      this.$router.push({path:'/learning/oldactivity/add',query:{id:row.id}})
    },
    save() {
      this.$refs["form1"].validate((valid) => {
        if (valid) {
          let parm = this.form1;
          let id = this.form1.id;
          let type = this.$route.query.type;
          parm.type = type;
          parm.receiver_id = JSON.stringify(parm.receiver_id);
          if (id) {
            this.$api.editMessage(parm).then((res) => {
              if (res.data.code == 0) {
                this.$message({
                  type: "success",
                  message: "保存成功!",
                });
              } else {
                this.$message.error("保存失败!");
              }
              this.getData();
              this.dialogVisible = false;
            });
          } else {
            this.$api.addMessage(parm).then((res) => {
              if (res.data.code == 0) {
                this.$message({
                  type: "success",
                  message: "保存成功!",
                });
              } else {
                this.$message.error("保存失败!");
              }
              this.getData();
              this.dialogVisible = false;
            });
          }
        }
      });
    },
  },
  created() {
    if(this.$route.query.id){
      this.form.journal_id=this.$route.query.id
    }
    this.getData();
    
  },
  beforeRouteEnter(to,from,next){
        next(vm=>{
            if(from.path.indexOf('add')>=0){
                vm.getData()
            }
        })
  }
};
</script>
