companyWelfare.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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">
  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. companyId: '',
  112. startWorkTime: '',
  113. endWorkTime: '',
  114. restTime: '', // 休息情况
  115. companyRestTime: companyRestTime,
  116. overTime: '', // 加班情况
  117. companyOvertimeSituation: companyOvertimeSituation,
  118. companyWelfare: companyWelfare,
  119. companyWelfareTag: [], // 公司福利
  120. showTimeModal: false,
  121. timeList: [],
  122. timeType: 1, // 1开始时间,2结束时间
  123. showWelfarePopup: false
  124. };
  125. },
  126. computed: {
  127. // 时间回显值
  128. defaultTime() {
  129. let currentTime = this.timeType == 1 ? this.startWorkTime : this.endWorkTime
  130. if (!currentTime) {
  131. return []
  132. }
  133. let hours = currentTime.split(':')[0]
  134. let min = currentTime.split(':')[1]
  135. let hoursIndex = 0
  136. let minIndex = 0
  137. if (this.timeList.length == 2) {
  138. hoursIndex = this.timeList[0].findIndex(item => item.value == hours)
  139. minIndex = this.timeList[1].findIndex(item => item.value == min)
  140. }
  141. return [hoursIndex < 0 ? 0 : hoursIndex, minIndex < 0 ? 0 : minIndex]
  142. }
  143. },
  144. onLoad() {
  145. this.initTimeList()
  146. this.getCompanyInfo()
  147. },
  148. methods: {
  149. // 初始化选择的时间列表
  150. initTimeList() {
  151. let hoursList = []
  152. let minList = []
  153. for (let i = 0; i < 60; i++) {
  154. let value = i < 10 ? `0${i}` : `${i}`
  155. if (i < 24) {
  156. hoursList.push({
  157. label: value,
  158. value
  159. })
  160. }
  161. minList.push({
  162. label: value,
  163. value
  164. })
  165. }
  166. this.timeList = [hoursList, minList]
  167. },
  168. // 跳转至下一步
  169. toNext() {
  170. uni.redirectTo({
  171. url: '/my/renzheng/editCompanyDesc'
  172. })
  173. },
  174. // 获取公司信息
  175. getCompanyInfo() {
  176. uni.showLoading({ title: '加载中' })
  177. this.$Request.get('/app/company/selectCompanyByUserId')
  178. .then((res) => {
  179. if (res.code != 0) {
  180. uni.showToast({
  181. title: res.msg || '查询状态失败',
  182. icon: 'none'
  183. });
  184. return
  185. }
  186. this.companyId = res.data.companyId
  187. const workTimes = res.data.workTime?.split('-')
  188. if (workTimes) {
  189. this.startWorkTime = workTimes[0]
  190. this.endWorkTime = workTimes[1]
  191. }
  192. this.restTime = res.data.workRestTime
  193. this.overTime = res.data.workOverTime
  194. if (res.data.welfare) {
  195. this.companyWelfareTag = res.data.welfare.split(',')
  196. }
  197. uni.hideLoading()
  198. })
  199. .catch((err) => {
  200. uni.hideLoading()
  201. uni.showToast({
  202. title: '网络异常',
  203. icon: 'none'
  204. })
  205. })
  206. },
  207. openSelectTimePopup(type) {
  208. this.timeType = type
  209. this.showTimeModal = true
  210. },
  211. // 选择时间
  212. confirmTime(e) {
  213. let time = e.map(item => item.value).join(':')
  214. this.timeType == 1 ? this.startWorkTime = time : this.endWorkTime = time
  215. },
  216. // 设置高亮class
  217. setLightClassName(type, value) {
  218. return type == 1 ? this.restTime == value : this.overTime == value
  219. },
  220. // 选择休息时间/加班情况
  221. handleSelect(type, value) {
  222. type == 1 ? this.restTime = value : this.overTime = value
  223. },
  224. // 选择福利
  225. handleChangeWelfare(value) {
  226. const index = this.companyWelfareTag.findIndex(tag => tag == value)
  227. index == -1 ? this.companyWelfareTag.push(value) : this.companyWelfareTag.splice(index, 1)
  228. },
  229. setWelfareClassName(tag) {
  230. return this.companyWelfareTag.includes(tag)
  231. },
  232. // 清空福利
  233. handleClear() {
  234. this.companyWelfareTag = []
  235. this.showWelfarePopup = false
  236. },
  237. // 比较时间大小
  238. compareTime(time1, time2) {
  239. const [h1, m1] = time1.split(":").map(Number);
  240. const [h2, m2] = time2.split(":").map(Number);
  241. if (h1 !== h2) {
  242. return h1 - h2;
  243. }
  244. return m1 - m2;
  245. },
  246. handleSave() {
  247. if (this.loading) return
  248. // 验证时间选择
  249. if (!this.startWorkTime || !this.endWorkTime) {
  250. uni.showToast({
  251. title: "请选择完整的工作时间",
  252. icon: "none",
  253. });
  254. return;
  255. }
  256. // 这里可以添加时间逻辑验证,比如结束时间不能早于开始时间
  257. if (this.compareTime(this.startWorkTime, this.endWorkTime) >= 0) {
  258. uni.showToast({
  259. title: "结束时间必须晚于开始时间",
  260. icon: "none",
  261. });
  262. return;
  263. }
  264. uni.showLoading({ title: '保存中' })
  265. this.loading = true
  266. // 将选择的时间数据传递到下一页或保存
  267. const companyData = {
  268. companyId: this.companyId,
  269. workTime: `${this.startWorkTime}-${this.endWorkTime}`,
  270. workRestTime: this.restTime,
  271. workOverTime: this.overTime,
  272. welfare: this.companyWelfareTag.join(',')
  273. };
  274. this.$Request.postJson('/app/company/updateCompany', companyData)
  275. .then(res => {
  276. if(res.code == 0){
  277. uni.showToast({
  278. title: '提交成功',
  279. duration: 1500,
  280. });
  281. setTimeout(()=>{
  282. uni.$emit('updateCompanyInfo')
  283. uni.navigateBack()
  284. }, 500)
  285. }
  286. this.loading = true
  287. uni.hideLoading()
  288. })
  289. .catch(() => {
  290. this.loading = true
  291. uni.hideLoading()
  292. })
  293. }
  294. }
  295. }
  296. </script>
  297. <style lang="scss" scoped>
  298. @import './company.scss';
  299. .welfare-popup {
  300. padding-bottom: 36rpx;
  301. .tags-wrapper {
  302. padding: 36rpx 64rpx 100rpx;
  303. .welfare-popup-title {
  304. color: rgba(31, 44, 55, 1);
  305. font-size: 32rpx;
  306. font-weight: 500;
  307. line-height: 44rpx;
  308. margin-bottom: 24rpx;
  309. }
  310. .welfare-tip {
  311. color: rgba(158, 158, 158, 1);
  312. font-size: 28rpx;
  313. font-weight: 400;
  314. line-height: 36rpx;
  315. margin-bottom: 24rpx;
  316. }
  317. .tags-box {
  318. .tag-item {
  319. margin-bottom: 24rpx;
  320. .tag-title {
  321. color: rgba(31, 44, 55, 1);
  322. font-size: 28rpx;
  323. font-weight: 500;
  324. line-height: 44rpx;
  325. margin-bottom: 24rpx;
  326. }
  327. }
  328. }
  329. }
  330. .buttons-wrapper {
  331. display: flex;
  332. align-items: center;
  333. justify-content: space-between;
  334. padding: 16rpx 40rpx;
  335. gap: 16rpx;
  336. .button {
  337. flex: 1;
  338. height: 80rpx;
  339. text-align: center;
  340. line-height: 80rpx;
  341. border-radius: 80rpx;
  342. font-size: 32rpx;
  343. &.plain {
  344. color: rgba(1, 107, 246, 1);
  345. background: rgba(1, 107, 246, 0.1);
  346. }
  347. &.primary {
  348. color: #fff;
  349. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1));
  350. }
  351. }
  352. }
  353. }
  354. </style>