<template>
  <div class="detail_contain">
    <p class="now_page_title">我的应用 / 应用仓库 / <span>应用详情</span></p>
    <div class="info_contain">
      <service-header
        :data="service_header_arr"
        @deploy="deploy"
        @editapp="editapp"
        @unline="unline"
        @unsell="unsell"
      ></service-header>
      <div class="type_box">
        <div class="type_title">
          <div
            v-for="(item, index) in service_arr[now_user]"
            :key="index + 1000"
            class="type_select"
            @click="now_service = index"
            :style="
              now_service == index ? { borderBottom: '4px solid #f5ab4c' } : {}
            "
          >
            {{ item }}
          </div>
        </div>
        <div class="type_box_select">
          <info-list
            :list_arr="list_arr"
            v-if="now_service == 0"
          >
            <div class="appcode" v-html="appcode" slot="app_code"></div>
          </info-list>
          
          <div v-if="now_service == 1&&now_user == 0">
              <p style="color:#8890a7;">镜像列表：</p>
            <table-um
                :headers="header_arr"
                url="imagearr"
                @actiondelete="actiondelete"
                ></table-um>
                <p>
                    <span class="addimage" @click="addImage">新增镜像</span>
                </p>
                <div v-if="addImageFlag">
                    <el-form ref="form" :rules="rules" :model="form" label-width="0px">
                        <el-form-item prop="name">
                            <p class="formname">镜像名称：</p>
                            <el-input v-model="form.name"></el-input>
                        </el-form-item>
                        <el-form-item prop="taps">
                            <p class="formname">镜像标签：</p>
                            <el-input v-model="form.taps"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <p class="formname">上传镜像包：</p>
                            <upload-file :multiple="false" :max="1" :drag="true" :list="imgList"  @getNewList="getNewList"></upload-file>
                        </el-form-item>
                    </el-form>
                </div>
                <div class="savebtn" v-if="addImageFlag">
                    <el-button>保存</el-button>
                    <el-button>取消</el-button>
                </div>
          </div>

          <div v-if="now_service == 2&&now_user == 0">
              <p style="color:#8890a7;">压缩包：</p>
              <p><img src="@/assets/imgs/ic_olddata.png" alt="">{{oldpag_name}} <span class="download">下载原压缩包</span> </p>
              <p style="color:#8890a7;margin:20px 0;">上传新的压缩包：</p>
              <div class="uploadtips">
                  <p style="margin-left:-11px;"><i class="el-icon-warning-outline"></i>压缩包上传提示：</p>
                  <p>1.必须包含以下文件：Chart.yaml，README.md，step.yaml，values.yaml，logo.png；</p>
                  <p>2.上述文件必须按照上述名称进行命名；</p>
                  <p>3.请将文件夹压缩为“.zip”、“.tgz”、“.tar.gz”格式，如：名称为redis-ha的文件夹压缩为redis-ha.zip。</p>
              </div>
                <upload-file :multiple="false" :max="1" :drag="true" :list="imgList1"  @getNewList="getNewList1"></upload-file>
                <div class="savebtn">
                    <el-button>保存</el-button>
                    <el-button>取消</el-button>
                </div>
          </div>

          <div v-if="(now_service == 3&&now_user == 0)||(now_service == 1&&now_user !== 0)">
              <service-tab-comments url="sjfw"></service-tab-comments>
          </div>
          
        </div>
      </div>
    </div>
    <dialog-action
      ref="myConfirm"
      :confirmOptions="tipsOptions"
    ></dialog-action>
  </div>
</template>

