<template>
  <div class="p-2">
    <el-card shadow="never" v-if="show">
      <el-table v-loading="loading" :data="manualChannelConfigList" @selection-change="handleSelectionChange">
        <el-table-column label="服务商ID" align="center" prop="providerId" />
        <el-table-column label="服务商名称" align="center" prop="providerName" />
        <el-table-column label="服务商使用状态" align="center" prop="status">
          <template #default="scope">
            <dict-tag :options="msg_service_status" :value="scope.row.status" />
          </template>
        </el-table-column>
        <el-table-column label="申请人" align="center" prop="createBy" />
        <el-table-column label="申请时间" align="center" prop="createTime" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="审核通过" placement="top">
              <el-button v-hasPermi="['msg:manualChannelConfig:save']" link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip content="审核不通过" placement="top">
              <el-button
                v-hasPermi="['msg:manualChannelConfig:remove']"
                link
                type="primary"
                icon="Delete"
                @click="handleDelete(scope.row)"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup name="manualChannelReview" lang="ts">
import { saveSendChannel, queryReviewSendChannel, removeSendChannelApply } from '@/api/msg/manualChannelConfig';
import { ManualChannelConfigVO, ManualChannelConfigQuery, ManualChannelConfigForm } from '@/api/msg/manualChannelConfig/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const { msg_service_status } = toRefs<any>(proxy?.useDict('msg_service_status'));
const manualChannelConfigList = ref<ManualChannelConfigVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(false);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const smsSendChannel = ref();
const channel = ref([]);
const show = ref(false);
const saveLoading = ref(false);
const updateChannel = ref();

const queryFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: ManualChannelConfigForm = {
  id: undefined,
  providerId: undefined,
  providerName: undefined,
  status: undefined
};
const data = reactive<PageData<ManualChannelConfigForm, ManualChannelConfigQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    providerId: undefined,
    providerName: undefined,
    status: undefined,
    params: {}
  },
  rules: {
    id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }],
    providerId: [{ required: true, message: '服务商ID不能为空', trigger: 'blur' }],
    providerName: [{ required: true, message: '服务商名称不能为空', trigger: 'blur' }],
    status: [{ required: true, message: '服务商使用状态(0-启用 1-禁用)不能为空', trigger: 'change' }]
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询手工短信发送通道配置列表 */
const getList = async () => {
  show.value = true;
  loading.value = true;
  const res = await queryReviewSendChannel();
  manualChannelConfigList.value = res;
  total.value = res.total;
  loading.value = false;
};



/**
 * 审核通过
 */
const handleUpdate = async (row) => {
  //  console.log(row);
  try {
    await proxy?.$modal
      .confirm('是否更新所有在途申请模板的发送通道？')
      .then(() => {
        updateChannel.value = 'Y';
      })
      .catch(() => {
        updateChannel.value = 'N';
      });
    //  console.log(updateChannel.value);
    row.updateChannel = updateChannel.value;
    await saveSendChannel(row);
    proxy?.$modal.msgSuccess('操作成功');
  } catch (error) {
  } finally {
    await getList();
  }
};

const handleDelete = async (row) => {
  //  console.log(row);
  try {
    await removeSendChannelApply(row);
    proxy?.$modal.msgSuccess('操作成功');
  } catch (error) {
  } finally {
    await getList();
  }
};

onMounted(() => {
  getList();
});
</script>
