postList.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <ion-page class="list-page company-list-page">
  3. <ion-header class="header-theme2">
  4. <ion-toolbar>
  5. <ion-buttons slot="start">
  6. <ion-icon :icon="arrowBackOutline" @click="back"></ion-icon>
  7. </ion-buttons>
  8. <ion-title>
  9. 企业信息收集
  10. </ion-title>
  11. </ion-toolbar>
  12. </ion-header>
  13. <ion-content>
  14. <div class="stepFlex" v-if="!isEdit">
  15. <div v-for="(record,key) in stepList" :key="key" class="stepFlex-item">
  16. <div
  17. :class="[(record.val < formState.dataModel?.statusVal || formState.dataModel?.statusVal==stepList[stepList.length-1].val) ? 'greenCircle' :record.val == formState.dataModel?.statusVal ? 'now' : 'greyCircle']"></div>
  18. <div v-if="key !== stepList.length - 1"
  19. :class="[record.val < formState.dataModel?.statusVal ? 'greenline' : 'greyline']"></div>
  20. <div class="stepFlex-item-label">
  21. <p class="stepFlex-item-label-title">{{ record.title }}</p>
  22. <p class="stepFlex-item-label-desc">{{ record.desc }}</p>
  23. </div>
  24. </div>
  25. </div>
  26. <ion-list class="list-content">
  27. <ion-item>
  28. <ion-grid>
  29. <ion-row>
  30. <ion-col size="9">
  31. <span style="background-color: #3a7be0;display: inline-block;width: 3px;color: transparent;">|</span>
  32. &nbsp;岗位信息
  33. </ion-col>
  34. <ion-col style="text-align: right;">
  35. <ion-icon :icon="addCircleOutline" @click="onAdd()" style="font-size: 24px;"></ion-icon>
  36. </ion-col>
  37. </ion-row>
  38. </ion-grid>
  39. </ion-item>
  40. <ion-item v-for="(record,key) in postList" :key="key" detail>
  41. <ion-grid>
  42. <ion-row>
  43. <ion-col>
  44. <ion-label style="display: flex;justify-content: space-between;">
  45. <ion-text>
  46. {{ record.postName }}
  47. </ion-text>
  48. </ion-label>
  49. </ion-col>
  50. </ion-row>
  51. <ion-row>
  52. <ion-col size="8">
  53. <ion-label>
  54. <p>
  55. <!-- {{ record.jobVacancyTime }}至{{ calculateEndDate(record.jobVacancyTime, record.validDay) }}-->
  56. {{ record.validTime }}至{{ calculateEndDate(record.validTime, record.validDay) }}
  57. </p>
  58. </ion-label>
  59. </ion-col>
  60. <ion-col>
  61. <ion-label>
  62. <p>
  63. 招聘数量:{{ record.recruitCount }}
  64. </p>
  65. </ion-label>
  66. </ion-col>
  67. </ion-row>
  68. </ion-grid>
  69. </ion-item>
  70. </ion-list>
  71. </ion-content>
  72. <ion-footer>
  73. <ion-toolbar>
  74. <div slot="end">
  75. <ion-button shape="round" expand="block" @click="onSave">提交</ion-button>
  76. </div>
  77. </ion-toolbar>
  78. </ion-footer>
  79. </ion-page>
  80. </template>
  81. <script lang="ts">
  82. import {computed, defineComponent, reactive, ref, watch} from "vue";
  83. import {useRoute, useRouter} from "vue-router";
  84. import {alertController, onIonViewDidEnter} from "@ionic/vue";
  85. import {arrowBackOutline, addCircleOutline} from 'ionicons/icons';
  86. import {saveCompanyPost, getCompanyPostList, getCompanyById} from '@/api/company/index'
  87. import dayjs from "dayjs";
  88. interface FormState {
  89. dataModel: any;
  90. }
  91. interface PostModel {
  92. postName?: string | null,
  93. recruitCount?: number | null,
  94. // jobVacancyTime?: string | null,
  95. validTime?: string | null,
  96. validDay: number | null
  97. }
  98. export default defineComponent({
  99. name: 'editPost',
  100. setup() {
  101. const router = useRouter();
  102. const route = useRoute();
  103. const isEdit = ref<any>();
  104. const postList = ref<PostModel[]>([]);
  105. const formState = reactive<FormState>({dataModel: {}});
  106. const stepList = ref([
  107. {
  108. title: '基础信息',
  109. desc: '企业基础信息',
  110. val: 1
  111. },
  112. {
  113. title: '岗位信息',
  114. desc: '企业岗位信息',
  115. val: 2
  116. }]);
  117. const onSave = () => {
  118. if (postList.value.length == 0) {
  119. presentAlert('没有要提交的岗位信息!');
  120. return null;
  121. }
  122. if (route.query.id) {
  123. getCompanyById(route.query.id + "").then(data => {
  124. formState.dataModel = data;
  125. formState.dataModel.postData = postList.value;
  126. saveCompanyPost(formState.dataModel).then(result => {
  127. if (result) {
  128. router.push({path: './list', query: {success: 1}});
  129. }
  130. })
  131. })
  132. } else {
  133. const jsonDataModel = localStorage.getItem("companyData");
  134. formState.dataModel = JSON.parse(jsonDataModel ?? "");
  135. formState.dataModel.postData = postList.value;
  136. saveCompanyPost(formState.dataModel).then(result => {
  137. if (result) {
  138. router.push({path: './list', query: {success: 1}});
  139. }
  140. })
  141. }
  142. }
  143. const loadData = () => {
  144. postList.value = [];
  145. getCompanyPostList({companyID: route.query.id, pageSize: 999, pageIndex: 1}).then(data => {
  146. postList.value = data.list;
  147. formatDataList();
  148. console.log(postList.value);
  149. });
  150. }
  151. const initData=()=>{
  152. if (route.query.id) {
  153. isEdit.value = true;
  154. }
  155. if (route.query.pageStatus == "3") {
  156. const jsonPostList = localStorage.getItem("postData");
  157. postList.value = JSON.parse(jsonPostList ?? "");
  158. formatDataList();
  159. console.log(postList);
  160. }
  161. if (route.query.id && route.query.pageStatus == "1") {
  162. loadData();
  163. } else if (!route.query.id && route.query.pageStatus == "1") {
  164. isEdit.value = false;
  165. formState.dataModel.statusVal = 2;
  166. postList.value = [];
  167. }
  168. }
  169. onIonViewDidEnter(() => {
  170. if(route.query.reload){
  171. initData();
  172. }
  173. });
  174. const formatDataList = () => {
  175. postList.value.map(item => {
  176. if (item.validTime)
  177. item.validTime = dayjs(item.validTime).format("YYYY-MM-DD");
  178. });
  179. }
  180. const onAdd = () => {
  181. const jsonPostList = JSON.stringify(postList.value);
  182. localStorage.removeItem("postData");
  183. localStorage.setItem("postData", jsonPostList);
  184. if (route.query.id) {
  185. router.push({path: './editPost', query: {addStatus: 1, id: route.query.id}});
  186. } else {
  187. router.push({path: './editPost', query: {addStatus: 1}});
  188. }
  189. }
  190. // 计算截止日期的方法
  191. const calculateEndDate = (validTime: any, validDay: any) => {
  192. debugger;
  193. const validDate = new Date(validTime);
  194. validDate.setDate(validDate.getDate() + Number.parseInt(validDay));
  195. // 获取年月日
  196. const year = validDate.getFullYear();
  197. const month = validDate.getMonth() + 1; // 注意月份是从0开始的,需要加1
  198. const day = validDate.getDate();
  199. return `${year}-${month}-${day}`;
  200. };
  201. const back = () => {
  202. if (isEdit.value) {
  203. router.push({path: './list'});
  204. } else {
  205. router.push({path: './edit', query: {pageStatus: 2}});
  206. }
  207. }
  208. const presentAlert = async (message: string) => {
  209. const alert = await alertController.create({
  210. header: '错误!',
  211. message: message,
  212. buttons: [
  213. '确定'
  214. ],
  215. });
  216. await alert.present();
  217. }
  218. watch(() => route.query, () => {
  219. if (route.query.date) {
  220. if (route.query.id && route.query.pageStatus == "1")
  221. loadData();
  222. }
  223. });
  224. return {
  225. formState,
  226. onAdd,
  227. postList,
  228. stepList,
  229. onSave,
  230. calculateEndDate,
  231. route,
  232. arrowBackOutline,
  233. addCircleOutline,
  234. presentAlert,
  235. router,
  236. isEdit,
  237. back
  238. }
  239. }
  240. });
  241. </script>
  242. <style lang="less">
  243. .next-btn {
  244. width: 100%;
  245. --border-radius: 0px;
  246. --background: #f2f2f5;
  247. margin: 20px 0 0 0;
  248. color: #363432;
  249. font-size: 14px;
  250. }
  251. .stepFlex {
  252. margin: 0;
  253. display: flex;
  254. width: 100%;
  255. .stepFlex-item {
  256. position: relative;
  257. flex: 1;
  258. text-align: center;
  259. margin-top: -10px;
  260. .stepFlex-item-label {
  261. padding-top: 60px;
  262. font-size: 14px;
  263. .stepFlex-item-label-title {
  264. margin-top: 30px;
  265. }
  266. .stepFlex-item-label-desc {
  267. margin-top: 5px;
  268. color: #b9b9bd;
  269. }
  270. }
  271. }
  272. .greenCircle {
  273. top: calc(50% - 15px);
  274. left: calc(50% - 4px);
  275. position: absolute;
  276. z-index: 2;
  277. width: 10px;
  278. height: 10px;
  279. border-radius: 50%;
  280. background-color: #31A2FE;
  281. }
  282. .now {
  283. top: calc(50% - 18px);
  284. left: calc(50% - 8px);
  285. position: absolute;
  286. z-index: 3;
  287. width: 16px;
  288. height: 16px;
  289. border-radius: 50%;
  290. background-color: #31A2FE;
  291. border: 4px solid #c5e8f9;
  292. }
  293. .greyCircle {
  294. top: calc(50% - 15px);
  295. left: calc(50% - 4px);
  296. position: absolute;
  297. z-index: 2;
  298. width: 10px;
  299. height: 10px;
  300. border-radius: 50%;
  301. background-color: #ccc;
  302. }
  303. .greenline {
  304. width: 100%;
  305. top: calc(50% - 11px);
  306. left: calc(50% - 2px);
  307. height: 2px;
  308. background-color: #31A2FE;
  309. position: absolute;
  310. }
  311. .greyline {
  312. height: 0;
  313. border: 1px dashed #ccc;
  314. width: 100%;
  315. top: calc(50% - 11px);
  316. left: calc(50% - 2px);
  317. position: absolute;
  318. }
  319. .company-list-page {
  320. .list-content {
  321. margin: 0px 15px !important;
  322. background-color: white !important;
  323. border-radius: 0 !important;
  324. ion-item {
  325. margin-top: 10px;
  326. font-size: 14px;
  327. border: 1px solid rgb(242, 242, 245);
  328. p {
  329. font-size: 12px;
  330. }
  331. }
  332. }
  333. }
  334. }
  335. </style>