<template>
  <el-dialog :modal-append-to-body="false" :title="title" v-bind="$attrs" width="700px"
             @close="onClose"
             @open="onOpen"
             v-on="$listeners"
  >
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="应用id">
        <el-input v-model="form.applyId" placeholder="请输入应用id" readonly/>
      </el-form-item>
      <el-form-item label="应用name">
        <el-input v-model="form.appName" placeholder="请输入应用名称" readonly/>
      </el-form-item>
      <el-form-item label="选择系统" prop="grayFlag">
        <div class="tag-group">
          <el-tag :type="form.systemType=='android'?'':'info'" @click="changeSys('android')">安卓</el-tag>
          <el-tag :type="form.systemType=='IOS'?'':'info'" @click="changeSys('IOS')">IOS</el-tag>
          <el-tag :type="form.systemType=='HarmonyOS'?'':'info'" @click="changeSys('HarmonyOS')">鸿蒙</el-tag>
        </div>
      </el-form-item>
      <el-form-item v-if="form.systemType!='IOS'" label="安装包" prop="apkId">
        <el-input v-model="form.apkId" class="input-with-select" placeholder="请选择包" readonly>
          <!--          <el-button slot="append" icon="el-icon-search" @click="handlePackOpen"></el-button>-->
        </el-input>
        <!--          <el-input v-model="form.apkId" placeholder="请输入安装包编号"/>-->
      </el-form-item>
      <el-form-item v-if="form.systemType=='IOS'" label="app store地址" prop="appStoreAddress">
        <el-input v-model="form.appStoreAddress" placeholder="请输入app store地址"/>
      </el-form-item>
      <el-form-item label="版本号" prop="version">
        <el-input v-model="form.version" placeholder="请输入版本号"/>
      </el-form-item>
      <el-form-item label="版本说明" prop="versionDesc">
        <el-input v-model="form.versionDesc" placeholder="请输入版本说明"/>
      </el-form-item>
      <el-form-item label="发布环境" prop="publishEnvironment">
        <el-radio-group v-model="form.publishEnvironment">
          <el-radio
              v-for="dict in environmentList"
              :key="dict.value"
              :label="parseInt(dict.id)"
          >{{ dict.name }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="发布策略" prop="publishStrategy">
        <el-radio-group v-model="form.publishStrategy">
          <el-radio
              v-for="dict in dict.type.release_strategy"
              :key="dict.value"
              :label="parseInt(dict.value)"
          >{{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="结果通知" prop="resultNotify">
        <el-switch
            v-model="form.resultNotify"
            :active-value="1"
            :inactive-value="0"
        />
      </el-form-item>
      <el-form-item label="公开版" prop="publicVersion">

        <el-switch
            v-model="form.publicVersion"
            :active-value="1"
            :inactive-value="0"
        />
      </el-form-item>
      <el-form-item label="强制更新" prop="forceUpdate">
        <el-switch
            v-model="form.forceUpdate"
            :active-value="1"
            :inactive-value="0"
        />
      </el-form-item>
      <el-form-item label="下载验证" prop="downloadVerification">
        <el-switch
            v-model="form.downloadVerification"
            :active-value="1"
            :inactive-value="0"
        />
      </el-form-item>
      <!--        <el-form-item label="更新对象(-1: 不限制, 白名单id)" prop="updateObject">-->
      <el-form-item label="更新对象" prop="updateObject">
        <el-radio-group v-model="form.updateObject">
          <el-radio
              v-for="dict in dict.type.release_user_type"
              :key="dict.value"
              :label="parseInt(dict.value)"
          >{{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="有效期开始时间" prop="validityStartTime">
        <el-date-picker v-model="form.validityStartTime"
                        clearable
                        placeholder="请选择有效期开始时间"
                        type="date"
                        value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="有效期结束时间" prop="validityEndTime">
        <el-date-picker v-model="form.validityEndTime"
                        clearable
                        placeholder="请选择有效期结束时间"
                        type="date"
                        value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <!--        <el-form-item label="备注" prop="remark">-->
      <!--          <el-input v-model="form.remark" placeholder="请输入备注"/>-->
      <!--        </el-form-item>-->
      <!--        <el-form-item label="逻辑删除,0:未删除,1:删除" prop="isDelete">-->
      <!--          <el-input v-model="form.isDelete" placeholder="请输入逻辑删除,0:未删除,1:删除"/>-->
      <!--        </el-form-item>-->
      <!--        <el-form-item label="创建人" prop="created">-->
      <!--          <el-input v-model="form.created" placeholder="请输入创建人"/>-->
      <!--        </el-form-item>-->
      <!--        <el-form-item label="更新人" prop="modified">-->
      <!--          <el-input v-model="form.modified" placeholder="请输入更新人"/>-->
      <!--        </el-form-item>-->
    </el-form>
  </el-dialog>
</template>
<script>

import { getPublish } from '@/api/deployment/publish'
import { listEnvironment } from '@/api/deployment/environment'

export default {
  name: 'AddPack',
  dicts: ['sys_yes_no'],
  props: {
    detailId: {
      type: String | Number,
      default: ''
    },
    openDetail: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // 遮罩层
      title: '添加安装包',
      loading: true,
      configName: undefined,
      form: {},
      moduleList: [],
      // 显示搜索条件
      showSearch: true,
      total: 0,
      environmentList: [],
      // 白名单配置表单验证
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sysApkName: null
      }
    }
  },
  // computed: {
  //   cachedViews() {
  //     return this.$props.openDetail
  //   }
  // },
  mounted() {
    console.log(this.detailId, 123321)

    this.$nextTick(() => {
      this.show = false
    })

    // nextTick(()=>{
    //   this.configName = this.$route.query.configName
    // })
    // this.getPublishList(this.detailId)
    this.getEnvironmentList()
  },
  methods: {

    /** 查询参数列表 */
    getPublishList(id) {
      this.loading = true
      getPublish(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '详情'
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 查询环境维护列表 */
    getEnvironmentList() {
      this.loading = true
      listEnvironment(this.queryParamsEnvironment).then(response => {
        this.environmentList = response.rows
      })
    },
    /** 新增当前包的按钮 */
    addPack(id, version, sysType) {
      this.$emit('addPack', {
        apkId: id,
        version: version,
        sysType: sysType
      })
    },

    closeModal() {
      this.$emit('close')
    },
    onOpen() {
      this.active = this.current
      this.key = ''
    },
    onClose() {
    }
  }
}
</script>
