wxQRcodeDialog.vue 7.91 KB
<template>
  <d2-dialog title="加微二维码"
             :is-visible="qRcodeVisible"
             class="qRcodeDailog"
             width="585px"
             @closeDialog="handleClose"
             @confirmDialog="handleAddConfirm">
    <!--  btnOkLabel="下载二维码" -->
    <div class="dialogContainer">
      <p class="merchantName">{{ merchantInfo.yqMerchantName }}</p>
      <p class="merchantId">{{ merchantInfo.yqMerchantId }}</p>
      <el-upload action=""
                 class="elupload"
                 list-type="picture-card"
                 accept=".jpg,.png"
                 :auto-upload="false"
                 :show-file-list="false"
                 :disabled="!!imgUrl"
                 :on-change="e => handleChange(e,)"
                 :on-preview="e => handlePreview(e, )"
                 :on-remove="e => handleRemove(e, )">
        <span class="img-btn">
          <img v-if="imgUrl"
               :src="imgUrl"
               class="rectImg">
          <span class="img-btns"
                v-if="imgUrl">
            <span class="btn-item">
              <i @click.stop="handleRemove()"
                 class="el-icon-delete" />
              <!-- <i @click.stop="handleImgLook"
                 class="el-icon-zoom-in"></i> -->
            </span>
          </span>
        </span>
        <i v-if="!imgUrl "
           class="el-icon-plus avatar-uploader-icon "
           style="color: #8c939d;">
          <span class="icon-text">上传图片</span>
        </i>
        <!-- <img v-if="!imgUrl "
             :src='examplePicUrl'
             class="rectImg"> -->
        <!-- <div slot="tip"
             class="el-upload__tip">只能上传jpg/png文件,且不超过1M</div> -->
      </el-upload>
      <!-- <span v-if="txtDescript">{{txtDescript}}</span> -->
      <!-- <p v-show="!imgUrl"
         slot="errorTips"
         class="car-error-txt">请上传{{txtDescript}}</p> -->
    </div>

  </d2-dialog>
</template>

