<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="促销标题" prop="promotionTitle">
              <el-input v-model="queryParams.promotionTitle" placeholder="请输入促销标题" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="发票名称" prop="invoiceName">
              <el-input v-model="queryParams.invoiceName" placeholder="请输入发票名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="规格代码" prop="specificationsCode">
              <el-input v-model="queryParams.specificationsCode" placeholder="请输入规格代码" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="条形码" prop="barCoding">
              <el-input v-model="queryParams.barCoding" placeholder="请输入条形码" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="产品描述" prop="productDescription">
              <el-input v-model="queryParams.productDescription" placeholder="请输入产品描述" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="产品重量" prop="productWeight">
              <el-input v-model="queryParams.productWeight" placeholder="请输入产品重量" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="重量单位" prop="weightUnit">
              <el-input v-model="queryParams.weightUnit" placeholder="请输入重量单位" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="产品体积" prop="productVolume">
              <el-input v-model="queryParams.productVolume" placeholder="请输入产品体积" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="体积单位" prop="volumeUnit">
              <el-input v-model="queryParams.volumeUnit" placeholder="请输入体积单位" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="售后服务" prop="afterSalesService">
              <el-input v-model="queryParams.afterSalesService" placeholder="请输入售后服务" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="服务保障  支持多选,分隔 (0=无忧退货,1=快速退款,2=免费包邮,3正品保障)" prop="serviceGuarantee">
              <el-input v-model="queryParams.serviceGuarantee" placeholder="请输入服务保障  支持多选,分隔 (0=无忧退货,1=快速退款,2=免费包邮,3正品保障)" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="是否安装服务：1=是，0=否" prop="isInstallService">
              <el-input v-model="queryParams.isInstallService" placeholder="请输入是否安装服务：1=是，0=否" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="安装费用" prop="installAmount">
              <el-input v-model="queryParams.installAmount" placeholder="请输入安装费用" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="分销价格" prop="distributionPrice">
              <el-input v-model="queryParams.distributionPrice" placeholder="请输入分销价格" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="标准尺寸" prop="standardSizes">
              <el-input v-model="queryParams.standardSizes" placeholder="请输入标准尺寸" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="克重" prop="gramWeight">
              <el-input v-model="queryParams.gramWeight" placeholder="请输入克重" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="透明度" prop="opacity">
              <el-input v-model="queryParams.opacity" placeholder="请输入透明度" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="是否可定制：1=是，0=否" prop="isCustomize">
              <el-input v-model="queryParams.isCustomize" placeholder="请输入是否可定制：1=是，0=否" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="定制描述" prop="customDescription">
              <el-input v-model="queryParams.customDescription" placeholder="请输入定制描述" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="产品利润" prop="productProfit">
              <el-input v-model="queryParams.productProfit" placeholder="请输入产品利润" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="报告需求" prop="reportRequire">
              <el-input v-model="queryParams.reportRequire" placeholder="请输入报告需求" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="审核评论" prop="reviewComments">
              <el-input v-model="queryParams.reviewComments" placeholder="请输入审核评论" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="供应商编号" prop="supplierNo">
              <el-input v-model="queryParams.supplierNo" placeholder="请输入供应商编号" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="数据来源" prop="dataSource">
              <el-input v-model="queryParams.dataSource" placeholder="请输入数据来源" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="发票规格" prop="invoiceSpecs">
              <el-input v-model="queryParams.invoiceSpecs" placeholder="请输入发票规格" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="增量" prop="increment">
              <el-input v-model="queryParams.increment" placeholder="请输入增量" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="采购编号" prop="purchaseNo">
              <el-input v-model="queryParams.purchaseNo" placeholder="请输入采购编号" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="采购名称" prop="purchaseName">
              <el-input v-model="queryParams.purchaseName" placeholder="请输入采购名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="供应商名称" prop="supplierName">
              <el-input v-model="queryParams.supplierName" placeholder="请输入供应商名称" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="采购经理编号" prop="purchaseManagerNo">
              <el-input v-model="queryParams.purchaseManagerNo" placeholder="请输入采购经理编号" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="采购经理姓名" prop="purchaseManagerName">
              <el-input v-model="queryParams.purchaseManagerName" placeholder="请输入采购经理姓名" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="参考链接" prop="referenceLink">
              <el-input v-model="queryParams.referenceLink" placeholder="请输入参考链接" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="销售量" prop="salesVolume">
              <el-input v-model="queryParams.salesVolume" placeholder="请输入销售量" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="发货时效" prop="deliveryTime">
              <el-input v-model="queryParams.deliveryTime" placeholder="请输入发货时效" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="PIT时间" prop="pitTime">
              <el-date-picker clearable
                v-model="queryParams.pitTime"
                type="date"
                value-format="YYYY-MM-DD"
                placeholder="请选择PIT时间"
              />
            </el-form-item>
            <el-form-item label="创建时的供应商标识" prop="createSupplier">
              <el-input v-model="queryParams.createSupplier" placeholder="请输入创建时的供应商标识" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="其他补充信息" prop="otherInfo">
              <el-input v-model="queryParams.otherInfo" placeholder="请输入其他补充信息" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="平台标识" prop="platformCode">
              <el-input v-model="queryParams.platformCode" placeholder="请输入平台标识" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['product:extend:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate()" v-hasPermi="['product:extend:edit']">修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete()" v-hasPermi="['product:extend:remove']">删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['product:extend:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="extendList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="关联 product_base.id" align="center" prop="productId" v-if="true" />
        <el-table-column label="促销标题" align="center" prop="promotionTitle" />
        <el-table-column label="发票名称" align="center" prop="invoiceName" />
        <el-table-column label="发票类型" align="center" prop="invoiceType" />
        <el-table-column label="规格代码" align="center" prop="specificationsCode" />
        <el-table-column label="条形码" align="center" prop="barCoding" />
        <el-table-column label="产品描述" align="center" prop="productDescription" />
        <el-table-column label="产品重量" align="center" prop="productWeight" />
        <el-table-column label="重量单位" align="center" prop="weightUnit" />
        <el-table-column label="产品体积" align="center" prop="productVolume" />
        <el-table-column label="体积单位" align="center" prop="volumeUnit" />
        <el-table-column label="售后服务" align="center" prop="afterSalesService" />
        <el-table-column label="服务保障  支持多选,分隔 (0=无忧退货,1=快速退款,2=免费包邮,3正品保障)" align="center" prop="serviceGuarantee" />
        <el-table-column label="是否安装服务：1=是，0=否" align="center" prop="isInstallService" />
        <el-table-column label="安装费用" align="center" prop="installAmount" />
        <el-table-column label="分销价格" align="center" prop="distributionPrice" />
        <el-table-column label="标准尺寸" align="center" prop="standardSizes" />
        <el-table-column label="克重" align="center" prop="gramWeight" />
        <el-table-column label="透明度" align="center" prop="opacity" />
        <el-table-column label="是否可定制：1=是，0=否" align="center" prop="isCustomize" />
        <el-table-column label="定制描述" align="center" prop="customDescription" />
        <el-table-column label="产品利润" align="center" prop="productProfit" />
        <el-table-column label="报告需求" align="center" prop="reportRequire" />
        <el-table-column label="审核评论" align="center" prop="reviewComments" />
        <el-table-column label="供应商编号" align="center" prop="supplierNo" />
        <el-table-column label="推送状态" align="center" prop="pushStatus" />
        <el-table-column label="数据来源" align="center" prop="dataSource" />
        <el-table-column label="发票规格" align="center" prop="invoiceSpecs" />
        <el-table-column label="增量" align="center" prop="increment" />
        <el-table-column label="采购编号" align="center" prop="purchaseNo" />
        <el-table-column label="采购名称" align="center" prop="purchaseName" />
        <el-table-column label="供应商名称" align="center" prop="supplierName" />
        <el-table-column label="采购经理编号" align="center" prop="purchaseManagerNo" />
        <el-table-column label="采购经理姓名" align="center" prop="purchaseManagerName" />
        <el-table-column label="参考链接" align="center" prop="referenceLink" />
        <el-table-column label="销售量" align="center" prop="salesVolume" />
        <el-table-column label="发货时效" align="center" prop="deliveryTime" />
        <el-table-column label="PIT时间" align="center" prop="pitTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.pitTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建时的供应商标识" align="center" prop="createSupplier" />
        <el-table-column label="其他补充信息" align="center" prop="otherInfo" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template #default="scope">
            <el-tooltip content="修改" placement="top">
              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['product:extend:edit']"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['product:extend:remove']"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <!-- 添加或修改产品扩展属性（低频访问字段）对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
      <el-form ref="extendFormRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="促销标题" prop="promotionTitle">
          <el-input v-model="form.promotionTitle" placeholder="请输入促销标题" />
        </el-form-item>
        <el-form-item label="发票名称" prop="invoiceName">
            <el-input v-model="form.invoiceName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="规格代码" prop="specificationsCode">
            <el-input v-model="form.specificationsCode" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="条形码" prop="barCoding">
          <el-input v-model="form.barCoding" placeholder="请输入条形码" />
        </el-form-item>
        <el-form-item label="产品描述" prop="productDescription">
            <el-input v-model="form.productDescription" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="产品重量" prop="productWeight">
          <el-input v-model="form.productWeight" placeholder="请输入产品重量" />
        </el-form-item>
        <el-form-item label="重量单位" prop="weightUnit">
          <el-input v-model="form.weightUnit" placeholder="请输入重量单位" />
        </el-form-item>
        <el-form-item label="产品体积" prop="productVolume">
          <el-input v-model="form.productVolume" placeholder="请输入产品体积" />
        </el-form-item>
        <el-form-item label="体积单位" prop="volumeUnit">
          <el-input v-model="form.volumeUnit" placeholder="请输入体积单位" />
        </el-form-item>
        <el-form-item label="售后服务" prop="afterSalesService">
          <el-input v-model="form.afterSalesService" placeholder="请输入售后服务" />
        </el-form-item>
        <el-form-item label="服务保障  支持多选,分隔 (0=无忧退货,1=快速退款,2=免费包邮,3正品保障)" prop="serviceGuarantee">
          <el-input v-model="form.serviceGuarantee" placeholder="请输入服务保障  支持多选,分隔 (0=无忧退货,1=快速退款,2=免费包邮,3正品保障)" />
        </el-form-item>
        <el-form-item label="是否安装服务：1=是，0=否" prop="isInstallService">
          <el-input v-model="form.isInstallService" placeholder="请输入是否安装服务：1=是，0=否" />
        </el-form-item>
        <el-form-item label="安装费用" prop="installAmount">
          <el-input v-model="form.installAmount" placeholder="请输入安装费用" />
        </el-form-item>
        <el-form-item label="分销价格" prop="distributionPrice">
          <el-input v-model="form.distributionPrice" placeholder="请输入分销价格" />
        </el-form-item>
        <el-form-item label="标准尺寸" prop="standardSizes">
          <el-input v-model="form.standardSizes" placeholder="请输入标准尺寸" />
        </el-form-item>
        <el-form-item label="克重" prop="gramWeight">
          <el-input v-model="form.gramWeight" placeholder="请输入克重" />
        </el-form-item>
        <el-form-item label="透明度" prop="opacity">
          <el-input v-model="form.opacity" placeholder="请输入透明度" />
        </el-form-item>
        <el-form-item label="是否可定制：1=是，0=否" prop="isCustomize">
          <el-input v-model="form.isCustomize" placeholder="请输入是否可定制：1=是，0=否" />
        </el-form-item>
        <el-form-item label="定制描述" prop="customDescription">
          <el-input v-model="form.customDescription" placeholder="请输入定制描述" />
        </el-form-item>
        <el-form-item label="产品利润" prop="productProfit">
          <el-input v-model="form.productProfit" placeholder="请输入产品利润" />
        </el-form-item>
        <el-form-item label="报告需求" prop="reportRequire">
          <el-input v-model="form.reportRequire" placeholder="请输入报告需求" />
        </el-form-item>
        <el-form-item label="审核评论" prop="reviewComments">
          <el-input v-model="form.reviewComments" placeholder="请输入审核评论" />
        </el-form-item>
        <el-form-item label="供应商编号" prop="supplierNo">
          <el-input v-model="form.supplierNo" placeholder="请输入供应商编号" />
        </el-form-item>
        <el-form-item label="数据来源" prop="dataSource">
          <el-input v-model="form.dataSource" placeholder="请输入数据来源" />
        </el-form-item>
        <el-form-item label="发票规格" prop="invoiceSpecs">
            <el-input v-model="form.invoiceSpecs" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="增量" prop="increment">
          <el-input v-model="form.increment" placeholder="请输入增量" />
        </el-form-item>
        <el-form-item label="采购编号" prop="purchaseNo">
          <el-input v-model="form.purchaseNo" placeholder="请输入采购编号" />
        </el-form-item>
        <el-form-item label="采购名称" prop="purchaseName">
          <el-input v-model="form.purchaseName" placeholder="请输入采购名称" />
        </el-form-item>
        <el-form-item label="供应商名称" prop="supplierName">
            <el-input v-model="form.supplierName" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="采购经理编号" prop="purchaseManagerNo">
          <el-input v-model="form.purchaseManagerNo" placeholder="请输入采购经理编号" />
        </el-form-item>
        <el-form-item label="采购经理姓名" prop="purchaseManagerName">
          <el-input v-model="form.purchaseManagerName" placeholder="请输入采购经理姓名" />
        </el-form-item>
        <el-form-item label="参考链接" prop="referenceLink">
            <el-input v-model="form.referenceLink" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="销售量" prop="salesVolume">
          <el-input v-model="form.salesVolume" placeholder="请输入销售量" />
        </el-form-item>
        <el-form-item label="发货时效" prop="deliveryTime">
          <el-input v-model="form.deliveryTime" placeholder="请输入发货时效" />
        </el-form-item>
        <el-form-item label="PIT时间" prop="pitTime">
          <el-date-picker clearable
            v-model="form.pitTime"
            type="datetime"
            value-format="YYYY-MM-DD HH:mm:ss"
            placeholder="请选择PIT时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建时的供应商标识" prop="createSupplier">
          <el-input v-model="form.createSupplier" placeholder="请输入创建时的供应商标识" />
        </el-form-item>
        <el-form-item label="其他补充信息" prop="otherInfo">
          <el-input v-model="form.otherInfo" placeholder="请输入其他补充信息" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Extend" lang="ts">
import { listExtend, getExtend, delExtend, addExtend, updateExtend } from '@/api/pmsProduct/extend';
import { ExtendVO, ExtendQuery, ExtendForm } from '@/api/pmsProduct/extend/types';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const extendList = ref<ExtendVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);

