<template>
  <div class="index-container height-100">
    <fl-table
      :config="state.tableConfig"
      :refreshCount="state.tableConfig.refreshCount"
      @triggerRowActions="handleRowActions"
      @triggerTableBatchActions="handleTableBatchActions"
      @triggerNewValChange="handleSearchEffExpandValChange"
    >
      <template #top-right>
        <div
          v-if="calcItemVisible('r_paintersideartwork_btn_notify')"
          class="justify-center fl-mr-md cursor row"
        >
          <a-badge :count="state.notifyCount">
            <img
              width="34"
              @click="handleOpenNotify"
              src="../../../assets/image/notify.png"
            />
          </a-badge>
        </div>
      </template>

      <template v-slot:exporttablecolumnfield="scoped">
        <AsyncRate :text="scoped.scoped.text" />
      </template>
    </fl-table>
  </div>

  <a-modal
    v-model:visible="state.modalVisible"
    :title="state.dialogData.title"
    :confirm-loading="state.btnLoading"
    centered
    @ok="handleDialogConfirm"
  >
    <div
      v-if="['unpass', 'reject'].includes(state.dialogData.type)"
      class="row"
    >
      <div v-if="state.dialogData.type === 'unpass'" class="col-3 fl-my-sm">
        可选择项
      </div>
      <div v-if="state.dialogData.type === 'unpass'" class="col-9 fl-my-sm">
        <fl-form-item
          type="select"
          field="remark"
          multiple="multiple"
          :val="state.dialogFormData.remark"
          :config="{
            options: state.rejectOptions,
          }"
          @triggerValChange="handleValChange"
        />
      </div>
      <div class="col-3 fl-my-sm">补充说明</div>
      <div class="col-9 fl-my-sm">
        <fl-form-item
          type="textarea"
          field="remark2"
          :rows="4"
          :val="state.dialogFormData.remark2"
          @triggerValChange="handleValChange"
        />
      </div>
    </div>
    <div v-if="['restart'].includes(state.dialogData.type)" class="row">
      <div class="col-3 fl-my-sm">原审批状态</div>
      <div class="col-9 fl-my-sm">
        {{
          getLabelByOptions(
            state.dialogFormData.defaultStatus,
            state.statusOptions
          )
        }}
      </div>
      <div class="col-3 fl-my-sm">新审批状态</div>
      <div class="col-9 fl-my-sm">
        <fl-form-item
          type="select"
          field="newStatus"
          :val="state.dialogFormData.newStatus"
          :config="{
            options: [
              {
                label: '通过',
                value: 4,
              },
              {
                label: '不通过',
                value: 3,
              },
              {
                label: '驳回',
                value: 6,
              },
            ],
          }"
          @triggerValChange="handleValChange"
        />
      </div>
      <div v-if="state.dialogFormData.newStatus === 3" class="col-3 fl-my-sm">
        理由
      </div>
      <div v-if="state.dialogFormData.newStatus === 3" class="col-9 fl-my-sm">
        <fl-form-item
          type="select"
          field="remark"
          multiple="multiple"
          :val="state.dialogFormData.remark"
          :config="{
            options: state.rejectOptions,
          }"
          @triggerValChange="handleValChange"
        />
      </div>
      <div v-if="state.dialogFormData.newStatus !== 4" class="col-3 fl-my-sm">
        补充说明
      </div>
      <div v-if="state.dialogFormData.newStatus !== 4" class="col-9 fl-my-sm">
        <fl-form-item
          type="textarea"
          field="remark2"
          :rows="4"
          :val="state.dialogFormData.remark2"
          @triggerValChange="handleValChange"
        />
      </div>
    </div>
  </a-modal>

  <fl-artwork-export-modal
    v-if="state.exportDialogVisible"
    :openCount="state.openCount"
    @triggerCloseModal="handleCloseExport"
  />

  <notify-modal
    v-if="state.notifyDialogVisible"
    :openCount="state.notifyOpenCount"
    :notifyCount="state.notifyCount"
    @triggerCloseModal="handleNotifyCloseExport"
    @calcNotifyCount="getNotify"
  />