<script>
import infoList from "@/components/infoList";
import tableUm from "@/components/table/table-um";
import serviceHeader from "@/components/service-header";
import dialogAction from "@/components/dialog-action";
import uploadFile from '@/components/upload_file'
import serviceTabComments from '@/components/service-tabs/service-tab-comments'
import { getRole } from "@/utils/common";
export default {
  components: {
    infoList,
    tableUm,
    serviceHeader,
    dialogAction,
    uploadFile,
    serviceTabComments,
  },
  data() {
    return {
      now_user: 0, //0：普通用户，1：组织管理员，2：超级管理员
      buy_style: 0,
      oldpag_name:'镜像文件002.rar',
      imgList: [],
      imgList1: [],
      form:{
          name: '',
          fileList:'',
          taps:''
      },
      fileList:'',
      rules:{
          name:[
              {required: true, message: '请输入镜像名称', trigger: 'blur'}
          ],
          taps:[
              {required: true, message: '请输入镜像标签', trigger: 'blur'}
          ],
      },
      tipsOptions: {
        title:'',
        message:"",
        btnSubmitText: "",
        btnCancelText: "",
        position: "",
      },
      service_arr: [
        ["基本信息", "镜像文件管理", "部署文件管理", "评分及评论"],
        ["基本信息", "评分及评论"],
        ["基本信息", "评分及评论"],
      ],
      service_header_arr: {
        name: "",
        first: [],
        second: [],
        yydetail: true,
        aqdetail: true,
      },
      now_service: 0,
      header_arr: [
        {
          prop: "jxmc",
          label: "镜像名称",
          minWidth: "33.33%",
          align: "center",
        },
        {
          prop: "bbh",
          label: "版本号",
          minWidth: "33.33%",
          align: "center",
        },
        {
          label: "操作",
          type: "Button",
          align: "center",
          minWidth: "33.33%",
          btnList: [
            {
              type: "actiondelete",
              label: "删除",
            },
          ],
        },
      ],
      
      list_arr: [
        {
          title: "应用简介：",
          info: "",
        },
        {
          title: "功能简介：",
          info: "",
        },
        {
          title: "应用场景：",
          info: "",
        },
        {
          title: "应用参数：",
          info: "",
          type: "solt",
          solt_name: "app_code",
        },
      ],
      appcode: "",
      addImageFlag:false
    };
  },
  watch: {

  },
  created() {
    this.now_user = this.$store.state.role;
    getRole().then((data) => {
      this.now_user = data;
      this.$store.commit("rolefun", data);
      this.getServiceInfo();
      this.getServiceBaseInfo();
    });
  },
  mounted() {},
  methods: {
      getNewList(val) {
        console.log(val);
        this.form.fileList = ""
        this.form.fileList = url.map((v,k)=>{
          return v.url
        }).join(';')
        console.log(this.form.fileList)
      },
      getNewList1(val) {
        console.log(val);
        this.fileList = ""
        this.fileList = url.map((v,k)=>{
          return v.url
        }).join(';')
        console.log(this.fileList)
      },
    addImage(){
        this.addImageFlag = true
    },
    actiondelete(){
        this.tipsOptions= {
            title:'',
            message:"",
            btnSubmitText: "",
            btnCancelText: "",
            position: "",
        }
        this.tipsOptions.message="是否删除该数据"
        this.tipsOptions.confirmSubmit = () => {
            console.log("deleteItem - ");
            this.$refs.myConfirm.hideModel();
        };
        this.$refs.myConfirm.showModel();
    },
    deploy(){
        console.log('0000');
    },
    editapp(){
        console.log('11111');
    },
    unline(val){
        console.log(val);
        this.tipsOptions= {
            title:'',
            message:"",
            btnSubmitText: "",
            btnCancelText: "",
            position: "",
        }
        this.tipsOptions.message="该操作会将该应用从应用商店的平台应用区域下线至开发者应用区域，下线前需向超级管理员发送通知，超级管理员通过后此应用将下线至开发者应用区域。"
        this.tipsOptions.btnSubmitText="发送通知"
        this.tipsOptions.position="left"
        this.tipsOptions.confirmSubmit = () => {
            console.log("deleteItem - ");
            this.$refs.myConfirm.hideModel();
        };
        this.$refs.myConfirm.showModel();
    },
    unsell(val){
        console.log(val);
        this.tipsOptions= {
            title:'',
            message:"",
            btnSubmitText: "",
            btnCancelText: "",
            position: "",
        }
        this.tipsOptions.message="申请下架应用需要向组织管理员发送通知，组织管理员通过下架请求后该应用将从应用商店下架。"
        this.tipsOptions.btnSubmitText="发送通知"
        this.tipsOptions.confirmSubmit = () => {
            console.log("deleteItem - ");
            this.$refs.myConfirm.hideModel();
        };
        this.$refs.myConfirm.showModel();
    },
    getServiceInfo() {
      this.$http
        .get("/static/appdetail.json")
        .then((response) => {
          let data = response.data.data;
          this.$set(this.service_header_arr, "name", data.appInfo.name);
          this.$set(this.service_header_arr, "first", data.appInfo.first);
          this.$set(this.service_header_arr, "second", data.appInfo.second);
        })
        .catch(function(response) {});
    },
    
    getServiceBaseInfo() {
      this.$http
        .get("/static/appdetail.json")
        .then((response) => {
          let data = response.data.data;
          this.$set(this.list_arr[0], "info", data.appbaseinfo.intorduce);
          this.$set(this.list_arr[1], "info", data.appbaseinfo.action);
          this.$set(this.list_arr[2], "info", data.appbaseinfo.use);
          this.appcode = data.appbaseinfo.appcode;
        })
        .catch(function(response) {});
    },
    
  },
};
</script>

<style>
.savebtn .el-button {
  float: right;
  margin-left: 20px;
  letter-spacing: 2px;
}
.savebtn .el-button:nth-of-type(1) {
  background-color: #0f2683;
  color: #f8f9fd;
}
.savebtn .el-button:nth-of-type(2) {
  background-color: #c3caf8;
  color: #0f2683;
}
</style>
<style scoped>
.detail_contain {
  width: 100%;
  padding: 0 20px;
  height: calc(100% - 55px);
}
.info_contain {
  padding: 25px 20px;
  background-color: #fff;
  width: 100%;
  box-shadow: 0px 3px 6px 0px #f4f7fc;
  border-radius: 12px;
  min-height: calc(100% - 20px);
  margin-bottom: 20px;
}
.now_page_title {
  margin: 15px 0;
  color: #898d9e;
}
.now_page_title span {
  color: #242c43;
}
.type_box {
  width: 100%;
}
.type_title {
  width: 100%;
  height: 65px;
  line-height: 65px;
  border-bottom: 2px solid #f4f7fc;
}
.type_select {
  float: left;
  width: auto;
  margin-right: 40px;
  height: 65px;
  cursor: pointer;
}
.type_box_select {
  padding: 30px 10px 10px 10px;
  width: 100%;
}

.savebtn {
  margin-top: 50px;
  overflow: hidden;
}
.appcode {
  white-space: pre-wrap;
  width: 100%;
  background-color: #f8f9fd;
  border-radius: 8px;
  padding: 24px;
  color: #58617a;
}
.addimage,.download{
    display: inline-block;
    color: #f8f9fd;
    font-size: 16px;
    width: 124px;
    height: 44px;
    line-height: 44px;
    text-align: center;
	background-color: #0f2683;
    border-radius: 8px;
    margin-top: 20px;
    cursor: pointer;
}
.download{
    background-color: #495feb;
    margin-left: 10px;
}
.formname{
    color: #8890a7;
}
.uploadtips{
    width: 750px;
	height: 141px;
	background-color: #f8f9fd;
    border-radius: 8px;
    padding: 20px 40px;
    color: #8890a7;
    line-height: 22px;
    margin-bottom: 20px;
}

</style>
