用工小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

365 lines
9.9 KiB

6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
3 months ago
6 months ago
4 months ago
6 months ago
3 months ago
6 months ago
4 months ago
6 months ago
3 months ago
6 months ago
6 months ago
6 months ago
6 months ago
3 months ago
6 months ago
3 months ago
6 months ago
4 months ago
3 months ago
4 months ago
6 months ago
3 months ago
6 months ago
4 months ago
6 months ago
3 months ago
6 months ago
3 months ago
4 months ago
3 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
3 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
3 months ago
6 months ago
3 months ago
4 months ago
6 months ago
4 months ago
3 months ago
4 months ago
3 months ago
4 months ago
3 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
4 months ago
6 months ago
  1. <template>
  2. <view>
  3. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" labelWidth="80">
  4. <view class="se-p-20">
  5. <view class="se-p-20 se-bgc-white se-br-10 se-fs-20">
  6. <u-form-item label="姓名" prop="name">
  7. <u--input v-model="form.name" class="se-bgc-f5" placeholder="请输入姓名名称"></u--input>
  8. </u-form-item>
  9. <!-- <u-form-item label="密码" prop="password">
  10. <u--input v-model="form.password" class="se-bgc-f5" placeholder="请输入您的密码"></u--input>
  11. </u-form-item> -->
  12. <u-form-item label="联系电话" prop="mobile">
  13. <u--input v-model="form.mobile" class="se-bgc-f5" placeholder="请输入联系方式"></u--input>
  14. </u-form-item>
  15. <u-form-item label="年龄" prop="age">
  16. <u--input v-model="form.age" class="se-bgc-f5" placeholder="请输入年龄"></u--input>
  17. </u-form-item>
  18. <u-form-item label="地址" prop="address">
  19. <u--input v-model="form.address" class="se-bgc-f5" placeholder="请输入地址"></u--input>
  20. </u-form-item>
  21. <u-form-item label="性别" prop="sex" @click="handleSexChange">
  22. <u--input @click="handleSexChange" readonly v-model="form.sex" placeholder="请选择性别"
  23. border="none"></u--input>
  24. <u-icon @click="handleSexChange" slot="right" name="arrow-right"></u-icon>
  25. </u-form-item>
  26. <u-form-item label="工种" prop="industryId" @click="handleIndChange">
  27. <u--input v-model="form.industryName" readonly placeholder="请选择工种" border="none"></u--input>
  28. <u-icon slot="right" name="arrow-right"></u-icon>
  29. </u-form-item>
  30. <u-form-item label="薪资待遇" prop="salary">
  31. <view class="se-flex se-flex-h-c">
  32. <u--input v-model="form.salaryMin" class="se-w-200" placeholder="最小值"></u--input>
  33. <text class="se-mx-10">~</text>
  34. <u--input v-model="form.salaryMax" class="se-w-200" placeholder="最大值"></u--input>
  35. </view>
  36. </u-form-item>
  37. <u-form-item label="个人介绍" prop="introduce">
  38. <u--textarea v-model="form.introduce" count maxlength="300" class="se-bgc-f5"
  39. placeholder="请选择个人介绍"></u--textarea>
  40. </u-form-item>
  41. </view>
  42. </view>
  43. <view class="se-p-20">
  44. <view class="se-px-20 se-pb-20 se-bgc-white se-br-10 se-fs-20">
  45. <u-form-item prop="idCardFile" labelWidth="2">
  46. <view class="se-flex se-flex-v-sa">
  47. <view class="se-py-20 se-w-p-100 se-flex">
  48. <view class="line-orange"></view>
  49. <view class="se-ml-10">
  50. 身份证上传正反面
  51. </view>
  52. </view>
  53. <view class="se-py-20 se-w-p-100">
  54. <u-upload :fileList="form.idCardFile" @afterRead="afterRead" @delete="deletePic" name="1" multiple :maxCount="10"></u-upload>
  55. </view>
  56. </view>
  57. </u-form-item>
  58. </view>
  59. </view>
  60. <view class="se-px-20 se-pt-20">
  61. <view class="se-px-20 se-pb-80 se-fs-20 se-flex">
  62. <view @click="submit" class="se-mx-10 se-flex-1 se-br-40 se-flex-h-c se-h-60 se-lh-60 se-ta-c se-fs-28 se-c-white se-bgc-orange">
  63. <text>保存</text>
  64. </view>
  65. <!-- <view
  66. class="se-mx-10 se-flex-1 se-b se-br-40 se-flex-h-c se-h-60 se-lh-60 se-ta-c se-fs-28 se-c-66 se-bgc-f5">
  67. <text>联系我们</text>
  68. </view> -->
  69. </view>
  70. </view>
  71. </u--form>
  72. <!-- 性别 -->
  73. <u-action-sheet :show="showSex" :actions="sexList" title="请选择性别" @close="showSex = false" @select="sexSelect"></u-action-sheet>
  74. <!-- 种类 -->
  75. <u-action-sheet :show="showType" :actions="typeList" title="请选择种类" @close="showType = false" @select="typeSelect"></u-action-sheet>
  76. </view>
  77. </template>
  78. <script>
  79. import {
  80. role,
  81. industryList,
  82. updateRole
  83. } from "@/common/api.js"
  84. export default {
  85. data() {
  86. return {
  87. showSex: false,
  88. sexList: [
  89. {
  90. name: '男',
  91. },
  92. {
  93. name: '女',
  94. }
  95. ],
  96. showType: false,
  97. typeList: [],
  98. fileList: [],
  99. form: {
  100. id:"",
  101. name: '',
  102. password: '',
  103. mobile: '',
  104. address:"",
  105. age: '',
  106. sex: '',
  107. industryId: '',
  108. industryName: "",
  109. salary: '',
  110. salaryMin: '',
  111. salaryMax: '',
  112. introduce: '',
  113. idCardFile: []
  114. },
  115. rules: {
  116. name: [{
  117. type: 'string',
  118. required: true,
  119. message: '请输入姓名名称',
  120. trigger: ['blur', 'change']
  121. }],
  122. industryId: [{
  123. type: 'string',
  124. required: true,
  125. message: '请选择行业',
  126. trigger: ['blur', 'change']
  127. }],
  128. address:[
  129. {
  130. type: 'string',
  131. required: true,
  132. message: '请选择地址',
  133. trigger: ['blur', 'change']
  134. }
  135. ],
  136. // password: [{
  137. // type: 'string',
  138. // required: true,
  139. // message: '请输入您的密码',
  140. // trigger: ['blur', 'change']
  141. // }],
  142. mobile: [{
  143. required: true,
  144. message: '请输入手机号',
  145. trigger: ['change', 'blur'],
  146. },
  147. {
  148. validator: (rule, value, callback) => {
  149. return uni.$u.test.mobile(value);
  150. },
  151. message: '手机号码不正确',
  152. trigger: ['change', 'blur'],
  153. },
  154. ],
  155. age: [{
  156. validator: (rule, value, callback) => {
  157. if (!value) {
  158. callback(new Error('年龄不能为空'));
  159. } else if (isNaN(value)) {
  160. callback(new Error('请输入数字'));
  161. } else if (value < 18 || value > 65) {
  162. callback(new Error('年龄必须在18至65岁之间'));
  163. } else {
  164. callback(); // 验证通过
  165. }
  166. },
  167. trigger: 'blur',
  168. }],
  169. sex: [{
  170. type: 'string',
  171. max: 1,
  172. required: true,
  173. message: '请选择性别',
  174. trigger: ['blur', 'change']
  175. }],
  176. salary: [{
  177. type: 'string',
  178. required: true,
  179. message: '请输入薪资待遇',
  180. trigger: ['blur', 'change']
  181. }],
  182. introduce: [{
  183. type: 'string',
  184. required: true,
  185. message: '请输入个人简介',
  186. trigger: ['blur', 'change']
  187. }],
  188. idCardFile: [{
  189. validator: (rule, value, callback) => {
  190. if (value === null || value === undefined || value === '' || (Array.isArray(
  191. value) && value.length === 0)) {
  192. callback(new Error('请选择身份证'));
  193. } else {
  194. callback();
  195. }
  196. },
  197. trigger: 'blur'
  198. }]
  199. },
  200. }
  201. },
  202. watch: {
  203. 'form.salaryMin': {
  204. handler(newVal, oldVal) {
  205. if (!uni.$u.test.isEmpty(newVal) && !uni.$u.test.isEmpty(this.form.salaryMax)) {
  206. this.form.salary = '有'
  207. } else {
  208. this.form.salary = ''
  209. }
  210. },
  211. immediate: true
  212. },
  213. 'form.salaryMax': {
  214. handler(newVal, oldVal) {
  215. if (!uni.$u.test.isEmpty(newVal) && !uni.$u.test.isEmpty(this.form.salaryMin)) {
  216. this.form.salary = '有'
  217. } else {
  218. this.form.salary = ''
  219. }
  220. },
  221. immediate: true
  222. }
  223. },
  224. mounted() {
  225. let worker = uni.getStorageSync("worker")
  226. if(worker){
  227. this.form.id = worker.id
  228. this.form.name = worker.userName
  229. this.form.mobile = worker.phone
  230. this.form.age = worker.age
  231. this.form.sex = worker.sex==1?'男':'女'
  232. this.form.introduce = worker.detail
  233. this.form.address = worker.address
  234. this.form.industryId = worker.industryId
  235. this.form.industryName = worker.industryName
  236. this.form.salaryMin = worker.moneyMin
  237. this.form.salaryMax = worker.moneyMax
  238. this.form.idCardFile = this.stringToKeyValueArray(worker.idCard)
  239. }
  240. },
  241. methods: {
  242. stringToKeyValueArray(str, delimiter1 = ',') {
  243. if(str){
  244. let arro = str.split(delimiter1);
  245. let arr = [];
  246. arro.forEach(items=>{
  247. let obj = {};
  248. obj["url"] = items
  249. arr.push(obj)
  250. })
  251. console.info(arr)
  252. return arr
  253. }else{
  254. return []
  255. }
  256. },
  257. handleIndChange() {
  258. this.showType = true
  259. },
  260. typeSelect(event) {
  261. console.info("selectIndClick", event)
  262. this.form.industryId = event.id
  263. this.form.industryName = event.name
  264. this.showType = false
  265. },
  266. onIndustryList() {
  267. industryList({}).then(response => {
  268. console.info(response)
  269. this.typeList = response.result
  270. }).catch(error => {
  271. })
  272. },
  273. handleSexChange() {
  274. this.showSex = true
  275. },
  276. sexSelect(e) {
  277. this.form.sex = e.name
  278. this.$refs.uForm.validateField('sex')
  279. },
  280. onRole() {
  281. let that = this
  282. let params = {
  283. id: that.form.id,
  284. userName: that.form.name,
  285. industryId: that.form.industryId,
  286. industryName: that.form.industryName,
  287. address:that.form.address,
  288. age: that.form.age,
  289. gender: that.form.sex=="男"?1:2,
  290. moneyMin: that.form.salaryMin,
  291. moneyMax: that.form.salaryMax,
  292. phone: that.form.mobile,
  293. detail: that.form.introduce,
  294. idCard: that.form.idCardFile.map(item => item.url).join(','),
  295. }
  296. if(this.form.id){
  297. updateRole(params).then(response=>{
  298. uni.$u.toast("保存成功!")
  299. setTimeout(()=>{
  300. uni.navigateBack({
  301. delta:1
  302. })
  303. },1500)
  304. }).catch(error=>{
  305. })
  306. }else{
  307. role(params).then(response => {
  308. uni.$u.toast("提交成功,等待申请")
  309. setTimeout(()=>{
  310. uni.switchTab({
  311. url:"/pages/home/index"
  312. })
  313. },1500)
  314. }).catch(error => {
  315. setTimeout(()=>{
  316. uni.switchTab({
  317. url:"/pages/home/index"
  318. })
  319. },1500)
  320. })
  321. }
  322. },
  323. submit() {
  324. this.$refs.uForm.validate().then(res => {
  325. this.onRole()
  326. }).catch(errors => {
  327. // uni.$u.toast('校验失败')
  328. })
  329. },
  330. deletePic(event) {
  331. this.form.idCardFile.splice(e.index, 1)
  332. },
  333. async afterRead(e) {
  334. let self = this
  335. e.file.forEach(file => {
  336. self.$Oss.ossUpload(file.url).then(url => {
  337. self.form.idCardFile.push({
  338. url
  339. })
  340. })
  341. })
  342. }
  343. },
  344. onReady() {
  345. this.onIndustryList()
  346. this.$refs.uForm.setRules(this.rules)
  347. },
  348. }
  349. </script>
  350. <style lang="scss" scoped>
  351. page {
  352. background-color: #f5f5f5 !important;
  353. }
  354. .line-orange {
  355. width: 8rpx;
  356. height: 32rpx;
  357. background: #ff7a31;
  358. border-radius: 4rpx;
  359. }
  360. </style>