<template>
  <div v-if="type == 1" class="l_bts">
    <!-- type ==1普通按钮组-->
    <div class="l-button" v-for="(it, index) in bts" :key="index" @click="btsEmit(it.methodName)">{{ it.name }}</div>
    <slot name="check"></slot>
  </div>
  <!-- type ==2 任务列表顶按钮组-->
  <div v-if="type == 2" class="l-bt-flex">
    <div v-for="(it, index) in (task == 'task' ? btsArry2 : btsArry) " :key="it.name">
      <div class="l-button" v-if="it.type == 'defalut'" @click="btsEmit(it.methodName)">{{ it.name }}</div>
      <div class="l-button2" v-if="it.type == 'plain'" @click="btsEmit(it.methodName)">{{ it.name }}</div>
      <el-dropdown size="small" split-button type="primary" @click="dropbtn(it.methodName, it.name)"
        v-if="it.type == 'dropdown'" @command="btsEmit" style="margin-right: 15px;">
        {{ it.name }}
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item v-for="its in it.dropdownlist" :key="its.methodName" :command="its.methodName">{{
              its.name
            }}</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
      <!-- 
      <el-dropdown v-if="it.type == 'dropdown'" @command="btsEmit">
        <div class="l-button">
          <span class="l-bt-flex" @click="dropbtn(it.name)">{{ it.name }}<img src="../../assets/ico-xl.png"
              class="ico-xl" /></span>
        </div>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item v-for="its in it.dropdownlist" :key="its.methodName" :command="its.methodName">{{
              its.name
            }}</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown> -->
    </div>
    <slot name="db"></slot>
  </div>
  <!--项目输出资料表弹框 -->
  <lcDailogzl v-model:dialogVisible="dialogVisible" @handelClose="handelClose" v-bind="$attrs" v-if="dialogVisible">
  </lcDailogzl>
  <!--排期弹框-->
  <lcDailogPQ v-model:pQshow="pQshow" @handelClose="handelClose" :planStratTime='planStratTime' :ids="ids" v-if="pQshow"
    v-bind="$attrs"></lcDailogPQ>
  <!--转派弹框-->
  <lcDailogZP v-model:zPshow="zPshow" @handelClose="handelClose" :userId='userId' :ids="ids" v-bind="$attrs"
    v-if="zPshow"></lcDailogZP>
  <!--人员变更弹框-->
  <lcDailogrybg v-model:rybgshow="rybgshow" @handelClose="handelClose" :reviewerUserId='reviewerUserId' :ids="ids"
    v-if="rybgshow" v-bind="$attrs">
  </lcDailogrybg>
  <!--人员驳回原因-->
  <lcDailogrybh v-model:bhshow="bhshow" @handelClose="handelClose" :ids="ids" :msg="msg" v-bind="$attrs" v-if="bhshow">
  </lcDailogrybh>
