import { upcloud_base_strategy,  } from "@/config/serviceSettings";
const remote = function(value) {
  return {
    autoLoad: true,
    remoteUrl: {
      url: upcloud_base_strategy + '/enum/v1',
      params: { typeNname: value },
      headers: {
        'Content-Type': 'application/JSON'
      },
      method: 'get'
    },
    doneBefore(data) {
      if (data && data.success) {
        var da = data.data
        var arr = da.map(x => {
          return {
            label: x.key,
            value: x.value
          }
        })
        data.data = arr
      }
      return data
    }
  }
}

const tablecolumns = function(that) {
  return {
    gridform: {
      ref: 'itemsRef',
      items: [
        {
          type: 'input',
          span: 6,
          labelCol:{ span: 8 },
          name: 'likeName',
          label: '名称，全模糊匹配',
          value: '' //初始化值
        },
        {
          type: 'select',
          name: 'category',
          label: '因子分类',
          disabled: true,
          value: that.strategyType,
          span: 6,
          on: {
            change(value, label, options, form) {
              // form.setFieldsValue({ 'field-select': value }
            }
          },
          ...remote('strategy')
        },
        {
          type: 'select',
          name: 'type',
          label: ' 因子类型',
          value: '',
          span: 6,
          on: {
            change(value, label, options, form) {
              // form.setFieldsValue({ 'field-select': value })
            }
          },
          ...remote('factor')
        },

        {
          span: 6,
          type: 'buttonGroup',
          style: { textAlign: 'left' },
          options: [
            {
              value: '查询',
              icon: 'search',
              btnType: 'primary',
              style: 'margin-right:10px;margin-left:20px;',
              htmlType: 'submit'
            },
            {
              value: '重置',
              name: 'ccz',
              icon: 'redo',
              on: {
                click(event, form) {
                  form.resetFields()
                }
              }
            }
          ]
        }
      ]
    },

    //策略表
    MainTable: {
      ref: 'MainTable',
      rowkey: 'id',
      columns: [
        {
          title: '规则因子ID',
          dataIndex: 'id',
          key: 'id',
          hidden: true
        },
        {
          title: '因子名称',
          dataIndex: 'name',
          key: 'name'
        },
        {
          title: '因子类型',
          dataIndex: 'type',
          key: 'type',
          scopedSlots: { customRender: 'type' }
        },

        {
          title: '分类',
          dataIndex: 'category',
          key: 'category'
        },
        {
          title: '值类型',
          key: 'valueType',
          dataIndex: 'valueType'
        },
        {
          title: '字段名',
          dataIndex: 'fieldName',
          key: 'fieldName'
        },
        //   {
        //     title: '匹配类型',
        //     key: 'matchType',
        //     dataIndex: 'matchType'
        //   },
        {
          title: '数据源类型',
          key: 'datasourceType',
          dataIndex: 'datasourceType'
        },

        {
          title: '操作',
          key: 'operation',
          scopedSlots: { customRender: 'operation' },
          align: 'center'
        }
      ],
      RemoteUrl: {
        url: upcloud_base_strategy + '/factor/v1/page	',
        method: 'get',
        headers: {
          'Content-Type': 'application/JSON'
        }
        // data: JSON.stringify({ pageNum: 1, pageSize: 10 }),
      }
    },
    RuleTable: {
      ref: 'rule',
      rowkey: 'key',
      columns: [
        {
          title: '优先级',
          dataIndex: 'name',
          key: 'name'
        },
        {
          title: '规则名称',
          dataIndex: 'age',
          key: 'age'
        },
        {
          title: '规则状态',
          dataIndex: 'address',
          key: 'address'
        },

        {
          title: '操作',
          key: 'operation',
          align: 'center',
          scopedSlots: { customRender: 'operation' }
        }
      ]
    }
  }
}

export default tablecolumns
