import React from 'react';
import Invoice from '../..';

const InvoiceController = Invoice.InvoiceController;

export default () => {
  const controller = React.useMemo(() => new MyInvoiceController(), []);
  return (
    <div>
      <Invoice controller={controller} />
    </div>
  );
};

/**
 * 继承 InvoiceController 并重写需要重写的方法
 */
class MyInvoiceController extends InvoiceController {

  constructor() {
    super();
    this.state.autoComplete.onItemNameSearch = async text => {
      return [
        {
          "itemName": "呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵",
          "taxClassificationCode": "1010112070000000000",
          "itemModelName": null,
          "shorthand": "蔬菜",
          "taxRate": undefined
        },
        {
          "itemName": "呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵呵",
          "taxClassificationCode": "1010112070000000000",
          "itemModelName": null,
          "shorthand": "蔬菜",
          "taxRate": undefined
        },
        {
          "itemName": "稻谷",
          "taxClassificationCode": "1010101040000000000",
          "itemModelName": null,
          "shorthand": "谷物",
          "taxRate": 3
        },
        {
          "itemName": "苹果",
          "taxClassificationCode": "1090111090000000000",
          "itemModelName": null,
          "shorthand": "小型起重设备",
          "taxRate": null
        },
        {
          "itemName": "银丝",
          "taxClassificationCode": "1080411120000000000",
          "itemModelName": null,
          "shorthand": "金属制品",
          "taxRate": 3
        },
        {
          "itemName": "布料",
          "taxClassificationCode": "1100101011100000000",
          "itemModelName": null,
          "shorthand": "发电",
          "taxRate": 2
        },
      ].slice() as any
    }
  }

  updateInvoiceNo = this.pipeline(async s => {
    return '--';
  })
}
