<template>
  <div>
    <el-dialog :visible.sync="childDialog">
      <el-form>
        <el-form-item label="选择应用">
          <el-select
            v-model="addForm.appId"
            placeholder="请选择"
            style="width: 200px"
            filterable
          >
            <el-option
              v-for="item in selectApps"
              :key="item.id"
              :label="item.label"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="cancelClick">取 消</el-button>
        <el-button type="primary" @click="putStorage" :plain="true"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- <el-button :plain="true" @click="open2">成功</el-button> -->
  </div>
</template>

<script>
/* 数据接口引入 */
import { getSelectApps, getTextedit } from "@/api/cloud";
export default {
  props: {
    rrr: String,

    childDialog: {
      type: Boolean,
      default() {
        return false;
      },
    },
    /* 拿到传过来的选中的素材文案id */
    ids: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      addForm: {
        appId: "",
        text: "",
      },
      selectApps: [],
      alertVisible: false,
    };
  },
  created() {
    this.APIgetSelectApps();
  },
  mounted() {},
  methods: {
    /* 数据获取 */
    APIgetSelectApps() {
      const params = {
        platformId: 4,
        menuCode: "putin.apps",
      };
      getSelectApps(params).then((res) => {
        console.log("创意素材组下的下拉列表", res);
        this.selectApps = res.result.data;
        console.log(this.selectApps);
      });
    },

    /* 取消按钮 */
    cancelClick() {
      this.$emit("cancelDialog");
    },

    /* 确定按钮 */
    putStorage() {
      console.log("4444", this.ids);
      console.log("aappid", this.addForm.appId);
      if (this.addForm.appId) {
        let params = {
          appId: this.addForm.appId,
          ids: this.ids.join(","),
          status: 2,
        };
        getTextedit(params).then((res) => {
          console.log(res);
          if (res.status === 200) {
            this.$message({
              type: "success",
              message: "添加成功",
              // this.APIgetBusinText();
              // console.log(this.checkedCities);
              // this.checkedCities = [];
            });
            this.$emit("successAdd");
          }
        });
      } else {
        this.$message({
          type: "info",
          message: "请选择应用",
        });
      }

      this.cancelClick(); // 关闭弹窗
    },
  },
};
</script>

<style>
</style>