SignDialog.vue 9.75 KB
<template>
  <GLDialog v-if="dialogShow" bigTitle="确认签收" mode="big" :visible.sync="dialogShow" :close-on-click-modal="false" @onCancel="handleDetailClose">
    <div class="detail-info">
      <div>
        发货单号:
        <span>{{ detailInfo.deliveryNumber }}</span>
      </div>
      <div>
        承运公司:
        <span>{{ detailInfo.deliveryCompany }}</span>
      </div>
      <div>
        发货时间:
        <span>{{ dayjs(detailInfo.deliveryDate).format('YYYY-MM-DD HH:mm:ss') }}</span>
      </div>
    </div>
    <div v-loading="loading || btnLoading">
      <div class="table-wrap">
        <el-form ref="addForm" :model="detailInfo" size="small">
          <GLTable :tableData="detailInfo.deliveryDetailList" :noDataImg="url" :tableParams="tableParams" :hasPage="false">
          </GLTable>
        </el-form>
        <div class="sign-box-wrap">
          <div class="preset-box">
            <div class="title">已有签名预设</div>
            <div v-if="signList.length" class="sign-img-box">
              <div v-for="(item, index) in signList" :key="index">
                <img :src="item.signFileUrl" @click="handleSignClick(item, index)" :class="{'active': activeSignIdx == index, 'sign-img': true}" alt="" />
              </div>
            </div>
            <div class="emptyCom" v-else>
              <img :src="emptyImgUrl" class="emptyImg" alt="" />
              <span class="tips">暂无数据</span>
            </div>
          </div>
          <div v-if="activeSignIdx != -1" class="sign-box">
            <img :src="signList[activeSignIdx].signFileUrl" class="check-sign-img" alt="" />
          </div>
          <div class="sign-box" v-show="activeSignIdx == -1">
            <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>
      </div>
    </div>
    <template slot="footer">
      <span class="dialog-footer">
        <el-button plain size="small" class="btn-three" @click="clear" :disabled="loading || btnLoading">重写</el-button>
        <el-button v-show="activeSignIdx == -1" plain size="small" class="btn-three" style="margin-left: 10px;" @click="undo" :disabled="loading ||btnLoading">撤销</el-button>
        <el-button type="primary" size="small" style="margin-left: 10px;" @click="save" v-loading="loading || btnLoading">确定</el-button>
      </span>
    </template>
  </GLDialog>
</template>

<script>
import * as dayjs from 'dayjs'
import { membraneTypeList } from '@/utils/constants.js'
export default {
  name: 'DeliverAdd',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default: () => { }
    }
  },
  computed: {
    dialogShow: {
      get() {
        if (this.visible) {
          this.getDetail()
        }
        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,
      activeSignIdx: -1,
      signList: [],
      emptyImgUrl: require('@/assets/empty.png'),
      membraneTypeList: membraneTypeList,
      dayjs: dayjs,
      goodsList: [],
      storeUsageList: [],
      refByYqShopList: [],
      tableParams: {
        tableOption: false,
        tableColumns: [
          {
            label: '商品名称',
            prop: 'upgradeGoodsName'
          },
          {
            label: '商品编号',
            prop: 'type'
          },
          {
            label: '发货数量',
            prop: '',
            formatter: cellValue => {
              return membraneTypeList.includes(cellValue.goodsType) ? `${cellValue.purchaseNumber}卷` : `${cellValue.purchaseNumber}件`
            }
          },
          {
            label: '可用库存数量',
            prop: '',
            formatter: cellValue => {
              return cellValue.stockNum + (membraneTypeList.includes(cellValue.goodsType) ? '米' : '件')
            }
          }
        ]
      },
      tableData: [],
      detailInfo: {}
    }
  },
  mounted() {
    this.getSignList()
  },
  methods: {
    undo() {
      this.$refs.signaturePad.undoSignature()
    },
    clear() {
      if (this.activeSignIdx != -1) {
        this.activeSignIdx = -1
        return true
      }
      this.$refs.signaturePad.clearSignature()
    },
    save() {
      // if (!this.$refs.signaturePad) {
      //   this.$message.warning('签名组件未加载')
      //   return
      // }
      const { isEmpty, data } = this.$refs.signaturePad.saveSignature()
      if (this.btnLoading) {
        return
      }
      if (isEmpty && this.activeSignIdx == -1) {
        this.$message({
          message: '请先完成签名',
          type: 'warning',
          customClass: 'message-Z-zinde'
        })
        return
      }
      console.log(data, '保存图片----')
      if (this.activeSignIdx != -1) {
        this.deliverySign(this.signList[this.activeSignIdx].signFileUrl)
      } else {
        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
        })
      }
    },

    getSignList() {
      const params = {
        merchantId: this.info.merchantId
      }
      this.$apis.delivery.getSignList(params).then(res => {
        console.log(res.list, 'res----')
        this.signList = res.list
      })
    },
    handleSignClick(item, index) {
      this.activeSignIdx = index
      this.$refs.signaturePad.clearSignature()
    },
    deliverySign(url) {
      const params = {
        id: this.info.orderDeliveryId,
        signFileUrl: url
      }
      this.btnLoading = true
      console.log(params, 'params----')
      this.$apis.delivery.deliverySign(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')
    },
    getDetail() {
      this.$apis.delivery.deliverySignDetail({ id: this.info.orderDeliveryId }).then(res => {
        const { data } = res
        if (res.code == 0) {
          this.detailInfo = data
        }
      })
    }
  }
}
</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;
  }
}

::v-deep.el-button.is-plain.btn-three {
  opacity: 1 !important;
}
.table-wrap {
  border: 1px solid #e5e5e5;
  padding: 16px;
  box-sizing: border-box;
  margin-top: 16px;

  ::v-deep .el-form-item__error {
    padding-top: 2px;
    z-index: 9999999;
    position: static;
  }
  .sign-box-wrap {
    display: flex;
    justify-content: space-between;
    height: 226px;
    margin: 24px auto 19px;
  }
  .preset-box {
    width: calc(100% - 640px);
    .title {
      color: #333333;
      font-size: 14px;
      font-weight: 600;
    }
    .sign-img-box {
      display: flex;
      flex-wrap: wrap;
    }
    .sign-img {
      width: 128px;
      height: 48px;
      cursor: pointer;
      border: 1px solid #ffffff;
      margin-top: 16px;
    }
    .sign-img:nth-child(odd) {
      margin-right: 14px;
    }
    .sign-img.active {
      border: 1px solid #5850ff;
    }
  }
  .check-sign-img {
    width: 640px;
    height: 226px;
  }

  .emptyCom {
    display: flex;
    flex-direction: column;
    justify-items: center;
    align-items: center;
    margin: 75px auto;
    text-align: center;

    .emptyImg {
      width: 64px;
      height: 41px;
    }
    .tips {
      color: #999999;
      font-size: 14px;
      margin: 16px 0;
    }
  }
  .sign-box {
    position: relative;
    width: 640px;
    height: 226px;
    border-radius: 4px;
    opacity: 1;
    border: 1px solid #e5e5e5;
    background: #fafafa;

    .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;
      }
    }
  }
}

.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>