</template>
<script setup>
import {
  ref,
  reactive,
  onBeforeMount,
  onMounted,
  getCurrentInstance,
  watch,
  nextTick,
  defineComponent,
  h,
} from "vue";
import flTable from "@/components/layout/table/commonTable.vue";
import flFormItem from "@/components/layout/form/formItem.vue";
import { getParamsByObj, getLabelByOptions } from "@/utils/helper/form";
import flArtworkExportModal from "./components/artworkexportmodal.vue";
import notifyModal from "./components/notifymodal.vue";
const currentInstance = getCurrentInstance();
import { processError, processSuccess } from "@/utils/helper/message";
import { NPopover } from "naive-ui";
const { $request, $hadRule } =
  currentInstance.appContext.config.globalProperties;
const state = reactive({
  notifyCount: 0,
  notifyDialogVisible: false,
  notifyOpenCount: 0,
  openCount: 0,
  exportDialogVisible: false,
  dialogData: {},

  viewCount: 0,
  viewExportCount: 0,
  clickRowData: {},
  // 弹窗数据
  dialogFormData: {
    defaultStatus: 0,
    newStatus: 0,
    remark: [],
    remark2: "",
  },
  modalVisible: false,
  btnLoading: false,
  dialogData: { title: "", type: "" }, //弹窗配置
  rejectOptions: [
    { label: "画作总平尺数需在240左右", value: "画作总平尺数需在240左右" },
    {
      label:
        "画作内容不可涉及政治因素、历史人物、历史事件、国旗、人民币、抗疫、现有品牌等",
      value:
        "画作内容不可涉及政治因素、历史人物、历史事件、国旗、人民币、抗疫、现有品牌等",
    },
    { label: "画作合影需要露出章款", value: "画作合影需要露出章款" },
    { label: "画作信息不全", value: "画作信息不全" },
  ],
  statusOptions: [
    {
      label: "通过",
      value: 4,
    },
    {
      label: "不通过",
      value: 3,
    },
    {
      label: "驳回",
      value: 6,
    },
    {
      label: "复审中",
      value: 7,
    },
    {
      label: "下期待用",
      value: 8,
    },
  ],
  tableConfig: {
    rowKey: "artistUid",
    slotRight: true,
    refreshCount: 0,
    listUrl: {
      url: "api/backend/artist/ArtistsArtworkStaticList",
      params: [],
    },
    tableMaxHeight: 600,
    // 画家姓名
    searchConfig: [
      {
        class: "fl-mt-sm",
        type: "text",
        label: "画家姓名",
        field: "artistName",
      },
      {
        class: "fl-mt-sm",
        type: "select",
        label: "画家流程状态",
        field: "isLock",
        clearable: true,
        config: {
          options: [
            {
              label: "已锁定",
              value: 1,
            },
            {
              label: "未锁定",
              value: 2,
            },
          ],
        },
      },
      {
        class: "fl-mt-sm",
        type: "text",
        label: "画家编号",
        field: "Tnum",
      },
      {
        class: "fl-mt-sm",
        type: "select",
        label: "是否大师",
        field: "isMaster",
        clearable: true,
        config: {
          options: [
            {
              label: "是",
              value: 1,
            },
            {
              label: "否",
              value: 2,
            },
          ],
        },
      },

      {
        class: "fl-mt-sm",
        type: "text",
        label: "画作名称",
        field: "artworkName",
        effExpand: true,
      },
      {
        class: "fl-mt-sm",
        type: "select",
        label: "画作流程状态",
        field: "baseAuditStatus",
        clearable: true,
        effExpand: true,
        config: {
          options: [
            {
              label: "画家暂存",
              value: 1,
            },
            {
              label: "待审核",
              value: 2,
            },
            {
              label: "已通过",
              value: 4,
            },
            {
              label: "不通过",
              value: 3,
            },
            {
              label: "驳回",
              value: 6,
            },
            {
              label: "复审中",
              value: 7,
            },
            {
              label: "未完成审批画作",
              value: 10,
            },
            {
              label: "下期待用",
              value: 8,
            },
          ],
        },
      },
      {
        class: "fl-mt-sm",
        type: "rangnum",
        label: ["画作平尺数起", "画作平尺数止"],
        clearable: true,
        field: ["rulerStart", "rulerEnd"],
        value: [null, null],
        style: "width: 340px;",
        effExpand: true,
        config: {
          bottomLabel: "平尺",
        },
      },
      {
        class: "fl-mt-sm",
        type: "select",
        label: "是否国展",
        field: "nationalExhibition",
        clearable: true,
        effExpand: true,
        config: {
          options: [
            {
              label: "无",
              value: 1,
            },
            {
              label: "入围国展",
              value: 2,
            },
            {
              label: "入选国展",
              value: 3,
            },
          ],
        },
      },
      {
        class: "fl-mt-sm",
        type: "select",
        label: "入选凭证",
        field: "queryHaveProof",
        clearable: true,
        effExpand: true,
        config: {
          options: [
            {
              label: "不限制",
              value: 0,
            },
            {
              label: "有入选凭证",
              value: 1,
            },
          ],
        },
      },
      {
        class: "fl-mt-sm",
        type: "text",
        label: "画作编号",
        field: "tfnum",
        effExpand: true,
      },
      {
        class: "fl-mt-sm",
        type: "text",
        label: "笔名",
        field: "penName",
      },
    ],
    columns: [
      {
        badge: "[%=noAuditArtworkTotal%]!==0",
        badgeField: "noAuditArtworkTotal",
        width: 120,
        type: "select",
        label: "当前流程状态",
        field: "isLock",
        options: [
          {
            label: "锁定",
            value: true,
            class: "status-primary",
          },
          {
            label: "未锁定",
            value: false,
            class: "status-draft",
          },
        ],
      },
      {
        width: 120,
        label: "画家姓名",
        field: "artistShowCount",
      },
      {
        type: "select",
        label: "是否大师",
        field: "isMaster",
        options: [
          {
            label: "是",
            value: true,
          },
          {
            label: "否",
            value: false,
          },
        ],
      },
      {
        width: 140,
        field: "overSeaTime",
        title: () =>
          h(
            NPopover,
            {
              trigger: "hover",
              showArrow: true,
              placement: "top",
            },
            {
              trigger: () =>
                h(
                  "span",
                  {
                    style:
                      "cursor: pointer; display: flex; align-items: center; gap: 4px;",
                  },
                  [
                    "海外合作日期",
                    h(
                      "svg",
                      {
                        xmlns: "http://www.w3.org/2000/svg",
                        viewBox: "0 0 512 512",
                        style: "width: 16px; height: 16px; color: #1890ff;",
                      },
                      [
                        h("path", {
                          d: "M448 256c0-106-86-192-192-192S64 150 64 256s86 192 192 192s192-86 192-192z",
                          fill: "none",
                          stroke: "currentColor",
                          "stroke-miterlimit": "10",
                          "stroke-width": "32",
                        }),
                        h("path", {
                          d: "M250.26 166.05L256 288l5.73-121.95a5.74 5.74 0 0 0-5.79-6h0a5.74 5.74 0 0 0-5.68 6z",
                          fill: "none",
                          stroke: "currentColor",
                          "stroke-linecap": "round",
                          "stroke-linejoin": "round",
                          "stroke-width": "32",
                        }),
                        h("path", {
                          d: "M256 367.91a20 20 0 1 1 20-20a20 20 0 0 1-20 20z",
                          fill: "currentColor",
                        }),
                      ]
                    ),
                  ]
                ),
              default: () =>
                h(
                  "div",
                  {
                    style: "padding: 8px; max-width: 300px;",
                  },
                  [
                    h("div", { style: "margin-bottom: 4px;" }, [
                      h("span", "红色日期代表合作不超过1年；"),
                    ]),
                    h("div", {}, [h("span", "黑色日期代表合作超过1年")]),
                  ]
                ),
            }
          ),
        render: (row) => {
          if (row.overseaIntervalMonth < 12) {
            return h(
              "div",
              {
                style: "color: red;",
              },
              [h("span", row.overSeaTime)]
            );
          } else {
            return h(
              "div",
              {
                style: "color: #000;",
              },
              [h("span", row.overSeaTime)]
            );
          }
        },
      },
      {
        width: 100,
        label: "画家编号",
        field: "tnum",
      },
      {
        label: "笔名",
        field: "penName",
      },
      {
        label: "身份证号",
        field: "idNum",
      },
      {
        sorter: true,
        label: "锁定日期",
        field: "latestLockTime",
        width: 130,
      },
      {
        sorter: true,
        label: "画作总数",
        field: "artworkTotal",
      },
      {
        sorter: true,
        label: "画作总平尺数",
        field: "rulerTotal",
      },
      {
        sorter: true,
        label: "通过画作总数",
        field: "passwdArtworkTotal",
      },
      {
        sorter: true,
        label: "通过画作总平尺数",
        field: "passedRulerTotal",
      },
      {
        sorter: true,
        label: "更新时间",
        field: "latestUpdatedAt",
      },
    ],
    slotRightClass: "col-12 row justify-end",
    tableBatchActions: [
      {
        notLimitSelect: true,
        actionType: "export_dialog",
        type: "primary",
        hasTableData: true,
        label: "导出画作信息",
      },
    ],
    expandConfig: {
      rowKey: "artworkUid",
      refreshCount: 0,
      listUrl: {
        url: "api/backend/artwork/preview/list",
        params: [
          {
            label: "artistUid",
            field: "artistUid",
          },
          {
            label: "sortField",
            value: "baseInfoArtistUpdateAt",
          },
          {
            label: "sortOrder",
            value: "descend",
          },
        ],
      },
      calcSearchConfigCount: 0,
      tableMaxHeight: 600,
      pagination: {
        pageSize: 20,
      },
      // 画作名称 流程状态
      searchConfig: [
        {
          class: "fl-mt-sm",
          type: "text",
          label: "画作名称",
          field: "artworkName",
        },
        {
          class: "fl-mt-sm",
          type: "select",
          label: "画作流程状态",
          field: "baseAuditStatus",
          clearable: true,
          config: {
            options: [
              {
                label: "画家暂存",
                value: 1,
              },
              {
                label: "待审核",
                value: 2,
              },
              {
                label: "已通过",
                value: 4,
              },
              {
                label: "不通过",
                value: 3,
              },
              {
                label: "驳回",
                value: 6,
              },
              {
                label: "复审中",
                value: 7,
              },
              {
                label: "未完成审批画作",
                value: 10,
              },
              {
                label: "下期待用",
                value: 8,
              },
            ],
          },
        },
        {
          class: "fl-mt-sm",
          type: "select",
          label: "数据状态",
          field: "history",
          value: false,
          config: {
            options: [
              {
                label: "历史",
                value: true,
              },
              {
                label: "未完成",
                value: false,
              },
            ],
          },
        },
        {
          class: "fl-mt-sm",
          type: "rangnum",
          label: ["画作平尺数起", "画作平尺数止"],
          clearable: true,
          field: ["rulerStart", "rulerEnd"],
          value: [null, null],
          style: "width: 340px;",
          config: {
            bottomLabel: "平尺",
          },
        },
        {
          class: "fl-mt-sm",
          type: "select",
          label: "是否国展",
          field: "nationalExhibition",
          clearable: true,
          config: {
            options: [
              {
                label: "无",
                value: 1,
              },
              {
                label: "入围国展",
                value: 2,
              },
              {
                label: "入选国展",
                value: 3,
              },
            ],
          },
        },
        {
          class: "fl-mt-sm",
          type: "select",
          label: "入选凭证",
          field: "queryHaveProof",
          clearable: true,
          config: {
            options: [
              {
                label: "不限制",
                value: 0,
              },
              {
                label: "有入选凭证",
                value: 1,
              },
            ],
          },
        },
        {
          class: "fl-mt-sm",
          type: "select",
          label: "导入状态",
          field: "inSource",
          clearable: true,
          config: {
            options: [
              {
                label: "未导入",
                value: 2,
              },
              {
                label: "已导入",
                value: 3,
              },
            ],
          },
        },
      ],
      columns: [
        {
          type: "select",
          label: "当前流程状态",
          field: "baseAuditStatus",
          width: 120,
          tipRight: {
            show: "[%=baseAuditStatus%]===3||[%=baseAuditStatus%]===6",
            title: "原因",
            style:
              "font-size: 20px;color: rgb(246 76 155);top: 0px;right: 0px;transform: translate(25px, 4px);",
            tipRightField: [
              {
                field: "baseAuditMark",
                type: "array",
              },
              "baseAuditMark2",
            ],
          },
          options: [
            {
              label: "画家暂存",
              value: 1,
              class: "status-draft",
            },
            {
              label: "待审核",
              value: 2,
              class: "status-draft",
            },
            {
              label: "已通过",
              value: 4,
              class: "status-primary",
            },
            {
              label: "不通过",
              value: 3,
              class: "status-danger",
            },
            {
              label: "驳回",
              value: 6,
              class: "status-danger",
            },
            {
              label: "复审中",
              value: 7,
              class: "status-draft",
            },
            {
              label: "下期待用",
              value: 8,
              class: "status-orange",
            },
          ],
        },
        {
          type: "select",
          label: "复审状态",
          field: "reviewStatus",
          width: 120,
          tipRight: {
            show: "[%=reviewStatus%]===3",
            title: "原因",
            style:
              "font-size: 20px;color: rgb(246 76 155);top: 0px;right: 0px;transform: translate(25px, 4px);",
            tipRightField: [
              {
                field: "reviewMark",
                type: "array",
              },
              "reviewMark2",
            ],
          },
          options: [
            {
              label: "复审中",
              value: 2,
              class: "status-draft",
            },
            {
              label: "已通过",
              value: 4,
              class: "status-primary",
            },
            {
              label: "不通过",
              value: 3,
              class: "status-danger",
            },
          ],
        },
        {
          width: 120,
          type: "select",
          label: "导入状态",
          field: "inSource",
          options: [
            {
              label: "画家服务",
              value: 1,
            },
            {
              label: "未导入",
              value: 2,
            },
            {
              label: "已导入",
              value: 3,
            },
          ],
        },
        {
          width: 80,
          label: "画作名称",
          field: "artworkName",
          type: "link",
          linkConfig: {
            type: "dialog",
          },
        },
        { width: 100, label: "画作编号", field: "tfnum", sorter: true },
        {
          type: "select",
          label: "画作类型",
          field: "artworkType",
          options: [
            {
              label: "优秀画作",
              value: 1,
            },
            {
              label: "赠画",
              value: 2,
            },
            {
              label: "卷轴",
              value: 3,
            },
            {
              label: "普通画作",
              value: 4,
            },
          ],
        },
        {
          label: "宽度",
          field: "width",
        },
        {
          label: "长度",
          field: "length",
        },
        {
          label: "平尺数",
          field: "ruler",
        },
        {
          type: "exporttablecolumnfield",
          label: "比值",
        },
        {
          popover: true,
          type: "image",
          label: "画作高清图",
          field: "hdPic",
          width: 120,
          ossWitdh: 1920,
          ossHeight: 1080,
        },
        {
          popover: true,
          type: "image",
          label: "画家画作合影",
          field: "artistPhoto",
          width: 120,
        },
        {
          popover: true,
          type: "image",
          label: "画作落款印章处细节图",
          field: "sealPic",
          width: 130,
        },
        {
          label: "申请时间",
          field: "createdAt",
          width: 100,
          sorter: true,
        },
        {
          label: "更新时间",
          field: "baseInfoArtistUpdateAt",
          width: 100,
          sorter: true,
        },
        {
          width: 120,
          type: "select",
          label: "国展",
          field: "nationalExhibition",
          options: [
            {
              label: "无",
              value: 1,
            },
            {
              label: "入围国展",
              value: 2,
            },
            {
              label: "入选国展",
              value: 3,
            },
          ],
        },
        {
          popover: true,
          type: "image",
          label: "入选凭证",
          field: "nationalExhibitionProof",
          width: 120,
        },
        {
          type: "tooltip",
          label: "文字释义",
          width: 120,
          field: "commentData",
        },
        {
          label: "操作",
          minWidth: "100px",
          actions: [
            {
              type: "primary",
              label: "通过",
              show: "[%=baseAuditStatus%]!==3&&[%=baseAuditStatus%]!==4&&[%=baseAuditStatus%]!==6&&[%=baseAuditStatus%]!==7&&[%=lockStatus%]!==3",
              notemit: true,
              shape: "round",
              class: "fl-ma-xs",
              permission: "r_ps_artwork_base_btn_pass",
              actionUrl: {
                url: "api/backend/artwork/auditFlow/audit",
                params: [
                  { type: "Array", label: "artworkUids", field: "artworkUid" },
                  {
                    label: "auditStatus",
                    value: 4,
                  },
                  {
                    label: "flowindex",
                    value: 2,
                  },
                ],
              },
            },
            {
              type: "danger",
              actionType: "unpass",
              label: "不通过",
              show: "[%=baseAuditStatus%]!==3&&[%=baseAuditStatus%]!==4&&[%=baseAuditStatus%]!==6&&[%=baseAuditStatus%]!==7&&[%=lockStatus%]!==3",
              shape: "round",
              class: "fl-ma-xs",
              permission: "r_ps_artwork_base_btn_unpass",
            },
            {
              type: "danger",
              actionType: "reject",
              label: "驳回",
              show: "[%=baseAuditStatus%]!==3&&[%=baseAuditStatus%]!==4&&[%=baseAuditStatus%]!==6&&[%=baseAuditStatus%]!==7&&[%=lockStatus%]!==3",
              shape: "round",
              class: "fl-ma-xs",
              permission: "r_ps_artwork_base_btn_reject",
            },
            {
              type: "primary",
              actionType: "restart_p",
              label: "重新审批",
              show: "[%=baseAuditStatus%]!==1&&[%=baseAuditStatus%]!==2&&[%=baseAuditStatus%]!==8&&[%=history%]===false",
              shape: "round",
              class: "fl-ma-xs",
            },
            {
              type: "primary",
              tooltip: true,
              show: "[%=inSource%]===1||[%=inSource%]===2",
              label: "导入",
              shape: "round",
              class: "fl-mx-xs fl-mt-xs",
              permission: "r_ps_artwork_base_btn_import",
              actionUrl: {
                url: "api/artwork/import",
                params: [
                  {
                    label: "artworkUid",
                    field: "artworkUid",
                  },
                ],
              },
            },
            {
              actionType: "wait_next",
              style: "background-color: #ffb015;color: #fff;",
              label: "下期待用",
              show: "[%=baseAuditStatus%]===1&&[%=history%]===false",
              shape: "round",
              class: "fl-ma-xs",
              actionUrl: {
                url: "api/backend/artwork/auditFlow/audit",
                params: [
                  { type: "Array", label: "artworkUids", field: "artworkUid" },
                  {
                    label: "auditStatus",
                    value: 8,
                  },
                  {
                    label: "flowindex",
                    value: 2,
                  },
                ],
              },
            },
            {
              actionType: "wait_next",
              style: "background-color: #ffb015;color: #fff;",
              label: "下期待用",
              show: "[%=baseAuditStatus%]===2&&[%=history%]===false",
              shape: "round",
              class: "fl-ma-xs",
              actionUrl: {
                url: "api/backend/artwork/auditFlow/audit",
                params: [
                  { type: "Array", label: "artworkUids", field: "artworkUid" },
                  {
                    label: "auditStatus",
                    value: 8,
                  },
                  {
                    label: "flowindex",
                    value: 2,
                  },
                ],
              },
            },
          ],
        },
      ],
    },
  },
  // queryUnfinishedAudit: {
  //   type: "select",
  //   label: "审批查询",
  //   field: "queryUnfinishedAudit",
  //   clearable: true,
  //   config: {
  //     options: [
  //       {
  //         label: "不限制",
  //         value: 0,
  //       },
  //       {
  //         label: "未完成审批画作",
  //         value: 1,
  //       },
  //     ],
  //   },
  // },
});
onBeforeMount(() => {
  getNotify();
});

