import * as api from './api';
import { CreateCrudOptionsProps, CreateCrudOptionsRet, UserPageQuery } from '@fast-crud/fast-crud';
import { inject } from 'vue';
import { parseQueryParams } from '/@/views/adManage/utils/tools.js';
import XEUtils from 'xe-utils';


export const createCrudOptions = function({ crudExpose, context }: CreateCrudOptionsProps): CreateCrudOptionsRet {
  const pageRequest = async (query: UserPageQuery) => {
    const params = parseQueryParams(context.value);
    XEUtils.assign(query, params);
    return await api.GetList(query);
  };

  //权限判定
  const hasPermissions = inject('$hasPermissions');

  return {
    crudOptions: {
      table: {},
      container: {
        fixedHeight: false
      },
      actionbar: {
        show: false
      },
      search: {
        show: true,
        buttons: {
          search: {
            show: false
          },
          reset: {
            show: false
          }
        }
      },
      // toolbar: {
      //   buttons: {
      //     search: {
      //       show: true,
      //     },
      //     compact: {
      //       show: false,
      //     },
      //   },
      // },
      request: {
        pageRequest
      },
      rowHandle: {
        show: false
      },
      columns: {
        searchTerm: {
          title: '搜索词',
          column: {
            width: '200px',
            fixed: 'left'
          }
        },
        Impression: {
          title: '曝光量',
          column: {
            align: 'center'
          }
        },
        Click: {
          title: '点击量',
          column: {
            align: 'center'
          }
        },
        Spend: {
          title: '花 费',
          column: {
            align: 'center'
          }
        },
        TotalPurchases: {
          title: '订单数',
          column: {
            align: 'center'
          }
        },
        TotalSales: {
          title: '花 费',
          column: {
            align: 'center'
          }
        },
        TotalUnitOrdered: {
          title: '销 量',
          column: {
            align: 'center'
          }
        },
        TotalSalesSameSKU: {
          title: '推广商品销售额',
          column: {
            width: '180',
            align: 'center'
          }
        },
        TotalSalesOtherSKU: {
          title: '其他商品销售额',
          column: {
            width: '180',
            align: 'center'
          }
        },
        TotalPurchasesSameSKU: {
          title: '推广商品订单数',
          column: {
            width: '180',
            align: 'center'
          }
        },
        TotalPurchasesOtherSKU: {
          title: '其他商品订单数',
          column: {
            width: '180',
            align: 'center'
          }
        },
        TotalUnitOrderedSameSKU: {
          title: '推广商品销量',
          column: {
            width: '180',
            align: 'center'
          }
        },
        TotalUnitOrderedOtherSKU: {
          title: '其它商品销量',
          column: {
            width: '180',
            align: 'center'
          }
        },
        CPC: {
          title: '点击成本',
          column: {
            width: '130',
            align: 'center'
          }
        },
        CTR: {
          title: '点击率',
          column: {
            align: 'center'
          }
        },
        PurchasesRate: {
          title: '转化率',
          column: {
            align: 'center'
          }
        },
        ACOS: {
          title: 'ACOS',
          column: {
            align: 'center'
          }
        },
        ROAS: {
          title: 'ROAS',
          column: {
            align: 'center'
          }
        },
        CPA: {
          title: '订单成本',
          column: {
            width: '130',
            align: 'center'
          }
        }
      }
    }
  };
};
