<template>
  <view class="pageBox">
    <view class="container _test_page">
      <component-form_query 
        ref="queryFormRef"
        v-model:controls="queryForm.controls"
        v-model:data="queryForm.data"
        @submit="(e:any)=>query(e)"
      />

      <component-list 
        ref="queryListRef"
        v-model:data="queryList.data"
        v-model:fields="queryList.fields"
        v-model:buttons="queryList.buttons"
        select_box="checkbox"
        @row_click="(e:any)=>rowClick(e)"
      />
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, reactive, computed, onBeforeMount, onMounted, onUnmounted, watch, nextTick } from 'vue'
import Storage from '@/common/utils/storage/index'
import { onPullDownRefresh, onLoad } from '@dcloudio/uni-app'
import EXEC from '@/common/utils/exec';
import { translate } from '@/common/utils/language/index'
import { http } from '@/common/utils/request'
import pagesJson from '@/pages.json'

onBeforeMount(async() => {
})
onMounted(()=>{
})
onUnmounted(() => {
})

const queryFormRef = ref(null)
const queryForm = <any>reactive({
  data: {
    table_refer: 'sys_user',
  },
  controls:{
    comp_id: {
      type: 'select',
      select: {
        type: 'comp_id',
      },
    },
    user_id:{
      type: 'input',
    },
    user_type:{
      type: 'select',
      select: {
        type: 'user_type',
      },
    },
    valid:{
      type: 'select',
      select: {
        type: 'Y_OR_N',
      },
    },
    table_refer:{
      type: 'input',
    },
  },
})
const query = (e:any) => {
  http.get('/sec/sql_execute/t/query', {
    ...e,
    exec_type: 'query',
    start: 1,
    limit: 20,
    udf_param_json: {"container_id":"202310152226587747","run_id":"202311061326413019"},
    query_header_field: 'comp_name,user_id,user_name,user_type_name,operating_post_name,valid,all_customer,all_org,all_wh,all_project,super_admin,account_expiry_time,last_login_time,notes,add_who,add_time,edit_who,edit_time',
  }).then((result:any) => {
    queryList.data = result['result']
  })
}
const rowClick = (e:any) => {
  uni.navigateTo({
      url: `/common/views/pages/test_user/page2?params=${JSON.stringify({user_id: e.user_id})}`,
    })
}

const queryListRef = ref(null)
const queryList = <any>reactive({
  data: {},
  fields: [
    { field: 'user_name', lv:1, },
    { field: 'user_id', lv:2, },
    { field: 'operating_post_name',  showLabel: true, grid: 2},
    { field: 'user_type_name', isStatus: true,  showLabel: true, expand: true },
    { field: 'valid',  showLabel: true, expand: true},
    { field: 'all_customer',  showLabel: true, expand: true},
    { field: 'all_org',  showLabel: true, expand: true},
    { field: 'all_wh',  showLabel: true, expand: true},
    { field: 'all_project',  showLabel: true, expand: true},
    { field: 'super_admin',  showLabel: true, expand: true},
    { field: 'account_expiry_time',  showLabel: true, expand: true, grid: 2},
  ],
  buttons:[
    {
      field: 'del',
      label: '删除',
      type: 'danger',
      click: (e:any) => {
      }
    }
  ]
})

</script>

<style lang="scss">
._test_page{
  background: #eaf1f7;
}
</style>