const queryFormRef = ref<ElFormInstance>();
const extendFormRef = ref<ElFormInstance>();

const dialog = reactive<DialogOption>({
  visible: false,
  title: ''
});

const initFormData: ExtendForm = {
  productId: undefined,
  promotionTitle: undefined,
  invoiceName: undefined,
  invoiceType: undefined,
  specificationsCode: undefined,
  barCoding: undefined,
  productDescription: undefined,
  productWeight: undefined,
  weightUnit: undefined,
  productVolume: undefined,
  volumeUnit: undefined,
  afterSalesService: undefined,
  serviceGuarantee: undefined,
  isInstallService: undefined,
  installAmount: undefined,
  distributionPrice: undefined,
  standardSizes: undefined,
  gramWeight: undefined,
  opacity: undefined,
  isCustomize: undefined,
  customDescription: undefined,
  productProfit: undefined,
  reportRequire: undefined,
  reviewComments: undefined,
  supplierNo: undefined,
  pushStatus: undefined,
  dataSource: undefined,
  invoiceSpecs: undefined,
  increment: undefined,
  purchaseNo: undefined,
  purchaseName: undefined,
  supplierName: undefined,
  purchaseManagerNo: undefined,
  purchaseManagerName: undefined,
  referenceLink: undefined,
  salesVolume: undefined,
  deliveryTime: undefined,
  pitTime: undefined,
  createSupplier: undefined,
  otherInfo: undefined,
  remark: undefined,
}
const data = reactive<PageData<ExtendForm, ExtendQuery>>({
  form: {...initFormData},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    promotionTitle: undefined,
    invoiceName: undefined,
    invoiceType: undefined,
    specificationsCode: undefined,
    barCoding: undefined,
    productDescription: undefined,
    productWeight: undefined,
    weightUnit: undefined,
    productVolume: undefined,
    volumeUnit: undefined,
    afterSalesService: undefined,
    serviceGuarantee: undefined,
    isInstallService: undefined,
    installAmount: undefined,
    distributionPrice: undefined,
    standardSizes: undefined,
    gramWeight: undefined,
    opacity: undefined,
    isCustomize: undefined,
    customDescription: undefined,
    productProfit: undefined,
    reportRequire: undefined,
    reviewComments: undefined,
    supplierNo: undefined,
    pushStatus: undefined,
    dataSource: undefined,
    invoiceSpecs: undefined,
    increment: undefined,
    purchaseNo: undefined,
    purchaseName: undefined,
    supplierName: undefined,
    purchaseManagerNo: undefined,
    purchaseManagerName: undefined,
    referenceLink: undefined,
    salesVolume: undefined,
    deliveryTime: undefined,
    pitTime: undefined,
    createSupplier: undefined,
    otherInfo: undefined,
    platformCode: undefined,
    params: {
    }
  },
  rules: {
    promotionTitle: [
      { required: true, message: "促销标题不能为空", trigger: "blur" }
    ],
    invoiceName: [
      { required: true, message: "发票名称不能为空", trigger: "blur" }
    ],
    invoiceType: [
      { required: true, message: "发票类型不能为空", trigger: "change" }
    ],
    specificationsCode: [
      { required: true, message: "规格代码不能为空", trigger: "blur" }
    ],
    barCoding: [
      { required: true, message: "条形码不能为空", trigger: "blur" }
    ],
    productDescription: [
      { required: true, message: "产品描述不能为空", trigger: "blur" }
    ],
    productWeight: [
      { required: true, message: "产品重量不能为空", trigger: "blur" }
    ],
    weightUnit: [
      { required: true, message: "重量单位不能为空", trigger: "blur" }
    ],
    productVolume: [
      { required: true, message: "产品体积不能为空", trigger: "blur" }
    ],
    volumeUnit: [
      { required: true, message: "体积单位不能为空", trigger: "blur" }
    ],
    afterSalesService: [
      { required: true, message: "售后服务不能为空", trigger: "blur" }
    ],
    serviceGuarantee: [
      { required: true, message: "服务保障  支持多选,分隔 (0=无忧退货,1=快速退款,2=免费包邮,3正品保障)不能为空", trigger: "blur" }
    ],
    installAmount: [
      { required: true, message: "安装费用不能为空", trigger: "blur" }
    ],
    distributionPrice: [
      { required: true, message: "分销价格不能为空", trigger: "blur" }
    ],
    standardSizes: [
      { required: true, message: "标准尺寸不能为空", trigger: "blur" }
    ],
    gramWeight: [
      { required: true, message: "克重不能为空", trigger: "blur" }
    ],
    opacity: [
      { required: true, message: "透明度不能为空", trigger: "blur" }
    ],
    customDescription: [
      { required: true, message: "定制描述不能为空", trigger: "blur" }
    ],
    productProfit: [
      { required: true, message: "产品利润不能为空", trigger: "blur" }
    ],
    reportRequire: [
      { required: true, message: "报告需求不能为空", trigger: "blur" }
    ],
    reviewComments: [
      { required: true, message: "审核评论不能为空", trigger: "blur" }
    ],
    supplierNo: [
      { required: true, message: "供应商编号不能为空", trigger: "blur" }
    ],
    pushStatus: [
      { required: true, message: "推送状态不能为空", trigger: "change" }
    ],
    dataSource: [
      { required: true, message: "数据来源不能为空", trigger: "blur" }
    ],
    invoiceSpecs: [
      { required: true, message: "发票规格不能为空", trigger: "blur" }
    ],
    increment: [
      { required: true, message: "增量不能为空", trigger: "blur" }
    ],
    purchaseNo: [
      { required: true, message: "采购编号不能为空", trigger: "blur" }
    ],
    purchaseName: [
      { required: true, message: "采购名称不能为空", trigger: "blur" }
    ],
    supplierName: [
      { required: true, message: "供应商名称不能为空", trigger: "blur" }
    ],
    purchaseManagerNo: [
      { required: true, message: "采购经理编号不能为空", trigger: "blur" }
    ],
    purchaseManagerName: [
      { required: true, message: "采购经理姓名不能为空", trigger: "blur" }
    ],
    referenceLink: [
      { required: true, message: "参考链接不能为空", trigger: "blur" }
    ],
    salesVolume: [
      { required: true, message: "销售量不能为空", trigger: "blur" }
    ],
    deliveryTime: [
      { required: true, message: "发货时效不能为空", trigger: "blur" }
    ],
    pitTime: [
      { required: true, message: "PIT时间不能为空", trigger: "blur" }
    ],
    createSupplier: [
      { required: true, message: "创建时的供应商标识不能为空", trigger: "blur" }
    ],
    otherInfo: [
      { required: true, message: "其他补充信息不能为空", trigger: "blur" }
    ],
    remark: [
      { required: true, message: "备注不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询产品扩展属性（低频访问字段）列表 */
const getList = async () => {
  loading.value = true;
  const res = await listExtend(queryParams.value);
  extendList.value = res.rows;
  total.value = res.total;
  loading.value = false;
}

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
}

/** 表单重置 */
const reset = () => {
  form.value = {...initFormData};
  extendFormRef.value?.resetFields();
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
}

/** 多选框选中数据 */
const handleSelectionChange = (selection: ExtendVO[]) => {
  ids.value = selection.map(item => item.productId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
const handleAdd = () => {
  reset();
  dialog.visible = true;
  dialog.title = "添加产品扩展属性（低频访问字段）";
}

/** 修改按钮操作 */
const handleUpdate = async (row?: ExtendVO) => {
  reset();
  const _productId = row?.productId || ids.value[0]
  const res = await getExtend(_productId);
  Object.assign(form.value, res.data);
  dialog.visible = true;
  dialog.title = "修改产品扩展属性（低频访问字段）";
}

/** 提交按钮 */
const submitForm = () => {
  extendFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.productId) {
        await updateExtend(form.value).finally(() =>  buttonLoading.value = false);
      } else {
        await addExtend(form.value).finally(() =>  buttonLoading.value = false);
      }
      proxy?.$modal.msgSuccess("操作成功");
      dialog.visible = false;
      await getList();
    }
  });
}

/** 删除按钮操作 */
const handleDelete = async (row?: ExtendVO) => {
  const _productIds = row?.productId || ids.value;
  await proxy?.$modal.confirm('是否确认删除产品扩展属性（低频访问字段）编号为"' + _productIds + '"的数据项？').finally(() => loading.value = false);
  await delExtend(_productIds);
  proxy?.$modal.msgSuccess("删除成功");
  await getList();
}

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download('product/extend/export', {
    ...queryParams.value
  }, `extend_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getList();
});
</script>
