<template>
  <div class="flex">
    <div class="mr-20px" style="width: 500px">
      <el-input
        v-model="searchForm.keyword"
        placeholder="请输入关键字查询"
        clearable
        class="mb-10px"
        @keyup.enter="getUserList"
      />

      <el-table :data="userList" @cell-click="selectUser">
        <el-table-column prop="name" label="员工姓名" />
        <el-table-column prop="phone" label="电话" />
        <el-table-column prop="workNum" label="工号" />
      </el-table>
      <!-- 分页 -->
      <Pagination
        v-model:limit="searchForm.pageSize"
        v-model:page="searchForm.pageNum"
        :total="total"
        @pagination="getUserList"
      />
    </div>
    <el-form :model="form" ref="sendForm" :rules="rules" label-width="100px" :inline="false">
      <el-form-item label="是否自动分配">
        <el-radio-group v-model="form.isAuto">
          <el-radio :label="1"> 自动分配 </el-radio>
          <el-radio :label="0"> 手动分配 </el-radio>
        </el-radio-group>
      </el-form-item>
      <div v-if="form.isAuto">
        <el-form-item label="线索来源">
          <div>
            <el-checkbox
              v-model="checkResourceAll"
              :indeterminate="resourceIndeterminate"
              @change="resourceCheckAllChange"
            >
              全选
            </el-checkbox>
            <el-checkbox-group v-model="form.resource" @change="resourceCheckedChange">
              <el-checkbox
                v-for="(item, index) in resourceOptions"
                :key="index"
                :label="item.value"
                :value="item.value"
              >
                {{ item.label }}
              </el-checkbox>
            </el-checkbox-group>
          </div>
        </el-form-item>
        <el-form-item label="权重配置">
          <el-input v-model="form.value" type="number" placeholder="请输入权重">
            <template #suffix> % </template>
          </el-input>
        </el-form-item>
      </div>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button>重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
const searchForm = ref({
  keyword: '',
  pageSize: 20,
  pageNum: 1
})

const total = ref(0)

const userList = ref([{ name: '张三', phone: '1888888888', workNum: '202101030001' }])

const form = ref({
  isAuto: 1,
  users: [1, 2],
  resource: [3],
  sendTime: '00:00'
})
const rules = ref({})

function getUserList() {
  console.log('获取列表')
}

function onSubmit() {
  console.log('hhahah')
}

const checkResourceAll = ref(false)
const resourceIndeterminate = ref(true)
const resourceOptions = ref([
  { label: '抖音', value: 1 },
  { label: '一点通', value: 2 },
  { label: '驾考宝典', value: 3 }
])

function resourceCheckAllChange(val) {
  form.value.resource = val ? resourceOptions.value.map((it) => it.value) : []
  resourceIndeterminate.value = false
}

function resourceCheckedChange(val) {
  const checkedCount = val.length
  checkResourceAll.value = checkedCount == resourceOptions.value.length
  resourceIndeterminate.value = checkedCount > 0 && checkedCount < resourceOptions.value.length
}

function selectUser(row) {
  console.log(row)
}
</script>

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