<!--包装设计详情-->
<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_title lc_ttop lc_add_ggdyb">包装原型</div>
    <lcbzyxtable v-model:bzyxTableData='data.bzyxTableData' v-model:selectlist='data.selectbzyxlist'></lcbzyxtable>
    <!--输出内容-->
    <div class="lc_title lc_ttop lc_add_ggdyb">输出文件</div>
    <div class="lc_cdlj">
      <div class="title">存档路径</div>
      <el-input type="textarea" placeholder="包装整套文档(包装盒/说明书/纸箱/产品渲染图/包装效果图等)，丝印文档，BOM，存档路径" v-model="data.files_text"
        class="lc_bz" style="min-height: 98px;" maxlength="500" show-word-limit />
    </div>
    <!--规格定义表-->
    <div class="lc_title1">规格定义表</div>
    <lcggdytab v-model:ggdyTableData='data.ggdyTableData' :nobts="['add', 'delet', 'bzbom']" :prtaskId='ids'></lcggdytab>
    <!--备注-->
    <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>
    <!-- 填写共享盘链接 -->
    <LcWriteLinks :key="bzyxpptdata.isShowLinksDialogIndex" v-model:isShowLinksDialog="bzyxpptdata.isShowLinksDialog"
      @getDragWriteData="getDragWriteData" />
  </el-main>
</template>
<script>
import { defineComponent, reactive, ref, onMounted, getCurrentInstance, provide } from 'vue';
import { cpPPT_defaultVal, cpppt_headerBtns, cpPPT_listHeader } from '../../../utils/lc_data'
import { addOrderNumber } from '../../../utils/lc'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
export default defineComponent({
  name: 'bzsj',
  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 data = reactive({
      baseInfo: {},//基础信息
      ggdyTableData: [],//规格定义表
      bzyxTableData: [],// 包装原型
      selectbzyxlist: [],// 勾选的包装原型
      files_text: '',
      //富文本
      height: 300,
      key: '',
      id: '',
      remark: '',// 备注
    })
    // 基本信息字段值
    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']
    })
    // 输出内容
    let bzyxpptdata = 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: {},
    })
    onMounted(() => {
      getPageInfo()
    })
    //按钮组操作
    function getPageInfo (value) {
      proxy.$http.get('project/task/packaging_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.files_text = res.data.files_text
          //包装原型表格
          data.bzyxTableData = addOrderNumber(res.data.packing)
          if (data.bzyxTableData && data.bzyxTableData.length > 0) {
            data.selectbzyxlist = []
            data.bzyxTableData.forEach(it => {
              if (it.selected == '1') {
                data.selectbzyxlist.push(it.id)
              }
            })
          }
          //备注
          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]
          })
        } 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/packaging_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,
        packing: data.bzyxTableData,
        files_text: data.files_text,
        skus: data.ggdyTableData,
      }).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 inputContent (value) {
      data.remark = value
    }
    return {
      data,
      ids,
      bzyxpptdata,
      addBaseInfo,
      lcButtons,
      btsEmit,
      getPageInfo,
      inputContent
    }
  }
})
</script>
<style scoped lang="scss">
@import '../../../assets/style/lc.scss';
</style>