<template>
  <el-button type="warning" size="small" @click="btnClick()" v-if="type == 'save'">
    <img src="@/assets/set.png" alt="">
    保存
  </el-button>
  <el-button type="primary" size="small" @click="btnClick()" v-else-if="type == 'upload'">
    <img src="@/assets/upload2.png" alt="">
    上传
  </el-button>
  <el-button type="primary" size="small" @click="add(1)" v-else-if="type == 'upload_image'">
    <img src="@/assets/upload2.png" alt="">
    上传图片
  </el-button>
  <el-button type="primary" size="small" @click="add(2)" v-else-if="type == 'upload_video'">
    <img src="@/assets/upload2.png" alt="">
    上传视频
  </el-button>
  <el-button type="primary" size="small" @click="add(3)" v-else-if="type == 'upload_fwb'">
    <img src="@/assets/upload2.png" alt="">
    上传图文
  </el-button>
</template>

<script>
export default {
  name: 'save',
  data() {
    return {
    };
  },
  props: {
    type: {
      default() {
        return 'save'
      }
    }
  },
  computed: {
  },
  watch: {
  },
  methods: {
    /* 新增并编辑素材 */
    add(type) {
      let classid = '9999' + JSON.parse(window.sessionStorage.getItem("active_account")).userid;
      this.$api.requested({
        "classname": "webmanage.saletool.sharematerial.sharematerial",
        "method": "insertOrUpdate",
        "content": {
          "title": "",
          "sat_sharematerial_classid": classid,
          "notes": "",
          "tag": [],
          "canfiledownload": 1,
          "content": "",
          "sat_sharematerialid": 0,
          type
        }
      }).then(res => {
        if (res.msg != '成功') return this.$message.error(res.data);
        window.sessionStorage.setItem('newMaterial', JSON.stringify(res.data));
        this.$router.push({
          path: '/upload_archives',
          query: {
            id: res.data.sat_sharematerialid
          }
        });
      })
    },
    btnClick(){
      this.$emit("btnClick")
    }
  },
};
</script>

<style scoped>
* {
  box-sizing: border-box;
}

/deep/span {
  display: flex;
  align-items: center;
}

img {
  padding-right: 5px;
}
</style>