</template>
<script setup name="LButton">
import { ElMessage } from 'element-plus'
import { defineProps, defineEmits, ref, reactive, getCurrentInstance, watch, defineExpose } from 'vue'
import { useRouter } from 'vue-router';
/* 数据层 */
let router = useRouter()
const { proxy } = getCurrentInstance()
const dialogVisible = ref(false)
const pQshow = ref(false)
const zPshow = ref(false)
const rybgshow = ref(false)
const bhshow = ref(false)
function handelClose (value) {
  dialogVisible.value = false
  pQshow.value = false
  zPshow.value = false
  rybgshow.value = false
  bhshow.value = false
}
const pop = defineProps(['type', 'bts', 'planStratTime', 'ids', 'userId', 'reviewerUserId', 'msg', 'task', 'projectName'])
let theids = ref('')
watch(
  () => pop.ids,
  (newValue, oldValue) => {
    theids.value = newValue
  }
)
const btsArry = reactive([
  {
    name: '保存',
    type: 'defalut',
    methodName: 'saveBt',
  },
  {
    name: '操作状态',
    defalutName: '操作状态',
    type: 'dropdown',
    dropdownlist: [{
      name: '排期',
      methodName: 'paiQi'
    }, {
      name: '转派',
      methodName: 'zhuangPai'
    }, {
      name: '暂停',
      methodName: 'zhanTing'
    }]
  }, {
    name: '提交',
    defalutName: '提交',
    methodName: 'submitBt',
    type: 'dropdown',
    dropdownlist: [{
      name: '提交',
      methodName: 'submitBt'
    }, {
      name: '撤销',
      methodName: 'revoke'
    }]
  },
  {
    name: '审核',
    defalutName: '审核',
    type: 'dropdown',
    methodName: 'passBt',
    dropdownlist: [{
      name: '通过',
      methodName: 'passBt'
    }, {
      name: '驳回',
      methodName: 'rejectBt'
    }]
  },
  {
    name: '项目资料',
    type: 'defalut',
    methodName: 'projectInfobt'

  },
  {
    name: '修改审核人',
    type: 'defalut',
    methodName: 'pepoleChange'
  },
  {
    name: '日志',
    type: 'defalut',
    methodName: 'log'
  },
])
const btsArry2 = reactive([
  {
    name: '操作状态',
    defalutName: '操作状态',
    type: 'dropdown',
    dropdownlist: [{
      name: '排期',
      methodName: 'pq'
    }, {
      name: '转派',
      methodName: 'zp'
    }, {
      name: '暂停',
      methodName: 'zt'
    }]
  }, {
    name: '提交',
    defalutName: '提交',
    type: 'dropdown',
    dropdownlist: [{
      name: '提交',
      methodName: 'tj'
    }, {
      name: '撤销',
      methodName: 'cx'
    }]
  },
  {
    name: '通过',
    type: 'defalut',
    methodName: 'pass',
  },
  {
    name: '修改审核人',
    type: 'defalut',
    methodName: 'rybg'
  },
])
const emit = defineEmits(["btsEmit", 'getPageInfo'])
function dropbtn (methodName, btname) {
  if (btname == '提交' || btname == '审核') {
    btsEmit(methodName)
  }
  // if (btname == '审核') {
  //   thepass()
  // }
  // if (btname == '提交') {
  //   thesubmit('submitBt')
  // }
  console.log(btname)
}
function btsEmit (value) {
  if (value == 'projectInfobt') {
    // 项目资料
    dialogVisible.value = true
  }
  if (value == 'paiQi') {
    // 排期
    pQshow.value = true
  }
  if (value == 'zhuangPai') {
    //转派
    zPshow.value = true
  }
  if (value == 'pepoleChange') {
    // 人员变更
    rybgshow.value = true
  }
  if (value == 'zhanTing') {
    //暂停
    if (theids) {
      proxy.$http.showLoading(false).get('project/task/ch_status', { ids: theids.value, type: 20 }).then(res => {
        if (res.errno == 200) {
          ElMessage({
            type: 'success',
            message: '操作成功'
          })
          emit("getPageInfo")
        } else {
          ElMessage({
            type: 'error',
            message: res.errmsg
          })
        }
      })
    }
  }
  if (value == 'passBt') {
    // thepass()
  }
  if (value == 'rejectBt') {
    // 驳回
    bhshow.value = true
  }
  if (value == 'revoke') {
    // 驳回 value == 'submitBt' 10是提交，0是撤回
    thesubmit(value)
  }
  // 日志
  if (value == 'log') {
    console.log('日志', theids, theids.value)
    router.push({ path: '/lcProject/log/prlog', query: { task_id: theids.value, projectName: pop.projectName } })
  }
  emit("btsEmit", value)
}
function thepass () {
  // 通过
  if (theids) {
    proxy.$http.showLoading(false).get('project/task/pass', { ids: theids.value, }).then(res => {
      if (res.errno == 200) {
        ElMessage({
          type: 'success',
          message: '操作成功'
        })
        emit("getPageInfo")
      } else {
        ElMessage({
          type: 'error',
          message: res.errmsg
        })
      }
    })
  }
}
function thesubmit (value) {
  if (theids.value) {
    proxy.$http.showLoading(false).get('project/task/submit', { ids: theids.value, examine_status: value == 'submitBt' ? 10 : 0 }).then(res => {
      if (res.errno == 200) {
        ElMessage({
          type: 'success',
          message: '操作成功'
        })
        emit("getPageInfo")
      } else {
        ElMessage({
          type: 'error',
          message: res.errmsg
        })
      }
    })
  } else {
    ElMessage({
      type: 'error',
      message: '请选择，在操作'
    })
  }
}
/* 曝露方法或者属性值给父组件或者其他子组件用 */
defineExpose({
  thepass,
  thesubmit
})
</script>
<style scoped lang="scss">
@import '@/assets/style/lc.scss';
</style>

