SignDialog.vue 5.31 KB
<template>
  <GLDialog v-if="dialogShow" bigTitle="签名预设" mode="big" :visible.sync="dialogShow" :close-on-click-modal="false" @onCancel="handleDetailClose">
    <div class="table-wrap" v-loading="btnLoading || loading">
      <div class="sign-box">
        <div class="red-txt">*空白区域内写下名字</div>
        <div class="background-text">签字区</div>
        <div class="signature-container">
          <VueSignaturePad width="100%" height="100%" ref="signaturePad" :options="options" />
        </div>
      </div>
    </div>
    <template slot="footer">
      <span class="dialog-footer">
        <el-button plain size="small" class="btn-three" @click="clear" :disabled="btnLoading || loading">重写</el-button>
        <el-button plain size="small" class="btn-three" @click="undo" :disabled="btnLoading || loading">撤销</el-button>
        <el-button type="primary" size="small" @click="save" :loading="btnLoading || loading">确定</el-button>
      </span>
    </template>
  </GLDialog>
</template>

<script>
import * as dayjs from 'dayjs'
export default {
  name: 'SignDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default: () => { }
    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  data() {
    return {
      options: {
        penColor: '#000',
        minWidth: 1,
        maxWidth: 2,
        dotSize: 1,
        velocityFilterWeight: 0.7,
        backgroundColor: 'rgba(255, 255, 255, 0.0)'
      },
      loading: false,
      btnLoading: false,
      dayjs: dayjs,
      detailInfo: {}
    }
  },
  created() { },
  methods: {
    undo() {
      this.$refs.signaturePad.undoSignature()
    },
    clear() {
      this.$refs.signaturePad.clearSignature()
    },
    save() {
      // if (!this.$refs.signaturePad) {
      //   this.$message.warning('签名组件未加载')
      //   return
      // }
      const { isEmpty, data } = this.$refs.signaturePad.saveSignature()
      if (this.loading) {
        return
      }
      if (isEmpty) {
        this.$message({
          message: '请先完成签名',
          type: 'warning',
          customClass: 'message-Z-zinde'
        })
        return
      }
      console.log(data, '保存图片----')
      const base64 = 'png@' + data.split('base64,')[1]
      this.loading = true
      this.$apis.sysBase.uploadImg({ file: base64, fileType: 'image' }).then(res => {
        console.log(res, 'res----')
        this.deliverySign(res)
      }).catch(() => {
        this.loading = false
      })
    },
    deliverySign(url) {
      if (this.btnLoading) {
        return true
      }
      const params = {
        id: this.info.orderDeliveryId,
        signFileUrl: url
      }
      this.btnLoading = true
      console.log(params, 'params----')
      this.$apis.sign.addSign(params)
        .then(res => {
          if (res.code == 0) {
            this.$message({
              message: '签名预设成功',
              type: 'success',
              customClass: 'message-Z-zinde'
            })
            this.$emit('handleConfirm')
          } else {
            this.$message({
              type: 'error',
              message: res.message,
              customClass: 'message-Z-zinde'
            })
          }
        })
        .finally(() => {
          this.btnLoading = false
        })
    },
    handleDetailClose() {
      this.$emit('handleClose')
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #666666ff;
  font-size: 14px;
  margin-bottom: 16px;

  span {
    color: #333333ff;
  }

  .add-btn {
    font-size: 14px;
    color: #5850ff;
    cursor: pointer;
  }
}

.table-wrap {
  // border: 1px solid #e5e5e5;
  // padding: 16px;
  // box-sizing: border-box;
  margin: 30px 0;

  ::v-deep .el-form-item__error {
    padding-top: 2px;
    z-index: 9999999;
    position: static;
  }
  .sign-box {
    position: relative;
    width: 640px;
    height: 226px;
    border-radius: 4px;
    opacity: 1;
    border: 1px solid #e5e5e5;
    background: #fafafa;
    margin: 24px auto 19px;

    .signature-container {
      position: relative;
      width: 640px;
      height: 226px;
    }

    .background-text {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 100%;
      text-align: center;
      color: #ededed;
      font-size: 88px;
      pointer-events: none;
    }

    ::v-deep .vue-signature-pad {
      position: relative;
      z-index: 2;
    }
    .red-txt {
      position: absolute;
      top: 8px;
      left: 262.5px;
      text-align: center;
      color: #eb4e4e;
      font-size: 12px;
    }
    .btns {
      position: absolute;
      bottom: 8px;
      right: 12px;
      display: flex;
      flex-direction: row-reverse;
      .el-button--mini {
        margin-left: 0px !important;
      }
    }
  }
}
::v-deep.el-button.is-plain.btn-three {
  opacity: 1 !important;
}
.look-card-wrap {
  max-height: 600px;
  overflow-y: scroll;
  overflow-x: hidden;

  ::v-deep.el-table th.el-table__cell > .cell {
    padding: 0 16px;
    text-align: center;
  }

  ::v-deep.el-table__body td.el-table__cell {
    text-align: center;
  }
}
</style>