<template>
  <div class="app-container pageTopForm">
    <el-form :model="queryParams" ref="queryRef" v-show="showSearch" size="small" label-width="68px" class="demo-ruleForm">
      <el-col :span="6">
        <el-form-item label="脚本名称" prop="scriptName">
          <el-input
            v-model="queryParams.scriptName"
            placeholder="请输入脚本名称"
            clearable
            @keyup.enter.native="handleQuery"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item class="lastBtnSty">
          <el-button type="primary" size="mini" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-col>
    </el-form>
    <TableList :columns="columns" :config="config" :modelIdent="this.$options.name" :queryParams="queryParams" :tableList="roleList" @fnClick="callback" @fnRenderList="getList" @value-change="handleValueChange"></TableList>
  </div>
</template>

<script setup>
  import TableList from "@/components/table/index.vue"
  import {listBusScript, delBusScript} from "@/api/disRevenue/earnManage"
  export default {
    name: 'BusinessScript',
    components: {TableList},
    data() {
      return {
        editStatus: false,
        loading: false,
        showSearch: true,
        roleList: [],
        queryParams: {
          total: 0,
          pageNum: 1,
          pageSize: 10
        },
        // 列显隐信息
        columns: {
          id: {label: 'ID'},
          scriptName: { label: `脚本名称`, visible: true},
          scriptPath: { label: `脚本文件地址`, visible: true},
          defaultParams: { label: `脚本默认参数`, visible: true},
        },
        config: {
          searcherForm: [
            {label: '资源组名称', prop: 'groupName', type: 'input'}
          ],
          tableButton: {
            top: [
              {content: '新增', fnCode: 'add', type: 'primary', icon: 'el-icon-plus', hasPermi: 'earnManage:businessScript:add'},
            ],
            line: [
              {content: '修改', fnCode: 'edit', type: 'text', icon: 'el-icon-edit', hasPermi: 'disRevenue:earnManage:businessScript:edit'},
              {content: '详情', fnCode: 'details', type: 'text', icon: 'el-icon-view', hasPermi: 'disRevenue:earnManage:businessScript:details'},
              {content: '删除', fnCode: 'delete', type: 'text', icon: 'el-icon-delete', hasPermi: 'disRevenue:earnManage:businessScript:delete'},
            ]
          }
        }
      }
    },
    created() {
      this.getList();
    },
    activated() {
      this.$nextTick(() => {
        this.getList();
      });
    },
    methods: {
      rowDataChange(row) {
        this.$set(row, 'editStatus', true);
      },
      // 处理子组件传递的新值
      handleValueChange(newValue) {
        // 父组件更新自身数据，实现同步
        this.showSearch = newValue;
        // console.log('父组件拿到新值:', newValue);
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        listBusScript(this.queryParams).then(response => {
          this.roleList = response.rows;
          this.queryParams.total = response.total;
          this.loading = false;
        })
      },

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryRef");
        this.handleQuery();
      },

      callback(result, rowData, selectChange) {
        if (result && result.fnCode) {
          switch (result.fnCode) {
            case 'add':
              this.$router.push({
                path:'/earnManage/businessScript/details'});
              break;
            case 'edit':
              this.$router.push({
                path:'/earnManage/businessScript/details',
                query: {
                  id: rowData.id
                }
              });
              break;
            case 'details':
              this.$router.push({
                path:'/earnManage/businessScript/details',
                query:{
                  id: rowData.id,
                  readonly: true
                }
              });
              break;
            case 'delete':
              this.$modal.confirm('是否确认删除数据项？').then(function() {
                return delBusScript(rowData.id)
              }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功")
              }).catch(() => {});
              break;
            case 'export':
              // let dataList = [];
              // Object.keys(this.columns).forEach(item => {
              //   if (item.visible) {
              //     dataList.push(item.prop);
              //   }
              // });
              // this.download("/system/Business/export", {properties: dataList,}, `业务管理_${new Date().getTime()}.xlsx`);
              let paramsList = Object.assign({}, this.queryParams,rowData);
              this.download("system/businessScript/export", paramsList, `业务脚本管理_${new Date().getTime()}.xlsx`, null, 'json');
              break;
            default:

          }
        }
      }
    }
  }
</script>
<style scoped>
  ::v-deep .lastBtnSty .el-form-item__content{
    margin-left: 10px!important;
  }
</style>
