<!--资料审核-ljm-->
<template>
  <el-main class="bg_white wrap_box lc_rw">
    <!-- 按钮组 -->
    <LcButtons ref="lcButtons" :type="2" @btsEmit="btsEmit($event)" :planStratTime="data.baseInfo.plan_start_time_text"
      :ids="ids" :projectName="data.baseInfo.project_name" :reviewerUserId="data.baseInfo.reviewer_user_id"
      :userId="data.baseInfo.leader_user_id" :msg="data.baseInfo.msg" @getPageInfo="getPageInfo"
      :deppgetPageInfo="getPageInfo" />
    <!-- 基础信息 -->
    <div class="lc_ttop">
      <lcBaseInfo ref="addBaseInfo" type="taskInfo"></lcBaseInfo>
    </div>
    <div class="lc-bsinfo">
      <!--市场分析PPT-->
      <div class="lc_title lc_ttop lc_add_ggdyb">输出文件</div>
      <lcwjsc v-model:loading="cpPPTdata.loading" v-model:tableHeigth="cpPPTdata.tableHeigth"
        v-model:listHeader="cpPPTdata.listHeader" v-model:defaultRow="cpPPTdata.defaultRow"
        v-model:tableHeader="cpPPTdata.tableHeader" v-model:notShowCol="cpPPTdata.notShowCol"
        v-model:staticList="cpPPTdata.staticList" v-model:beforeStrList="cpPPTdata.beforeStrList"
        @getClickBtnType="getClickBtnType_ppt" @uploadAddRow="uploadAddRow" />
      <!--备注-->
      <div class="lc_ttop lc_bzt">备注</div>
      <div style="padding-bottom: 50px;">
        <lctinymce :id="data.id" ref="editor" :height="data.height" :cur-value="remark" :key="data.key"
          @input="inputContent"></lctinymce>
      </div>
    </div>
    <!-- 填写共享盘链接 -->
    <LcWriteLinks :key="cpPPTdata.isShowLinksDialogIndex" v-model:isShowLinksDialog="cpPPTdata.isShowLinksDialog"
      @getDragWriteData="getDragWriteData" />
  </el-main>
</template>
<script setup name="zlsh">
import { getCurrentInstance, reactive, ref, provide } from 'vue'
import { getBaseInfoFile, getComCurrentDate } from '../../../utils/lc_jx_utils/lc_jx.js'
import { cpPPT_defaultVal, cpppt_headerBtns, cpPPT_listHeader } from '../../../utils/lc_data'// 获取人员
import { downloadMod } from '../../../utils/lc'
import { ElMessage } from 'element-plus'
import { useRoute, } from 'vue-router'
/* 数据层 */
const route = useRoute()
const ids = ref(route.query.prBasetaskId)
const { proxy } = getCurrentInstance()
provide('project_id', route.query.id)
let remark = ref('')
// 基本信息组件值
const addBaseInfo = ref()
const lcButtons = ref()
// 详情数据
let data = reactive({
  baseInfo: {},
  //富文本
  height: 300,
  key: '',
  id: ''
})
// 基本信息字段值
let baseInfokeys = reactive({
  keyArry: ['sn', 'project_sn', 'name', 'required_time_text', 'status', 'leader_user_id', 'reviewer_user_id', 'task_status_text', 'examine_status_text', 'project_id', 'project_name', 'plan_start_time', 'plan_start_time_text', 'plan_end_time', 'plan_end_time_text', 'end_time_text']
})

// 市场分析PPT资料
let cpPPTdata = reactive({
  tableTitle: '任务信息列表',
  tableHeigth: 180,
  loading: false,
  isShowLinksDialog: false,
  listHeader: JSON.parse(JSON.stringify(cpPPT_listHeader)),
  defaultRow: JSON.parse(JSON.stringify(cpPPT_defaultVal)),
  tableHeader: JSON.parse(JSON.stringify(cpppt_headerBtns)),
  notShowCol: [],
  beforeStrList: [],
  staticList: {},
})

