<!--项目管理列表-->
<!--顶部搜索-->
<template>
  <el-form :label-position="labelPosition" :model="theformdata" ref="former" label-width="124px">
    <el-row :gutter="16"
      v-for="(item, index) in  (type == 'task' ? fromdItems2 : type == 'log' ? fromdItems3 : fromdItems)" :key="index">
      <el-col :span="24 / (item.length)" class="s-item" v-for="it in item" :key="it.label"
        :style="{ 'margin-left': it.m_left }">
        <el-form-item :label="it.label" :prop="it.vModel">
          <!-- 输入框-->
          <el-input v-model="theformdata[it.vModel]" v-if="it.type == 'input'" :placeholder="it.placeholder"
            maxlength="25"></el-input>
          <!--选择框-->
          <el-select v-model="theformdata[it.vModel]" v-if="it.type == 'select'" :placeholder="it.placeholder" clearable
            filterable>
            <el-option v-for="item in it.childlist" :key="item.value" :label="item.label" :value="item.value">
            </el-option>
          </el-select>
          <!--日期框-->
          <el-date-picker v-if="it.type == 'datepick'" v-model="theformdata[it.vModel]" type="daterange"
            range-separator="-" :placeholder="it.placeholder" value-format="YYYY/MM/DD" format="YYYY/MM/DD">
          </el-date-picker>
          <!--按钮-->
          <div class="s-bts" v-if="it.type == 'button'">
            <div class="l-button" v-for="item in it.childlist" :key="item.name"
              @click="btEmint(item.methodName, theformdata)">{{ item.name }}</div>
          </div>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script setup name= "lSearch">
