<style lang="scss" scoped>
.preview {
  .el-form-item {
    margin-bottom: 15px;
  }
  label,
  p {
    line-height: 25px !important;
  }
}
/deep/.avatar-uploader .el-upload {
  width: 148px;
  height: 148px;
  line-height: 148px;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  .avatar {
    width: 100%;
    height: auto;
  }
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 68px;
  height: 68px;
  line-height: 68px;
  text-align: center;
}
.avatar {
  width: 68px;
  height: 68px;
  display: block;
}
/deep/.speaker_avatar .el-upload {
  width: 80px;
  height: 80px;
  line-height: 80px;
}
</style>
<template>
  <section>
    <p>中科院全刊</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"
              @clear="getData"
            ></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="add" type="primary">添加期刊</el-button>
          </el-form-item>
        </el-form>
      </div>
      <el-table
        class="table"
        :data="list"
        height="50vh"
        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" width="180" label="期刊名称">
        </el-table-column>
        <el-table-column prop="wxcode" label="微信号"> </el-table-column>
        <el-table-column prop="subject_name" label="主办单位">
        </el-table-column>
        <el-table-column prop="desc" width="300" label="简介">
        </el-table-column>
        <el-table-column prop="name" label="中文名称"> </el-table-column>
        <el-table-column prop="ename" label="外文名称"> </el-table-column>
        <el-table-column prop="languages" label="语种"> </el-table-column>
        <el-table-column prop="editor" label="主编"> </el-table-column>
        <el-table-column prop="corganizers" label="主管单位"> </el-table-column>
        <el-table-column prop="publishingUnit" label="办刊单位">
        </el-table-column>
        <el-table-column prop="publishingTime" label="创刊时间">
        </el-table-column>
        <el-table-column prop="domestic" label="国内刊号"> </el-table-column>
        <el-table-column prop="issn" label="国际刊号"> </el-table-column>
        <el-table-column prop="website" label="期刊官网"> </el-table-column>
        <el-table-column prop="editorialAddress" label="编辑部地址">
        </el-table-column>
        <el-table-column prop="zip" width="150" label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" @click="showQrcode(scope.row)"
              >二维码上传</el-button
            >
            <el-button type="text" @click="showJournal(scope.row)"
              >查看</el-button
            >
            <el-button class="edit" type="text" @click="edit(scope.row)"
              >编辑</el-button
            >
            <el-button class="del" @click="del" 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"
      />
      <!--二维码上传-->
      <el-dialog
        class="fu-dialog"
        :title="dialogTitle"
        :close-on-click-modal="false"
        :visible.sync="dialogVisible"
      >
        <el-form
          size="small"
          class="preview"
          :inline="false"
          label-width="100px"
          :model="form1"
          ref="form1"
        >
          <el-form-item label="上传二维码：" prop="img">
            <el-upload
              class="avatar-uploader"
              action="/api/admin/uploadfile"
              :show-file-list="false"
              :on-success="handleAvatarSuccess"
            >
              <img v-if="form1.qrcode" :src="form1.qrcode" class="avatar" />
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
            <span style="font-size: 12px; color: #999999"
              >建议图片尺寸为：210*160</span
            >
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button size="small" type="normal" @click="dialogVisible=false,this.form1={}">取消</el-button>
          <el-button size="small" type="primary" @click="save">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </section>
</template>
<script>
import Page from "../../components/Page";
export default {
  components: {
    Page,
  },
  data() {
    return {
      //   edit:0,
      form: { name: "", page: 1, page_size: 20 },
      total: 1,
      list: [{ name: "2333" }],
      loading: false,
      input: "",
      dialogVisible: false,
      dialogTitle: "",
      form1: {},
    };
  },
  methods: {
    showQrcode(row){
      this.form1.qrcode = row.qrcode;
      this.dialogVisible = true;
    },
    showJournal(row){
      this.$router.push({
        path:"/journal/journal/show",
        query:{id:row.id}
      })
    },
    //封面
    handleAvatarSuccess(res, file) {
      this.$set(this.form1,'img',file.response.data)
    },
    gopage(size) {
      if (size) {
        this.form.page_size = size;
      }
      this.form.page = this.$refs.pageButton.page;
      this.getData();
    },
    edit(row) {
      this.$router.push({
        path: "/journal/journal/add",
        query: { id: row.id },
      });
    },
    add() {
      this.$router.push({ path: "/journal/journal/add" });
    },
    detail(id) {
      this.$router.push({
        path: "/company/detail",
        query: { id: id, page: this.form.page, page_size: this.form.page_size },
      });
    },
    search() {
      this.getData();
    },
    getData() {
      var parm = this.form;
      this.loading = true;
      this.$api.getJournalList(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.deleteEnterprise({ id: id }).then((res) => {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.getData();
        });
      });
    },
  },
  created() {
    this.getData();
  },
};
</script>
