 <!-- 项目新增-->
<template>
  <el-main class="bg_white wrap_box lcpg">
    <!-- 按钮组-->
    <LcButtons ref="lcButtons" :type="1" @btsEmit="btsEmit($event)" :bts="btsArry"></LcButtons>
    <!-- 基本信息-->
    <lcBaseInfo ref="addBaseInfo" type="info"></lcBaseInfo>
    <!--任务信息-->
    <div class="lc-bsinfo">
      <!-- <div class="lc_title">任务信息列表</div>
      <JxOricoTable ref="lc_rwxxTB" v-model:listHeader="data.listHeader" v-model:defaultRow="data.defaultRow"
        v-model:tableHeader="data.tableHeader" v-model:notShowCol="data.notShowCol" v-model:staticList="data.staticList"
        v-model:beforeStrList="data.beforeStrList" v-model:singleChangeList="data.singleChangeList"
        @getClickBtnType="getClickBtnType" @getRouteInfo="getRouteInfo">
      </JxOricoTable> -->
      <!--规格定义表-->
      <!-- <div class="lc_title lc_ttop lc_add_ggdyb">规格定义表</div>
      <lcggdytab v-model:ggdyTableData='data.ggdyTableData' :ggdybts="data.ggdybts"></lcggdytab> -->
      <!--备注-->
      <div class="lc_ttop lc_bzt">备注</div>
      <div style="padding-bottom: 50px;">
        <lctinymce ref="editor" :height="data.height" :cur-value="remark" @input="inputContent" :id="data.id"
          :key="data.key"></lctinymce>
      </div>
    </div>
  </el-main>
</template>
<script setup name="addProject">
import { ElMessage } from 'element-plus'
import { reactive, ref, getCurrentInstance, provide } from 'vue';
import { useStore } from 'vuex'
import { tasklist, rw_listHeader, addprlisttopBt } from '../../../utils/lc_data'// 获取人员
import { getUsers, getTaskdata } from '../../../utils/lc'// 获取人员
import { useRouter } from 'vue-router'
/* 数据 */
let { proxy } = getCurrentInstance()// this替代
const router = useRouter()
let store = useStore()
provide('project_id', null)
let remark = ref('')
// 任务信息列表
let data = reactive({
  is_saveclick: true,
  ggdyTableData: [],// 规格定义表
  tableTitle: '任务信息列表',
  listHeader: JSON.parse(JSON.stringify(rw_listHeader)),
  defaultRow: tasklist,
  tableHeader: [],
  notShowCol: [],
  beforeStrList: ['mt', 'dsp'],
  ggdybts: 'add',
  staticList: { mtlist: [{ id: 1, name: '测试1' }, { id: 2, name: '测试2' }, { id: 3, name: '测试3' }] },
  //富文本
  height: 300,
  key: '',
  id: ''
})
data.listHeader[0].type = 'text'
const btsArry = reactive(JSON.parse(JSON.stringify(addprlisttopBt)))
// 基本信息组件值
const addBaseInfo = ref()
const lcButtons = ref()
/* 初始化获取数据 */
getUsers({ page: 1, size: 999999, nickname: '' }).then(res => {
  data.staticList.mtlist = []
  res.data.forEach(it => {
    data.staticList.mtlist.push({ id: it.id, name: it.nickname })
  })
})
getTaskdata().then(res => {
  data.defaultRow = []
  res.forEach(it => {
    data.defaultRow.push({
      id: 0,
      name: it.name,
      leader_user_id: '',
      reviewer_user_id: '',
      committed_step: '',
      status: '',
      msg: '',
      plan_start_time: '',
      plan_end_time: '',
      start_time: '',
      end_time: '',
      remark: '',
      extend: '',
      project_id: '',
      basetask_id: it.basetask_id
    })
  })
})
/*保存之后关闭新增当前页面打开编辑 */
function closeAddOpen (id) {
  let index = null
  store.state.topNavTag.tags.forEach((el, inde) => {
    el.fullPath.indexOf('add') != -1 ? index = inde : false
  });
  if (index) {
    store.dispatch('topNavTag/removeNavTag', index)
  }
  router.push({
    path: '/lcProject/projectMange/edit',
    query: { id: id }
  })
}
//富文本编辑器
function inputContent (value) {
  remark.value = value
}
//按钮组操作
function btsEmit (value) {
  // 点击新增项目
  if (value == 'saveProject') {
    addProject()
  }
  if (value == 'pushdown') {
    if (baseInfo.value.id) {
      addProject()
      data.xtshow = true
    } else {
      ElMessage({
        type: 'error',
        message: '请先保存之后在下推'
      })
    }
  }
}
// 新增项目
function addProject () {
  let adddata = JSON.parse(JSON.stringify(addBaseInfo.value.form))
  if (adddata.name && adddata.cate_id && adddata.brand_ids) {
    adddata.brand_ids = adddata.brand_ids.join(',')
    adddata.cate_id = adddata.cate_id && adddata.cate_id.length > 0 ? adddata.cate_id[adddata.cate_id.length - 1] : ''
    adddata.remark = remark.value
    adddata.task = JSON.parse(JSON.stringify(data.defaultRow))
    if (data.is_saveclick) {
      data.is_saveclick = false
      proxy.$http.showLoading(false).post('project/project/edit', adddata).then(res => {
        if (res.errno == 200) {
          ElMessage({
            type: 'success',
            message: '保存成功'
          })
          router.push({
            path: '/lcProject/projectMange/edit',
            query: { id: res.data.info.id }
          })
          closeAddOpen(res.data.info.id)
        } else {
          ElMessage({
            type: 'error',
            message: res.errmsg
          })
        }
      })
      setTimeout(() => {
        data.is_saveclick = true
      }, 6000)
    } else {
      ElMessage.error('重复点击，请稍后再试')
    }
  } else {
    if (!adddata.name) {
      ElMessage({
        type: 'error',
        message: '请填写项目名称'
      })
      return
    }
    if (!adddata.leader_user_id) {
      ElMessage({
        type: 'error',
        message: '请项目负责人'
      })
      return
    }
    if (!adddata.cate_id) {
      ElMessage({
        type: 'error',
        message: '请选择产品分类'
      })
      return
    }
    if (!adddata.brand_ids) {
      ElMessage({
        type: 'error',
        message: '请选择项目包含品牌'
      })
      return
    }
  }
}
// 表格行点击
function getClickBtnType (value) {
}
// 获取路由跳转信息
function getRouteInfo (row) {
}
</script>
<style scoped lang="scss">
@import '../../../assets/style/lc.scss';
</style>
