companyImg.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view class="company">
  3. <nav-bar title="公司认证" color="#000"></nav-bar>
  4. <view class="company-content">
  5. <!-- 营业执照上传 -->
  6. <view class="company-title">上传公司营业执照</view>
  7. <view class="company-desc">请上传“{{ companyName }}”的营业执照</view>
  8. <view class="upload-img">
  9. <image v-if="filePath" :src="filePath" mode="aspectFit"
  10. style="height:100%; width:100%; border-radius:8rpx"></image>
  11. <view v-else class="text-item" @click="chooseImage">
  12. <u-icon name="plus" color="#999" size="40" style="margin-bottom: 8rpx;"></u-icon>
  13. 上传营业执照
  14. </view>
  15. <view v-if="filePath" class="delete-btn" @click="deleteImage">×</view>
  16. </view>
  17. <view class="warning-title">注意事项</view>
  18. <view class="warning-desc">1.请上传所填公司一致的营业执照</view>
  19. <view class="warning-desc">2.营业执照信息和公章清晰可辨</view>
  20. <!-- 在职证明上传 -->
  21. <view class="upload-img">
  22. <view v-if="pdfFilePath" class="text-item">
  23. <u-icon name="file-text" color="#016bf6" size="40"></u-icon>
  24. <text style="margin-top: 8rpx;">已选择 PDF</text>
  25. <view class="delete-btn" @click="deletePDF">×</view>
  26. </view>
  27. <fileSelector v-else :isShowStyle="false" title="上传在职证明" allowType=".pdf" @fileSelected="choosePDF" />
  28. </view>
  29. <view class="warning-title">注意事项</view>
  30. <view class="warning-desc">1.请上传加盖公章的在职证明(仅限 PDF 文件)</view>
  31. <!-- 公司证明上传 -->
  32. <view class="upload-group">
  33. <view v-for="(img, index) in companyProofList" :key="index" class="upload-img">
  34. <image :src="img" mode="aspectFill" style="width:100%;height:100%;border-radius:8rpx;"></image>
  35. <view class="delete-btn" @click="deleteCompanyProof(index)">×</view>
  36. </view>
  37. <view v-if="companyProofList.length < 4" class="upload-img text-item" @click="chooseCompanyProof">
  38. <u-icon name="plus" color="#999" size="40" style="margin-bottom: 8rpx;"></u-icon>
  39. 上传公司证明
  40. </view>
  41. </view>
  42. <view class="warning-title">注意事项</view>
  43. <view class="warning-desc">1.请上传公司前台LOGO照1-2张</view>
  44. <view class="warning-desc">2.请上传公司办公区照片1-2张</view>
  45. </view>
  46. <view class="bottom-btn" @click="goUnderReview">确认并提交</view>
  47. </view>
  48. </template>
  49. <script>
  50. import navBar from "@/components/nav-bar/index.vue";
  51. import configdata from '../../common/config.js';
  52. // 引入组件
  53. import fileSelector from '@/uni_modules/zhouquan-fileSelector/components/zhouquan-fileSelector/file-selector.vue';
  54. export default {
  55. data() {
  56. return {
  57. companyName: "",
  58. companyId: "",
  59. filePath: "", // 营业执照本地路径
  60. licenseUrl: "", // 营业执照上传后URL
  61. pdfFilePath: "", // 在职证明本地路径
  62. employmentVerification: "", // PDF 上传后URL
  63. companyProofList: [], // 公司证明本地预览图
  64. companyProofUrls: [], // 上传后URL列表
  65. action: configdata.APIHOST1 + '/alioss/upload'
  66. };
  67. },
  68. components: { navBar,fileSelector},
  69. onLoad(options) {
  70. if (options.companyName) this.companyName = decodeURIComponent(options.companyName);
  71. if (options.companyId) this.companyId = options.companyId;
  72. },
  73. methods: {
  74. // 通用上传
  75. async uploadSingleFile(path) {
  76. return new Promise((resolve, reject) => {
  77. uni.uploadFile({
  78. url: this.action,
  79. filePath: path,
  80. name: 'file',
  81. success: (res) => {
  82. const data = JSON.parse(res.data);
  83. if (data.code === 0 && data.data) resolve(data.data);
  84. else reject(data.msg || '上传失败');
  85. },
  86. fail: (err) => reject(err)
  87. });
  88. });
  89. },
  90. // ======= 营业执照上传 =======
  91. async chooseImage() {
  92. uni.chooseImage({
  93. count: 1,
  94. success: async (res) => {
  95. let tempFilePath = res.tempFilePaths[0];
  96. // HEIC 转换
  97. if (tempFilePath.toLowerCase().endsWith('.heic')) {
  98. try {
  99. tempFilePath = await this.convertHeicToJpg(tempFilePath);
  100. } catch (e) {
  101. return uni.showToast({ title: 'HEIC 转换失败,请使用 JPG/PNG', icon: 'none' });
  102. }
  103. }
  104. this.filePath = tempFilePath;
  105. // 自动上传
  106. uni.showLoading({ title: '上传营业执照中...' });
  107. try {
  108. this.licenseUrl = await this.uploadSingleFile(tempFilePath);
  109. uni.showToast({ title: '上传成功', icon: 'success' });
  110. } catch (e) {
  111. uni.showToast({ title: '上传失败', icon: 'none' });
  112. } finally {
  113. uni.hideLoading();
  114. }
  115. }
  116. });
  117. },
  118. deleteImage() {
  119. this.filePath = "";
  120. this.licenseUrl = "";
  121. },
  122. // ======= 在职证明上传 (PDF) =======
  123. async choosePDF(e) {
  124. var that = this
  125. const validExtensions = ['pdf', 'doc', 'docx'];
  126. const ext = e.name.split('.').pop().toLowerCase();
  127. if (!validExtensions.includes(ext)) {
  128. this.$queue.showToast('仅支持PDF/DOC/DOCX格式')
  129. return;
  130. }
  131. uni.getFileInfo({
  132. filePath: e.path,
  133. success: (info) => {
  134. let attachment_size = (info.size / 1024).toFixed(1)
  135. that.$queue.uploadFile(e.path, function (path) {
  136. if (path){
  137. that.pdfFilePath = path;
  138. that.employmentVerification = path;
  139. }else
  140. that.$queue.showToast('文件上传失败')
  141. })
  142. },
  143. fail: (err) => {
  144. console.error('获取失败', err);
  145. }
  146. });
  147. },
  148. deletePDF() {
  149. this.pdfFilePath = "";
  150. this.employmentVerification = "";
  151. },
  152. // ======= 公司证明上传(多图) =======
  153. async chooseCompanyProof() {
  154. if (this.companyProofList.length >= 4) {
  155. return uni.showToast({ title: '最多上传4张图片', icon: 'none' });
  156. }
  157. uni.chooseImage({
  158. count: 4 - this.companyProofList.length,
  159. success: async (res) => {
  160. const imgs = res.tempFilePaths;
  161. for (let img of imgs) {
  162. this.companyProofList.push(img);
  163. uni.showLoading({ title: '上传中...' });
  164. try {
  165. const url = await this.uploadSingleFile(img);
  166. this.companyProofUrls.push(url);
  167. } catch (e) {
  168. uni.showToast({ title: '部分图片上传失败', icon: 'none' });
  169. } finally {
  170. uni.hideLoading();
  171. }
  172. }
  173. }
  174. });
  175. },
  176. deleteCompanyProof(index) {
  177. this.companyProofList.splice(index, 1);
  178. this.companyProofUrls.splice(index, 1);
  179. },
  180. // ======= HEIC 转 JPG =======
  181. convertHeicToJpg(path) {
  182. return new Promise((resolve, reject) => {
  183. uni.getImageInfo({
  184. src: path,
  185. success: (img) => {
  186. const ctx = uni.createCanvasContext('myCanvas', this);
  187. ctx.drawImage(path, 0, 0, img.width, img.height);
  188. ctx.draw(false, () => {
  189. uni.canvasToTempFilePath({
  190. canvasId: 'myCanvas',
  191. fileType: 'jpg',
  192. quality: 0.9,
  193. success: (res) => resolve(res.tempFilePath),
  194. fail: (err) => reject(err)
  195. }, this);
  196. });
  197. },
  198. fail: (err) => reject(err)
  199. });
  200. });
  201. },
  202. // ======= 提交 =======
  203. async goUnderReview() {
  204. if (!this.licenseUrl) return uni.showToast({ title: '请上传营业执照', icon: 'none' });
  205. if (!this.employmentVerification) return uni.showToast({ title: '请上传在职证明PDF', icon: 'none' });
  206. if (this.companyProofUrls.length === 0) return uni.showToast({ title: '请上传公司证明图片', icon: 'none' });
  207. const data = {
  208. companyId: this.companyId,
  209. companyCertification: this.licenseUrl,
  210. employmentVerification: this.employmentVerification,
  211. companyVerification: this.companyProofUrls.join(',')
  212. };
  213. uni.showLoading({ title: '提交中...' });
  214. try {
  215. const res = await this.$Request.postJson("/app/company/updateCompany", data);
  216. uni.hideLoading();
  217. if (res.code === 0) {
  218. uni.showToast({ title: '提交成功', icon: 'success' });
  219. uni.navigateTo({ url: "/package/jobIntention/completeMsg" });
  220. } else {
  221. uni.showToast({ title: res.msg || '提交失败', icon: 'none' });
  222. }
  223. } catch (e) {
  224. uni.hideLoading();
  225. console.error('提交失败', e);
  226. uni.showToast({ title: '网络异常,请重试', icon: 'none' });
  227. }
  228. }
  229. }
  230. };
  231. </script>
  232. <canvas canvas-id="myCanvas" style="width:1px;height:1px;position:absolute;top:-1000rpx"></canvas>
  233. <style scoped lang="scss">
  234. .company {
  235. position: absolute;
  236. left: 0;
  237. right: 0;
  238. top: 0;
  239. bottom: 0;
  240. display: flex;
  241. flex-direction: column;
  242. font-family: DM Sans;
  243. .company-content {
  244. flex: 1;
  245. padding: 40rpx;
  246. box-sizing: border-box;
  247. overflow-y: auto;
  248. .company-title {
  249. color: #333;
  250. font-size: 40rpx;
  251. font-weight: 600;
  252. margin-bottom: 20rpx;
  253. }
  254. .company-desc {
  255. color: #666;
  256. font-size: 24rpx;
  257. line-height: 32rpx;
  258. }
  259. .upload-img {
  260. width: 142rpx;
  261. height: 142rpx;
  262. display: flex;
  263. justify-content: center;
  264. align-items: center;
  265. margin-top: 20rpx;
  266. position: relative;
  267. }
  268. .upload-group {
  269. display: flex;
  270. flex-wrap: wrap;
  271. gap: 20rpx;
  272. margin-top: 20rpx;
  273. }
  274. .text-item {
  275. width: 142rpx;
  276. height: 142rpx;
  277. color: #666;
  278. font-size: 16rpx;
  279. display: flex;
  280. justify-content: center;
  281. align-items: center;
  282. flex-direction: column;
  283. background: #eee;
  284. border-radius: 12rpx;
  285. }
  286. .delete-btn {
  287. position: absolute;
  288. top: 0;
  289. right: 0;
  290. width: 36rpx;
  291. height: 36rpx;
  292. line-height: 36rpx;
  293. text-align: center;
  294. background: rgba(0, 0, 0, 0.5);
  295. color: #fff;
  296. border-radius: 50%;
  297. font-size: 28rpx;
  298. z-index: 10;
  299. }
  300. .warning-title {
  301. color: #666;
  302. font-size: 24rpx;
  303. margin-top: 20rpx;
  304. font-weight: 500;
  305. }
  306. .warning-desc {
  307. color: #666;
  308. font-size: 24rpx;
  309. margin-top: 8rpx;
  310. }
  311. }
  312. .bottom-btn {
  313. border-radius: 999px;
  314. background: #016bf6;
  315. display: flex;
  316. justify-content: center;
  317. align-items: center;
  318. color: #fff;
  319. font-size: 32rpx;
  320. padding: 16rpx 32rpx;
  321. margin: 20rpx;
  322. margin-bottom: 110rpx;
  323. }
  324. }
  325. </style>