<template>
  <div>
    <el-dialog title="设置" v-model="dialogVisible">
      <div>
        <el-form label-width="auto">
          <el-form-item label="审核状态">
            <el-radio-group
              v-model="state.form.status"
              class="ml-4"
              name="status"
            >
              <el-radio :label="1" size="large">通过</el-radio>
              <el-radio :label="2" size="large">不通过</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注信息" v-if="state.form.status == 2">
            <el-input
              v-model="state.form.comment"
              type="textarea"
              :rows="5"
              placeholder="选填请输入不通过的理由"
              clearable
            />
          </el-form-item>
        </el-form>
      </div>
      <template #footer>
        <div>
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="handleSubmit">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import { request } from "@/utils";
import { ElMessage } from "element-plus";
import { ref, computed, defineProps, defineEmits, watch, reactive } from "vue";
const props = defineProps({
  show: {
    type: Boolean,
    default: false
  },
  id: {
    type: Number
  }
});
const emits = defineEmits(["update:show", "success"]);
const dialogVisible = computed({
  get() {
    return props.show;
  },
  set(n) {
    emits("update:show", n);
  }
});

watch(
  () => dialogVisible.value,
  n => {
    if (n) {
      getDetail();
    } else {
    }
  }
);
const status = ref(0);
const radio1 = ref(3);
const state = reactive({
  detail: {},
  form: {
    status: 0,
    comment: ""
  }
});
const getDetail = () => {
  if (!props.id) {
    return;
  }
  request.get(`/mallService/mechanism/goods/${props.id}`).then(resp => {
    state.detail = resp.data;
    state.form.status = resp.data.goods.verifyStatus;
  });
};
const handleSubmit = () => {
  request
    .put(`/mallService/mechanism/goods/verifyStatus/${state.form.status}`, {
      ids: [props.id],
      comment: state.form.comment
    })
    .then(resp => {
      ElMessage.success(resp.message);
      dialogVisible.value = false;
      emits("success");
    });
};
</script>
