<template>
  <el-dialog
    :title="$t1('查询提取码')"
    :append-to-body="true"
    :modal-append-to-body="true"
    :close-on-click-modal="false"
    :visible.sync="showDialog"
    :modal="false"
    custom-class="dialog-style list-dialog dialog-checkbox pd_8"
    width="350px"
    v-el-drag-dialog
    :before-close="dialogClose"
  >
    <div class="cont">
      <el-form
        ref="editCategoryForm"
        :model="formData"
        label-width="102px"
        class="adSearchForm"
        style="height: auto; width: auto"
      >
        <el-form-item :label="$t1('提取码')">
          <el-input v-model="formData.extractedCode" clearable class="all-width" />
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain class="button-sty" @click="dialogClose">
        <i class="el-icon-close el-icon"></i>
        {{ $t2("取 消", "system.button.cancel2") }}
      </el-button>
      <el-button type="primary" @click="dialogConfirm" class="button-sty">
        <i class="el-icon-check el-icon"></i>
        {{ $t1("确定") }}
      </el-button>
    </span>
    <viewDialog
      v-if="showViewDialog"
      :visiable.sync="showViewDialog"
      @close="dialogClose"
      :extractedRow="extractedRow"
    ></viewDialog>
  </el-dialog>
</template>
<script>
import viewDialog from "./viewDialog.vue";

export default {
  name: "createDialog",
  components: {
    viewDialog,
  },
  data() {
    return {
      showDialog: true,
      formData: {
        extractedCode: null,
      },
      showViewDialog: false,
      extractedRow: {},
    };
  },
  methods: {
    dialogConfirm() {
      if (!this.formData.extractedCode) {
        this.$baseAlert(this.$t1("提取码不能为空"));
        return;
      }
      this.$http({
        aes: true,
        url: USER_PREFIX + `/form_develop/getExtractedObjData`,
        method: `post`,
        data: {
          stringOne: this.formData.extractedCode,
        },
        isLoading: true,
        success: (res) => {
          let rows = res.objx || [];
          if (rows.length) {
            let row = rows[0];
            let obj = row.obj;
            if (!obj) {
              this.$baseAlert(this.$t1("提取对象为空"));
              return;
            }
            this.extractedRow = row;
            this.showDialog = false;
            this.showViewDialog = true;
          } else {
            this.$baseAlert(this.$t1("无效提取码"));
          }
        },
      });
    },
    dialogClose() {
      this.showDialog = false;
      this.$emit("update:visiable", false);
    },
  },
};
</script>

<style scoped></style>
