signature.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <div class="signature-container">
  3. <div class="imgbox">
  4. <div v-if="!img" class="img-framework" @click="handleUpdateSignature">
  5. <van-icon name="plus" color="#817f7f" size="34" />
  6. </div>
  7. <img v-else :src="img" alt="个签">
  8. <div class="state">
  9. <van-icon :name="examineIconName" size="20" />
  10. <span>{{ signatureStateText }}</span>
  11. </div>
  12. </div>
  13. <div class="btnbox" @click="handleResetSignature">
  14. <span>重新上传</span>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import { waitAuthentication, getChooseImages } from '@/utils/dingtalk'
  20. import updateUserInfoMixin from './updateUserInfo.mixin'
  21. import { mapState } from 'vuex'
  22. import upload from '@/utils/upload'
  23. export default {
  24. mixins: [
  25. updateUserInfoMixin
  26. ],
  27. computed: {
  28. ...mapState('user', {
  29. // 签名状态:0=待审核,1=审核通过,2=审核驳回
  30. signatureStateText: state => state.signatureStateText,
  31. }),
  32. examineIconName () {
  33. return 'checked'
  34. },
  35. },
  36. data () {
  37. return {
  38. img: require('@/assets/index/index-business-libs.png'),
  39. }
  40. },
  41. mounted() {
  42. const that = this
  43. waitAuthentication({
  44. jsApiList: [],
  45. errorCallback: that.handleAError.bind(that),
  46. readyCallback: that.handleAReady.bind(that)
  47. })
  48. },
  49. methods: {
  50. handleAError (error) {
  51. console.log('error', error);
  52. },
  53. handleAReady (){
  54. this.handleResetSignature()
  55. },
  56. // NOTE:点击上传个签
  57. handleUpdateSignature() {
  58. const params = {
  59. type: 4,
  60. signature: this.img
  61. }
  62. this.put_userinfo(params, true)
  63. },
  64. // NOTE: 重新上传个签
  65. async handleResetSignature () {
  66. let toastLoadingInstance = null
  67. try {
  68. const result = await getChooseImages({})
  69. console.log('%c chooseimg res >>>', 'background: blue; color: #fff', result);
  70. toastLoadingInstance = this.$toast.loading({
  71. message: '图片上传中',
  72. duration: 0
  73. })
  74. // TODO: Update image
  75. const uploadResult = await upload(result.files)
  76. console.log('%c upload result >>>', 'background: blue; color: #fff', uploadResult);
  77. // TODO: Update userinfo
  78. this.img = uploadResult
  79. this.handleUpdateSignature()
  80. } catch (error) {
  81. console.log('getChooseImage error', error);
  82. } finally {
  83. if (toastLoadingInstance) {
  84. toastLoadingInstance.clear()
  85. }
  86. }
  87. },
  88. }
  89. }
  90. </script>
  91. <style lang="less">
  92. @import url("@/styles/variables.less");
  93. .signature {
  94. &-container {
  95. display: flex;
  96. flex-direction: column;
  97. align-items: center;
  98. padding: 50px 14px 0;
  99. }
  100. }
  101. .imgbox {
  102. margin-bottom: 80px;
  103. .img-framework {
  104. display: flex;
  105. flex-direction: row;
  106. align-items: center;
  107. justify-content: center;
  108. width: 180px;
  109. height: 180px;
  110. border-radius: 8px;
  111. border: 1px dashed #817f7f;
  112. }
  113. img {
  114. width: 180px;
  115. height: 180px;
  116. border-radius: 5px;
  117. overflow: hidden;
  118. }
  119. .state {
  120. display: flex;
  121. align-items: center;
  122. justify-content: center;
  123. padding: 15px 0;
  124. text-align: center;
  125. .van-icon {
  126. color: @main-color;
  127. }
  128. span {
  129. margin-left: 8px;
  130. font-size: @text-secondery-size;
  131. font-family: PingFangSC-Regular, PingFang SC;
  132. font-weight: 400;
  133. color: @text-xsecondery-color;
  134. line-height: 20px;
  135. }
  136. }
  137. }
  138. </style>