<!--首批订单需求-->
<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' pageTag="spxdmx" @openXDmxModel='openXDmxModel'
        :nobts="['add', 'delet']" :prtaskId='ids'>
      </lcggdytab>
      <!--规格定义表-->
      <div class="lc_title lc_ttop lc_add_ggdyb">输出内容</div>
      <div class="l-button" @click="gospxdMx">下单明细</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>
    <!--首批订单数量详情-->
    <el-dialog title="下单详情" v-model="data.xtshow" width="550" style="padding-top: 0;">
      <h1 style="text-align: center;padding-bottom: 5px;">{{ data.skuName }}</h1>
      <div>
        <el-table :data="data.noticeTableData" border :max-height="550" show-summary>
          <el-table-column prop="depart" label="部门" width="250" />
          <el-table-column prop="num" label="数量(pcs)" width="200" align="right" />
        </el-table>
      </div>
    </el-dialog>
  </el-main>
</template>
<script>
import { defineComponent, reactive, ref, onMounted, getCurrentInstance, provide } from 'vue';
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { thenoticeTableData } from '../../../utils/lc_data'// 获取人员
export default defineComponent({
  name: "spddxq",
  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({
      skuName: '',
      baseInfo: {},
      ggdyTableData: [],
      xtshow: false,
      noticeTableData: JSON.parse(JSON.stringify(thenoticeTableData)),
      //富文本
      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"]
    });
    onMounted(() => {
      getPageInfo()
    })
    //点击规格定义表首批订单数量，查看删库下单详情
    function openXDmxModel (sku) {
      console.log(sku)
      data.xtshow = true
      data.skuName = sku.skuName
      noticeOrder(sku.skuId)
      //这里是获取数据
    }
    //按钮组操作
    function getPageInfo (value) {
      proxy.$http.get("project/task/first_order_demand/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];
          });
        }
        else {
          ElMessage({
            type: "success",
            message: res.errmsg
          });
        }
      });
    }
    // 确认通知下单
    function noticeOrder (skuId) {
      if (skuId) {
        proxy.$http.get("project/task/first_order_demand/sku_order_info", { sku_id: skuId }).then(res => {
          if (res.errno == 200) {
            data.noticeTableData.forEach(it => {
              it.num = res.data[it.depart_code]
            })
          }
        })
      }
    }
    //按钮组操作
    function btsEmit (value) {
      // 提交和审核先做保存的动作
      if (value == 'passBt' || value == 'submitBt') {
        handelSavePage(value)
      }
      // 保存
      if (value == 'saveBt') {
        handelSavePage()
      }
    }
    // 保存页面
    function handelSavePage (bttype) {
      proxy.$http.showLoading(false).post("project/task/first_order_demand/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,
      }).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 gospxdMx () {
      route.push({
        path: '/lcProject/taskMange/spxdxqMx', query: {
          id: route.currentRoute.value.query.id,
          prBasetaskId: route.currentRoute.value.query.prBasetaskId,
          leader_user_id: data.baseInfo.leader_user_id // 任务负责人id
        }
      })
    }
    //富文本编辑器
    function inputContent (value) {
      data.remark = value;
    }
    return {
      data,
      ids,
      addBaseInfo, lcButtons,
      btsEmit,
      getPageInfo,
      inputContent,
      gospxdMx,
      openXDmxModel
    };
  }
})
</script>
<style scoped lang="scss">
@import '../../../assets/style/lc.scss';

::v-deep .el-dialog__body {
  padding-top: 0;
}
</style>