onMounted(() => {});
const getNotify = () => {
  let url = "api/artistInfoArtwork/reviewAuditMessage/static";
  let params = {};
  $request.HTTP.components.postDataByParams(url, params).then(
    (res) => {
      if (res.status === 0) {
        state.notifyCount = res.data.noReadNum;
      }
    },
    (err) => {
      processError(err.response.data.msg);
    }
  );
};
const calcItemVisible = (permission) => {
  return $hadRule(permission);
};
const handleOpenNotify = () => {
  state.notifyDialogVisible = true;
  state.notifyOpenCount++;
};
const handleRowActions = (btnConfig, rowData) => {
  if (btnConfig.actionType === "unpass") {
    handleUnpass(rowData);
  }
  if (btnConfig.actionType === "reject") {
    handleReject(rowData);
  }
  if (btnConfig.actionType === "create_artwork_extra") {
    let url = "api/backend/artwork/supplement/generate";
    let params = getParamsByObj(
      {},
      [{ type: "Array", label: "artworkUids", field: "artworkUid" }],
      rowData
    );
    btnConfig.btnLoading = true;
    $request.HTTP.components.postDataByParams(url, params).then(
      (res) => {
        if (res.status === 0) {
          state.tableConfig.expandConfig.refreshCount++;
          processSuccess("操作成功!");
        } else {
          processError(res.msg);
        }
        btnConfig.btnLoading = false;
      },
      (err) => {
        btnConfig.btnLoading = false;
        processError(err.response.data.msg);
      }
    );
  }
  if (btnConfig.actionType === "restart_p") {
    handleRestart(rowData);
  }
};
const handleTableBatchActions = (selectedRows, config, rowData) => {
  if (config.actionType === "export_dialog") {
    state.exportDialogVisible = true;
    state.openCount++;
  }
};