import { onMounted, onUnmounted, reactive, ref, defineProps, defineEmits, getCurrentInstance, defineExpose } from 'vue'
import { getProjectTasks_list, getProjectLog_list } from '../../utils/lc'
import { projectMangeSearch_data, taskMangeSearch_data, projectLogSearch_data } from '../../utils/lc_data'
const prop = defineProps(['type'])
const labelPosition = ref('right')
let theformdata = ref(JSON.parse(JSON.stringify(prop.type == 'task' ? taskMangeSearch_data : prop.type == 'log' ? projectLogSearch_data : projectMangeSearch_data)))
console.log(prop.type, theformdata)
const fromdItems2 = reactive([
  [{ label: '任务编号', type: 'input', vModel: 'sn', placeholder: '请输入任务编号', m_left: '' },
  { label: '任务名称', type: 'input', vModel: 'name', placeholder: '请输入任务名称', m_left: '' },
  { label: '任务负责人', type: 'input', vModel: 'leader_user_name', placeholder: '请输入任务负责人', m_left: '' },

  {
    label: '业务状态', type: 'select', childlist: [
      { value: '-1', label: '全部', },
      { value: '0', label: '排期等待', },
      { value: '10', label: '进行中', },
      { value: '20', label: '暂停', },
      { value: '30', label: '已结束', },
    ], vModel: 'task_status', placeholder: '请选择', m_left: '-2%'
  },
  {
    label: '审核状态', type: 'select', childlist: [
      { value: '-1', label: '全部', },
      { value: '0', label: '未提交', },
      { value: '10', label: '未审核', },
      { value: '20', label: '已结束', }
    ], vModel: 'examine_status', placeholder: '请选择', m_left: '-2%'
  }],
  [
    { label: '所属项目名称', type: 'input', vModel: 'project_name', placeholder: '请输入所属项目名称', m_left: '' },
    { label: '任务完成日期', type: 'datepick', vModel: 'end_time', placeholder: '年/月/日', m_left: '-4.2%' },
    { label: '预计开始日期', type: 'datepick', vModel: 'plan_start_time', placeholder: '年/月/日', m_left: '-4.2%' },
    { label: '', type: 'button', childlist: [{ name: '查询', methodName: 'searchhandle' }, { name: '重置', methodName: 'resethandel' }], m_left: '8%' }
  ]
])
const fromdItems = reactive([
  [{ label: '项目名称', type: 'input', vModel: 'name', placeholder: '请输入项目名称', m_left: '' },
  { label: '项目负责人', type: 'input', vModel: 'leader_user_name', placeholder: '请输入项目负责人', m_left: '-2%' },
  {
    label: '项目状态', type: 'select', childlist: [
      { value: 0, label: '全部', },
      { value: 10, label: '已保存', },
      { value: 20, label: '暂停', },
      { value: 30, label: '进行中', },
      { value: 40, label: '结束', },
    ], vModel: 'status', placeholder: '请选择', m_left: '-2%'
  },
  { label: '当前任务', type: 'select', childlist: [], vModel: 'task_id', placeholder: '请选择 ', m_left: '-2%' },
  { label: '项目预计开始日期', type: 'datepick', vModel: 'plan_start_time', placeholder: '年/月/日', m_left: '0%' },
  { label: '项目预计结束日期', type: 'datepick', vModel: 'plan_end_time', placeholder: '年/月/日', m_left: '2%' }],
  [{
    label: '项目优先级', type: 'select', childlist: [
      { value: '', label: '全部' },
      { value: 0, label: 'P0' },
      { value: 1, label: 'P1' },
      { value: 2, label: 'P2' },
      { value: 3, label: 'P3' },
      { value: 4, label: 'P4' }

    ], vModel: 'level', placeholder: '请选择'
  },
  { label: '项目开始时间', type: 'datepick', vModel: 'start_time', placeholder: '年/月/日', m_left: '-2%' },
  { label: '项目结束时间', type: 'datepick', vModel: 'end_time', placeholder: '年/月/日', m_left: '1%' },
  { label: '项目量产日期', type: 'datepick', vModel: 'product_time', placeholder: '年/月/日', m_left: '1%' },
  { label: '项目上架日期', type: 'datepick', vModel: 'online_time', placeholder: '年/月/日', m_left: '1%' },
  { label: '', type: 'button', childlist: [{ name: '查询', methodName: 'searchhandle' }, { name: '重置', methodName: 'resethandel' }], m_left: '-2%' }]
])
const fromdItems3 = reactive([
  [{ label: '项目', type: 'input', vModel: 'keywords', placeholder: '请输入项目名称，项目编号', m_left: '' },
  { label: '变更人', type: 'input', vModel: 'user_name', placeholder: '请输入变更人', m_left: '-2%' },
  { label: '变更对象', type: 'select', childlist: [], vModel: 'module', placeholder: '请选择 ', m_left: '-2%' },
  { label: '变更类型', type: 'select', childlist: [], vModel: 'type', placeholder: '请选择 ', m_left: '-1%' },
  { label: '变更时间', type: 'datepick', vModel: 'thetime', placeholder: '年/月/日', m_left: '-2%' }],
  [
    { label: '', type: 'button', childlist: [{ name: '查询', methodName: 'searchhandle' }, { name: '重置', methodName: 'resethandel' }, { name: '导出', methodName: 'logexportbt' }] }
  ]
])
onMounted(() => {
  if (prop.type == 'task') {
    if (window.sessionStorage.getItem("taskSearchdata")) {
      theformdata.value = JSON.parse(window.sessionStorage.getItem("taskSearchdata"))
    }
  } else {
    if (window.sessionStorage.getItem("projectSearchdata") && prop.type !== 'log') {
      theformdata.value = JSON.parse(window.sessionStorage.getItem("projectSearchdata"))
    } else {
      if (window.sessionStorage.getItem("projectLogSearchdata")) {
        theformdata.value = JSON.parse(window.sessionStorage.getItem("projectLogSearchdata"))
      }
    }
  }
  if (prop.type == 'log') {
    getProjectLog_list().then(res => {
      fromdItems3[0][3].childlist = []
      for (let key in res.type) {
        fromdItems3[0][3].childlist.push({
          label: res.type[key],
          value: key
        })
      }
      fromdItems3[0][2].childlist = []
      res.module.forEach(it => {
        fromdItems3[0][2].childlist.push({
          label: it,
          value: it
        })
      });
      console.log(fromdItems3[0][3].childlist, fromdItems3[0][2].childlist)
      console.log('日志下拉选项', res)
    })
  }
})
onUnmounted(() => {
  if (prop.type == 'task') {
    window.sessionStorage.setItem("taskSearchdata", JSON.stringify(theformdata.value));
  } else {
    if (prop.type == 'log') {
      window.sessionStorage.setItem("projectLogSearchdata", JSON.stringify(theformdata.value));
    } else {
      window.sessionStorage.setItem("projectSearchdata", JSON.stringify(theformdata.value));
    }
  }

});
// 当前任务
getProjectTasks_list().then(res => {
  fromdItems[0][3].childlist = res
})
const { proxy } = getCurrentInstance()
const emit = defineEmits(["resethandel", 'searchhandle', 'logexportbt'])
function btEmint (methodName, theformdata) {
  if (methodName == 'resethandel') {
    proxy.$refs.former.resetFields()
  }
  emit(methodName, theformdata)
}
/* 曝露方法或者属性值给父组件或者其他子组件用 */
defineExpose({
  theformdata
})
</script>
<style scoped lang="scss">
@import '../../assets/style/lc.scss';
</style>