companyWelfare.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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">2</text>
  9. <text>/6</text>
  10. </view>
  11. <view class="main-title">公司福利</view>
  12. <view>选择公司提供的福利信息,以吸引更多求职者</view>
  13. <view class="section">
  14. <view class="title">工作时间</view>
  15. <view class="input-wrapper">
  16. <view class="input-content flex-1" @click="openSelectTimePopup(1)">
  17. <text class="input-value" v-if="startWorkTime">{{ startWorkTime }}</text>
  18. <text class="input-placeholder" v-else>请选择开始时间</text>
  19. </view>
  20. <view>至</view>
  21. <view class="input-content flex-1" @click="openSelectTimePopup(2)">
  22. <text class="input-value" v-if="endWorkTime">{{ endWorkTime }}</text>
  23. <text class="input-placeholder" v-else>请选择结束时间</text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="section">
  28. <view class="title">休息时间(可选)</view>
  29. <view class="select-button-wrapper">
  30. <view
  31. class="select-button"
  32. :class="{ 'select-active-button': setLightClassName(1, item) }"
  33. v-for="(item, index) in companyRestTime"
  34. :key="index"
  35. @click="handleSelect(1, item)"
  36. >{{ item }}</view>
  37. </view>
  38. </view>
  39. <view class="section">
  40. <view class="title">加班情况(可选)</view>
  41. <view class="select-button-wrapper">
  42. <view
  43. class="select-button"
  44. :class="{ 'select-active-button': setLightClassName(2, item) }"
  45. v-for="(item, index) in companyOvertimeSituation"
  46. :key="index"
  47. @click="handleSelect(2, item)"
  48. >{{ item }}</view>
  49. </view>
  50. </view>
  51. <view class="section">
  52. <view class="title">公司福利</view>
  53. <view class="input-wrapper" @click="showWelfarePopup = true">
  54. <view class="tags" v-if="companyWelfareTag.length">
  55. <view class="tag" v-for="(item, index) in companyWelfareTag" :key="index">{{ item }}</view>
  56. </view>
  57. <view class="tags-placeholder" v-else>请选择公司福利</view>
  58. <u-icon name="arrow-down" style="paddingLeft: 6px;"></u-icon>
  59. </view>
  60. </view>
  61. <!-- 时间组件 -->
  62. <u-select
  63. v-model="showTimeModal"
  64. :default-value="defaultTime"
  65. mode="mutil-column"
  66. :list="timeList"
  67. @confirm="confirmTime"
  68. ></u-select>
  69. <!-- 福利弹窗 -->
  70. <u-popup v-model="showWelfarePopup" :mask-close-able="false" mode="top" border-radius="14">
  71. <view class="welfare-popup" :style="{ paddingTop: BarHeight + 'px' }">
  72. <view class="tags-wrapper">
  73. <view class="welfare-popup-title">公司福利标签</view>
  74. <view class="welfare-tip">选择公司提供的福利信息,以吸引更多求职者</view>
  75. <view class="tags-box">
  76. <view class="tag-item" v-for="(item, index) in companyWelfare" :key="index">
  77. <view class="tag-title">{{ item.title }}</view>
  78. <view class="tags">
  79. <view
  80. class="tag"
  81. :class="{ 'active-tag': setWelfareClassName(tag) }"
  82. v-for="tag in item.content"
  83. :key="tag"
  84. @click="handleChangeWelfare(tag)"
  85. >{{ tag }}</view>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <view class="buttons-wrapper">
  91. <view class="button plain" @click="handleClear">清空</view>
  92. <view class="button primary" @click="showWelfarePopup = false">确定</view>
  93. </view>
  94. </view>
  95. </u-popup>
  96. </view>
  97. <view class="fixed-button">
  98. <view class="button" @click="handleSave">保存</view>
  99. </view>
  100. </view>
  101. </template>
  102. <script>
  103. import navBar from '@/components/nav-bar/index.vue'
  104. import { companyRestTime, companyOvertimeSituation, companyWelfare } from '@/constants/common.js'
  105. export default {
  106. components: {
  107. navBar
  108. },
  109. data() {
  110. return {
  111. BarHeight: 0,
  112. companyId: '',
  113. startWorkTime: '',
  114. endWorkTime: '',
  115. restTime: '', // 休息情况
  116. companyRestTime: companyRestTime,
  117. overTime: '', // 加班情况
  118. companyOvertimeSituation: companyOvertimeSituation,
  119. companyWelfare: companyWelfare,
  120. companyWelfareTag: [], // 公司福利
  121. showTimeModal: false,
  122. timeList: [],
  123. timeType: 1, // 1开始时间,2结束时间
  124. showWelfarePopup: false
  125. };
  126. },
  127. computed: {
  128. // 时间回显值
  129. defaultTime() {
  130. let currentTime = this.timeType == 1 ? this.startWorkTime : this.endWorkTime
  131. if (!currentTime) {
  132. return []
  133. }
  134. let hours = currentTime.split(':')[0]
  135. let min = currentTime.split(':')[1]
  136. let hoursIndex = 0
  137. let minIndex = 0
  138. if (this.timeList.length == 2) {
  139. hoursIndex = this.timeList[0].findIndex(item => item.value == hours)
  140. minIndex = this.timeList[1].findIndex(item => item.value == min)
  141. }
  142. return [hoursIndex < 0 ? 0 : hoursIndex, minIndex < 0 ? 0 : minIndex]
  143. }
  144. },
  145. onLoad() {
  146. // #ifdef APP-PLUS
  147. let systemInfo = uni.getSystemInfoSync();
  148. this.BarHeight = systemInfo.statusBarHeight;
  149. // #endif
  150. this.initTimeList()
  151. this.getCompanyInfo()
  152. },
  153. methods: {
  154. // 初始化选择的时间列表
  155. initTimeList() {
  156. let hoursList = []
  157. let minList = []
  158. for (let i = 0; i < 60; i++) {
  159. let value = i < 10 ? `0${i}` : `${i}`
  160. if (i < 24) {
  161. hoursList.push({
  162. label: value,
  163. value
  164. })
  165. }
  166. minList.push({
  167. label: value,
  168. value
  169. })
  170. }
  171. this.timeList = [hoursList, minList]
  172. },
  173. // 跳转至下一步
  174. toNext() {
  175. uni.redirectTo({
  176. url: '/my/renzheng/editCompanyDesc'
  177. })
  178. },
  179. // 获取公司信息
  180. getCompanyInfo() {
  181. uni.showLoading({ title: '加载中' })
  182. this.$Request.get('/app/company/selectCompanyByUserId')
  183. .then((res) => {
  184. if (res.code != 0) {
  185. uni.showToast({
  186. title: res.msg || '查询状态失败',
  187. icon: 'none'
  188. });
  189. return
  190. }
  191. this.companyId = res.data.companyId
  192. const workTimes = res.data.workTime?.split('-')
  193. if (workTimes) {
  194. this.startWorkTime = workTimes[0]
  195. this.endWorkTime = workTimes[1]
  196. }
  197. this.restTime = res.data.workRestTime
  198. this.overTime = res.data.workOverTime
  199. if (res.data.welfare) {
  200. this.companyWelfareTag = res.data.welfare.split(',')
  201. }
  202. uni.hideLoading()
  203. })
  204. .catch((err) => {
  205. uni.hideLoading()
  206. uni.showToast({
  207. title: '网络异常',
  208. icon: 'none'
  209. })
  210. })
  211. },
  212. openSelectTimePopup(type) {
  213. this.timeType = type
  214. this.showTimeModal = true
  215. },
  216. // 选择时间
  217. confirmTime(e) {
  218. let time = e.map(item => item.value).join(':')
  219. this.timeType == 1 ? this.startWorkTime = time : this.endWorkTime = time
  220. },
  221. // 设置高亮class
  222. setLightClassName(type, value) {
  223. return type == 1 ? this.restTime == value : this.overTime == value
  224. },
  225. // 选择休息时间/加班情况
  226. handleSelect(type, value) {
  227. type == 1 ? this.restTime = value : this.overTime = value
  228. },
  229. // 选择福利
  230. handleChangeWelfare(value) {
  231. const index = this.companyWelfareTag.findIndex(tag => tag == value)
  232. index == -1 ? this.companyWelfareTag.push(value) : this.companyWelfareTag.splice(index, 1)
  233. },
  234. setWelfareClassName(tag) {
  235. return this.companyWelfareTag.includes(tag)
  236. },
  237. // 清空福利
  238. handleClear() {
  239. this.companyWelfareTag = []
  240. this.showWelfarePopup = false
  241. },
  242. // 比较时间大小
  243. compareTime(time1, time2) {
  244. const [h1, m1] = time1.split(":").map(Number);
  245. const [h2, m2] = time2.split(":").map(Number);
  246. if (h1 !== h2) {
  247. return h1 - h2;
  248. }
  249. return m1 - m2;
  250. },
  251. handleSave() {
  252. if (this.loading) return
  253. // 验证时间选择
  254. if (!this.startWorkTime || !this.endWorkTime) {
  255. uni.showToast({
  256. title: "请选择完整的工作时间",
  257. icon: "none",
  258. });
  259. return;
  260. }
  261. // 这里可以添加时间逻辑验证,比如结束时间不能早于开始时间
  262. if (this.compareTime(this.startWorkTime, this.endWorkTime) >= 0) {
  263. uni.showToast({
  264. title: "结束时间必须晚于开始时间",
  265. icon: "none",
  266. });
  267. return;
  268. }
  269. uni.showLoading({ title: '保存中' })
  270. this.loading = true
  271. // 将选择的时间数据传递到下一页或保存
  272. const companyData = {
  273. companyId: this.companyId,
  274. workTime: `${this.startWorkTime}-${this.endWorkTime}`,
  275. workRestTime: this.restTime,
  276. workOverTime: this.overTime,
  277. welfare: this.companyWelfareTag.join(',')
  278. };
  279. this.$Request.postJson('/app/company/updateCompany', companyData)
  280. .then(res => {
  281. if(res.code == 0){
  282. uni.showToast({
  283. title: '提交成功',
  284. duration: 1500,
  285. });
  286. setTimeout(()=>{
  287. uni.$emit('updateCompanyInfo')
  288. uni.navigateBack()
  289. }, 500)
  290. }
  291. this.loading = true
  292. uni.hideLoading()
  293. })
  294. .catch(() => {
  295. this.loading = true
  296. uni.hideLoading()
  297. })
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss" scoped>
  303. @import './company.scss';
  304. .welfare-popup {
  305. padding-bottom: 36rpx;
  306. .tags-wrapper {
  307. padding: 36rpx 64rpx 100rpx;
  308. .welfare-popup-title {
  309. color: rgba(31, 44, 55, 1);
  310. font-size: 32rpx;
  311. font-weight: 500;
  312. line-height: 44rpx;
  313. margin-bottom: 24rpx;
  314. }
  315. .welfare-tip {
  316. color: rgba(158, 158, 158, 1);
  317. font-size: 28rpx;
  318. font-weight: 400;
  319. line-height: 36rpx;
  320. margin-bottom: 24rpx;
  321. }
  322. .tags-box {
  323. .tag-item {
  324. margin-bottom: 24rpx;
  325. .tag-title {
  326. color: rgba(31, 44, 55, 1);
  327. font-size: 28rpx;
  328. font-weight: 500;
  329. line-height: 44rpx;
  330. margin-bottom: 24rpx;
  331. }
  332. }
  333. }
  334. }
  335. .buttons-wrapper {
  336. display: flex;
  337. align-items: center;
  338. justify-content: space-between;
  339. padding: 16rpx 40rpx;
  340. gap: 16rpx;
  341. .button {
  342. flex: 1;
  343. height: 80rpx;
  344. text-align: center;
  345. line-height: 80rpx;
  346. border-radius: 80rpx;
  347. font-size: 32rpx;
  348. &.plain {
  349. color: rgba(1, 107, 246, 1);
  350. background: rgba(1, 107, 246, 0.1);
  351. }
  352. &.primary {
  353. color: #fff;
  354. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1));
  355. }
  356. }
  357. }
  358. }
  359. </style>