<template>
  <div>
    <el-card class="!border-none" shadow="never">
      <el-form
        ref="formRef"
        class="mb-[-16px]"
        :model="queryParams"
        :inline="true"
      >
        <el-form-item label="用户信息">
          <el-input
            class="w-[280px]"
            v-model="queryParams.keyword"
            placeholder="用户编号/昵称/手机号码"
            clearable
            @keyup.enter="resetPage"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="resetPage">查询</el-button>
          <el-button @click="resetParams">重置</el-button>
          <export-data
            class="ml-2.5"
            :fetch-fun="getUserList"
            :params="queryParams"
            :page-size="pager.size"
          />
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="!border-none mt-4" shadow="never">
      <el-table size="large" v-loading="pager.loading" :data="pager.lists">
        <el-table-column label="用户编号" prop="sn" min-width="120" />
        <el-table-column label="头像" min-width="100">
          <template #default="{ row }">
            <el-avatar :src="row.avatar" :size="50" />
          </template>
        </el-table-column>
        <el-table-column label="账号" prop="account" min-width="120" />
        <el-table-column label="姓名" prop="nickname" min-width="100" />
        <el-table-column label="联系方式" prop="mobile" min-width="100" />
        <el-table-column
          label="隶属公司"
          prop="company_name"
          min-width="180"
          align="center"
        >
          <template #default="{ row }">
            {{ row.company?.company_name || "/" }}
          </template>
        </el-table-column>
        <el-table-column label="所在乡镇" prop="street_name" min-width="120" />
        <el-table-column label="授权身份" prop="role_name" min-width="120">
          <template #default="{ row }">
            <span
              v-if="row.admin_id == row.company?.admin_id"
              style="color: #67c23a"
              >公司后台管理人员</span
            >
            <span v-else style="color: #fe0000">无</span>
          </template>
        </el-table-column>
        <el-table-column
          label="是否签约"
          prop="is_contract"
          align="center"
          min-width="120"
        >
          <template #default="{ row }">
            <span v-if="row.is_contract == 1" style="color: #67c23a"
              >已签约</span
            >
            <span v-else style="color: #fe0000">未签约</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="400" align="center" fixed="right">
          <template #default="{ row }">
            <el-button v-perms="['user.user/detail']" type="primary" link>
              <router-link
                :to="{
                  path: getRoutePath('user.user/detail'),
                  query: {
                    id: row.id,
                  },
                }"
              >
                详情
              </router-link>
            </el-button>
            <template v-if="row.company_id != 0 && row.is_contract == 0">
              <el-button
                v-perms="['auth.admin/Draftingcontracts']"
                type="primary"
                link
              >
                <router-link
                  :to="{
                    path: getRoutePath('user.user/detail'),
                    query: {
                      id: row.id,
                      mode: 'initiate',
                    },
                  }"
                >
                  发起合同
                </router-link>
              </el-button>

              <el-button
                v-perms="['auth.admin/Draftingcontracts']"
                type="primary"
                link
              >
                <router-link
                  :to="{
                    path: getRoutePath('user.user/detail'),
                    query: {
                      id: row.id,
                      mode: 'uplode',
                    },
                  }"
                >
                  上传合同
                </router-link>
              </el-button>
              <el-button
                v-perms="['auth.admin/Draftingcontracts']"
                type="primary"
                link
                @click="
                  (showPop = true),
                    (showConctactPop = true),
                    (contractId = row.id)
                "
                >生成个人合同</el-button
              >
              <el-button
                v-perms="['auth.admin/postsms']"
                type="primary"
                link
                @click="(showPop = true), (contractId = row.id)"
                >重新短信</el-button
              >
            </template>
            <!-- <el-button
                                    v-if="row.root != 1"
                                    v-perms="['auth.admin/delete']"
                                    type="danger"
                                    link
                                    @click="handleDelete(row.id)"
                                    >删除</el-button
                                >
                                <el-button
                                    v-if="row.is_contract == 1"
                                    v-perms="['auth.admin/abolition']"
                                    type="danger"
                                    link
                                    @click="handleAbolition(row.id)"
                                    >废除合同</el-button
                                >
                                <template v-if="row.company_id != 0 && row.is_contract == 0">
                                    <el-button
                                        v-perms="['auth.admin/Draftingcontracts']"
                                        type="primary"
                                        link
                                        @click="
                                            ;(showPop = true),
                                                (showConctactPop = true),
                                                (contractId = row.id)
                                        "
                                        >生成个人合同</el-button
                                    >
                                    <el-button
                                        v-perms="['auth.admin/postsms']"
                                        type="primary"
                                        link
                                        @click=";(showPop = true), (contractId = row.id)"
                                        >重新短信</el-button
                                    >
                                </template> -->
          </template>
        </el-table-column>
      </el-table>

      <el-dialog v-model="showPop" @close="offPop">
        <h1>重要提醒</h1>
        <div class="content" v-if="showConctactPop">
          请确认信息是否有误,发送合同,请确认信息是否有误,发送电子合同后短时间内将不可再次发送.
        </div>
        <div class="content" v-else>
          确认签约短信将在60秒后发送,请注意查收,并点击短信链接进行线上合同签约
        </div>
        <p class="btn_menu">
          <el-button
            type="primary"
            size="large"
            v-if="showConctactPop"
            @click="creContct"
            >确认创建</el-button
          >
          <el-button type="primary" size="large" v-else @click="sendMsg"
            >确认</el-button
          >
          <el-button type="info" size="large" @click="offPop">返回</el-button>
        </p>
      </el-dialog>
      <div class="flex justify-end mt-4">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
  </div>
</template>
<script lang="ts" setup name="consumerLists">
import { usePaging } from "@/hooks/usePaging";
import { getRoutePath } from "@/router";
import {
  getUserList,
  creatContact,
  initiateContact,
  upContact,
} from "@/api/consumer";
import { ClientMap } from "@/enums/appEnums";
import feedback from "@/utils/feedback";

const queryParams = reactive({
  keyword: "",
  channel: "",
  create_time_start: "",
  create_time_end: "",
});
const contractId = ref(0);
const showPop = ref(false);
const showConctactPop = ref(false);
const offPop = () => {
  showPop.value = false;
  showConctactPop.value = false;
};
const creContct = () => {
  //   feedback.msgSuccess("复制成功");
  creatContact({ id: contractId.value }).then(() => {
    feedback.msgSuccess("发送成功");
  });
  offPop();
};
const sendMsg = () => {
  //   sendMsgApi({ id: contractId.value }).then((res) => {
  //     feedback.msgSuccess("发送成功");
  //   });
  offPop();
};
// const handleDelete = async (id: number) => {
//     await feedback.confirm('确定要删除？')
//     await adminDelete({ id })
//     getLists()
// }
// const handleAbolition = async (id: number) => {
//     await feedback.confirm('确定要废除合同？')
//     await abolition({ id })
//     getLists()
// }
const { pager, getLists, resetPage, resetParams } = usePaging({
  fetchFun: getUserList,
  params: queryParams,
});
onActivated(() => {
  getLists();
});

getLists();
</script>
<style>
h1 {
  text-align: center;
  font-weight: bold;
  font-size: 30px;
  color: red;
  margin-bottom: 10px;
}

.content {
  font-size: 20px;
}

.info {
  color: red;
  font-weight: bold;
  font-size: 18px;
  display: inline-block;
  margin: 0 5px;
}

.btn_menu {
  margin-top: 10vh;
  display: flex;
  justify-content: space-around;
}
</style>
