<template>
  <div class="customer-css" >
    <!--  查询时间和产品  -->
    <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: 0px;" >
      <el-row>
        <el-col :span="24" style="">
          <el-form-item :label="'产品编码:'">
            <!-- <span style="cursor: pointer" slot="label" @click="getBaseList(1100)"><a href="#">产品编码</a></span> -->
            <el-input v-model="searchData.partNo" style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="'NPC货号:'">
            <el-input v-model="searchData.npc" style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="'产品名称:'">
            <el-input v-model="searchData.partDesc" style="width: 130px"></el-input>
          </el-form-item>
          <el-form-item :label="' '">
            <el-button class="customer-bun-min" type="primary" @click="getMainData" style="">查询</el-button>
            <el-button @click="addPart()" type="primary" style="margin-left: 2px">新增</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-table
      :height="height"
      :data="mainDataList"
      border
      ref="mainTable"
      highlight-current-row
      @row-click="changeData"
      v-loading="dataListLoading"
      style="margin-top: 0px; width: 100%;">
      <el-table-column
        v-for="(item,index) in columnArray1" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{
            item.columnProp === 'partStage'
              ? formatPartStageDesc(scope.row.partStage)
              : scope.row[item.columnProp]
          }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                             style="width: 100px; height: 100px"/></span>
        </template>
      </el-table-column>
      <!-- 操作列 -->
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="160"
        label="Action">
        <template slot-scope="scope">
          <!-- <el-link style="cursor: pointer" v-if="scope.row.flowStatus === 'COMPLETED' || scope.row.flowStatus === 'TERMINATED'" @click="handleRestart(scope.row)">重新审批 |</el-link>
          <el-link style="cursor: pointer" v-if="scope.row.flowStatus === 'RUNNING'" @click="openApproveDialog(scope.row)">审批 |</el-link> -->
          <el-link style="cursor: pointer" @click="editPart(scope.row)">编辑 |</el-link>
          <el-link style="cursor: pointer" @click="deletePart(scope.row)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页插件 -->
    <el-pagination style="margin-top: 0px"
                   @size-change="sizeChangeHandle"
                   @current-change="currentChangeHandle"
                   :current-page="pageIndex"
                   :page-sizes="[20, 50, 100, 200, 500]"
                   :page-size="pageSize"
                   :total="totalPage"
                   layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <el-tabs v-model="activeName" style="margin-top: 0px; width: 99%;" @tab-click="tabClick" class="customer-tab" type="border-card">
      <el-tab-pane label="基础信息" name="basicInfo" style="">
        <basicInfo ref="basicInfo"></basicInfo>
      </el-tab-pane>
      <el-tab-pane label="规格参数" name="specParams" style="">
        <specParams ref="specParams"></specParams>
      </el-tab-pane>
      <el-tab-pane label="关联供应商" name="suppliers" style="">
        <suppliers ref="suppliers"></suppliers>
      </el-tab-pane>
      <el-tab-pane label="审批与放行" name="approval" style="">
        <approval ref="approval"></approval>
      </el-tab-pane>
      <el-tab-pane label="附件" name="attachments" style="">
        <attachments ref="attachments"></attachments>
      </el-tab-pane>
    </el-tabs>

    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>

    <!-- 产品编辑对话框 -->
    <el-dialog :title="isAdd ? '新增产品' : '编辑产品'" :visible.sync="partDialogVisible" width="600px" top="3vh" :close-on-click-modal="false" class="part-dialog">
      <div class="dialog-content">
        <el-form
          :model="currentpart"
          :rules="partRules"
          ref="partForm"
          label-position="top"
          class="part-form">
          <div class="form-section">
            <el-row :gutter="24">
              <el-col :span="6">
                <el-form-item label="产品编码" prop="partNo">
                  <el-input v-model="currentpart.partNo" :disabled="!isAdd"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="NPC货号" prop="npc">
                  <el-input v-model="currentpart.npc"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item>
                  <span style="cursor: pointer" slot="label" @click="getBaseList(526)"><a href="#">产品分类</a></span>
                  <el-input v-model="currentpart.category" style="width: 130px"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item>
                  <span style="cursor: pointer" slot="label" @click="getBaseList(510)"><a href="#">计量单位</a></span>
                  <el-input v-model="currentpart.unit" style="width: 130px"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="24">
                <el-col :span="12">
                <el-form-item label="产品名称" prop="partDesc">
                  <el-input v-model="currentpart.partDesc"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="产品规格" prop="partSpec">
                  <el-input v-model="currentpart.partSpec"></el-input>
                </el-form-item>
              </el-col>             
            </el-row>
          </div>

          <div class="form-section">
            <el-row :gutter="24">
              <el-col :span="6">
                <el-form-item >
                  <span style="cursor: pointer" slot="label" @click="getBaseList(529)"><a href="#">采购员</a></span>
                  <el-input v-model="currentpart.buyerName" style="width: 130px"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item >
                  <span style="cursor: pointer" slot="label" @click="getBaseList(528)"><a href="#">sourcing专员</a></span>
                  <el-input v-model="currentpart.sourcingName" style="width: 130px"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                  <el-form-item>
                  <span style="cursor: pointer" slot="label" @click="getBaseList(527)"><a href="#">属性模板</a></span>
                  <el-input v-model="currentpart.codeNo" ></el-input>
                </el-form-item>
              </el-col>
               <el-col :span="6">
               <el-form-item label="状态">
                  <el-select v-model="currentpart.status" placeholder="请选择" >
                    <el-option label="启用" value="N"></el-option>
                    <el-option label="停用" value="Y"></el-option>                 
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>

          <div class="form-section">
            <el-row :gutter="24">
              <el-col :span="24">
                <el-form-item label="备注">
                  <el-input v-model="currentpart.remark" type="textarea" :rows="2" resize="none" ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="margin-top: 20px">
        <el-button type="primary" @click="savePart()">保存</el-button>
        <el-button @click="partDialogVisible = false">取消</el-button>
      </div>
    </el-dialog>

     <!-- 审批对话框 - rqrq -->
    <!-- <el-dialog
      title="审批"
      :visible.sync="approveDialogVisible"
      width="550px"
      :close-on-click-modal="false"
      v-drag>
      <el-form :model="approveData" label-position="top">
          <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="是否特殊放行">
              <el-select v-model="approveData.specialRelease" style="width: 100%">
                <el-option label="否" value="N"></el-option>
                <el-option label="是" value="Y"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="审批意见">
          <el-input type="textarea" v-model="approveData.comment" :rows="3" placeholder="请输入审批意见"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 60px;text-align:center">
          <el-button type="success" @click="submitApprove('APPROVED')" :loading="approveLoading">同意</el-button>
        <el-button type="danger" @click="submitApprove('REJECTED')" :loading="approveLoading">驳回</el-button>
        <el-button @click="approveDialogVisible = false" :disabled="approveLoading">取消</el-button>
      </el-footer>
    </el-dialog> -->
  </div>
