<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="checkUserAll"
              :indeterminate="userIndeterminate"
              @change="userCheckAllChange"
            >
              全选
            </el-checkbox>
            <el-checkbox-group v-model="form.users" @change="userCheckedChange">
              <el-checkbox
                v-for="(item, index) in userOptions"
                :key="index"
                :label="item.value"
                :value="item.value"
              >
                {{ item.label }}
              </el-checkbox>
            </el-checkbox-group>
          </div>
        </el-form-item> -->
        <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="权重配置">
          <div>
            <el-radio-group v-model="form.isRandom">
              <el-radio :label="1">
                <Tooltip message="根据剩余的线索平均分配到未分配线索的所有人" />
                平均分配
              </el-radio>
              <el-radio :label="0"> 权重分配 </el-radio>
            </el-radio-group>
            <div v-if="form.isRandom == 0">
              <div v-for="(item, index) in intentionOptions" :key="index" class="flex mb-10px">
                <div class="mr-15px" style="width: 100px">{{ item.label }}</div>
                <el-input v-model="item.value" type="number" placeholder="请输入权重">
                  <template #suffix> % </template>
                </el-input>
              </div>
            </div>
          </div>
        </el-form-item>
        <el-form-item label="分配时间">
          <el-time-picker
            v-model="form.sendTime"
            placeholder="任意时间点"
            format="HH:mm"
            value-format="HH:mm"
            :clearable="false"
          />
        </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(1)

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

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

// const checkUserAll = ref(false)
// const userIndeterminate = ref(true)
// const userOptions = ref([
//   { label: '张三', value: 1 },
//   { label: '李四', value: 2 },
//   { label: '王二', value: 3 }
// ])

// function userCheckAllChange(val) {
//   form.value.users = val ? userOptions.value.map((it) => it.value) : []
//   userIndeterminate.value = false
// }

// function userCheckedChange(val) {
//   const checkedCount = val.length
//   checkUserAll.value = checkedCount == userOptions.value.length
//   userIndeterminate.value = checkedCount > 0 && checkedCount < userOptions.value.length
// }

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
}

const intentionOptions = ref([
  { label: '高意向', value: 20 },
  { label: '中意向', value: 20 },
  { label: '低意向', value: 20 },
  { label: '未知意向', value: 40 }
])

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

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