qr-painter.js 9.67 KB
import dayjs from 'dayjs';
export default {
  data() {
    return {
      posterCss: { width: '150rpx', height: '150rpx', padding: '11rpx', backgroundColor: '#FFFFFF', borderRadius: '50%', objectFit: 'cover' }, // 二维码大小样式
      QRcss: { position: 'fixed', left: '52rpx', bottom: '24rpx', display: 'flex' }, // 二维码定位样式
    };
  },
  methods: {
    saveQrImage() {
      this.$refs.painter.canvasToTempFilePathSync({
        fileType: 'jpg',
        // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
        pathType: 'url',
        quality: 1,
        success: res => {
          uni.saveImageToPhotosAlbum({
            filePath: res.tempFilePath,
            success: () => {
              this.qrShow = false;
              uni.showToast({ title: '保存成功', icon: 'none' });
            },
          });
        },
      });
    },
    getPoster(item, params, wxcode) {
      let driverInfo = item.driverName ? item.driverName : '';
      driverInfo += item.driverMobile ? item.driverMobile : '';
      let vehicle = item.vehicleLicenseNum;
      if (item.trailerLicenseNum) {
        vehicle += '·' + item.trailerLicenseNum;
      }
      return {
        css: {
          width: '640rpx',
          height: '880rpx',
          backgroundImage: 'url(https://zeyi-tms-product.oss-cn-hangzhou.aliyuncs.com/image/freight/b6988d70-26db-490c-9ddf-e59c554fa2ff.png)',
          objectFit: 'cover',
        },
        views: [
          {
            type: 'view',
            views: [
              {
                type: 'text',
                text: '订  单 号:',
                css: {
                  width: '300rpx',
                  height: '33rpx',
                  fontSize: '24rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#999999',
                  lineHeight: '33rpx',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '169rpx',
                  left: '75rpx',
                },
              },
              {
                type: 'text',
                text: params.code,
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '24rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#121212',
                  lineHeight: '33rpx',
                  overflow: 'hidden',
                  textOverflow: 'ellipsis',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '169rpx',
                  left: '195rpx',
                },
              },
              {
                type: 'text',
                text: '任务日期:',
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '24rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#999999',
                  lineHeight: '33rpx',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '204rpx',
                  left: '75rpx',
                },
              },
              {
                type: 'text',
                text: dayjs(params.loadTime).format('YYYY-MM-DD'),
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '24rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#121212',
                  lineHeight: '33rpx',
                  overflow: 'hidden',
                  textOverflow: 'ellipsis',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '204rpx',
                  left: '195rpx',
                },
              },
              {
                type: 'text',
                text: params.startCityName + '-' + params.startAreaName,
                css: {
                  width: '400rpx',
                  height: '40rpx',
                  fontSize: '36rpx',
                  fontSamily: 'PingFangSC-Semibold, PingFang SC',
                  fontWeight: '600',
                  color: '#051B33',
                  lineHeight: '40rpx',
                  overflow: 'hidden',
                  textOverflow: 'ellipsis',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '270rpx',
                  left: '129rpx',
                },
              },
              {
                type: 'text',
                text: params.endCityName + '-' + params.endAreaName,
                css: {
                  width: '400rpx',
                  height: '40rpx',
                  fontSize: '36rpx',
                  fontSamily: 'PingFangSC-Semibold, PingFang SC',
                  fontWeight: '600',
                  color: '#051B33',
                  lineHeight: '40rpx',
                  overflow: 'hidden',
                  textOverflow: 'ellipsis',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '405rpx',
                  left: '129rpx',
                },
              },
              {
                type: 'text',
                text: '总里程:' + item.distance + 'KM',
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '24rpx',
                  fontWeight: '400',
                  fontSamily: 'PingFangSC-Medium, PingFang SC',
                  color: '#999999',
                  lineHeight: '33rpx',
                  position: 'fixed',
                  top: '345rpx',
                  left: '129rpx',
                },
              },
              {
                type: 'text',
                text: '订单备注:',
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '24rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#999999',
                  lineHeight: '33rpx',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '477rpx',
                  left: '75rpx',
                },
              },
              {
                type: 'text',
                text: params.remark,
                css: {
                  width: '350rpx',
                  height: '33rpx',
                  fontSize: '24rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#121212',
                  lineHeight: '33rpx',
                  overflow: 'hidden',
                  textOverflow: 'ellipsis',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '477rpx',
                  left: '195rpx',
                },
              },
              {
                type: 'text',
                text: '司 机:',
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '26rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#FFFFFF',
                  lineHeight: '33rpx',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '564rpx',
                  left: '75rpx',
                },
              },
              {
                type: 'text',
                text: driverInfo,
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '26rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#FFFFFF',
                  lineHeight: '33rpx',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '564rpx',
                  left: '180rpx',
                },
              },
              {
                type: 'text',
                text: '车牌号:' + vehicle,
                css: {
                  width: '400rpx',
                  height: '33rpx',
                  fontSize: '26rpx',
                  fontSamily: 'PingFangSC-Regular',
                  color: '#FFFFFF',
                  lineHeight: '33rpx',
                  display: 'block',
                  boxOrient: 'vertical',
                  lineClamp: 1 /* 这里是超出几行省略 */,
                  position: 'fixed',
                  top: '613rpx',
                  left: '75rpx',
                },
              },
            ],
          },
          {
            type: 'view',
            css: this.QRcss,
            views: [
              {
                src: wxcode,
                type: 'image',
                css: this.posterCss,
              },
            ],
          },
        ],
      };
    },
  },
};