<template>
  <div class="p-2">
    <!--查询区域-->
    <div class="jeecg-basic-table-form-container">
      <a-form ref="formRef" @keyup.enter.native="searchQuery" :model="queryParam" :label-col="labelCol"
        :wrapper-col="wrapperCol">
        <a-row :gutter="24">
          <a-col :lg="6">
            <a-form-item name="instructionTagId">
              <template #label><span title="分类标签">分类标签</span></template>
              <j-dict-select-tag v-model:value="queryParam.instructionTagId"
                :dictCode="`nu_config_service_instruction_tag,instruction_name,id,del_flag = 0 and iz_enabled = 0 order by sort asc`"
                :orgCode="queryParam.dataSourceCode" :ignoreDisabled="true" placeholder="请选分类标签" allowClear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="categoryId">
              <template #label><span title="服务类别">服务类别</span></template>
              <j-dict-select-tag type="list" v-model:value="queryParam.categoryId" :orgCode="queryParam.dataSourceCode"
                :dictCode="`nu_config_service_category,category_name,id,del_flag = 0 and iz_enabled = 0 and instruction_id = '${queryParam.instructionTagId || ''}' order by sort asc`"
                :ignoreDisabled="true" placeholder="请选择服务类别" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="typeId">
              <template #label><span title="服务类型">服务类型</span></template>
              <j-dict-select-tag type="list" v-model:value="queryParam.typeId" :orgCode="queryParam.dataSourceCode"
                :dictCode="`nu_config_service_type,type_name,id,del_flag = 0 and iz_enabled = 0 and category_id = '${queryParam.categoryId || ''}' order by sort asc`"
                placeholder="请选择服务类型" :ignoreDisabled="true" allowClear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="directiveName">
              <template #label><span title="服务指令">服务指令</span></template>
              <JInput v-model:value="queryParam.directiveName" placeholder="请输入服务指令名称" allowClear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="cycleType">
              <template #label><span title="周期类型">周期类型</span></template>
              <j-dict-select-tag type="list" v-model:value="queryParam.cycleType" :orgCode="queryParam.dataSourceCode"
                dictCode="period_type" placeholder="请选择周期类型" :ignoreDisabled="true" allowClear />
            </a-form-item>
          </a-col>
          <!-- <a-col :lg="6">
            <a-form-item name="bodyTags">
              <template #label><span title="体型标签">体型标签</span></template>
              <j-dict-select-tag type='list' v-model:value="queryParam.bodyTags"
                :dictCode="`nu_config_body_tag,tag_name,id,del_flag = '0' and iz_enabled = 0 order by sort asc`" :ignoreDisabled="true"
                placeholder="请选择体型标签" allowClear />
            </a-form-item>
          </a-col>
          <a-col :lg="6">
            <a-form-item name="emotionTags">
              <template #label><span title="情绪标签">情绪标签</span></template>
              <j-dict-select-tag type="list" v-model:value="queryParam.emotionTags"
                :dictCode="`nu_config_emotion_tag,tag_name,id,del_flag = '0' and iz_enabled = 0 order by sort asc`" :ignoreDisabled="true"
                placeholder="请选择情绪标签" allowClear />
            </a-form-item>
          </a-col> -->
          <!-- <a-col :lg="6">
            <a-form-item name="izEnabled">
              <template #label><span title="是否启用">是否启用</span></template>
              <j-dict-select-tag type='list' v-model:value="queryParam.izEnabled" dictCode="iz_enabled"
                :ignoreDisabled="true" placeholder="请选择是否启用" allowClear />
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-col :lg="6">
                <a-button type="primary" preIcon="ant-design:search-outlined" @click="searchQuery">查询</a-button>
                <a-button type="primary" preIcon="ant-design:reload-outlined" @click="searchReset"
                  style="margin-left: 8px">重置</a-button>
              </a-col>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--引用表格-->
    <BasicTable @register="registerTable">
      <!--插槽:table标题-->
      <template #tableTitle>
      </template>
      <template v-slot:bodyCell="{ column, record, index, text }">
        <template v-if="column.dataIndex === 'bodyTagList'">
          <span :title="text.map((item) => item.tagName).join('、')">{{text.map((item) =>
            item.tagName).join('、')}}</span>
        </template>
        <template v-if="column.dataIndex === 'emotionTagList'">
          <span :title="text.map((item) => item.tagName).join('、')">{{text.map((item) =>
            item.tagName).join('、')}}</span>
        </template>
      </template>
    </BasicTable>
  </div>
</template>

<script lang="ts" name="serviceDirective-configServiceDirective" setup>
import { ref, reactive, onMounted } from 'vue';
import { BasicTable, TableAction } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { columns, superQuerySchema } from './ConfigServiceDirective.data';
import { listByDS } from './ConfigServiceDirective.api';
import { useUserStore } from '/@/store/modules/user';
import JInput from "/@/components/Form/src/jeecg/components/JInput.vue";
import JDictSelectTag from '/@/components/Form/src/jeecg/components/JDictSelectTag.vue';
import { cloneDeep } from "lodash-es";
import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';

const formRef = ref();
const queryParam = reactive<any>({});
const toggleSearchStatus = ref<boolean>(false);
const registerModal = ref();
const userStore = useUserStore();
//注册table数据
const { prefixCls, tableContext, onExportXls, onImportXls } = useListPage({
  tableProps: {
    title: '服务指令',
    api: listByDS,
    columns,
    canResize: false,
    useSearchForm: false,
    showIndexColumn: true,
    showActionColumn: false,
    immediate: false,
    pagination: {
      current: 1,
      pageSize: 10,
      pageSizeOptions: ['10', '20', '50', '100'],
    },
    beforeFetch: async (params) => {
      queryParam.izEnabled = '0'
      return Object.assign(params, queryParam);
    },
    actionColumn: {
      width: 160,
      fixed: 'right',
    },
  },
});
const [registerTable, { reload, collapseAll, updateTableDataRecord, findTableDataRecord, getDataSource }, { rowSelection, selectedRowKeys }] = tableContext;
const labelCol = reactive({
  xs: 24,
  sm: 6,
  xl: 6,
  xxl: 6
});
const wrapperCol = reactive({
  xs: 24,
  sm: 18,
});


/**
 * 查询
 */
function searchQuery() {
  reload();
}

/**
 * 重置
 */
function searchReset() {
  formRef.value.resetFields();
  selectedRowKeys.value = [];
  //刷新数据
  reload();
}



function init(record) {
  queryParam.dataSourceCode = record.orgCode;
  reload();
}

defineExpose({
  init,
});
</script>

<style lang="less" scoped>
.jeecg-basic-table-form-container {
  padding: 0;

  .table-page-search-submitButtons {
    display: block;
    margin-bottom: 24px;
    white-space: nowrap;
  }

  .query-group-cust {
    min-width: 100px !important;
  }

  .query-group-split-cust {
    width: 30px;
    display: inline-block;
    text-align: center
  }

  .ant-form-item:not(.ant-form-item-with-help) {
    margin-bottom: 16px;
    height: 32px;
  }

  :deep(.ant-picker),
  :deep(.ant-input-number) {
    width: 100%;
  }
}

audio::-webkit-media-controls-timeline {
  display: none;
}

audio::-webkit-media-controls-current-time-display,
audio::-webkit-media-controls-time-remaining-display {
  display: none;
}

.btnPrivate {
  height: 34px;
  margin-left: 4px;
}
</style>