/* 初始化 */
getPageInfo()
/* 方法层 */
// 物料报价详情
function getPageInfo (value) {
  proxy.$http.get('project/task/file_review/info', { id: route.query.prBasetaskId }).then(res => {
    if (res.errno == 200) {
      data.baseInfo = JSON.parse(JSON.stringify(res.data))
      ids.value = res.data.id
      // 上下文件管理列表
      cpPPTdata.defaultRow = res.data.files.file_review ? getBaseInfoFile(res.data.files.file_review) : []
      //备注
      remark.value = res.data.remark
      // 驳回原因
      addBaseInfo.value.data.reject = res.data && res.data.reject ? res.data.reject : ''
      // 基础信息
      baseInfokeys.keyArry.forEach(it => {
        addBaseInfo.value.taskform[it] = res.data[it]
      })
    } else {
      ElMessage({
        type: 'success',
        message: res.errmsg
      })
    }
  })
}
//按钮组操作
function btsEmit (value) {
  // 提交和审核先做保存的动作
  if (value == 'passBt' || value == 'submitBt') {
    handelSavePage(value)
  }
  // 保存
  if (value == 'saveBt') {
    handelSavePage()
  }
}
// 保存页面
function handelSavePage (bttype) {
  proxy.$http.showLoading(false).post('project/task/file_review/edit', {
    id: data.baseInfo.id,
    leader_user_id: addBaseInfo.value.taskform['leader_user_id'],
    reviewer_user_id: addBaseInfo.value.taskform['reviewer_user_id'],
    plan_start_time: addBaseInfo.value.taskform['plan_start_time_text'],
    plan_end_time: addBaseInfo.value.taskform['plan_end_time_text'],
    remark: remark.value,
    skus: data.ggdyTableData,
    files: { 'file_review': cpPPTdata.defaultRow },
  }).then(res => {
    if (res.errno == 200) {
      ElMessage({
        type: 'success',
        message: res.errmsg
      })
      if (bttype == 'submitBt') {
        lcButtons.value.thesubmit(bttype)
      }
      if (bttype == 'passBt') {
        lcButtons.value.thepass(bttype)
      }
      getPageInfo()
    } else {
      ElMessage({
        type: 'error',
        message: res.errmsg
      })
    }
  })
}
// 表格按钮 -- 点击
function getClickBtnType_ppt (type, selRow, code, allData) {
  //下载模板
  if (type == 'download') {
    downloadMod(data.baseInfo.basetask_id, '资料审核')
  }
  if (type == 'write_links') {
    cpPPTdata.isShowLinksDialogIndex = data.isShowLinksDialogIndex + 1
    cpPPTdata.isShowLinksDialog = true
    cpPPTdata.btnTamplteList = JSON.parse(JSON.stringify(allData))
  }
}
// 文件上传
function uploadAddRow (s_list) {
  cpPPTdata.loading = true
  let list = JSON.parse(JSON.stringify(s_list.table_list))
  list.push({ id: 0, title: s_list.name, create_time: s_list.date, remark: '', url_type: 'file', isDownLoadShow: 'yes', url: s_list.url, downLoadUrl: s_list.url })
  cpPPTdata.defaultRow = list
  setTimeout(() => {
    proxy.$message.success('文件上传成功')
    cpPPTdata.loading = false
  }, 800);
}
//富文本编辑器
function inputContent (value) {
  remark.value = value
}
// 填写共享盘链接
function getDragWriteData (val) {
  cpPPTdata.loading = true
  cpPPTdata.btnTamplteList.push({ id: 0, title: val, create_time: getComCurrentDate(), remark: '', url_type: 'link', url: '' })
  cpPPTdata.defaultRow = cpPPTdata.btnTamplteList
  setTimeout(() => {
    proxy.$message.success('链接添加成功')
    cpPPTdata.loading = false
  }, 800);
}

</script>
<style scoped lang="scss">
@import '../../../assets/style/lc.scss';
</style>