<script>
// import baseDialog from '@/components/baseDialog/baseDialog'
import { uploadImg } from '@/api/sys.base'
import { yqMerchantConfigDetail, serviceMerchantRelateQrcode } from '@/api/serviceManage'
export default {
  name: 'WxQRcodeDialog',
  components: {
    // baseDialog
  },
  props: {
    qRcodeVisible: {
      type: Boolean,
      default: false
    },
    merchantInfo: {
      type: Object
      // default: function () {
      //   return {
      //     merchantId: '44209883',
      //     merchantName: 'test'
      //   }
      // }
    }
  },
  data() {
    return {
      imgUrl: '',
      defaultImgUrl: ''
      // oldImgUrl: ''
      // dialogConfig: {
      //   setting: {
      //     showClose: true,
      //     appendToBody: false,
      //     // width: '720px',
      //     btnList: [
      //     ]
      //   },
      //   config: {
      //     title: '上传加微二维码',
      //     width: '720px'
      //   }

      // }
    }
  },
  mounted() {
    this.yqMerchantConfigDetail()
  },
  methods: {
    yqMerchantConfigDetail() {
      // let parmas = this.merchantInfo.merchantId
      yqMerchantConfigDetail({ yqMerchantId: this.merchantInfo.yqMerchantId }).then((result) => {
        console.log(result)
        const { workWechatQrcode } = result
        this.imgUrl = workWechatQrcode
        this.defaultImgUrl = workWechatQrcode
      }).catch((err) => {
        console.log(err)
      })
    },
    handleClose() {
      this.$emit('update:qRcodeVisible', false)
    },
    async handleAddConfirm() {
      // 跟原来不一样认为是修改

      if (this.defaultImgUrl != this.imgUrl) {
        const params = {
          yqMerchantId: this.merchantInfo.yqMerchantId,
          imgUrl: this.imgUrl
        }
        const result = await serviceMerchantRelateQrcode(params)
        console.log(result)
        this.notice.okTips()
        // .then((result) => {
        //   console.log(result)
        // }).catch((err) => {
        //   console.log(err)
        // });
      }
      this.handleClose()
    },
    handleChange(file, attrName, targetItem) {
      if (!(file.size / 1024 / 1024 < 1)) {
        this.$message.error('请上传小于1M的图片')
        return false
      }
      this.handleImgChange({ file })
      // this.$emit('handleImgChange', { file: file, attrName: attrName, targetItem: targetItem })
    },
    handlePreview() { },
    handleRemove(attrName, targetItem) {
      // this.$emit('handleImgRemove', { attrName: attrName, targetItem: targetItem })
      this.imgUrl = ''
    },
    handleImgChange({ file, attrName, targetItem }) {
      // var hasFnList = ['idCard', 'idCardBack', 'bankCard', 'businessLicense', 'authorizerIdCard']
      console.log(file)
      var reader = new FileReader()
      var fileInfo = file.raw
      reader.readAsDataURL(fileInfo)
      reader.onload = e => {
        const imgFile = e.target.result
        const base64 = fileInfo.name.split('.')[1] + '@' + imgFile.split(',')[1]
        uploadImg({ file: base64 }).then(res => {
          console.log(res)
          // http://qcimg01.glsx.com.cn:7060/group1/M00/02/25/wKgD3mMMeE2AIylRAADPUBbxKwQ414.png
          this.imgUrl = res
          // this.picObj[attrName].url = res
          // this.editForm.papers[this.picObj[attrName].attrName] = this.picObj[attrName].url
          // this.writeToEditForm(attrName)
          // this.$refs.editFormRef.$refs.editForm.clearValidate(targetItem.name)
          // if (hasFnList.includes(attrName)) {
          //   targetItem.autoRecognitionFn(res, attrName)
          // }
        })
      }
    },
    handleImgRemove({ attrName, targetItem }) {
      this.picObj[attrName].url = ''
      delete this.editForm.papers[this.picObj[attrName].attrName]
      // this.writeToEditForm(attrName, false)
      // this.$refs.editFormRef.$refs.editForm.validateField(targetItem.name)
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep.qRcodeDailog {
  // color: rebeccapurple;
  // .el-dialog__header {
  //   border: none;
  // }
  .el-icon-plus {
    // position: relative;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
  .icon-text {
    position: absolute;
    white-space: nowrap;
    top: 28px;
    left: -14px;
    margin-top: 8px;
    font-size: 14px;
  }
}
.dialogContainer {
  box-sizing: border-box;
  width: 300px;
  height: 290px;
  margin: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  // align-items: center;
  // justify-content: center;
  text-align: left;

  border: 1px solid #e8e8e8;
  p {
    margin: 0;
  }
  .merchantName {
    font-weight: 600;
    margin-bottom: 10px;
  }
  .elupload {
    margin: auto;
    position: relative;
  }

  .disabled .el-upload--picture-card {
    display: none;
  }
  .el-upload--picture-card {
    width: 140px;
    height: 92px;
    line-height: 98px;
  }
  .rectImg {
    width: 100%;
    height: 100%;
    object-fit: contain;
    // overflow: ;
    // width: 137px;
    // height: 90px;
  }

  .img-btn {
    display: inline-block;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
  .img-btn .img-btns {
    display: none;
    position: absolute;
    width: 146px;
    height: 146px;
    left: 0;
    top: 0;
    z-index: 2;
    color: #fff;
    background: rgba(0, 0, 0, 0.5);
  }
  .img-btn .img-btns .btn-item {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }

  .img-btn .img-btns .btn-item {
    display: flex;
    width: 70%;
    justify-content: space-around;
  }

  .img-btn:hover .img-btns {
    display: block;
  }
  .el-upload--picture-card i {
    color: #fff;
  }
}

// .gl-upload-img .car-error-txt {
//   font-size: 12px;
//   line-height: 6px;
//   margin: 0 0;
// }
</style>