uploadLicense.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <!-- @format -->
  2. <template>
  3. <view class="container">
  4. <view style="color: #3c9cff" class="informationTitle"
  5. >上传身份信息 (个人注册前需要先注册企业账号)</view
  6. >
  7. <view class="cardImage">
  8. <view class="conmpan">
  9. <view style="width: 85%; margin: 0 auto">
  10. <u-form>
  11. <u-form-item
  12. labelPosition="top"
  13. labelWidth="160"
  14. :required="true"
  15. label="企业社会统一信用代码"
  16. >
  17. <u-input
  18. @blur="handleDetect"
  19. v-model="conmpanCode"
  20. placeholder="请输入企业社会统一信用代码"
  21. ></u-input>
  22. </u-form-item>
  23. </u-form>
  24. </view>
  25. </view>
  26. <view class="updateContent" :style="{ opacity: !isPass ? '0.5' : 1 }">
  27. <view style="margin: 0 auto">
  28. <u-upload
  29. name="1"
  30. :disabled="!isPass"
  31. :fileList="fileList1"
  32. @afterRead="afterRead"
  33. @delete="deletePic"
  34. :maxCount="1"
  35. width="280"
  36. height="180"
  37. >
  38. <view class="uploadTipcContent">
  39. <view class="cardImg">
  40. <image
  41. style="height: 180rpx; width: 400rpx"
  42. mode="widthFix"
  43. :src="require('@/static/images/cardzm.png')"
  44. ></image>
  45. <view class="topic"> 请上传被授权人身份证人像照片 </view>
  46. </view>
  47. </view>
  48. </u-upload>
  49. </view>
  50. </view>
  51. <view class="updateContent" :style="{ opacity: !isPass ? '0.5' : 1 }">
  52. <view style="margin: 0 auto">
  53. <u-upload
  54. :disabled="!isPass"
  55. name="2"
  56. :fileList="fileList2"
  57. @afterRead="afterRead"
  58. @delete="deletePic"
  59. :maxCount="1"
  60. width="280"
  61. height="180"
  62. >
  63. <view class="uploadTipcContent">
  64. <view class="cardImg">
  65. <image
  66. style="height: 180rpx; width: 430rpx; margin-left: 30rpx"
  67. mode="widthFix"
  68. :src="require('@/static/images/cardbm.png')"
  69. ></image>
  70. <view class="topic"> 请上传被授权人身份证国徽照片 </view>
  71. </view>
  72. </view>
  73. </u-upload>
  74. </view>
  75. </view>
  76. </view>
  77. <u-modal
  78. @cancel="showModal = false"
  79. confirmText="退出"
  80. @confirm="handleCancel"
  81. :show="showModal"
  82. :title="'提示'"
  83. :content="'您输入的企业没有注册,需要先进行企业注册。'"
  84. ></u-modal>
  85. </view>
  86. </template>
  87. <script>
  88. import { checkMechanismIsExist } from "@/api/login";
  89. export default {
  90. data() {
  91. return {
  92. showModal: false,
  93. isPass: false,
  94. fileList1: [],
  95. fileList2: [],
  96. conmpanCode: "",
  97. };
  98. },
  99. props: {
  100. formdData: {
  101. type: Object,
  102. default: () => ({}),
  103. },
  104. },
  105. created() {
  106. if (this.formdData.cardFrontImg || this.formdData.cardBackImg) {
  107. this.fileList1[0] = {
  108. url: this.$baseUrl + this.formdData.cardFrontImg,
  109. };
  110. this.fileList2[0] = {
  111. url: this.$baseUrl + this.formdData.cardBackImg,
  112. };
  113. }
  114. },
  115. methods: {
  116. handleCancel() {
  117. this.showModal = false;
  118. },
  119. deletePic(event) {
  120. this[`fileList${event.name}`].splice(event.index, 1);
  121. },
  122. // 新增图片
  123. async afterRead(event) {
  124. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  125. let lists = [].concat(event.file);
  126. let fileListLen = this[`fileList${event.name}`].length;
  127. lists.map((item) => {
  128. this[`fileList${event.name}`].push({
  129. ...item,
  130. status: "uploading",
  131. message: "上传中",
  132. });
  133. });
  134. for (let i = 0; i < lists.length; i++) {
  135. const result = await this.uploadFilePromise(lists[i].url);
  136. let item = this[`fileList${event.name}`][fileListLen];
  137. this[`fileList${event.name}`].splice(
  138. fileListLen,
  139. 1,
  140. Object.assign(item, {
  141. status: "success",
  142. message: "",
  143. url: JSON.parse(result.data).fileName,
  144. })
  145. );
  146. if (event.name == 1) {
  147. this.$emit("update:formdData", {
  148. ...this.formdData,
  149. cardFrontImg: JSON.parse(result.data).fileName,
  150. });
  151. } else {
  152. this.$emit("update:formdData", {
  153. ...this.formdData,
  154. cardBackImg: JSON.parse(result.data).fileName,
  155. });
  156. }
  157. fileListLen++;
  158. }
  159. },
  160. //上传
  161. uploadFilePromise(url) {
  162. return new Promise((resolve, reject) => {
  163. let a = uni.uploadFile({
  164. url: `${this.$baseUrl}/api/common/upload`, // 仅为示例,非真实的接口地址
  165. filePath: url,
  166. name: "file",
  167. success: (res) => {
  168. setTimeout(() => {
  169. resolve(res);
  170. }, 1000);
  171. },
  172. });
  173. });
  174. },
  175. //检测企业代码是否合法
  176. async handleDetect() {
  177. if (!this.conmpanCode) return;
  178. uni.showLoading({
  179. title: "检测企业是否注册...",
  180. });
  181. try {
  182. let { code } = await checkMechanismIsExist({ code: this.conmpanCode });
  183. if (code == 200) {
  184. this.isPass = true;
  185. uni.showToast({
  186. title: "检测通过",
  187. //将值设置为 success 或者直接不用写icon这个参数
  188. //显示持续时间为 2秒
  189. duration: 2000,
  190. });
  191. }
  192. } catch (error) {
  193. this.isPass = false;
  194. }
  195. },
  196. },
  197. };
  198. </script>
  199. <style lang="scss">
  200. .container {
  201. height: 100vh;
  202. background: #fff;
  203. }
  204. .cardImg {
  205. width: 100%;
  206. display: flex;
  207. justify-content: center;
  208. }
  209. .conmpan {
  210. width: 100%;
  211. margin: 0 auto;
  212. background: #fff;
  213. }
  214. .topic {
  215. color: #909399;
  216. font-size: 24rpx;
  217. width: 400rpx;
  218. margin: 20rpx auto 0;
  219. font-family: "宋体";
  220. position: absolute;
  221. bottom: 20rpx;
  222. left: 50%;
  223. transform: translateX(-43%);
  224. }
  225. .uploadTipcContent {
  226. width: 600rpx;
  227. height: 260rpx;
  228. position: relative;
  229. // padding: 30rpx;
  230. // border: 1px dotted#909399;
  231. }
  232. .updateContent {
  233. display: flex;
  234. background: #fff;
  235. padding: 20rpx;
  236. }
  237. .informationTitle {
  238. margin-bottom: 30rpx;
  239. font-size: 30;
  240. }
  241. .contentItems {
  242. width: 100%;
  243. border-radius: 6px;
  244. background: #fff;
  245. margin: 0rpx auto 30rpx;
  246. padding: 20rpx 30rpx 20rpx;
  247. .content {
  248. border-bottom: 1px solid rgb(242, 242, 242);
  249. padding: 0rpx 0 10rpx;
  250. display: flex;
  251. justify-content: space-between;
  252. align-items: center;
  253. }
  254. .content:last-child {
  255. border-bottom: none;
  256. }
  257. .title {
  258. font-size: 30rpx;
  259. color: black;
  260. letter-spacing: 3rpx;
  261. }
  262. .message {
  263. margin-left: 70rpx;
  264. text-align: right;
  265. // width: 420rpx;
  266. font-size: 30rpx;
  267. color: rgb(146, 146, 146);
  268. // white-space: nowrap;
  269. // /* 禁止文本换行 */
  270. // overflow: hidden;
  271. // /* 隐藏超出容器的文本 */
  272. // text-overflow: ellipsis;
  273. /* 使用省略号表示被截断的文本 */
  274. }
  275. }
  276. </style>