<template>
  <div>
    <el-form :model="searchForm" inline label-width="0">
      <el-form-item>
        <el-input v-model="searchForm.name" placeholder="机构名称" />
      </el-form-item>
      <el-form-item>
        <el-select v-model="searchForm.auditType" clearable filterable placeholder="审核状态">
          <el-option label="待审核" :value="1" />
          <el-option label="已通过" :value="2" />
          <el-option label="未通过" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery"> 搜索 </el-button>
        <!-- <el-button type="primary" @click="handleAdd" v-hasPermi="['question:database:add']">
          新增
        </el-button> -->
      </el-form-item>
    </el-form>

    <el-table :data="tableList" border stripe>
      <el-table-column type="index" width="50" />
      <el-table-column prop="name" label="机构名称" />
      <el-table-column prop="applyUser" label="申请人" />
      <el-table-column prop="phone" label="联系方式" />
      <el-table-column prop="createTime" label="申请时间" />
      <el-table-column prop="auditRemark" label="审核状态" />
      <el-table-column prop="auditUser" label="审核人" />
      <el-table-column prop="auditTime" label="审核时间" />
      <!-- 操作 -->
      <el-table-column label="操作" fixed="right" width="150">
        <template #default="{ row }">
          <el-button
            v-if="row.auditType == 1"
            type="primary"
            link
            v-hasPermi="['JoinUs:Station:audit']"
            @click="handleDetail(row, 'audit')"
          >
            审核
          </el-button>
          <el-button
            v-else
            type="primary"
            link
            v-hasPermi="['JoinUs:Station:audit']"
            @click="handleDetail(row, 'detail')"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <Pagination
      :total="total"
      v-model:page="searchForm.pageNo"
      v-model:limit="searchForm.pageSize"
      @pagination="getList"
    />

    <Dialog v-model="dialogVisible" title="机构详情" style="width: 1000px">
      <el-form
        :model="form"
        ref="formRef"
        :rules="rules"
        label-position="top"
        :disabled="form.auditType != 1"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="机构名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入机构名称" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系人" prop="applyUser">
              <el-input v-model="form.applyUser" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="联系方式" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入电话" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训机构宣传文案" prop="xcwa">
              <el-input
                v-model="form.name"
                type="textarea"
                :autosize="{ minRows: 2 }"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训机构地址" prop="address">
              <el-input
                v-model="form.address"
                type="textarea"
                :autosize="{ minRows: 2 }"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训项目-多旋翼" prop="dxy">
              <el-checkbox-group v-model="form.dxy">
                <el-checkbox
                  v-for="item in driverOptions"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训项目-垂直起降" prop="czqj">
              <el-checkbox-group v-model="form.czqj">
                <el-checkbox
                  v-for="item in driverOptions"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训项目-直升机" prop="zsj">
              <el-checkbox-group v-model="form.zsj">
                <el-checkbox
                  v-for="item in driverOptions"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="培训项目-固定翼" prop="gdy">
              <el-checkbox-group v-model="form.gdy">
                <el-checkbox
                  v-for="item in driverOptions"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="合格证图片" prop="hgztp">
              <UploadImg v-model="form.hgztp" height="100px" width="100px" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="培训机构Logo" prop="logo">
              <UploadImg v-model="form.logo" height="100px" width="100px" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="主页宣传图" prop="zyxct">
              <UploadImgs v-model="form.zyxct" :limit="6" height="100px" width="100px" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="优势标签" prop="ysbq">
              <el-checkbox-group v-model="form.ysbq">
                <el-checkbox
                  v-for="item in goodOptions"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="其他服务" prop="qtfw">
              <el-checkbox-group v-model="form.qtfw">
                <el-checkbox
                  v-for="item in serviceOptions"
                  :key="item.value"
                  :label="item.value"
                  :value="item.value"
                >
                  {{ item.label }}
                </el-checkbox>
              </el-checkbox-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="其他诉求" prop="qtsq">
              <el-input
                v-model="form.qtsq"
                type="textarea"
                :autosize="{ minRows: 2 }"
                placeholder="请输入"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <div v-if="dialogType == 'audit'">
          <el-row>
            <el-divider direction="horizontal" content-position="left">审核信息</el-divider>
            <el-col :span="6" :offset="0">
              <el-form-item label="审核结果" prop="shjg">
                <el-radio-group v-model="form.shjg">
                  <el-radio :label="2" :value="2">通过</el-radio>
                  <el-radio :label="3" :value="3">不通过</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="18" :offset="0">
              <el-form-item label="审核说明" prop="shsm">
                <el-input v-model="form.shsm" placeholder="请输入" />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
      </el-form>
      <template #footer>
        <el-button type="primary" @click="submitForm">保 存</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </template>
    </Dialog>
  </div>
</template>

<script setup name="Station">
const searchForm = ref({
  name: '',
  auditType: 1,
  pageNo: 1,
  pageSize: 20
})

const tableList = ref([])
const total = ref(0)

const form = ref({})
const rules = {
  name: { required: true, message: '请输入名称', trigger: 'blur' },
  applyUser: { required: true, message: '请输入创建人', trigger: 'blur' },
  phone: { required: true, message: '请输入手机号', trigger: 'blur' }
}
const dialogVisible = ref(false)
const dialogType = ref('audit')
const driverOptions = ref([
  { label: '小型-视距内驾驶员', value: 1 },
  { label: '小型-超视距驾驶员', value: 2 },
  { label: '小型-教员', value: 3 },
  { label: '中型-视距内驾驶员', value: 4 },
  { label: '中型-超视距驾驶员', value: 5 },
  { label: '中型-教员', value: 6 }
])

const goodOptions = ref([
  { label: '服务好', value: 1 },
  { label: '交通便利', value: 2 },
  { label: '提供住宿', value: 3 },
  { label: '免费接送', value: 4 }
])

const serviceOptions = ref([
  { label: '希望平台主动推荐学员', value: 1 },
  { label: '接受团购学员报名', value: 2 },
  { label: '希望平台推荐教员资源', value: 3 },
  { label: '希望平台推荐无人机相关的设备', value: 4 }
])

onMounted(() => {
  handleQuery()
})

function handleQuery() {
  searchForm.value.pageNo = 1
  getList()
}

function getList() {
  //   getStationList(searchForm.value).then((res) => {
  //     console.log(res)
  //   })
  tableList.value = [
    {
      id: 1,
      name: '机构1',
      createTime: '2021-01-01',
      applyUser: '张三',
      phone: '18888888888',
      auditType: 2,
      auditTime: '2021-02-01',
      auditUser: 'admin',
      auditRemark: '审核通过'
    },
    {
      id: 2,
      name: '机构2',
      auditType: 1,
      applyUser: '李四',
      phone: '19999999999'
    }
  ]
  total.value = 2
}

function handleDetail(row, type) {
  console.log(type)
  dialogVisible.value = true
  form.value = { ...row }
}

function submitForm() {
  dialogVisible.value = false
}
</script>

<style lang="scss" scoped></style>