const handleUnpass = (rowData) => {
  state.dialogData.title = "请填写不通过理由";
  state.dialogData.type = "unpass";
  state.dialogFormData = {
    defaultStatus: rowData.baseAuditStatus,
    newStatus: 3,
    remark: [],
    remark2: "",
  };
  state.clickRowData = JSON.parse(JSON.stringify(rowData));
  state.modalVisible = true;
};
const handleReject = (rowData) => {
  state.dialogData.title = "请填写驳回理由";
  state.dialogData.type = "reject";
  state.dialogFormData = {
    defaultStatus: rowData.baseAuditStatus,
    newStatus: 6,
    remark: [],
    remark2: "",
  };
  state.clickRowData = JSON.parse(JSON.stringify(rowData));
  state.modalVisible = true;
};
const handleRestart = (rowData) => {
  state.dialogData.title = "重新审批";
  state.dialogData.type = "restart";
  state.dialogFormData = {
    defaultStatus: rowData.baseAuditStatus,
    newStatus: 4,
    remark: [],
    remark2: "",
  };
  state.clickRowData = JSON.parse(JSON.stringify(rowData));
  state.modalVisible = true;
};
const handleWaitNext = (rowData) => {
  console.log(rowData);
};
const handleValChange = (val, field) => {
  state.dialogFormData[field] = val;
  if (field === "newStatus") {
    state.dialogFormData.remark = [];
    state.dialogFormData.remark2 = "";
  }
};
const handleDialogConfirm = () => {
  let submitData = JSON.parse(JSON.stringify(state.dialogFormData));
  if (
    submitData.newStatus !== 4 &&
    submitData.remark.length === 0 &&
    submitData.remark2.length === 0
  ) {
    processError("请选择或填写理由！");
    return;
  }
  let url = "api/backend/artwork/auditFlow/audit";
  let params = getParamsByObj(
    {},
    [
      { type: "Array", label: "artworkUids", field: "artworkUid" },
      {
        label: "auditStatus",
        value: submitData.newStatus,
      },
      {
        label: "flowindex",
        value: 2,
      },
    ],
    state.clickRowData
  );
  params.auditMark = submitData.remark.join(",");
  params.auditMark2 = submitData.remark2;
  state.btnLoading = true;
  $request.HTTP.components.postDataByParams(url, params).then(
    (res) => {
      if (res.status === 0) {
        state.modalVisible = false;
        state.tableConfig.expandConfig.refreshCount++;
      } else {
        processError(res.msg);
      }
      state.btnLoading = false;
    },
    (err) => {
      state.btnLoading = false;
      processError(err.response.data.msg);
    }
  );
};
const handleCloseExport = () => {
  state.exportDialogVisible = false;
};
const handleNotifyCloseExport = () => {
  state.notifyDialogVisible = false;
};
const handleSearchEffExpandValChange = ({ val, config }) => {
  if (config.effExpand) {
    state.tableConfig.expandConfig.searchConfig.forEach((item) => {
      if (JSON.stringify(config.field) === JSON.stringify(item.field)) {
        item.value = val;
      }
    });
    state.tableConfig.expandConfig.calcSearchConfigCount++;
  }
};
const calcRate = (text) => {
  let url = text.hdPic;
  if (!url) return Promise.resolve("-");

  return new Promise((resolve) => {
    let file = new Image();
    file.src = url;

    file.onload = () => {
      const max = Math.max(file.width, file.height);
      const min = Math.min(file.width, file.height);
      const ratio = (Math.floor((max / min) * 100) / 100).toFixed(2);
      resolve(ratio);
    };

    file.onerror = () => {
      resolve("-");
    };
  });
};

// 在setup中定义AsyncRate组件
const AsyncRate = defineComponent({
  props: {
    text: Object,
  },
  data() {
    return {
      ratio: "-",
    };
  },
  async mounted() {
    this.ratio = await calcRate(this.text);
  },
  render() {
    return h("span", this.ratio);
  },
});

// 在setup中注册组件
const components = {
  AsyncRate,
};
</script>
<style scoped></style>
