companyBaseInfo.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="page-container">
  3. <nav-bar title="公司信息">
  4. <view class="nav-bar-right-btn" slot="right" @click="toNext">跳过</view>
  5. </nav-bar>
  6. <view class="content">
  7. <view class="num-title">
  8. <text class="current-num">1</text>
  9. <text>/6</text>
  10. </view>
  11. <view class="main-title">基本信息</view>
  12. <view>开始完善公司主页吧,让求职者了解公司</view>
  13. <view class="section">
  14. <view class="title">公司Logo</view>
  15. <view>该logo将出现在公司主页及公司下展示的所有职位上</view>
  16. <view class="upload-wrapper flex align-center" @click="chooseImage">
  17. <image :src="companyLogo || '/static/logo.png'" class="logo" mode="aspectFill"></image>
  18. <view class="tip-text">重新上传</view>
  19. </view>
  20. <view>请上传清晰且完整的图片</view>
  21. </view>
  22. <view class="section">
  23. <view class="title">公司名称</view>
  24. <view class="input-wrapper">
  25. <input v-model="companyName" placeholder="请输入公司名称" maxlength="100" class="input" placeholder-class="placeholder-class" />
  26. </view>
  27. </view>
  28. <view class="section">
  29. <view class="title">公司全称</view>
  30. <view style="height: 32rpx;">{{ companyAllName }}</view>
  31. </view>
  32. <view class="section">
  33. <view class="title">融资阶段</view>
  34. <view class="input-wrapper" @click="openSelectModal(1)">
  35. <view class="input-content">
  36. <text class="input-value" v-if="companyDevelop">{{ companyDevelop }}</text>
  37. <text class="input-placeholder" v-else>请选择融资阶段</text>
  38. </view>
  39. <u-icon name="arrow-down"></u-icon>
  40. </view>
  41. </view>
  42. <view class="section">
  43. <view class="title">人员规模</view>
  44. <view class="input-wrapper" @click="openSelectModal(2)">
  45. <view class="input-content">
  46. <text class="input-value" v-if="companyPeople">{{ companyPeople }}</text>
  47. <text class="input-placeholder" v-else>请选择人员规模</text>
  48. </view>
  49. <u-icon name="arrow-down"></u-icon>
  50. </view>
  51. </view>
  52. <view class="section">
  53. <view class="title"><text class="required">*</text>公司业务类型</view>
  54. <view>
  55. <u-checkbox-group size="24">
  56. <u-checkbox
  57. label-size="24"
  58. @change="checkboxChange"
  59. v-model="item.checked"
  60. v-for="item in companyTypeList" :key="item.value"
  61. :name="item.value"
  62. >{{item.label}}</u-checkbox>
  63. </u-checkbox-group>
  64. </view>
  65. </view>
  66. <u-select
  67. v-model="showSelect"
  68. :default-value="defaultValue"
  69. :list="selectList"
  70. @confirm="confirmSelect"
  71. ></u-select>
  72. </view>
  73. <view class="fixed-button">
  74. <view class="button" @click="handleSave">保存</view>
  75. </view>
  76. <!-- 权限说明弹窗 -->
  77. <u-popup mode="top" ref="permission">
  78. <view class="popup-content">
  79. <view class="popup-text-permission">选择/拍摄照片需要相机/相册权限,用于上传用户头像</view>
  80. </view>
  81. </u-popup>
  82. </view>
  83. </template>
  84. <script>
  85. import navBar from '@/components/nav-bar/index.vue'
  86. import { companyType, companyDevelop, companyPeopleNum } from '@/constants/common.js'
  87. export default {
  88. components: {
  89. navBar
  90. },
  91. data() {
  92. return {
  93. companyId: '',
  94. companyLogo: '',
  95. companyName: '',
  96. companyAllName: '',
  97. companyDevelop: '', // 融资阶段
  98. companyPeople: '', // 人员规模
  99. companyTypes: [], // 公司类型
  100. loading: false,
  101. showSelect: false,
  102. openType: 1, // 1融资阶段 2人员规模
  103. uploading: false,
  104. uploadProgress: 0,
  105. };
  106. },
  107. computed: {
  108. // 公司业务类型
  109. companyTypeList() {
  110. return companyType.map(type => {
  111. if (this.companyTypes.includes(type.value)) {
  112. type.checked = true
  113. } else {
  114. type.checked = false
  115. }
  116. return type
  117. })
  118. },
  119. // 选择器列表数据
  120. selectList() {
  121. return (this.openType == 1 ? companyDevelop : companyPeopleNum).map(item => {
  122. return {
  123. value: item,
  124. label: item
  125. }
  126. }) || []
  127. },
  128. // 回显数组
  129. defaultValue() {
  130. const index = (this.openType == 1 ? companyDevelop : companyPeopleNum).findIndex(item => {
  131. if (this.openType == 1 && item == this.companyDevelop) {
  132. return item
  133. }
  134. if (this.openType != 1 && item == this.companyPeople) {
  135. return item
  136. }
  137. })
  138. return [index == -1 ? 0 : index]
  139. }
  140. },
  141. onLoad() {
  142. this.getCompanyInfo()
  143. },
  144. methods: {
  145. // 跳转至下一步
  146. toNext() {
  147. uni.redirectTo({
  148. url: '/my/renzheng/companyWelfare'
  149. })
  150. },
  151. // 获取公司信息
  152. getCompanyInfo() {
  153. uni.showLoading({ title: '加载中' })
  154. this.$Request.get('/app/company/selectCompanyByUserId')
  155. .then((res) => {
  156. if (res.code != 0) {
  157. uni.showToast({
  158. title: res.msg || '查询状态失败',
  159. icon: 'none'
  160. });
  161. return
  162. }
  163. this.companyId = res.data.companyId
  164. this.companyLogo = res.data.companyLogo
  165. this.companyName = res.data.companyName
  166. this.companyAllName = res.data.companyAllName
  167. this.companyDevelop = res.data.companyDevelop
  168. this.companyPeople = res.data.companyPeople
  169. // 设置公司业务类型
  170. if (res.data.type) {
  171. const types = JSON.parse(res.data.type)
  172. this.companyTypes= types
  173. }
  174. uni.hideLoading()
  175. })
  176. .catch((err) => {
  177. uni.hideLoading()
  178. uni.showToast({
  179. title: '网络异常',
  180. icon: 'none'
  181. })
  182. })
  183. },
  184. // 选择图片
  185. async chooseImage() {
  186. // 1. 检查权限状态
  187. const hasPermission = await this.$queue.checkPermission(
  188. 'camera',
  189. '选择/拍摄照片需要相机/相册权限,用于上传用户头像',
  190. this
  191. );
  192. // 2. 如果未授权或者用户拒绝,显示提示
  193. if (!hasPermission) {
  194. return;
  195. }
  196. uni.chooseImage({
  197. count: 1,
  198. sizeType: ["compressed"], // 可以指定是原图还是压缩图,默认二者都有
  199. sourceType: ["album", "camera"], // 可以指定来源是相册还是相机,默认二者都有
  200. success: (res) => {
  201. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  202. const tempFilePaths = res.tempFilePaths;
  203. // 这里可以添加图片验证
  204. this.validateAndUploadImage(tempFilePaths[0]);
  205. },
  206. fail: (error) => {
  207. console.log("选择图片失败:", error);
  208. uni.showToast({
  209. title: "选择图片失败",
  210. icon: "none",
  211. });
  212. },
  213. });
  214. },
  215. // 验证并上传图片
  216. validateAndUploadImage(tempFilePath) {
  217. // 获取图片信息
  218. uni.getImageInfo({
  219. src: tempFilePath,
  220. success: (imageInfo) => {
  221. console.log("图片信息:", imageInfo);
  222. // 开始上传
  223. this.uploadImage(tempFilePath);
  224. },
  225. fail: (error) => {
  226. console.log("获取图片信息失败:", error);
  227. this.uploadImage(tempFilePath); // 即使获取信息失败也继续上传
  228. },
  229. });
  230. },
  231. // 上传图片到服务器
  232. uploadImage(filePath) {
  233. this.uploading = true;
  234. this.uploadProgress = 0;
  235. // 模拟上传进度
  236. const progressTimer = setInterval(() => {
  237. this.uploadProgress += 10;
  238. if (this.uploadProgress >= 90) {
  239. clearInterval(progressTimer);
  240. }
  241. }, 100);
  242. this.$queue.uploadFile(filePath, (path) => {
  243. if (path) {
  244. clearInterval(progressTimer);
  245. this.uploadProgress = 100;
  246. this.companyLogo = path
  247. uni.showToast({
  248. title: '上传成功',
  249. icon: 'success'
  250. });
  251. } else {
  252. uni.showToast({
  253. title: data.message || '上传失败',
  254. icon: 'none'
  255. });
  256. }
  257. setTimeout(() => {
  258. this.uploading = false;
  259. }, 500);
  260. })
  261. },
  262. checkboxChange(item) {
  263. if (item.value) {
  264. this.companyTypes.push(item.name)
  265. } else {
  266. const index = this.companyTypes.findIndex(type => type.value == item.name)
  267. this.companyTypes.splice(index, 1)
  268. }
  269. },
  270. openSelectModal(type) {
  271. this.openType = type
  272. this.showSelect = true
  273. },
  274. // 选择select数据
  275. confirmSelect(e) {
  276. let item = e[0]
  277. if (this.openType == 1) {
  278. this.companyDevelop = item.value
  279. } else {
  280. this.companyPeople = item.value
  281. }
  282. },
  283. handleSave() {
  284. if (this.loading) return
  285. if (!this.companyTypes.length) {
  286. return this.$queue.showToast('请选择公司类型')
  287. }
  288. uni.showLoading({ title: '保存中' })
  289. this.loading = true
  290. let companyData = {
  291. companyId: this.companyId,
  292. companyLogo: this.companyLogo,
  293. companyName: this.companyName,
  294. companyAllName: this.companyAllName,
  295. companyDevelop: this.companyDevelop,
  296. companyPeople: this.companyPeople,
  297. type: JSON.stringify(this.companyTypes)
  298. }
  299. this.$Request.postJson('/app/company/updateCompany', companyData)
  300. .then(res => {
  301. if(res.code == 0){
  302. uni.showToast({
  303. title: '提交成功',
  304. duration: 1500,
  305. });
  306. setTimeout(()=>{
  307. uni.$emit('updateCompanyInfo')
  308. uni.navigateBack()
  309. }, 500)
  310. }
  311. this.loading = true
  312. uni.hideLoading()
  313. })
  314. .catch(() => {
  315. this.loading = true
  316. uni.hideLoading()
  317. })
  318. }
  319. }
  320. }
  321. </script>
  322. <style lang="scss" scoped>
  323. @import './company.scss';
  324. </style>