</template>

<script>
/* 组件 */

import {
  searchPartList,
  createPart,
  updatePart,
  deletePart
} from '@/api/part/partInfo.js'
import excel from '@/utils/excel-util.js'
import Chooselist from '@/views/modules/common/Chooselist_eam'
import basicInfo from './com_part_BasicInfo'
import specParams from './com_part_SpecParams'
import suppliers from './com_part_Suppliers'
import approval from './com_part_Approval'
import attachments from './com_part_Attachments'

import {
  approveNodeInstance,
  restartFlowInstance
} from '@/api/workFlow/workFlow.js'

export default {
    watch: {
      searchData: {
        deep: true,
        handler: function (newV, oldV) {
          this.searchData.partNo = this.searchData.partNo.toUpperCase()
          this.searchData.npc = this.searchData.npc.toUpperCase()
          this.searchData.category = this.searchData.category.toUpperCase()
          this.searchData.unit = this.searchData.unit.toUpperCase()
          this.searchData.codeNo = this.searchData.codeNo.toUpperCase()
          this.searchData.partDesc = this.searchData.partDesc.toUpperCase()
          this.searchData.partSpec = this.searchData.partSpec.toUpperCase()
        }
      },
      currentpart: {
        deep: true,
        handler: function (newV, oldV) {
          this.currentpart.partNo = this.currentpart.partNo.toUpperCase()
          this.currentpart.npc = this.currentpart.npc.toUpperCase()
          this.currentpart.category = this.currentpart.category.toUpperCase()
          this.currentpart.unit = this.currentpart.unit.toUpperCase()
          this.currentpart.codeNo = this.currentpart.codeNo.toUpperCase()
          this.currentpart.partDesc = this.currentpart.partDesc.toUpperCase()
          this.currentpart.partSpec = this.currentpart.partSpec.toUpperCase()
        }
      }
    },
  data () {
    return {
      functionId: this.$route.meta.menuId,
      height: 200,
      currentRow: {},
      searchData: {
        partNo: '',
        npc: '',
        partDesc: '',
        partSpec: '',
        buyerName: '',
        sourcingName: '',
        category: '',
        unit: '',
        status: '',
        codeNo: '',
        createBy: '',
        site: this.$store.state.user.site,
        page: 1,
        limit: 10
      },
      pageIndex: 1,
      pageSize: 50,
      totalPage: 0,
      tagNo: '',
      mainDataList: [],
      dataListLoading: false,
      activeName: 'basicInfo',
        // 审批对话框
      approveDialogVisible: false,
      approveLoading: false,
      approveData: {
        applyNo: '',
        // nodeCode: '',
        // nodeName: '',
        // departmentName: '',  // 审批部门 - rqrq
        // assigneeName: '',
        site: '',
        orderType: '',
        comment: '',
        flowCode: '',
        flowVersion: null
      },
      columnArray1: [
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTablePartNo',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'partNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '产品编码',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableNpc',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'npc',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'NPC货号',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTablePartDesc',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'partDesc',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '产品名称',
          columnWidth: '200',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTablepartSpec',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'partSpec',
          headerAlign: 'center',
          align: 'left',
          columnLabel: '产品规格',
          columnWidth: '150',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableBuyerName',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'buyerName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '采购员',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableSourcingName',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'sourcingName',
          headerAlign: 'center',
          align: 'center',
          columnLabel: 'sourcing专员',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableCategory',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'category',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '产品分类',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableUnit',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'unit',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '计量单位',
          columnWidth: '80',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTablePartStage',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'partStage',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '物料阶段',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableStatus',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'status',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '状态',
          columnWidth: '80',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableCodeNo',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'codeNo',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '属性模板',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        },
        {
          userId: this.$store.state.user.name,
          functionId: this.functionId,
          serialNumber: 'partTableCreateBy',
          tableId: 'partTable',
          tableName: '产品信息',
          columnProp: 'createBy',
          headerAlign: 'center',
          align: 'center',
          columnLabel: '创建人',
          columnWidth: '100',
          columnHidden: false,
          columnImage: false,
          columnSortable: false,
          sortLv: 0,
          status: true,
          fixed: false
        }
        //  {
        //   userId: this.$store.state.user.name,
        //   functionId: this.functionId,
        //   serialNumber: 'partTableDepartmentName',
        //   tableId: 'partTable',
        //   tableName: '产品信息',
        //   columnProp: 'departmentName',
        //   headerAlign: 'center',
        //   align: 'center',
        //   columnLabel: '审批部门',
        //   columnWidth: '100',
        //   columnHidden: false,
        //   columnImage: false,
        //   columnSortable: false,
        //   sortLv: 0,
        //   status: true,
        //   fixed: false
        // },
        //  {
        //   userId: this.$store.state.user.name,
        //   functionId: this.functionId,
        //   serialNumber: 'partTableApproverName',
        //   tableId: 'partTable',
        //   tableName: '产品信息',
        //   columnProp: 'assigneeName',
        //   headerAlign: 'center',
        //   align: 'center',
        //   columnLabel: '要求审批人',
        //   columnWidth: '100',
        //   columnHidden: false,
        //   columnImage: false,
        //   columnSortable: false,
        //   sortLv: 0,
        //   status: true,
        //   fixed: false
        // },
        //  {
        //   userId: this.$store.state.user.name,
        //   functionId: this.functionId,
        //   serialNumber: 'partTableFlowStatus',
        //   tableId: 'partTable',
        //   tableName: '产品信息',
        //   columnProp: 'flowStatus',
        //   headerAlign: 'center',
        //   align: 'center',
        //   columnLabel: '审批状态',
        //   columnWidth: '100',
        //   columnHidden: false,
        //   columnImage: false,
        //   columnSortable: false,
        //   sortLv: 0,
        //   status: true,
        //   fixed: false
        // }
      ],
      exportName: '产品信息' + this.dayjs().format('YYYYMMDDHHmmss'),
      // 产品对话框相关
      partDialogVisible: false,
      isAdd: true,
      currentpart: {
        partNo: '',
        npc: '',
        partDesc: '',
        partSpec: '',
        buyerName: '',
        sourcingName: '',
        category: '',
        unit: '',
        status: 'N',
        codeNo: '',
        createBy: '',
        remark: '',
        site: this.$store.state.user.site,
      },
      partRules: {
         partNo: [
          { required: true, message: ' ', trigger: 'blur' }
        ],
         partDesc: [
          { required: true, message: ' ', trigger: 'blur' }
        ],
         npc: [
          { required: true, message: ' ', trigger: 'blur' }
        ],
         partSpec: [
        { required: true, message: ' ', trigger: 'blur' }
        ]
     
       
      }
    }
  },
  /* 组件 */
  components: {
    Chooselist,
    basicInfo,
    specParams,
    suppliers,
    approval,
    attachments
  },

  created() {
    this.getMainData()
  },

  mounted () {
    this.$nextTick(() => {
      this.height = (window.innerHeight - 280) / 2
    })
  },
 

  methods: {
    formatPartStageDesc (partStage) {
      return partStage === 'Approved' ? '正式物料' : '新增物料'
    },
    getBaseList (val, type) {
      this.tagNo = val
      this.$nextTick(() => {
        let strVal = ''
        if (val === 1100) {
          strVal = this.searchData.partNo
        }
        if (this.tagNo === 526) {
          strVal = this.currentpart.category
        }

          if (this.tagNo === 510) {
          strVal = this.currentpart.unit
        }
        if (val === 529) {
          strVal = this.currentpart.buyerName
        }
        if (val === 528) {
          strVal = this.currentpart.sourcingName
        }
      
        if (val === 527) {
          strVal = this.currentpart.codeNo
        }

        this.$refs.baseList.init(val, strVal?strVal:'')
      })
    },

    /* 列表方法的回调 */
    getBaseData (val) {
      if (this.tagNo === 1100) {
        this.searchData.partNo = val.part_no
      }
      if (this.tagNo === 526) {
        this.currentpart.category = val.family_id
      }

        if (this.tagNo === 510) {
        this.currentpart.unit = val.UMID
      }
      if (this.tagNo === 529) {
        this.currentpart.buyerName = val.UserName
      }
      if (this.tagNo === 528) {
        this.currentpart.sourcingName = val.UserName
      }
    
      if (this.tagNo === 527) {
        this.currentpart.codeNo = val.code_no
      }
    },
    
    getMainData () {
      this.searchData.limit = this.pageSize
      this.searchData.page = this.pageIndex
      searchPartList(this.searchData).then(({data}) => {
        if (data.code === 0) {
        // 处理列表数据，确保可以正确显示嵌套属性
          this.mainDataList = data.page.list.map(item => {
            // 方式1：将嵌套属性提取到顶层
            if (item.flowNodeInstanceData) {
              item.departmentName = item.flowNodeInstanceData.departmentName;
              item.assigneeName = item.flowNodeInstanceData.assigneeName;
             
            } else {
              item.departmentName = '';
              item.assigneeName = '';
            
            }
            return item;
          });

            
          // this.mainDataList = data.page.list
          this.pageIndex = data.page.currPage
          this.pageSize = data.page.pageSize
          this.totalPage = data.page.totalCount
          // 判断是否全部存在数据
          if (this.mainDataList.length > 0) {
            // 设置选中行
            this.$refs.mainTable.setCurrentRow(this.mainDataList[0])
            this.changeData(this.mainDataList[0])
          } else {
            this.changeData(null)
          }
        }
        this.dataListLoading = false
      })
    },
    
    tabClick (tab, event) {
      this.refreshCurrentTabTable()
    },
    
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getMainData()
    },

    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getMainData()
    },
    
    changeData (row) {
      this.currentRow = JSON.parse(JSON.stringify(row))
      this.refreshCurrentTabTable()
    },
    
    refreshCurrentTabTable () {
      if (this.currentRow === '' || this.currentRow === null) {
        this.currentRow = {site: '', partNo: ''}
      }
      if (this.activeName === 'basicInfo') {
        this.refreshBasicInfo()
      }
      if (this.activeName === 'specParams') {
        this.refreshSpecParams()
      }
      if (this.activeName === 'suppliers') {
        this.refreshSuppliers()
      }
      if (this.activeName === 'approval') {
        this.refreshApproval()
      }
      if (this.activeName === 'attachments') {
        this.refreshAttachments()
      }
    },
    
    async exportExcel () {
      this.searchData.limit = -1
      this.searchData.page = 1
      excel.exportTable({
        url: '/part/searchPartList',
        columnMapping: this.columnArray1,
        mergeSetting: [],
        params: this.searchData,
        fileName: this.exportName + '.xlsx',
        rowFetcher: res => res.data,
        columnFormatter: [
          { columnProp: 'partStage', formatter: (val) => this.formatPartStageDesc(val) }
        ],
        dropColumns: []
      })
    },
    
    refreshBasicInfo () {
      let inData = {
        site: this.currentRow.site,
        partNo: this.currentRow.partNo,
        partDesc: this.currentRow.partDesc,
        height: Number(this.height) - 20
      }
      this.$refs.basicInfo.init(inData)
    },
    
    refreshSpecParams () {
      let inData = {
        site: this.currentRow.site,
        partNo: this.currentRow.partNo,
        codeNo: this.currentRow.codeNo,
        functionType:"P",
        height: Number(this.height) - 20
      }
      this.$refs.specParams.init(inData)
    },
    
    refreshSuppliers () {
      let inData = {
        site: this.currentRow.site,
        partNo: this.currentRow.partNo,
        height: Number(this.height) - 20
      }
      this.$refs.suppliers.init(inData)
    },
    
    refreshApproval () {
      let inData = {
        site: this.currentRow.site,
        orderRef1: this.currentRow.partNo,
        orderType: '产品资料',
        height: Number(this.height) - 20
      }
      this.$refs.approval.init(inData)
    },
    
    refreshAttachments () {
      let inData = {
        orderRef1: this.currentRow.site,
        orderRef2: this.currentRow.partNo,
        orderRef3: this.currentRow.partDesc,
        orderReftype: 'part',  
        height: Number(this.height) - 20
      }
      this.$refs.attachments.init(inData)
    },
    
    // 新增产品
    addPart() {
      this.isAdd = true
      this.currentpart = {
        partNo: '',
        npc: '',
        partDesc: '',
        partSpec: '',
        buyerName: '',
        sourcingName: '',
        category: '',
        unit: '',
        status: 'N',
        codeNo: '',
        createBy: this.$store.state.user.name,
        remark: '',
        site: this.$store.state.user.site,
      }
      this.partDialogVisible = true
    },
    
    // 编辑产品
    editPart(row) {
      if (!row) {
        this.$message.warning('请选择一个产品修改')
        return
      }
      this.isAdd = false
      this.currentpart = {...row}
      this.partDialogVisible = true
    },
    
    // 保存产品
    savePart() {
      this.$refs.partForm.validate((valid) => {
        if (valid) {
          const apiCall = this.isAdd ? createPart(this.currentpart) : updatePart(this.currentpart)

          apiCall.then(({data}) => {
            if (data && data.code === 0) {
              this.$message.success(this.isAdd ? '新增产品成功' : '修改产品成功')
              this.partDialogVisible = false
              this.getMainData()
            } else {
              this.$message.error(data.msg || '操作失败')
            }
          }).catch(error => {
            this.$message.error('操作失败: ' + error.message)
          })
        } else {
          this.$message.warning('请填写必填字段')
        }
      })
    },

    // 删除产品
    deletePart(row) {
      this.$confirm('你确定删除该产品?', '确认删除', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deletePart(row.id).then(({data}) => {
          if (data && data.code === 0) {
            this.$message.success('产品删除成功')
            this.getMainData()
          } else {
            this.$message.error(data.msg || '删除失败')
          }
        }).catch(error => {
          this.$message.error('删除失败: ' + error.message)
        })
      })
    }
     // 打开审批对话框
    // openApproveDialog(row) {
    //   this.approveData = {
    //     applyNo: row.flowNodeInstanceData.applyNo,
    //     site: row.flowNodeInstanceData.site,
    //     orderType: row.flowNodeInstanceData.orderType,
    //     flowCode: row.flowNodeInstanceData.flowCode,
    //     flowVersion: row.flowNodeInstanceData.flowVersion,
    //     nodeCode: row.flowNodeInstanceData.nodeCode,
    //     comment: ''
       
    //   }
    //   this.approveDialogVisible = true
    // },
    // 提交审批
    // submitApprove(action) {
    //   if (action === 'REJECTED' && !this.approveData.comment) {
    //     this.$message.warning('驳回时必须填写审批意见')
    //     return
    //   }
    //   this.approveLoading = true
    //   approveNodeInstance({
    //     applyNo: this.approveData.applyNo,
    //     nodeCode: this.approveData.nodeCode,
    //     site: this.approveData.site,
    //     orderType: this.approveData.orderType,
    //     specialRelease: this.approveData.specialRelease,
    //     action: action,
    //     comment: this.approveData.comment
    //   }).then(({ data }) => {
    //     if (data && data.code === 0) {
    //       this.$message.success(action === 'APPROVED' ? '审批通过成功' : '驳回成功')
    //       this.approveDialogVisible = false
    //       //刷新列表
    //       this.getMainData()
    //     } else {
    //       this.$message.error(data.msg || '操作失败')
    //     }
    //   }).finally(() => {
    //     this.approveLoading = false
    //   })
    // },

    // 重新审批 - rqrq
    //  handleRestart(row) {
    //   this.$confirm('确定要重新发起审批流程吗？', '提示', {
    //     confirmButtonText: '确定',
    //     cancelButtonText: '取消',
    //     type: 'warning'
    //   }).then(() => {
    //     restartFlowInstance({
    //       applyNo: row.applyNo,
    //       site: row.site,
    //       orderType: row.orderType
    //     }).then(({ data }) => {
    //       if (data && data.code === 0) {
    //         this.$message.success('重新审批成功')
    //         this.getMainData()
    //       } else {
    //         this.$message.error(data.msg || '操作失败')
    //       }
    //     })
    //   }).catch(() => {})
    // }
   
  }

}
</script>

