import request from '@/utils/request'
import { UPCLOUD_RDC_TMS_MAINDATA_SERVICE, UPCLOUD_RDC_TMS_BMS_SERVICE } from '@/config/serviceSettings.js'


//录入费用运单
const expenseCodeConfig = (self) => {
  return {
    tableConfig: {
      columns: [
        { dataIndex: 'id', title: 'ID', hidden: true },
        { dataIndex: 'expenseName', title: '费用名称' },
        { dataIndex: 'expenseCode', title: '费用编码' },
        { dataIndex: 'expenseTypeName', title: '费用类型' },
      ],
    },
    toolBar: {
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      items: [
        {
          type: 'input',
          name: 'expenseName',
          label: '费用名称',
          value: '',
        },
        {
          name: 'expenseCode',
          label: '费用编码',
          value: '',
        },
      ],
    },
    remoteUrl: {
      url: UPCLOUD_RDC_TMS_BMS_SERVICE + '/shipBill/feeManagement/v1.0',
      method: 'post',
    },
    rowKey: 'id',
    remoteData: { status: 1 },
  }
}

export default (self, expData = []) => {
  return [
    { dataIndex: 'id', title: 'ID', hidden: true, width: 100, type: 'txt' },
    { dataIndex: 'expenseID', title: '费用ID', hidden: true, type: 'txt' },
    {
      ...expenseCodeConfig(self),
      dataIndex: 'expenseCode',
      title: '费用编码',
      type: 'searchModal',
      targetClick: true,
      width: 120,
      required: true,
      targetValueKey: 'expenseCode',
      on: {
        change({ record, value, modalRowData, index }) {
          const { expenseName, id: expenseId, expenseAccountCode, expenseAccountName, expenseTypeName, expenseType } = modalRowData[0]
          record.expenseName = expenseName
          record.expenseId = expenseId
          value = record.expenseAccountCode = expenseAccountCode
          record.expenseAccountName = expenseAccountName
          record.expenseTypeName = expenseTypeName
          record.expenseType = expenseType
        },
      },
    },
    {
      dataIndex: 'expenseName',
      targetClick: false,
      type: 'txt',
      title: '费用名称',
      width: 120,
    },
    {
      dataIndex: 'expenseAccountCode',

      title: '费用科目编码',
      type: 'txt',
      width: 120,
    },
    {
      dataIndex: 'expenseAccountName',
      width: 120,

      title: '费用科目名称',
      type: 'txt',
    },
    { dataIndex: 'expenseTypeName', width: 120, title: '费用类型', type: 'txt' },
    { dataIndex: 'taxAmt', width: 120, title: '金额', type: 'txt',hidden:true },

    {
      width: 140,
      dataIndex: 'amount',
      title: '含税金额',
      type: 'number',
      align: 'center',
      defaultValue: 0,
      // fixed: 'right',
      on: {
        change({ value, record }) {
          self.handleMoney('amount', record, value)
        },
      },
    },
    {
      dataIndex: 'taxPoint',
      title: '税点',
      width: 80,
      type: 'select',
      align: 'center',
      get options() {
        return self.options?.TAX_POINT ?? []
      },
      required: true,
      defaultValue: 0,
      autoLoad: false,
      on: {
        change({ value, record }) {
          self.handleMoney('taxPoint', record, value)
        },
      }
    },


    {
      dataIndex: 'tax',
      title: '税额',
      width: 120,
      align: 'center',
      // type: 'number',
      type: 'txt',
      //  disabled: true,
      defaultValue: 0,

    },

    {
      type: 'txt',
      dataIndex: 'noTaxAmt',
      width: 120,
      align: 'center',
      title: '未税金额',
      defaultValue: 0,
    },
    {
      dataIndex: 'memo',
      title: '费用说明',
      width: 200,
      type: 'textarea',
      on: {
        change({ value, record }) {
          record.memo = value
          console.log(value)
        },
      },
    },

    {
      required: true,
      dataIndex: 'isShare',
      title: '费用操作',
      fixed: 'right',
      align: 'center',
      // disabled: true,
      width: 150,
      type: 'select',
      options: [
        {
          label: '费用分摊到每一单',
          value: 1,
        },
        {
          label: '费用到每一单',
          value: 0,
        },
      ],
      defaultValue: 1,


    },

    {
      type: 'delRow',
      fixed: 'right',
      width: 40,
      align: 'center',
    },
  ]
}
