<!--结构设计-->
<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">
      <div class="lc_title lc_ttop lc_add_ggdyb">输入文件</div>
      <!--规格定义表-->
      <div class="lc_title1">规格定义表</div>
      <Lcggdytab v-model:ggdyTableData='data.ggdyTableData' :nobts="['add', 'delet']" :prtaskId='ids'></Lcggdytab>
      <div class="lc_title lc_ttop lc_add_ggdyb">输出文件</div>
      <div v-for="(item, index) in data.tableAfterArr" :key="index">
        <div class="lc_title1">{{ data['table_title_' + item] }}</div>
        <lcwjsc pageTage='jgsj' :titleTag="data['table_title_' + item]" v-model:loading="data['loading_' + item]"
          v-model:code="data.tableAfterArr[index]" v-model:tableHeigth="data['tableHeigth_' + item]"
          v-model:listHeader="data['listHeader_' + item]" v-model:defaultRow="data['defaultRow_' + item]"
          v-model:tableHeader="data['tableHeader_' + item]" v-model:notShowCol="data['notShowCol_' + item]"
          v-model:staticList="data['staticList_' + item]" v-model:beforeStrList="data['beforeStrList_' + item]"
          @getClickBtnType="getClickBtnTypeMany" @uploadAddRow="uploadAddRowMany" @editDataEmit="editDataEmitMany" />
      </div>
      <!--备注-->
      <div class="lc_ttop lc_bzt">备注</div>
      <div style="padding-bottom: 50px;">
        <lctinymce :id="data.id" ref="editor" :height="data.height" :cur-value="data.remark" @input="inputContent"
          :key="data.key"></lctinymce>
      </div>
    </div>
    <!-- 填写共享盘链接 -->
    <LcWriteLinks :key="data.isShowLinksDialogIndex" v-model:isShowLinksDialog="data.isShowLinksDialog"
      v-model:linksTitle="data.linksTitle" @getDragWriteData="getDragWriteData" />
  </el-main>
