import VtxBaseModal from "../../../../vtx-base-modal";
import React from 'react';
import { CcService } from "../../../api";
import { getVtxToken } from '@vtx/utils';
import "./index.less";
import { Button, Image, message, Space } from 'antd';
import { VmInfoCollection, VmTable, VmTitle, VmWrapper } from "../../../../_components";
import useSettings from "../../../../_hooks/useSettings";
import { paramSerializer } from "../../../../_util";
import dayjs from "dayjs";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
var Content = function Content(_ref) {
  var data = _ref.data;
  var _CcService$useWeightL = CcService.useWeightList(data.carId, data.collectStartTime, data.collectEndTime),
    weightList = _CcService$useWeightL.weightList;
  var infoData = [{
    label: '联单编号',
    value: data.draftCode,
    key: 'draftCode'
  }, {
    label: '收运单位名称',
    value: data.collectUnitName,
    key: 'collectUnitName'
  }, {
    label: '车牌号',
    value: data.carCode,
    key: 'carCode'
  }, {
    label: '收运人员',
    value: data.collectStaffNames,
    key: 'collectStaffNames'
  }, {
    label: '垃圾类型',
    value: data.garbageTypeStr,
    key: 'garbageTypeStr'
  }];
  var columns = [{
    title: '产生单位名称',
    dataIndex: 'restaurantName'
  }, {
    title: '桶数（桶）',
    dataIndex: 'trashNum',
    align: 'right'
  }, {
    title: '重量（kg）',
    dataIndex: 'netWeight',
    align: 'right'
  }, {
    title: '收运时间（时分）',
    dataIndex: 'weighTime',
    render: function render(text) {
      return text ? dayjs(text).format('HH:mm') : '';
    }
  }, {
    title: '产生单位签字',
    dataIndex: 'restaurantSignature',
    render: function render(text) {
      return text ? /*#__PURE__*/_jsx(Image, {
        src: "/vortex/rest/cloud/np/file/downloadFileThumbnail?outputQuality=0.5&scale=0.2&id=".concat(text, "&token=").concat(token),
        preview: {
          destroyOnClose: true,
          src: "/cloudFile/common/downloadFile?id=".concat(text, "&token=").concat(token),
          maskClassName: 'maskClass'
        },
        alt: "\u7B7E\u5B57",
        style: {
          width: 100,
          height: 100
        }
      }) : '-';
    }
  }];
  var columns2 = [{
    title: '处置单位名称',
    dataIndex: 'disposeUnitName'
  }, {
    title: '重量（kg）',
    dataIndex: 'carWeight',
    align: 'right'
  }, {
    title: '入场时间',
    dataIndex: 'collectStartTime'
  }, {
    title: '处置单位签字',
    dataIndex: 'factorySignFileId',
    render: function render(text) {
      return text ? /*#__PURE__*/_jsx(Image, {
        src: "/vortex/rest/cloud/np/file/downloadFileThumbnail?outputQuality=0.5&scale=0.2&id=".concat(text, "&token=").concat(token),
        preview: {
          destroyOnClose: true,
          src: "/cloudFile/common/downloadFile?id=".concat(text, "&token=").concat(token),
          maskClassName: 'maskClass'
        },
        alt: "\u7B7E\u5B57",
        style: {
          width: 100,
          height: 100
        }
      }) : '-';
    }
  }];
  var token = getVtxToken('token');
  var onDownload = function onDownload() {
    var params = {
      id: data.id,
      token: getVtxToken('token')
    };
    if (data.collectStartTime && data.collectEndTime) {
      window.location.href = "/cloud/cc-reborn/api/v101/draftDisposeUnit/draftPdfDownload?".concat(paramSerializer(params));
    } else {
      message.warn('该收运联单没有称重记录，无法下载');
    }
  };
  var disposeUnitName = data.disposeUnitName,
    disposeUnitCode = data.disposeUnitCode,
    collectStartTime = data.collectStartTime,
    carWeight = data.carWeight,
    factorySignFileId = data.factorySignFileId;
  var weighbridge = [{
    disposeUnitName: disposeUnitName,
    disposeUnitCode: disposeUnitCode,
    collectStartTime: collectStartTime,
    carWeight: carWeight,
    factorySignFileId: factorySignFileId
  }];
  return /*#__PURE__*/_jsx("div", {
    style: {
      padding: 10
    },
    children: /*#__PURE__*/_jsx(VmWrapper, {
      title: "\u8054\u5355\u4FE1\u606F",
      extra: /*#__PURE__*/_jsx(Space, {
        children: /*#__PURE__*/_jsx(Button, {
          onClick: function onClick() {
            return onDownload();
          },
          type: 'primary',
          children: "\u5BFC\u51FA\u8054\u5355"
        })
      }),
      children: /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(VmInfoCollection, {
          data: infoData,
          horizontal: true,
          width: "50%",
          ellipsis: true
        }), /*#__PURE__*/_jsx(VmTitle, {
          title: '收运信息'
        }), /*#__PURE__*/_jsx(VmTable, {
          columns: columns,
          dataSource: weightList || [],
          height: 220,
          pagination: false
        }), /*#__PURE__*/_jsx(VmTitle, {
          title: '处置信息'
        }), /*#__PURE__*/_jsx(VmTable, {
          columns: columns2,
          dataSource: weighbridge || [],
          height: 220,
          pagination: false
        })]
      })
    })
  });
};
var Detail = function Detail(_ref2) {
  var onCancel = _ref2.onCancel,
    info = _ref2.info;
  var _useSettings = useSettings(),
    theme = _useSettings.theme;
  return /*#__PURE__*/_jsx(VtxBaseModal, {
    title: '联单管理 > ',
    subTitle: '查看',
    tabs: [{
      key: 'info'
    }],
    contents: {
      info: /*#__PURE__*/_jsx(Content, {
        data: info
      })
    },
    visible: true,
    onCancel: onCancel,
    theme: theme
  });
};
export default Detail;