info.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <div class="info">
  3. <header>
  4. <h5>基本信息</h5>
  5. <div class="opts">
  6. <el-button type="info" @click="onCancel">取消</el-button>
  7. <el-button type="primary" @click="onSubmit">保存</el-button>
  8. </div>
  9. </header>
  10. <div class="edit">
  11. <el-form ref="form" :rules="rules" :model="form" label-width="147px">
  12. <el-form-item label="昵称" prop="nickname">
  13. <el-input v-model="form.nickname" maxlength="50"></el-input>
  14. </el-form-item>
  15. <el-form-item label="工作状态" prop="type">
  16. <el-select v-model="form.type" placeholder="请选择">
  17. <el-option
  18. v-for="type in types"
  19. :key="type.value"
  20. :label="type.label"
  21. :value="type.value"
  22. ></el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="职业方向" prop="direction_op">
  26. <el-select v-model="form.occupation_op" placeholder="请选择">
  27. <el-option
  28. v-for="item in directions"
  29. :key="item.occupation_id"
  30. :label="item.occupation_name"
  31. :value="item.occupation_id"
  32. ></el-option>
  33. </el-select>
  34. <el-select v-model="form.direction_op" placeholder="请选择">
  35. <el-option
  36. v-for="item in subDirections"
  37. :key="item.direction_id"
  38. :label="item.direction_name"
  39. :value="item.direction_id"
  40. ></el-option>
  41. </el-select>
  42. </el-form-item>
  43. <el-form-item label="所在地区" prop="city_op_id">
  44. <el-select v-model="form.province_op_id" placeholder="请选择" @change="getCities">
  45. <el-option v-for="item in provinces" :key="item.id" :label="item.name" :value="item.id"></el-option>
  46. </el-select>
  47. <!-- <el-date-picker
  48. type="date"
  49. placeholder="选择日期"
  50. v-model="form.date1"
  51. style="width: 100%;"
  52. ></el-date-picker>-->
  53. <el-select v-model="form.city_op_id" placeholder="请选择">
  54. <el-option v-for="item in cities" :key="item.id" :label="item.name" :value="item.id"></el-option>
  55. </el-select>
  56. <!-- <el-time-picker placeholder="选择时间" v-model="form.date2" style="width: 100%;"></el-time-picker> -->
  57. </el-form-item>
  58. <el-form-item label="日薪" prop="work_price">
  59. <el-input-number
  60. :min="300"
  61. :max="2000"
  62. controls-position="right"
  63. v-model="form.work_price"
  64. :style="{width: '150px', marginRight: '10px'}"
  65. ></el-input-number>元/天(8小时)
  66. </el-form-item>
  67. <el-form-item label="可工作时间" prop="workday">
  68. <div class="times">
  69. <el-checkbox v-model="form.workday" label="工作日"></el-checkbox>
  70. <el-time-select
  71. v-model="form.workdayStart"
  72. :picker-options="{
  73. start: '00:00',
  74. step: '00:30',
  75. end: '24:00'
  76. }"
  77. placeholder="开始时间"
  78. ></el-time-select>
  79. <span class="to">至</span>
  80. <el-time-select
  81. v-model="form.workdayEnd"
  82. :picker-options="{
  83. start: '00:00',
  84. step: '00:30',
  85. end: '24:00'
  86. }"
  87. placeholder="结束时间"
  88. ></el-time-select>
  89. </div>
  90. <div class="times">
  91. <el-checkbox v-model="form.weekend" label="周末"></el-checkbox>
  92. <el-time-select
  93. v-model="form.weekendStart"
  94. :picker-options="{
  95. start: '00:00',
  96. step: '00:30',
  97. end: '24:00'
  98. }"
  99. placeholder="开始时间"
  100. ></el-time-select>
  101. <span class="to">至</span>
  102. <el-time-select
  103. v-model="form.weekendEnd"
  104. :picker-options="{
  105. start: '00:00',
  106. step: '00:30',
  107. end: '24:00'
  108. }"
  109. placeholder="结束时间"
  110. ></el-time-select>
  111. </div>
  112. </el-form-item>
  113. </el-form>
  114. </div>
  115. </div>
  116. </template>
  117. <script>
  118. import { mapState } from "vuex";
  119. const types = [
  120. {
  121. value: "2",
  122. label: "求职"
  123. },
  124. {
  125. value: "4",
  126. label: "自由职业"
  127. },
  128. {
  129. value: "5",
  130. label: "正常工作"
  131. }
  132. ];
  133. export default {
  134. data() {
  135. return {
  136. rules: {
  137. nickname: [
  138. {
  139. required: true,
  140. message: "请完善昵称信息",
  141. trigger: "blur"
  142. },
  143. { max: 50, message: "昵称不得超过50字符", trigger: "blur" },
  144. {
  145. validator: (rule, value, callback) => {
  146. console.log(this.regPhone);
  147. if (this.regPhone.test(value)) {
  148. callback(new Error("请不要使用手机号作为昵称"));
  149. } else {
  150. callback();
  151. }
  152. },
  153. trigger: "blur"
  154. },
  155. {
  156. validator: (rule, value, callback) => {
  157. if (this.regSpecialChar.test(value)) {
  158. callback(new Error("昵称不得使用特殊字符"));
  159. } else {
  160. callback();
  161. }
  162. },
  163. trigger: "blur"
  164. }
  165. ],
  166. type: [
  167. {
  168. required: true,
  169. message: "请设置当前工作状态",
  170. trigger: "change"
  171. }
  172. ],
  173. direction_op: [
  174. {
  175. required: true,
  176. validator: (rule, value, callback) => {
  177. if (!this.form.direction_op || !this.form.occupation_op) {
  178. callback(new Error("请设置职业方向信息"));
  179. } else {
  180. callback();
  181. }
  182. },
  183. trigger: "change"
  184. }
  185. ],
  186. city_op_id: [
  187. {
  188. required: true,
  189. validator: (rule, value, callback) => {
  190. if (!this.form.city_op_id || !this.form.occupation_op) {
  191. callback(new Error("请设置所在地区信息"));
  192. } else {
  193. callback();
  194. }
  195. },
  196. trigger: "change"
  197. }
  198. ],
  199. work_price: [
  200. {
  201. required: true,
  202. message: "请设置日薪",
  203. trigger: "blur"
  204. },
  205. {
  206. validator: (rule, value, callback) => {
  207. if (value < 300 || value > 2000) {
  208. callback(new Error("日薪只允许设置300--2000范围内的正整数"));
  209. } else {
  210. callback();
  211. }
  212. },
  213. trigger: "blur"
  214. }
  215. ],
  216. workday: [
  217. {
  218. required: true,
  219. validator: (rule, value, callback) => {
  220. console.log(value);
  221. if (!this.form.workday && !this.form.weekend) {
  222. callback(new Error("请完善可工作时间"));
  223. } else if (
  224. (this.form.workday &&
  225. (!this.form.workdayStart || !this.form.workdayEnd)) ||
  226. (this.form.weekend &&
  227. (!this.form.weekendStart || !this.form.weekendEnd))
  228. ) {
  229. callback(new Error("请完善可工作时间"));
  230. } else {
  231. console.log(this.$refs.form);
  232. callback();
  233. }
  234. },
  235. trigger: "change"
  236. }
  237. ],
  238. weekend: [
  239. {
  240. validator: (rule, value, callback) => {
  241. if (!value && !this.form.workday) {
  242. callback(new Error("请完善可工作时间"));
  243. } else if (
  244. value &&
  245. (!this.form.weekendStart || !this.form.weekendEnd)
  246. ) {
  247. callback(new Error("请完善周末可工作时间"));
  248. } else {
  249. callback();
  250. }
  251. },
  252. trigger: "change"
  253. }
  254. ]
  255. },
  256. userInfo: {},
  257. form: {
  258. nickname: "",
  259. type: "",
  260. work_price: 300,
  261. occupation_op: "",
  262. direction_op: "",
  263. address: ["", ""],
  264. region: "",
  265. workday: true,
  266. weekend: false,
  267. workdayStart: "",
  268. workdayEnd: "",
  269. weekendStart: "",
  270. weekendEnd: "",
  271. dailyRate: "",
  272. workdayTime: "",
  273. province_op_id: "",
  274. city_op_id: ""
  275. },
  276. editing: false,
  277. types,
  278. directions: [],
  279. regions: [],
  280. provinces: [],
  281. cities: []
  282. };
  283. },
  284. computed: {
  285. ...mapState(["regPhone", "regSpecialChar"]),
  286. subDirections: function() {
  287. let direction = this.form.occupation_op;
  288. let current = null;
  289. this.directions.map(dir => {
  290. if (dir.occupation_id === direction) {
  291. current = dir;
  292. }
  293. });
  294. if (!current) {
  295. return [];
  296. }
  297. return current.children;
  298. },
  299. typeShow: function() {
  300. const types = this.types;
  301. const type = this.form.type;
  302. let show = "-";
  303. for (let i = 0, len = types.length; i < len; i++) {
  304. if (types[i].value == type) {
  305. show = `${types[i].label}`;
  306. }
  307. }
  308. return show;
  309. },
  310. occupationShow: function() {
  311. const directions = this.directions;
  312. let show = "-";
  313. for (let i = 0, len = directions.length; i < len; i++) {
  314. if (directions[i].occupation_id == this.form.occupation_op) {
  315. const subs = directions[i].children;
  316. for (let j = 0, len = subs.length; j < len; j++) {
  317. if (subs[j].direction_id == this.form.direction_op) {
  318. show = `${directions[i].occupation_name} - ${subs[j].direction_name}`;
  319. }
  320. }
  321. }
  322. }
  323. return show;
  324. },
  325. provinceShow: function() {
  326. const directions = this.directions;
  327. let show = "-";
  328. for (let i = 0, len = directions.length; i < len; i++) {
  329. if (directions[i].occupation_id == this.type) {
  330. show = `${directions[i].occupation_name}`;
  331. }
  332. }
  333. return show;
  334. }
  335. },
  336. watch: {
  337. "form.occupation_op": function() {
  338. if (this.form.occupation_op !== this.userInfo.occupation_op) {
  339. this.userInfo.occupation_op=this.form.occupation_op;
  340. this.form.direction_op = "";
  341. }
  342. }
  343. },
  344. async mounted() {
  345. this.userInfo = await this.getUserInfo();
  346. const user = this.userInfo;
  347. console.log(user);
  348. this.form.nickname = user.nickname;
  349. this.form.type = user.type && user.type !== "0" ? user.type : "";
  350. this.form.occupation_op =
  351. user.occupation_op && user.occupation_op !== "0"
  352. ? user.occupation_op
  353. : "";
  354. this.form.direction_op =
  355. user.direction_op && user.direction_op !== "0" ? user.direction_op : "";
  356. this.form.work_price = user.work_price;
  357. this.form.province_op_id =
  358. user.province_op_id && user.province_op_id !== "0"
  359. ? user.province_op_id
  360. : "";
  361. this.form.city_op_id =
  362. user.city_op_id && user.city_op_id !== "0" ? user.city_op_id : "";
  363. const work_time_op = user.work_time_op;
  364. if (work_time_op) {
  365. if (work_time_op.weekend) {
  366. this.form.weekend = true;
  367. this.form.weekendStart = work_time_op.weekend[0];
  368. this.form.weekendEnd = work_time_op.weekend[1];
  369. } else {
  370. this.form.weekend = false;
  371. }
  372. if (work_time_op.workday) {
  373. this.form.workday = true;
  374. this.form.workdayStart = work_time_op.workday[0];
  375. this.form.workdayEnd = work_time_op.workday[1];
  376. } else {
  377. this.form.workday = false;
  378. }
  379. }
  380. this.getDirection();
  381. this.getProvinces();
  382. this.form.province_op_id = this.form.province_op_id
  383. ? this.form.province_op_id
  384. : "";
  385. if (this.form.province_op_id) {
  386. this.getCities(this.form.province_op_id, true);
  387. }
  388. },
  389. methods: {
  390. async onSubmit() {
  391. this.cnzz("签约","签约页面+基本信息保存","");
  392. //console.log("submit!");
  393. this.$refs["form"].validate(async valid => {
  394. if (!valid) {
  395. // this.$message.error("填写有误");
  396. return false;
  397. }
  398. const form = this.form;
  399. const work_time_op = {};
  400. if (form.weekend) {
  401. work_time_op.weekend = [form.weekendStart, form.weekendEnd];
  402. }
  403. if (form.workday) {
  404. work_time_op.workday = [form.workdayStart, form.workdayEnd];
  405. }
  406. const data = {
  407. work_time_op: JSON.stringify(work_time_op),
  408. province_op_id: this.form.province_op_id,
  409. city_op_id: this.form.city_op_id,
  410. // district_op_name: '',
  411. // work_time_per_work: '',
  412. // work_remote: '',
  413. // work_area: '',
  414. // province_op: '', // 远程工作
  415. work_price: form.work_price,
  416. nickname: form.nickname,
  417. type: form.type,
  418. occupation_op: form.occupation_op,
  419. direction_op: form.direction_op
  420. };
  421. const res = await this.$axios.$post("/api/user/update_info", data);
  422. if (res.status === 1) {
  423. this.$message.success("保存成功!");
  424. this.editing = false;
  425. } else {
  426. // this.$message.error(res.info);
  427. }
  428. });
  429. },
  430. async getDirection() {
  431. const res = await this.$axios.$post("/api/direction/get_all_data");
  432. this.directions = res.data || [];
  433. },
  434. async getProvinces() {
  435. const res = await this.$axios.$post("/api/geo/get_province_list");
  436. this.provinces = res.data || [];
  437. },
  438. async getCities(id, flag) {
  439. if (!flag) {
  440. this.form.city_op_id = "";
  441. }
  442. const res = await this.$axios.$post(
  443. "/api/geo/get_city_list_by_province",
  444. { prov_id: id }
  445. );
  446. this.cities = res.data || [];
  447. this.form.city_op = res.data[0].id;
  448. },
  449. async onCancel() {
  450. this.form.nickname = this.userInfo.nickname;
  451. this.form.type = this.userInfo.type;
  452. this.form.occupation_op = this.userInfo.occupation_op;
  453. this.form.direction_op = this.userInfo.direction_op;
  454. this.form.work_price = this.userInfo.work_price;
  455. let work_time_op = this.userInfo.work_time_op;
  456. if (work_time_op.weekend) {
  457. this.form.weekend = true;
  458. this.form.weekendStart = work_time_op.weekend[0];
  459. this.form.weekendEnd = work_time_op.weekend[1];
  460. } else {
  461. this.form.weekend = false;
  462. }
  463. if (work_time_op.workday) {
  464. this.form.workday = true;
  465. this.form.workdayStart = work_time_op.workday[0];
  466. this.form.workdayEnd = work_time_op.workday[1];
  467. } else {
  468. this.form.workday = false;
  469. }
  470. }
  471. }
  472. };
  473. </script>
  474. <style lang="scss" scoped>
  475. .info {
  476. .edit {
  477. > form {
  478. margin-top: 44px;
  479. .el-select,
  480. .el-input {
  481. width: 217px;
  482. margin-right: 10px;
  483. }
  484. .times {
  485. margin-bottom: 20px;
  486. .el-checkbox {
  487. width: 88px;
  488. }
  489. .to {
  490. margin-right: 10px;
  491. }
  492. .el-input {
  493. width: 136px;
  494. }
  495. }
  496. }
  497. }
  498. }
  499. </style>