</template>
<script>
import { defineComponent, reactive, ref, onMounted, getCurrentInstance, provide } from 'vue';
import { getBaseInfoFile, getComCurrentDate, addOrderNumber } from '../../../utils/lc_jx_utils/lc_jx.js'
import { tableColumns_c, tableDefaultVal_c, tableHeaderBtns_c, _data } from '../../../utils/lc_jx_utils/lc_jgsj_json.js'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { downloadMod } from '../../../utils/lc'
export default defineComponent({
  name: 'jgsj',
  setup (props) {
    let route = useRouter()
    provide('project_id', route.currentRoute.value.query.id)
    const addBaseInfo = ref()
    const lcButtons = ref()
    let { proxy } = getCurrentInstance()
    const ids = ref(route.currentRoute.value.query.prBasetaskId)
    let thedata = {
      baseInfo: {},//基础信息
      ggdyTableData: [],//规格定义表
      //富文本
      height: 300,
      key: '',
      id: '',
      remark: '',// 备注
    }
    let data = reactive({ ..._data, ...thedata })
    // 基本信息字段值
    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']
    })
    onMounted(() => {
      data.tableAfterArr.forEach(el => {
        data['listHeader_' + el] = JSON.parse(JSON.stringify(tableColumns_c))
        data['defaultRow_' + el] = JSON.parse(JSON.stringify(tableDefaultVal_c))
        data['tableHeader_' + el] = JSON.parse(JSON.stringify(tableHeaderBtns_c))
      })
      getPageInfo()
    })
    //按钮组操作
    function getPageInfo (value) {
      proxy.$http.get('project/task/structural_design/info', { id: route.currentRoute.value.query.prBasetaskId }).then(res => {
        if (res.errno == 200) {
          data.baseInfo = JSON.parse(JSON.stringify(res.data))
          ids.value = res.data.id
          //规格定义表
          data.ggdyTableData = res.data.skus
          //备注
          data.remark = 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]
          })
          // 输出文件集合
          data.defaultRow_c = res.data.files.product_structural ? getBaseInfoFile(res.data.files.product_structural) : []
          data.defaultRow_p = res.data.files.product_parts ? getBaseInfoFile(res.data.files.product_parts) : []
          data.defaultRow_a = res.data.files.structure_bom ? getBaseInfoFile(res.data.files.structure_bom) : []
          data.defaultRow_b = res.data.files.hpid ? getBaseInfoFile(res.data.files.hpid) : []
          data.defaultRow_d = res.data.files.mpid ? getBaseInfoFile(res.data.files.mpid) : []
          data.defaultRow_e = res.data.files.ppid ? getBaseInfoFile(res.data.files.ppid) : []
          data.defaultRow_f = res.data.files.pcba_hpfd ? getBaseInfoFile(res.data.files.pcba_hpfd) : []
          data.defaultRow_g = res.data.files['3d_pr'] ? getBaseInfoFile(res.data.files['3d_pr']) : []
          data.defaultRow_h = res.data.files['2d_psr'] ? getBaseInfoFile(res.data.files['2d_psr']) : []
          data.defaultRow_i = res.data.files.fsm ? getBaseInfoFile(res.data.files.fsm) : []
          data.defaultRow_j = res.data.files.modd ? getBaseInfoFile(res.data.files.modd) : []
          data.defaultRow_k = res.data.files.asm ? getBaseInfoFile(res.data.files.asm) : []
          data.defaultRow_l = res.data.files.padtd ? getBaseInfoFile(res.data.files.padtd) : []

        } 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/structural_design/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: data.remark,
        skus: data.ggdyTableData,
        files: {
          'product_structural': data.defaultRow_c,
          'product_parts': data.defaultRow_p,
          'structure_bom': data.defaultRow_a,
          'hpid': data.defaultRow_b,
          'mpid': data.defaultRow_c,
          'mpid': data.defaultRow_d,
          'ppid': data.defaultRow_e,
          'pcba_hpfd': data.defaultRow_f,
          '3d_pr': data.defaultRow_g,
          '2d_psr': data.defaultRow_h,
          'fsm': data.defaultRow_i,
          'modd': data.defaultRow_j,
          'asm': data.defaultRow_k,
          'padtd': data.defaultRow_l
        },
      }).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 getClickBtnTypeMany (type, selRow, code, allData) {
      //下载模板
      if (type == 'download') {
        downloadMod(data.baseInfo.basetask_id, '结构设计')
      }
      if (type == 'write_links') {
        data.writeLinksCode = code
        data['btnTamplteList' + code.toLocaleUpperCase()] = JSON.parse(JSON.stringify(allData))
        data.isShowLinksDialogIndex = data.isShowLinksDialogIndex + 1
        data.isShowLinksDialog = true
      }
    }
    // 输出文件 - 表格 编辑
    function editDataEmit (list) { }
    // 文件上传
    function uploadAddRowMany (s_list, code) {
      data['loading_' + code] = 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 })
      data['defaultRow_' + code] = list
      setTimeout(() => {
        proxy.$message.success('文件上传成功')
        data['loading_' + code] = false
      }, 800);
    }
    // 表格编辑
    function editDataEmitMany (list, code) { }
    // 填写共享盘链接
    function getDragWriteData (val) {
      data['loading_' + data.writeLinksCode] = true
      data['btnTamplteList' + data.writeLinksCode.toLocaleUpperCase()].push({ id: 0, title: val, create_time: getComCurrentDate(), remark: '', url_type: 'link', url: '' })
      data['defaultRow_' + data.writeLinksCode] = data['btnTamplteList' + data.writeLinksCode.toLocaleUpperCase()]
      setTimeout(() => {
        proxy.$message.success('链接添加成功')
        data['loading_' + data.writeLinksCode] = false
      }, 800);
    }
    //富文本编辑器
    function inputContent (value) {
      data.remark = value
    }
    return {
      data,
      ids,
      addBaseInfo, lcButtons,
      btsEmit,
      getPageInfo,
      getClickBtnTypeMany,
      getDragWriteData,
      editDataEmit,
      uploadAddRowMany,
      editDataEmitMany,
      inputContent
    }
  }
})
</script>
<style scoped lang="scss">
@import '../../../assets/style/lc.scss';
</style>