<!--当前页面的标签样式-->
<style scoped lang="scss">

/deep/ .customer-tab .el-tabs__content {
  padding: 5px !important;
}

/* 产品对话框整体样式 */
.part-dialog {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.part-dialog .el-dialog {
  margin-top: 5vh !important;
  margin-bottom: 5vh !important;
}

.part-dialog .el-dialog__header {
  padding: 20px 25px 15px 25px;
  border-bottom: 1px solid #E4E7ED;
}

.part-dialog .el-dialog__body {
  padding: 25px 25px 25px 25px;
  max-height: 75vh;
  overflow-y: auto;
  min-height: 400px;
}

.dialog-content {
  width: 100%;
}

/* 产品表单样式 */
.part-form {
  width: 100%;
}

.part-form .el-form-item {
  margin-bottom: 1px;
}

.part-form .el-form-item__label {
  font-weight: 500;
  color: #303133;
  line-height: 32px;
  padding-right: 12px;
}

.part-form .el-form-item__content {
  line-height: normal;
}

/* 表单分组样式 */
.form-section {
  margin-bottom: 5px;
}

.form-section:last-child {
  margin-bottom: 5px;
}

/* 输入框样式 */
.part-form .el-input,
.part-form .el-textarea,
.part-form .el-date-editor {
  width: 100%;
}

/* 文本域样式优化 */
.part-form .el-textarea__inner {
  resize: none;
  font-family: inherit;
  line-height: 1.5;
}

/* 对话框底部按钮居中 */
.dialog-footer-center {
  text-align: center;
  padding: 15px 0 5px 0;
  border-top: 1px solid #E4E7ED;
  margin-top: 15px;
}

.dialog-footer-center .el-button {
  margin: 0 10px;
  min-width: 90px;
  height: 36px;
  padding: 0 20px;
  font-size: 14px;
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .part-dialog {
    width: 95% !important;
  }

  .part-dialog .el-dialog__body {
    padding: 20px 20px 15px 20px;
  }
}

@media (max-width: 768px) {
  .part-form .el-col {
    margin-bottom: 20px;
  }

  .form-section {
    margin-bottom: 35px;
  }

  .part-form .el-form-item__label {
    line-height: 28px;
    height: 28px;
  }
}
</style>