caregiverForm.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. <template>
  2. <view class="container">
  3. <u-navbar :title="title" leftIconColor="#333" titleStyle="color:#333" :autoBack="true" placeholder></u-navbar>
  4. <view class="form-box">
  5. <u--form labelWidth="140rpx" :model="formData" :rules="rules" ref="uForm">
  6. <u-form-item label="常驻医院" prop="hospitalName" borderBottom @click="showHospital = true">
  7. <u-input :border="none" disabled v-model="formData.hospitalName" disabledColor="#ffffff"
  8. placeholder="请选择医院" inputAlign="right" />
  9. <u-icon slot="right" name="arrow-right" color="#999999"></u-icon>
  10. </u-form-item>
  11. <u-form-item label="护工姓名" prop="name" borderBottom required>
  12. <u--input v-model="formData.name" border="none" placeholder="请输入" :disabled="type == 'view'"
  13. maxlength="10" inputAlign="right"></u--input>
  14. </u-form-item>
  15. <u-form-item label="形象照片" prop="photographUrl" borderBottom required labelPosition="top">
  16. <view class="upload-box">
  17. <u-upload :fileList="formData.photographUrlList" file="image" :multiple="false" :maxCount="1"
  18. @afterRead="afterRead" @delete="deletePic" name="upload1" width="75" height="75">
  19. </u-upload>
  20. <span class="tips">支持png、jpg和gif格式,限制1张</span>
  21. </view>
  22. </u-form-item>
  23. <u-form-item label="性别" prop="genderName" borderBottom @click="showSex = true" required>
  24. <u-input :border="none" disabled v-model="formData.genderName" disabledColor="#ffffff"
  25. placeholder="请选择" inputAlign="right" />
  26. <u-icon slot="right" name="arrow-right" color="#999999"></u-icon>
  27. </u-form-item>
  28. <u-form-item label="身份证号" prop="idCard" borderBottom required>
  29. <u--input v-model="formData.idCard" border="none" placeholder="请输入" :disabled="type == 'view'"
  30. maxlength="18" inputAlign="right"></u--input>
  31. </u-form-item>
  32. <u-form-item label="年龄" prop="age" borderBottom required>
  33. <u--input type="number" maxlength="3" v-model="formData.age" placeholder-class="input-placeholder"
  34. border="none" clearable placeholder="请输入" :disabled="type == 'view'"
  35. inputAlign="right"></u--input>
  36. </u-form-item>
  37. <u-form-item label="手机号" prop="phoneNumber" borderBottom required>
  38. <u--input type="number" v-model="formData.phoneNumber" placeholder-class="input-placeholder"
  39. border="none" clearable placeholder="必填,请输入手机号码" maxlength="11" :disabled="type == 'view'"
  40. inputAlign="right"></u--input>
  41. </u-form-item>
  42. <u-form-item label="工作年限" prop="workYears" borderBottom required>
  43. <u--input type="number" maxlength="3" v-model="formData.workYears"
  44. placeholder-class="input-placeholder" border="none" clearable placeholder="请输入"
  45. :disabled="type == 'view'" inputAlign="right"></u--input>
  46. </u-form-item>
  47. <u-form-item label="从业证书" prop="name" borderBottom required labelPosition="top">
  48. <view class="upload-box" v-for="item,index in formData.nursingCertificateList" :key="index">
  49. <view class="name-box">
  50. <u--input v-model="item.certificateName" placeholder="请输入" maxlength="10"></u--input>
  51. <span class="btn btn1" @click="addUpload">新增</span>
  52. <span class="btn btn2" v-if="index > 0" @click="deleteUpload(index)">删除</span>
  53. </view>
  54. <u-upload :fileList="item.pictureUrlList" file="image" :multiple="false" :maxCount="1"
  55. @afterRead="(event) => afterRead2(event, index)"
  56. @delete="(event) => deletePic2(event, index)" :name="'upload_' + index" width="75"
  57. height="75">
  58. </u-upload>
  59. <span class="tips">支持png、jpg和gif格式,限制1张</span>
  60. </view>
  61. </u-form-item>
  62. <u-form-item label="接单状态" prop="orderReceivingStatus" borderBottom required>
  63. <view class="switch-box">
  64. <span class="name">开启或关闭接单</span>
  65. <u-switch v-model="formData.orderReceivingStatus" activeColor="#4B91D1" inactiveColor="#D8D8D8"
  66. inactiveValue="0" activeValue="1"></u-switch>
  67. </view>
  68. </u-form-item>
  69. <u-form-item label="排序号" prop="sortOrder" borderBottom required>
  70. <view class="switch-box">
  71. <u-number-box v-model="formData.sortOrder" max="999" min="1"></u-number-box>
  72. </view>
  73. </u-form-item>
  74. </u--form>
  75. </view>
  76. <!-- 底部按钮 -->
  77. <view class="footer-box" v-if="type != 'view'">
  78. <view class="btn-box">
  79. <view class="submit-btn" @click="submitForm">保存</view>
  80. </view>
  81. </view>
  82. <u-action-sheet :show="showSex" :actions="sexList" title="请选择性别" @close="showSex = false" @select="sexSelect"
  83. safeAreaInsetBottom>
  84. </u-action-sheet>
  85. <u-action-sheet :show="showHospital" :actions="hospitalList" title="请选择性别" @close="showHospital = false"
  86. @select="hospitalSelect" safeAreaInsetBottom>
  87. </u-action-sheet>
  88. </view>
  89. </template>
  90. <script>
  91. import {
  92. dictData
  93. } from "@/api/home.js"
  94. import {
  95. storage
  96. } from "@/utils/tools.js"
  97. import {
  98. getNurseDetail,
  99. getHospitalListByManage,
  100. updateNurseInfo,
  101. addNurseInfo
  102. } from "@/api/hospital.js"
  103. export default {
  104. data() {
  105. return {
  106. type: 'add',
  107. title: '新增护工',
  108. formData: {
  109. hospitalName: '',
  110. hospitalId: '',
  111. genderName: '',
  112. sex: '',
  113. name: '',
  114. age: '',
  115. photographUrlList: [],
  116. photographUrl: '',
  117. idCard: '',
  118. age: '',
  119. phoneNumber: '',
  120. workYears: undefined,
  121. nursingCertificateList: [{
  122. certificateName: '',
  123. pictureUrl: '',
  124. pictureUrlList: [],
  125. }],
  126. orderReceivingStatus: '1',
  127. sortOrder: 1,
  128. enableStatus: 0,
  129. },
  130. rules: {
  131. hospitalName: [{
  132. required: true,
  133. message: '请选择医院',
  134. trigger: ['blur', 'change'],
  135. }],
  136. name: [{
  137. required: true,
  138. message: '请填写姓名',
  139. trigger: ['blur', 'change'],
  140. }],
  141. photographUrl: [{
  142. required: true,
  143. message: '请选择头像',
  144. trigger: ['blur', 'change'],
  145. }, {
  146. validator: (rule, value, callback) => {
  147. if (value && value.length > 0) {
  148. callback();
  149. } else {
  150. callback(new Error('请上传照片'));
  151. }
  152. },
  153. trigger: 'change'
  154. }],
  155. sex: [{
  156. required: true,
  157. message: '请选择性别',
  158. trigger: ['blur', 'change'],
  159. }],
  160. idCard: [{
  161. required: true,
  162. message: '请填写身份证号',
  163. trigger: ['blur', 'change'],
  164. },
  165. {
  166. // 自定义验证函数
  167. validator: (rule, value, callback) => {
  168. // 返回true表示校验通过,返回false表示不通过
  169. return this.$u.test.idCard(value)
  170. },
  171. message: '身份证不正确',
  172. // 触发器可以同时用blur和change
  173. trigger: ['blur', 'change'],
  174. }
  175. ],
  176. age: [{
  177. required: true,
  178. message: '请填写年龄',
  179. trigger: ['blur', 'change'],
  180. },
  181. {
  182. pattern: /^[1-9]\d*$/,
  183. message: '请输入正确的年龄',
  184. trigger: 'blur',
  185. }
  186. ],
  187. phoneNumber: [{
  188. required: true,
  189. message: '请输入手机号',
  190. trigger: ['change', 'blur'],
  191. },
  192. {
  193. validator: (rule, value, callback) => {
  194. // uni.$u.test.mobile()就是返回true或者false的
  195. return uni.$u.test.mobile(value);
  196. },
  197. message: '手机号码不正确',
  198. // 触发器可以同时用blur和change
  199. trigger: ['change', 'blur'],
  200. }
  201. ],
  202. workYears: [{
  203. required: true,
  204. message: '请填写工作年限',
  205. trigger: ['blur'],
  206. },
  207. {
  208. pattern: /^[1-9]\d*$/,
  209. message: '请输入正确的工作年限',
  210. trigger: 'blur',
  211. },
  212. ],
  213. // sortOrder: [{
  214. // required: true,
  215. // message: '请填写排序号',
  216. // trigger: ['blur', 'change'],
  217. // }]
  218. },
  219. showHospital: false,
  220. hospitalList: [],
  221. showSex: false,
  222. sexList: [{
  223. name: '未知',
  224. value: 0
  225. },
  226. {
  227. name: '男',
  228. value: 1
  229. },
  230. {
  231. name: '女',
  232. value: 2
  233. },
  234. ],
  235. certificateList: [{
  236. certificateName: '',
  237. pictureUrl: [],
  238. }],
  239. infoId: '',
  240. }
  241. },
  242. onReady() {
  243. this.$refs.uForm.setRules(this.rules);
  244. },
  245. onLoad(option) {
  246. if (option.type) {
  247. this.type = option.type
  248. if (this.type == 'add') {
  249. this.title = '新增护工'
  250. } else if (this.type == 'edit') {
  251. this.title = '编辑护工'
  252. }
  253. }
  254. if (option.id) {
  255. this.infoId = option.id
  256. this.getNurseDetail(this.infoId);
  257. } else {
  258. this.getHospitalList()
  259. this.getSexList();
  260. }
  261. },
  262. methods: {
  263. //获取于老师关联的医院
  264. getHospitalList() {
  265. let that = this;
  266. getHospitalListByManage().then(res => {
  267. if (res.code == 200) {
  268. let data = res.data;
  269. that.hospitalList = data;
  270. if (that.infoId) {
  271. that.formData.hospitalName = that.hospitalList.find(item => item.id == that
  272. .formData
  273. .hospitalId).name
  274. }
  275. }
  276. })
  277. .catch((err) => {
  278. console.log(err);
  279. })
  280. },
  281. //获取性别字典
  282. getSexList() {
  283. let that = this;
  284. dictData('sys_user_sex').then(res => {
  285. let data = res.data;
  286. data.forEach(item => {
  287. item.name = item.dictLabel
  288. })
  289. that.sexList = data;
  290. if (that.infoId) {
  291. that.formData.genderName = that.sexList.find(item => item.dictValue == that
  292. .formData
  293. .sex).name
  294. }
  295. }, err => {
  296. console.log(err);
  297. }).finally(() => {
  298. });
  299. },
  300. getNurseDetail(id) {
  301. let that = this;
  302. getNurseDetail(id).then(res => {
  303. if (res.code == 200) {
  304. let data = res.data;
  305. //在hospitalList中查找和formData中hospitalId 一样的值,取值hospitalName
  306. data.photographUrlList = [{
  307. url: data.photographUrl,
  308. }]
  309. if (data.nursingCertificateList.length == 0) {
  310. data.nursingCertificateList.push({
  311. certificateName: '',
  312. pictureUrl: '',
  313. pictureUrlList: [],
  314. })
  315. } else {
  316. data.nursingCertificateList.forEach(item => {
  317. item.pictureUrlList = [{
  318. url: item.pictureUrl,
  319. }]
  320. })
  321. }
  322. data.workYears = JSON.stringify(data.workYears)
  323. that.formData = data;
  324. that.getSexList();
  325. that.getHospitalList();
  326. }
  327. })
  328. .catch((err) => {
  329. console.log(err);
  330. })
  331. },
  332. // valChange(e) {
  333. // console.log('当前值为: ' + e.value)
  334. // this.formData.sortOrder = e.value
  335. // },
  336. addUpload() {
  337. this.formData.nursingCertificateList.push({
  338. certificateName: '',
  339. pictureUrl: '',
  340. pictureUrlList: [],
  341. })
  342. },
  343. deleteUpload(index) {
  344. this.formData.nursingCertificateList.splice(index, 1)
  345. },
  346. hospitalSelect(e) {
  347. this.formData.hospitalName = e.name;
  348. this.formData.hospitalId = e.id
  349. },
  350. sexSelect(e) {
  351. this.formData.sex = e.dictValue;
  352. this.formData.genderName = e.dictLabel
  353. },
  354. afterRead(e) {
  355. console.log(e)
  356. uni.showLoading({
  357. title: '上传中',
  358. });
  359. uni.uploadFile({
  360. url: uni.$u.http.config.baseURL + '/common/upload',
  361. filePath: e.file.url,
  362. name: 'file',
  363. header: {
  364. apiToken: storage.get('apiToken')
  365. },
  366. success: (res) => {
  367. uni.hideLoading();
  368. let data = JSON.parse(res.data);
  369. console.log('data', data);
  370. if (data.code != 200) return
  371. this.formData.photographUrlList = [{
  372. url: data.data.url,
  373. }]
  374. this.formData.photographUrl = data.data.url;
  375. console.log('this.formData.photographUrl', this.formData.photographUrl);
  376. //验证photographUrl
  377. this.$refs.uForm.validateField('photographUrl');
  378. uni.showToast({
  379. title: '上传成功',
  380. icon: 'success',
  381. duration: 1000
  382. })
  383. },
  384. fail: (err) => {
  385. console.log(err);
  386. uni.hideLoading();
  387. uni.showModal({
  388. content: err.errMsg,
  389. showCancel: false
  390. });
  391. }
  392. });
  393. },
  394. deletePic(e) {
  395. this.formData.photographUrl.splice(e.index, 1);
  396. },
  397. afterRead2(event, index) {
  398. console.log(`第${index}个循环上传组件上传前`, event);
  399. console.log(event)
  400. uni.showLoading({
  401. title: '上传中',
  402. });
  403. uni.uploadFile({
  404. url: uni.$u.http.config.baseURL + '/common/upload',
  405. filePath: event.file.url,
  406. name: 'file',
  407. header: {
  408. apiToken: storage.get('apiToken')
  409. },
  410. success: (res) => {
  411. uni.hideLoading();
  412. let data = JSON.parse(res.data);
  413. if (data.code != 200) return
  414. this.formData.nursingCertificateList[index].pictureUrl = data.data.url;
  415. this.formData.nursingCertificateList[index].pictureUrlList.push({
  416. url: data.data.url,
  417. })
  418. console.log('this.formData.nursingCertificateList', this.formData
  419. .nursingCertificateList);
  420. uni.showToast({
  421. title: '上传成功',
  422. icon: 'success',
  423. duration: 1000
  424. })
  425. },
  426. fail: (err) => {
  427. console.log(err);
  428. uni.hideLoading();
  429. uni.showModal({
  430. content: err.errMsg,
  431. showCancel: false
  432. });
  433. }
  434. });
  435. },
  436. deletePic2(e, index) {
  437. this.formData.nursingCertificateList[index].pictureUrl = [];
  438. },
  439. submitForm() {
  440. console.log("formData", this.formData);
  441. this.$refs.uForm.validate().then((res) => {
  442. if (res) {
  443. if (this.type == 'add') {
  444. addNurseInfo(this.formData).then(res => {
  445. uni.$u.toast('新增成功');
  446. setTimeout(() => {
  447. uni.navigateBack({
  448. delta: 1,
  449. });
  450. }, 1000)
  451. }, err => {
  452. console.log(err);
  453. }).finally(() => {
  454. });
  455. } else {
  456. updateNurseInfo(this.formData).then(res => {
  457. uni.$u.toast('修改成功');
  458. setTimeout(() => {
  459. // uni.$emit('returnAddress', this.formData);
  460. uni.navigateBack({
  461. delta: 1,
  462. });
  463. }, 1000)
  464. }, err => {
  465. console.log(err);
  466. }).finally(() => {
  467. });
  468. }
  469. }
  470. })
  471. .catch((errors) => {
  472. console.log(",errors", errors);
  473. uni.$u.toast('校验失败');
  474. });
  475. },
  476. }
  477. }
  478. </script>
  479. <style scoped lang="scss">
  480. .container {
  481. padding: 20rpx;
  482. padding-bottom: 200rpx;
  483. .form-box {
  484. padding: 20rpx;
  485. background-color: #fff;
  486. ::v-deep .u-input {
  487. padding: 15rpx !important;
  488. }
  489. ::v-deep .u-upload {
  490. margin-top: 15rpx;
  491. }
  492. .upload-box {
  493. margin-top: 20rpx;
  494. .name-box {
  495. display: flex;
  496. align-items: center;
  497. margin-top: 20rpx;
  498. .btn {
  499. padding: 10rpx 20rpx;
  500. background-color: #4B91D1;
  501. color: #fff;
  502. border-radius: 10rpx;
  503. margin-left: 20rpx;
  504. border: 1rpx solid #4B91D1;
  505. }
  506. .btn2 {
  507. background-color: #fff;
  508. color: #FF0000;
  509. border: 1rpx solid #FF0000;
  510. }
  511. }
  512. }
  513. .switch-box {
  514. display: flex;
  515. align-items: center;
  516. justify-content: flex-end;
  517. padding: 20rpx 0;
  518. .name {
  519. margin-right: 20rpx;
  520. font-size: 30rpx;
  521. }
  522. }
  523. }
  524. .footer-box {
  525. position: fixed;
  526. bottom: 0;
  527. display: flex;
  528. align-items: center;
  529. justify-content: space-between;
  530. width: 100%;
  531. padding: 50rpx 30rpx;
  532. box-sizing: border-box;
  533. font-size: 28rpx;
  534. background-color: #fff;
  535. box-shadow: 0 -2rpx 30rpx #c5c5c53a;
  536. .btn-box {
  537. width: 100%;
  538. .submit-btn {
  539. display: block;
  540. width: 100%;
  541. height: 80rpx;
  542. line-height: 80rpx;
  543. text-align: center;
  544. color: #fff;
  545. background-color: #026EB7;
  546. border-radius: 50rpx;
  547. }
  548. }
  549. }
  550. }
  551. </style>