const defaultProps = {
  label: 'classificationName',
  children: 'children',
  value: 'classificationName'
}
export const modalConfig = (_this) => ({
  formItems: [
    {
      key: 'guaranteeYear',
      type: 'year',
      label: '保障年度',
      options: {
        placeholder: '请选择保障年度',
        'value-format': 'yyyy'
      },
      colLayout: { span: 24 }
    },
    { key: 'aircaftNumber', type: 'input', label: '飞机数量', colLayout: { span: 24 } },
    { key: 'aircaftDuration', type: 'input', label: '飞行时长（小时）', colLayout: { span: 24 } },
    { key: 'priceFactor', type: 'input', label: '价格因素', colLayout: { span: 24 } }
  ],
  labelWidth: '140px',
  itemStyle: { padding: '10px 7px' },
  width: '500px', // 弹框宽度
  rules: {
    guaranteeYear: [{ required: true, message: '请输入保障年度', trigger: 'blur' }],
    aircaftNumber: [{ required: true, message: '请输入飞机数量', trigger: 'blur' }],
    aircaftDuration: [{ required: true, message: '请输入飞行时长（小时）', trigger: 'blur' }],
    priceFactor: [
      { required: true, message: '请输入价格因素', trigger: 'blur' },
      {
        validator: (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请输入数字'))
          } else {
            const reg = /^(\d+|\d+\.\d+)$/
            if (reg.test(value)) {
              callback()
            } else {
              callback(new Error('请输入整数或小数'))
            }
          }
        }
      }
    ]
  }
})

/**
 *
 * @param {*} _this 当前vue 的实例
 * @returns  返回一个表格配置数组
 */

export const columns = (_this) => [
  {
    prop: 'guaranteeYear',
    label: '保障年度'
  },
  {
    prop: 'aircaftNumber',
    label: '飞机数量'
  },
  {
    prop: 'aircaftDuration',
    label: '飞行时长（小时）'
  },
  {
    prop: 'priceFactor',
    label: '价格因素'
  },
  {
    prop: 'yearTotalPrice',
    label: '总价'
  },
  {
    prop: 'unitPrice',
    label: '单架飞机保障价格'
  },
  {
    prop: 'perHourUnitPrice',
    label: '单架飞机/小时保障价格'
  },

  {
    prop: 'goodRate',
    label: '保障良好率',
    render: (h, params) => {
      return h('span', { style: '' }, `${params.row.goodRate}%`)
    }
  },

  {
    button: true,
    label: '操作',
    width: '240px',
    group: [
      {
        name: '编辑',
        type: 'text',
        round: false,
        plain: false,
        onClick: (row, index, scope) => {
          _this.handUpdate(row)
        }
      },
      {
        name: '删除',
        type: 'text',
        round: false,
        plain: false,
        onClick: (row, index, scope) => {
          _this.handRemove(row)
        }
      },
      {
        name: '价格清单',
        type: 'text',
        round: false,
        plain: false,
        onClick: (row, index, scope) => {
          _this.handPriceList(row)
        }
      }
    ]
  }
]

export const data = [
  {
    id: '1',
    guarantee: 2023,
    airplaneNumber: '80',
    flightLength: '20000',
    priceFactor: '1.1',
    guaranteedGood: '50%',
    zj: '1100',
    djfjbzjg: '5000',
    djfjbzjgxs: '21100'
  },
  { id: '2', guarantee: 2022, airplaneNumber: '60', flightLength: '18000', priceFactor: '1.2', guaranteedGood: '70%', zj: '1100', djfjbzjg: '5000', djfjbzjgxs: '21100' },
  { id: '3', guarantee: 2021, airplaneNumber: '50', flightLength: '17000', priceFactor: '1.3', guaranteedGood: '20%', zj: '1100', djfjbzjg: '5000', djfjbzjgxs: '21100' }
]
/**
 *
 * @returns 返回表格基础配置项
 */
export const options = {
  stripe: true, // 斑马纹
  mutiSelect: true, // 多选框
  index: false, // 显示序号， 多选则 mutiSelect
  loading: false, // 表格动画
  initTable: true, // 是否一挂载就加载数据
  border: true,
  height: 'calc(100vh - 300px)'
}
