import { MockMethod } from 'vite-plugin-mock';
import { mock, Random } from 'mockjs';
import { resultPageSuccess } from '../_util';
Random.extend({
  phone: function () {
    const phonePrefixs = ['132', '135', '189']; // 自己写前缀哈
    return this.pick(phonePrefixs) + mock(/\d{8}/); //Number()
  },
});
// console.log(Random.phone());
// 生成 1 - 10 个 随机手机号码

const demoList = (() => {
  const result: any[] = [];
  for (let index = 0; index < 200; index++) {
    const { phone } = mock({
      phone: '@phone',
    });
    const { phone2 } = mock({
      phone2: '@phone',
    });
    result.push({
      id: `${index}`,
      'orderNo|23': '@integer(0,9)',
      name: '@ctitle(5,15)',
      'orderType|1': [0, 1, 2, 3],
      'orderStatus|1': [0, 1, 2, 3],
      'shipingStatus|1': [0, 1],
      'paymentStatus|1': [0, 1],
      'shipingCompany|1': [
        '顺丰速运',
        'EMS',
        '韵达快递',
        '百世快递',
        '申通快递',
        '中通快递',
        '韵达快递',
      ],
      'shipingNo|28': '@integer(5,15)',
      'shipingAmount|2': '@integer(1,15)',
      shipingName: '@cname',
      shipingPhone: phone,

      shipingAddress: '@city(true)',
      deliverName: '@cname',
      deliverPhone: phone2,
      deliverAddress: '@city(true)',
      scene: {
        'id|1': '@integer(1,15)',
        name: '@ctitle(5,15)',
      },
      'amount|3': '@integer(1,15)',
      'totalAmount|3': '@integer(1,15)',
      createTime: '@datetime',
      paidTime: '@datetime',
    });
  }
  return result;
})();

export default [
  {
    url: '/basic-api/zfb/order/list',
    timeout: 1000,
    method: 'get',
    response: ({ query }) => {
      const { page = 1, pageSize = 20 } = query;
      return resultPageSuccess(page, pageSize, demoList);
    },
  },
] as MockMethod[];
