<template>
  <div class="index-container height-100">
    <fl-table
      :config="state.tableConfig"
      :refreshCount="state.tableConfig.refreshCount"
      @triggerRowActions="handleRowActions"
      @triggerTableBatchActions="handleTableBatchActions"
    >
    </fl-table>
  </div>

  <fl-artist-export-modal
    v-if="state.exportDialogVisible"
    :openCount="state.openCount"
    @triggerCloseModal="handleCloseExport"
  />
</template>
<script setup>
import {
  ref,
  reactive,
  onBeforeMount,
  onMounted,
  getCurrentInstance,
  watch,
  nextTick,
} from "vue";
import flTable from "@/components/layout/table/commonTable.vue";
import { processError, processSuccess } from "@/utils/helper/message";

import flArtistExportModal from "./components/artistexportmodal.vue";
const currentInstance = getCurrentInstance();
const { $request } = currentInstance.appContext.config.globalProperties;
const state = reactive({
  openCount: 0,
  exportDialogVisible: false,

  tableConfig: {
    rowKey: "accId",
    refreshCount: 0,
    listUrl: {
      url: "api/user/view/list/get",
      params: [
        {
          label: "isArtist",
          value: 2,
        },
        {
          label: "omitFields",
          value: [
            "exist_index_supply_data",
            "exist_pending_artwork_supply_data",
          ],
        },
      ],
    },
    // 画家姓名 邀请人
    searchConfig: [
      {
        class: "fl-mt-sm",
        type: "inputsearch",
        label: "画家姓名",
        field: "artistName",
      },
      {
        class: "fl-mt-sm",
        type: "text",
        label: "邀请人",
        field: "multInviterName",
      },
      {
        class: "fl-mt-sm",
        type: "text",
        label: "画家编号",
        field: "tnum",
      },
      {
        class: "fl-mt-sm",
        type: "select",
        label: "画家优先级",
        field: "LowState",
        clearable: true,
        config: {
          options: [
            {
              label: "低优先级",
              value: 1,
            },
            {
              label: "非低优先级",
              value: 2,
            },
          ],
        },
      },
      {
        class: "fl-mt-sm",
        type: "select",
        label: "性别",
        field: "sex",
        clearable: true,
        config: {
          options: [
            {
              label: "男",
              value: "男",
            },
            {
              label: "女",
              value: "女",
            },
          ],
        },
      },
      {
        class: "fl-mt-sm",
        type: "text",
        label: "籍贯",
        field: "nativePlace",
      },
      {
        class: "fl-mt-sm",
        type: "rangnum",
        label: ["合作次数起", "合作次数止"],
        clearable: true,
        field: ["artShowCountStart", "artShowCountEnd"],
        value: [null, null],
        style: "width: 340px;",
      },
    ],
    columns: [
      {
        width: 120,
        type: "select",
        label: "当前流程状态",
        field: "isLock",
        options: [
          {
            label: "锁定",
            value: true,
            class: "status-primary",
          },
          {
            label: "未锁定",
            value: false,
            class: "status-draft",
          },
        ],
      },
      {
        width: 120,
        type: "select",
        label: "导入状态",
        field: "insource",
        options: [
          {
            label: "画家服务",
            value: 1,
          },
          {
            label: "未导入",
            value: 2,
          },
          {
            label: "已导入",
            value: 3,
          },
        ],
      },
      {
        width: 100,
        label: "合作次数",
        field: "artShowCount",
      },
      {
        width: 160,
        label: "画家姓名",
        field: "artistShowCount",
        remark: {
          show: "[%=lowState%]==='1'",
          title: "低优先级",
          titleClass: "font-12 color-draft",
        },
      },
      {
        width: 100,
        label: "画家编号",
        field: "tnum",
      },
      {
        label: "笔名",
        field: "penName",
      },
      {
        label: "艺名",
        field: "stageName",
      },
      {
        label: "性别",
        field: "sex",
      },
      {
        label: "年龄",
        field: "age",
      },
      {
        width: 180,
        label: "身份证号",
        field: "idNum",
      },
      {
        width: 120,
        label: "手机号",
        field: "telNum",
      },
      {
        type: "select",
        width: 120,
        label: "是否党员",
        field: "isCpc",
        options: [
          {
            label: "未填写",
            value: 0,
          },
          {
            label: "是",
            value: 1,
          },
          {
            label: "否",
            value: 2,
          },
        ],
      },
      {
        type: "select",
        width: 120,
        label: "党派",
        field: "faction",
        options: [
          {
            label: "未填写",
            value: 0,
          },
          {
            label: "中国共产党",
            value: 1,
          },
          {
            label: "中国国民党革命委员会",
            value: 2,
          },
          {
            label: "中国民主同盟",
            value: 3,
          },
          {
            label: "中国民主建国会",
            value: 4,
          },
          {
            label: "中国民主促进会",
            value: 5,
          },
          {
            label: "中国农工民主党",
            value: 6,
          },
          {
            label: "中国致公党",
            value: 7,
          },
          {
            label: "九三学社",
            value: 8,
          },
          {
            label: "台湾民主自治同盟",
            value: 9,
          },
        ],
      },
      {
        type: "select",
        width: 120,
        label: "是否体制内",
        field: "isSystemUnit",
        options: [
          {
            label: "未填写",
            value: 0,
          },
          {
            label: "是",
            value: 1,
          },
          {
            label: "否",
            value: 2,
          },
        ],
      },
      {
        type: "tooltip",
        label: "邀请人",
        field: "inviterRealName",
      },
      {
        width: 120,
        label: "籍贯",
        field: "nativePlace",
      },
      { type: "array", width: 120, label: "联系地址", field: "address" },
      {
        width: 120,
        label: "开户银行",
        field: "bankName",
      },
      {
        label: "开户账号",
        field: "bankNum",
        width: 180,
      },
      {
        width: 120,
        popover: true,
        type: "image",
        label: "银行卡(正)",
        field: "bankFrontImg",
      },
      {
        width: 120,
        popover: true,
        type: "image",
        label: "银行卡(反)",
        field: "bankBackImg",
      },
      { type: "tooltip", label: "个人简历", field: "artistProfile" },
      {
        width: 120,
        popover: true,
        type: "image",
        label: "身份证(正)",
        field: "idcardFront",
      },
      {
        width: 120,
        popover: true,
        type: "image",
        label: "身份证(反)",
        field: "idcardBack",
      },
      {
        width: 120,
        popover: true,
        type: "image",
        label: "画家近照",
        field: "photo",
      },
      {
        sorter: true,
        label: "申请时间",
        field: "createdAt",
        width: 120,
      },
      {
        label: "更新时间",
        field: "updatedAt",
        width: 100,
      },
      {
        width: 120,
        title: "操作",
        actions: [
          {
            type: "danger",
            label: "锁定",
            show: "[%=isLock%]===false",
            shape: "round",
            permission: "r_ps_artist_btn_lock",
            class: "fl-mx-xs fl-mt-xs",
            actionUrl: {
              url: "api/user/lock",
              params: [
                {
                  label: "accId",
                  field: "accId",
                },
                {
                  label: "isLock",
                  value: true,
                },
              ],
            },
          },
          {
            type: "primary",
            label: "解锁",
            show: "[%=isLock%]===true",
            shape: "round",
            permission: "r_ps_artist_btn_unlock",
            class: "fl-mx-xs fl-mt-xs",
            actionUrl: {
              url: "api/user/lock",
              params: [
                {
                  label: "accId",
                  field: "accId",
                },
                {
                  label: "isLock",
                  value: false,
                },
              ],
            },
          },
          {
            type: "primary",
            tooltip: true,
            show: "[%=insource%]===1||[%=insource%]===2",
            label: "导入",
            shape: "round",
            permission: "r_ps_artist_btn_createimport",
            class: "fl-mx-xs fl-mt-xs",
            actionUrl: {
              url: "api/artist/import",
              params: [
                {
                  label: "artistUid",
                  field: "artistUid",
                },
              ],
            },
          },
          {
            type: "danger",
            show: "[%=isLock%]===true",
            label: "撤销锁定",
            shape: "round",
            permission: "r_ps_artist_btn_revoke",
            class: "fl-mx-xs fl-mt-xs",
            actionUrl: {
              url: "api/user/lockRollback",
              params: [
                {
                  label: "uid",
                  field: "artistUid",
                },
              ],
            },
          },
        ],
      },
    ],
    slotRightClass: "col-12 row",
    tableBatchActionsClass: "col-12 row justify-end",
    tableBatchActions: [
      {
        notLimitSelect: true,
        actionType: "export_dialog",
        type: "primary",
        hasTableData: true,
        label: "导出画家信息",
      },
    ],
  },
});
onBeforeMount(() => {});
onMounted(() => {});

const handleRowActions = (btnConfig, rowData) => {};

const handleTableBatchActions = (selectedRows, config, rowData) => {
  if (config.actionType === "export_dialog") {
    state.exportDialogVisible = true;
    state.openCount++;
  }
};
const handleCloseExport = () => {
  state.exportDialogVisible = false;
};
</script>
<style scoped></style>
