addPatient.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <view class="form-box">
  5. <view class="form-item vali">
  6. <text class="label">姓名</text>
  7. <input class="input-width" type="text" v-model="form.patientName" @blur="validateInput" placeholder="请如实填写您的真实姓名" placeholder-class="form-input" />
  8. <text class="error" v-if="nameValied">{{ errorMessage }}</text>
  9. </view>
  10. <view class="form-item">
  11. <text class="label">身份证号</text>
  12. <input class="input-width" type="idcard" v-model="form.idCard" placeholder="请如实填写身份证号" placeholder-class="form-input" />
  13. </view>
  14. <view class="form-item">
  15. <text class="label">性别</text>
  16. <radio-group style="display: flex;align-items: center;">
  17. <label style="margin-right: 50upx;">
  18. <radio @click="genderChange(1)" value="1" :checked="form.gender===1" style="margin-right: 16upx;" />
  19. <text class="sex-text">男</text>
  20. </label>
  21. <label>
  22. <radio @click="genderChange(2)" value="2" :checked="form.gender===2" style="margin-right: 16upx;" />
  23. <text class="sex-text">女</text>
  24. </label>
  25. </radio-group>
  26. </view>
  27. <view class="form-item">
  28. <text class="label">出生年月</text>
  29. <picker class="birth-picker" mode="date" @change="bindDateChange">
  30. <view class="right-box">
  31. <view class="input-box">
  32. <input type="text" :value="form.birthday" placeholder="请选择出生年月" placeholder-class="form-input" disabled="disabled" />
  33. </view>
  34. <image class="arrow" src="../../static/images/arrow_gray.png" mode=""></image>
  35. </view>
  36. </picker>
  37. </view>
  38. <!-- <view class="form-item">
  39. <text class="label">联系电话</text>
  40. <input type="number" value="" placeholder="请输入联系电话" placeholder-class="form-input" />
  41. </view> -->
  42. </view>
  43. </view>
  44. <view class="btn-box">
  45. <view class="sub-btn" @click="submit()">保存就诊人</view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import {getPatientById,addPatient,editPatient} from '@/api/patient'
  51. export default {
  52. data() {
  53. return {
  54. type:null,
  55. patientId:null,
  56. errorMessage:"",
  57. nameValied:false,
  58. form: {
  59. gender: 1,
  60. birthday: ''
  61. }
  62. };
  63. },
  64. onLoad(option) {
  65. this.type=option.type;
  66. console.log(this.type)
  67. if(this.type=='edit'){
  68. this.patientId=option.patientId;
  69. this.getPatientById();
  70. }
  71. },
  72. methods:{
  73. genderChange(type){
  74. this.form.gender=type
  75. },
  76. getPatientById(){
  77. var data={patientId:this.patientId};
  78. getPatientById(data).then(
  79. res => {
  80. if(res.code==200){
  81. this.form=res.data;
  82. }else{
  83. uni.showToast({
  84. title: res.msg,
  85. });
  86. }
  87. },
  88. rej => {}
  89. );
  90. },
  91. validateInput() {
  92. const regex = /^[\u4e00-\u9fa5]{1,}$/;//汉字
  93. if (!regex.test(this.form.patientName)) {
  94. this.nameValied=true;
  95. this.errorMessage = '姓名必须为汉字';
  96. } else {
  97. this.nameValied=false;
  98. this.errorMessage = '';
  99. }
  100. },
  101. submit(){
  102. if(this.form.patientName==''){
  103. uni.showToast({
  104. icon:'none',
  105. title: '请填写姓名'
  106. });
  107. return;
  108. }
  109. // if(this.form.idCard==''){
  110. // uni.showToast({
  111. // icon:'none',
  112. // title: '请填写身份证号'
  113. // });
  114. // return;
  115. // }
  116. const regex = /^[\u4e00-\u9fa5]{1,}$/;//汉字
  117. if (!regex.test(this.form.patientName)) {
  118. uni.showToast({
  119. icon:'none',
  120. title: '姓名必须为汉字'
  121. });
  122. return;
  123. }
  124. if(this.type=="add"){
  125. this.addPatient()
  126. }
  127. else if(this.type=="edit"){
  128. this.editPatient()
  129. }
  130. },
  131. editPatient(){
  132. editPatient(this.form).then(
  133. res => {
  134. if(res.code==200){
  135. uni.showToast({
  136. icon:'success',
  137. title: "操作成功",
  138. });
  139. setTimeout(function() {
  140. uni.$emit('refreshPatient');
  141. uni.navigateBack({
  142. delta: 1
  143. })
  144. }, 500);
  145. }else{
  146. uni.showToast({
  147. icon:'none',
  148. title: res.msg,
  149. });
  150. }
  151. },
  152. rej => {}
  153. );
  154. },
  155. addPatient(){
  156. addPatient(this.form).then(
  157. res => {
  158. if(res.code==200){
  159. uni.showToast({
  160. icon:'success',
  161. title: "操作成功",
  162. });
  163. setTimeout(function() {
  164. uni.$emit('refreshPatient');
  165. uni.navigateBack({
  166. delta: 1
  167. })
  168. }, 500);
  169. }else{
  170. uni.showToast({
  171. icon:'none',
  172. title: res.msg,
  173. });
  174. }
  175. },
  176. rej => {}
  177. );
  178. },
  179. // 出生日期选择
  180. bindDateChange: function(e) {
  181. this.form.birthday = e.target.value
  182. },
  183. }
  184. }
  185. </script>
  186. <style lang="scss">
  187. page{
  188. height: 100%;
  189. }
  190. .content{
  191. height: 100%;
  192. display: flex;
  193. flex-direction: column;
  194. justify-content: space-between;
  195. .inner{
  196. height: calc(100% - 120upx);
  197. padding: 20upx;
  198. .form-box{
  199. padding: 20upx 30upx;
  200. background: #FFFFFF;
  201. border-radius: 16upx;
  202. .form-item{
  203. height: 103rpx;
  204. display: flex;
  205. align-items: center;
  206. justify-content: space-between;
  207. border-bottom: 1px solid #F1F1F1;
  208. position: relative;
  209. &:last-child{
  210. border-bottom: none;
  211. }
  212. .label{
  213. font-size: 30upx;
  214. font-family: PingFang SC;
  215. font-weight: 500;
  216. color: #222222;
  217. margin-bottom: 10rpx;
  218. }
  219. .input-width{
  220. width: calc(100% - 150upx);
  221. text-align: right;
  222. line-height: 103rpx;
  223. height: 103rpx;
  224. }
  225. .form-input{
  226. font-size: 30upx;
  227. font-family: PingFang SC;
  228. font-weight: 500;
  229. color: #999999;
  230. text-align: right;
  231. }
  232. .sex-text{
  233. font-size: 30upx;
  234. font-family: PingFang SC;
  235. font-weight: 500;
  236. color: #111111;
  237. line-height: 30upx;
  238. }
  239. .birth-picker {
  240. display: flex;
  241. align-items: center;
  242. .right-box{
  243. display: flex;
  244. align-items: center;
  245. .input-box{
  246. width: 400upx;
  247. display: flex;
  248. align-items: center;
  249. justify-content: flex-end;
  250. input{
  251. text-align: right;
  252. }
  253. }
  254. .arrow{
  255. width: 13upx;
  256. height: 23upx;
  257. margin-left: 20upx;
  258. }
  259. }
  260. }
  261. }
  262. .vali{
  263. height: 123rpx;
  264. .label{
  265. margin-bottom: 20rpx;
  266. }
  267. .input-width{
  268. line-height: 123rpx;
  269. height: 123rpx;
  270. margin-bottom: 20rpx;
  271. }
  272. .form-input{
  273. }
  274. }
  275. .error{
  276. color:red;
  277. font-size: 24rpx;
  278. position: absolute;
  279. left: 0;
  280. bottom: 10rpx;
  281. border-bottom: 1px solid #F1F1F1;
  282. }
  283. }
  284. }
  285. .btn-box{
  286. height: 120upx;
  287. padding: 0 30upx;
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. background: #FFFFFF;
  292. .sub-btn{
  293. width: 100%;
  294. height: 88upx;
  295. line-height: 88upx;
  296. text-align: center;
  297. font-size: 30upx;
  298. font-family: PingFang SC;
  299. font-weight: bold;
  300. color: #FFFFFF;
  301. background: #018C39;
  302. border-radius: 44upx;
  303. }
  304. }
  305. }
  306. </style>