<template>
  <div>
    <el-button type="primary" size="small" @click="onShow">添加</el-button>
    <el-drawer
        title="添加数据过滤"
        :visible.sync="drawer"
        size="700px"
        direction="rtl"
        append-to-body
        :show-close="false"
        @close="drawer = false;$refs.form.resetFields()">
      <div class="drawer__panel">
        <el-row>
          <el-form :model="form" :rules="rules" ref="form"  size="mini" label-position="right">
            <el-col :span="24">
              <el-form-item label="表格名称:" label-width="90px" prop="table_name">
                <el-select v-model="form.table_name" filterable placeholder="请选择表格名称" style="width: 100%">
                  <el-option
                      v-for="item in tableData"
                      :key="item.table_name"
                      :label="item.table_name"
                      :value="item.table_name">
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="查询语句:" label-width="90px" prop="sqlstr">
                <el-input type="textarea" :rows="10" v-model="form.sqlstr" autocomplete="off" placeholder="请输入查询语句"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注:" label-width="90px" prop="sqlstr">
                <p>:userid 登陆的账号ID</p>
                <p>:sys_enterpriseid 登陆账号的所属企业ID，缺省值为0</p>
                <p>:departmentid 登陆账号的所属部门ID，缺省值为0</p>
                <p>:subuserids 登陆账号的下级账号ID，如[1,2,3]</p>
                <p>:subdepartmentids 登陆账号所在部门的下级部门ID，如[1,2,3]</p>
                <p>:hrid  人员ID</p>
                <p>:subhrids 下级人员ID</p>
                <p>:subsys_enterpriseids 下级企业ID</p>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="drawer = false;$refs.form.resetFields()" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: "filteringAdd",
  data(){
    return {
      param:{
        "classname": "sysmanage.develop.optiontype.optiontype",
        "method": "optiontypeselect",
        "content": {
          "pageNumber": 1,
          "pageSize": 20,
          "typename": 'tablenameselect',
          "parameter": {
          }
        }
      },
      loading: false,
      drawer:false,
      tableShow:false,
      tableData:[],
      options:[],
      total:0,
      currentPage:0,
      form:{
        roleid:'',
        sys_role_datalimitid:0,
        table_name:"",
        sqlstr:""
      },
      rules:{
        table_name: [
          { required: true, message: '请选择数据表', trigger: 'change' },
        ],
      }
    }
  },
  methods:{
    onShow(){
      this.drawer = true
      this.queryTable()
    },
    async queryTable(){
      this.$store.dispatch('optiontypeselect','tablenameselect').then(res=>{
        this.tableData = res.data
      })
    },
    checkTable(val){
      this.form.table_name = val.table_name
    },
    onSubmit(){
      this.$refs.form.validate(async(valid) =>{
        if (!valid) return false
        this.form.roleid = this.$route.query.id
        const res = await this.$api.requested({
            "id": 20230216181501,
            "content":this.form
        })
        this.tool.showMessage(res,()=>{
          this.drawer = false
          this.$refs.form.resetFields()
          this.$emit('addSuccess')
        })
      })
    },
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>