uploadLicense.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!-- @format -->
  2. <template>
  3. <view class="container">
  4. <view style="color: #3c9cff" class="informationTitle">上传身份信息</view>
  5. <view class="cardImage">
  6. <view class="updateContent">
  7. <view style="margin: 0 auto">
  8. <u-upload
  9. name="1"
  10. :fileList="fileList1"
  11. @afterRead="afterRead"
  12. @delete="deletePic"
  13. :maxCount="1"
  14. width="280"
  15. height="180"
  16. >
  17. <view class="uploadTipcContent">
  18. <view>
  19. <view style="display: flex; justify-content: center">
  20. <u-icon
  21. name="arrow-upward"
  22. color="#2979ff"
  23. size="28"
  24. ></u-icon>
  25. </view>
  26. <u-button
  27. :customStyle="{ color: '#3c9cff', fontSize: '26rpx' }"
  28. type="text"
  29. size="small"
  30. >点击上传</u-button
  31. >
  32. </view>
  33. <view class="topic"> 请上传被授权人身份证正面照片 </view>
  34. </view>
  35. </u-upload>
  36. </view>
  37. </view>
  38. <view class="updateContent">
  39. <view style="margin: 0 auto">
  40. <u-upload
  41. name="2"
  42. :fileList="fileList2"
  43. @afterRead="afterRead"
  44. @delete="deletePic"
  45. :maxCount="1"
  46. width="280"
  47. height="180"
  48. >
  49. <view class="uploadTipcContent">
  50. <view>
  51. <view style="display: flex; justify-content: center">
  52. <u-icon
  53. name="arrow-upward"
  54. color="#2979ff"
  55. size="28"
  56. ></u-icon>
  57. </view>
  58. <u-button
  59. :customStyle="{ color: '#3c9cff', fontSize: '26rpx' }"
  60. type="text"
  61. size="small"
  62. >点击上传</u-button
  63. >
  64. </view>
  65. <view class="topic"> 请上传被授权人身份证背面照片 </view>
  66. </view>
  67. </u-upload>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. export default {
  75. data() {
  76. return {
  77. fileList1: [],
  78. fileList2: [],
  79. };
  80. },
  81. props: {
  82. formdData: {
  83. type: Object,
  84. default: () => ({}),
  85. },
  86. },
  87. created() {
  88. if (this.formdData.cardFrontImg || this.formdData.cardBackImg) {
  89. this.fileList1[0] = {
  90. url: this.$baseUrl + this.formdData.cardFrontImg,
  91. };
  92. this.fileList2[0] = {
  93. url: this.$baseUrl + this.formdData.cardBackImg,
  94. };
  95. }
  96. },
  97. methods: {
  98. deletePic(event) {
  99. this[`fileList${event.name}`].splice(event.index, 1);
  100. },
  101. // 新增图片
  102. async afterRead(event) {
  103. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  104. let lists = [].concat(event.file);
  105. let fileListLen = this[`fileList${event.name}`].length;
  106. lists.map((item) => {
  107. this[`fileList${event.name}`].push({
  108. ...item,
  109. status: "uploading",
  110. message: "上传中",
  111. });
  112. });
  113. for (let i = 0; i < lists.length; i++) {
  114. const result = await this.uploadFilePromise(lists[i].url);
  115. let item = this[`fileList${event.name}`][fileListLen];
  116. this[`fileList${event.name}`].splice(
  117. fileListLen,
  118. 1,
  119. Object.assign(item, {
  120. status: "success",
  121. message: "",
  122. url: JSON.parse(result.data).fileName,
  123. })
  124. );
  125. if (event.name == 1) {
  126. this.$emit("update:formdData", {
  127. ...this.formdData,
  128. cardFrontImg: JSON.parse(result.data).fileName,
  129. });
  130. } else {
  131. this.$emit("update:formdData", {
  132. ...this.formdData,
  133. cardBackImg: JSON.parse(result.data).fileName,
  134. });
  135. }
  136. fileListLen++;
  137. }
  138. },
  139. //上传
  140. uploadFilePromise(url) {
  141. return new Promise((resolve, reject) => {
  142. let a = uni.uploadFile({
  143. url: `${this.$baseUrl}/api/common/upload`, // 仅为示例,非真实的接口地址
  144. filePath: url,
  145. name: "file",
  146. success: (res) => {
  147. setTimeout(() => {
  148. resolve(res);
  149. }, 1000);
  150. },
  151. });
  152. });
  153. },
  154. },
  155. };
  156. </script>
  157. <style lang="scss">
  158. .topic {
  159. color: #909399;
  160. font-size: 24rpx;
  161. width: 400rpx;
  162. margin: 20rpx auto 0;
  163. font-family: "宋体";
  164. }
  165. .uploadTipcContent {
  166. width: 555rpx;
  167. height: 260rpx;
  168. padding: 30rpx;
  169. border: 1px dotted#909399;
  170. }
  171. .updateContent {
  172. display: flex;
  173. background: #fff;
  174. padding: 30rpx;
  175. }
  176. .informationTitle {
  177. margin-bottom: 30rpx;
  178. font-size: 30;
  179. }
  180. .contentItems {
  181. width: 100%;
  182. border-radius: 6px;
  183. background: #fff;
  184. margin: 0rpx auto 30rpx;
  185. padding: 20rpx 30rpx 20rpx;
  186. .content {
  187. border-bottom: 1px solid rgb(242, 242, 242);
  188. padding: 0rpx 0 10rpx;
  189. display: flex;
  190. justify-content: space-between;
  191. align-items: center;
  192. }
  193. .content:last-child {
  194. border-bottom: none;
  195. }
  196. .title {
  197. font-size: 30rpx;
  198. color: black;
  199. letter-spacing: 3rpx;
  200. }
  201. .message {
  202. margin-left: 70rpx;
  203. text-align: right;
  204. // width: 420rpx;
  205. font-size: 30rpx;
  206. color: rgb(146, 146, 146);
  207. // white-space: nowrap;
  208. // /* 禁止文本换行 */
  209. // overflow: hidden;
  210. // /* 隐藏超出容器的文本 */
  211. // text-overflow: ellipsis;
  212. /* 使用省略号表示被截断的文本 */
  213. }
  214. }
  215. </style>