<!--规格定义-->
<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>
      <div class="lc_title1">规格定义表</div>
      <Lcggdytab v-model:ggdyTableData='data.ggdyTableData' ref="theggdyTableData" :prtaskId='ids' pageTag="ggdy">
      </Lcggdytab>
      <!--规格/板框定义PPT-->
      <div class="lc_title lc_ttop lc_add_ggdyb">输出内容</div>
      <div class="lc_title1">规格/板框定义PPT</div>
      <lcwjsc v-model:loading="ggdypptdata.loading" v-model:tableHeigth="ggdypptdata.tableHeigth"
        v-model:listHeader="ggdypptdata.listHeader" v-model:defaultRow="ggdypptdata.defaultRow"
        v-model:tableHeader="ggdypptdata.tableHeader" v-model:notShowCol="ggdypptdata.notShowCol"
        v-model:staticList="ggdypptdata.staticList" v-model:beforeStrList="ggdypptdata.beforeStrList"
        @getClickBtnType="getClickBtnType_ggdyppt" @uploadAddRow="uploadAddRow" />
      <!--规格定价表格-->
      <div class="lc_title1">规格定价表格</div>
      <lcwjsc v-model:loading="ggdjdata.loading" v-model:tableHeigth="ggdjdata.tableHeigth"
        v-model:listHeader="ggdjdata.listHeader" v-model:defaultRow="ggdjdata.defaultRow"
        v-model:tableHeader="ggdjdata.tableHeader" v-model:notShowCol="ggdjdata.notShowCol"
        v-model:staticList="ggdjdata.staticList" v-model:beforeStrList="ggdjdata.beforeStrList"
        @getClickBtnType="getClickBtnType_ggdjppt" @uploadAddRow="uploadAddRowdj" />
      <!--备注-->
      <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="ggdypptdata.isShowLinksDialogIndex" v-model:isShowLinksDialog="ggdypptdata.isShowLinksDialog"
      @getDragWriteData="getDragWriteData" />
    <LcWriteLinks :key="ggdjdata.isShowLinksDialogIndex" v-model:isShowLinksDialog="ggdjdata.isShowLinksDialog"
      @getDragWriteData="getDragWriteDatadj" />
  </el-main>
</template>
<script>
import { defineComponent, reactive, ref, onMounted, getCurrentInstance, 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 { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
export default defineComponent({
  name: 'ggdy',
  setup (props) {
    let route = useRouter()
    provide('project_id', route.currentRoute.value.query.id)
    const addBaseInfo = ref()
    const lcButtons = ref()
    const theggdyTableData = ref()
    let { proxy } = getCurrentInstance()
    const ids = ref(route.currentRoute.value.query.prBasetaskId)
    let data = reactive({
      baseInfo: {},//基础信息
      ggdyTableData: [],//规格定义表
      //富文本
      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']
    })
    // 规格/板框定义PPT
    let ggdypptdata = 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: {},
    })
    // 规格定价
    let ggdjdata = 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/sku_define/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
          res.data.skus.forEach((it, index) => {
            it.indextb = index
          })
          theggdyTableData.value.data.ggdyTableData = res.data.skus
          // 规格定义板框
          ggdypptdata.defaultRow = res.data.files.sku_ppt ? getBaseInfoFile(res.data.files.sku_ppt) : []
          // 规格定价
          ggdjdata.defaultRow = res.data.files.sku_price_excel ? getBaseInfoFile(res.data.files.sku_price_excel) : []
          //备注
          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/sku_define/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: { sku_ppt: ggdypptdata.defaultRow, sku_price_excel: ggdjdata.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_ggdyppt (type, selRow, code, allData) {
      //下载模板
      if (type == 'download') {
        downloadMod(data.baseInfo.basetask_id, '规格板框')
      }
      if (type == 'write_links') {
        ggdypptdata.isShowLinksDialogIndex = data.isShowLinksDialogIndex + 1
        ggdypptdata.isShowLinksDialog = true
        ggdypptdata.btnTamplteList = JSON.parse(JSON.stringify(allData))
      }
    }
    // 表格按钮 -- 规格定价定义点击
    function getClickBtnType_ggdjppt (type, selRow, code, allData) {
      //下载模板
      if (type == 'download') {
        downloadMod(data.baseInfo.basetask_id, '规格定价')
      }
      if (type == 'write_links') {
        ggdjdata.isShowLinksDialogIndex = data.isShowLinksDialogIndex + 1
        ggdjdata.isShowLinksDialog = true
        ggdjdata.btnTamplteList = JSON.parse(JSON.stringify(allData))
      }
    }
    // 文件上传
    function uploadAddRow (s_list) {
      ggdypptdata.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 })
      ggdypptdata.defaultRow = list
      setTimeout(() => {
        proxy.$message.success('文件上传成功')
        ggdypptdata.loading = false
      }, 800);
    }
    // 文件上传-定价
    function uploadAddRowdj (s_list) {
      ggdjdata.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 })
      ggdjdata.defaultRow = list
      setTimeout(() => {
        proxy.$message.success('文件上传成功')
        ggdjdata.loading = false
      }, 800);
    }
    // 填写共享盘链接
    function getDragWriteData (val) {
      ggdypptdata.loading = true
      ggdypptdata.btnTamplteList.push({ id: 0, title: val, create_time: getComCurrentDate(), remark: '', url_type: 'link', url: '' })
      ggdypptdata.defaultRow = ggdypptdata.btnTamplteList
      setTimeout(() => {
        proxy.$message.success('链接添加成功')
        ggdypptdata.loading = false
      }, 800);
    }
    // 填写共享盘链接-定价
    function getDragWriteDatadj (val) {
      ggdjdata.loading = true
      ggdjdata.btnTamplteList.push({ id: 0, title: val, create_time: getComCurrentDate(), remark: '', url_type: 'link', url: '' })
      ggdjdata.defaultRow = ggdjdata.btnTamplteList
      setTimeout(() => {
        proxy.$message.success('链接添加成功')
        ggdjdata.loading = false
      }, 800);
    }
    //富文本编辑器
    function inputContent (value) {
      data.remark = value
    }

    return {
      data,
      ids,
      ggdypptdata,
      ggdjdata,
      addBaseInfo, lcButtons,
      theggdyTableData,
      btsEmit,
      getPageInfo,
      getClickBtnType_ggdyppt,
      getClickBtnType_ggdjppt,
      uploadAddRow,
      uploadAddRowdj,
      getDragWriteData,
      getDragWriteDatadj,
      inputContent
    }
  }
})
</script>
<style scoped lang="scss">
@import '../../../assets/style/lc.scss';
</style>