form.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="container">
  3. <view class="form-box">
  4. <u--form labelWidth="80rpx" :model="formData" :rules="rules" ref="uForm">
  5. <u-form-item label="姓名" prop="name" borderBottom required>
  6. <u--input v-model="formData.name" placeholder-class="input-placeholder" border="none"
  7. placeholder="必填,请输入证件上的姓名" :disabled="type == 'view'" maxlength="10" inputAlign="right"></u--input>
  8. </u-form-item>
  9. <u-form-item label="电话" prop="mobile" borderBottom required>
  10. <u--input v-model="formData.mobile" placeholder-class="input-placeholder" border="none" clearable
  11. placeholder="必填,请输入手机号码" maxlength="11" :disabled="type == 'view'" inputAlign="right"></u--input>
  12. </u-form-item>
  13. <u-form-item label="性别" prop="gender" borderBottom @click="showSex = true">
  14. <u-input :border="none" disabled v-model="formData.genderName" disabledColor="#ffffff"
  15. placeholder="请选择" inputAlign="right" />
  16. <u-icon slot="right" name="arrow-right" color="#999999"></u-icon>
  17. </u-form-item>
  18. <u-form-item label="年龄" prop="age" borderBottom >
  19. <u--input v-model="formData.age" placeholder-class="input-placeholder" border="none" clearable
  20. placeholder="请输入年龄" :disabled="type == 'view'" inputAlign="right"></u--input>
  21. </u-form-item>
  22. <u-form-item label="关系" prop="relationship" borderBottom @click="showShip = true">
  23. <u-input :border="none" disabled v-model="formData.relationshipName" disabledColor="#ffffff"
  24. placeholder="请选择" inputAlign="right" />
  25. <u-icon slot="right" name="arrow-right" color="#999999"></u-icon>
  26. </u-form-item>
  27. </u--form>
  28. </view>
  29. <u-action-sheet :show="showSex" :actions="sexList" title="请选择性别" @close="showSex = false" @select="sexSelect"
  30. safeAreaInsetBottom>
  31. </u-action-sheet>
  32. <u-action-sheet :show="showShip" :actions="relationshipList" title="请选择关系" @close="showShip = false"
  33. @select="shipSelect" safeAreaInsetBottom>
  34. </u-action-sheet>
  35. <!-- 底部按钮 -->
  36. <view class="footer-box" v-if="type != 'view'">
  37. <view class="btn-box">
  38. <view class="submit-btn" @click="submitForm">保存</view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. dictData
  46. } from "@/api/home.js"
  47. import {
  48. addPatient,
  49. editPatient,
  50. getPatientDetail
  51. } from "@/api/user.js"
  52. export default {
  53. components: {},
  54. data() {
  55. return {
  56. showSex: false,
  57. sexList: [{
  58. name: '未知',
  59. value: 0
  60. },
  61. {
  62. name: '男',
  63. value: 1
  64. },
  65. {
  66. name: '女',
  67. value: 2
  68. },
  69. ],
  70. showShip: false,
  71. relationshipList: [],
  72. formData: {
  73. name: '',
  74. mobile: '',
  75. gender: '',
  76. age: '',
  77. relationship: '',
  78. },
  79. isDefault: [],
  80. selectData: [],
  81. rules: {
  82. name: [{
  83. required: true,
  84. message: '请填写姓名',
  85. trigger: ['blur', 'change'],
  86. }, ],
  87. mobile: [{
  88. required: true,
  89. message: '请填写电话',
  90. trigger: ['blur', 'change'],
  91. }, {
  92. pattern: /^(?:(?:\+|00)86)?1(?:3[\d]|4[5-79]|5[0-35-9]|6[5-7]|7[0-8]|8[\d]|9[189])\d{8}$/,
  93. message: '请输入正确的电话',
  94. trigger: 'blur',
  95. }],
  96. gender: [{
  97. required: true,
  98. message: '请选择性别',
  99. type: 'number',
  100. trigger: ['blur', 'change'],
  101. }, ],
  102. age: [{
  103. required: true,
  104. message: '请填写年龄,必须为数字',
  105. type: 'number',
  106. trigger: ['blur', 'change'],
  107. }, ],
  108. relationship: [{
  109. required: true,
  110. message: '请填写关系',
  111. trigger: ['blur', 'change'],
  112. }, ],
  113. },
  114. type: 'add',
  115. InfoId: '',
  116. isRegionUser: false,
  117. regionName: '',
  118. listData: [],
  119. }
  120. },
  121. onReady() {
  122. this.$refs.uForm.setRules(this.rules);
  123. },
  124. onLoad(option) {
  125. if (option.id) {
  126. //编辑
  127. console.log("option", option);
  128. this.type = option.type || 'add';
  129. this.InfoId = option.id || '';
  130. this.getInfo();
  131. } else if (option.type == 'view') {
  132. //查看
  133. this.type = option.type;
  134. this.formData = JSON.parse(option.item)
  135. } else {
  136. //新增
  137. this.getSexList()
  138. this.getRelationshipList()
  139. }
  140. },
  141. methods: {
  142. //获取性别字典
  143. getSexList() {
  144. let that = this;
  145. dictData('sys_user_sex').then(res => {
  146. let data = res.data;
  147. data.forEach(item => {
  148. item.name = item.dictLabel
  149. })
  150. that.sexList = data;
  151. if (that.InfoId) {
  152. that.formData.genderName = that.sexList.find(item => item.dictValue == that.formData
  153. .gender).name
  154. }
  155. }, err => {
  156. console.log(err);
  157. }).finally(() => {
  158. });
  159. },
  160. //获取关系字典
  161. getRelationshipList() {
  162. let that = this;
  163. dictData('patient_relationship').then(res => {
  164. let data = res.data;
  165. data.forEach(item => {
  166. item.name = item.dictLabel
  167. })
  168. this.relationshipList = data;
  169. if (that.InfoId) {
  170. this.formData.relationshipName = this.relationshipList.find(item => item.dictValue == this
  171. .formData.relationship).name
  172. }
  173. }, err => {
  174. console.log(err);
  175. }).finally(() => {
  176. });
  177. },
  178. sexSelect(e) {
  179. this.formData.gender = e.dictValue
  180. this.formData.genderName = e.name
  181. this.$refs.uForm.validateField('gender')
  182. },
  183. shipSelect(e) {
  184. this.formData.relationship = e.dictValue
  185. this.formData.relationshipName = e.name
  186. this.$refs.uForm.validateField('relationship')
  187. },
  188. // 显示选择器
  189. showPicker() {
  190. if (this.type == 'view') return
  191. this.$refs.treePicker._show();
  192. },
  193. //监听选择(ids为数组)
  194. selectChange(ids, names) {
  195. console.log(ids, names)
  196. this.formData.deliveryAreaId = ids[2]
  197. this.formData.deliveryCityId = ids[1]
  198. this.formData.deliveryProvinceId = ids[0]
  199. this.formData.regionName = names[0] + '/' + names[1] + '/' + names[2]
  200. },
  201. handleSelect(e) {
  202. console.log("e", e);
  203. // this.formData.defaultStatus =
  204. if (e[0] == 1) {
  205. this.formData.defaultStatus = 1
  206. } else {
  207. this.formData.defaultStatus = 0
  208. }
  209. },
  210. submitForm() {
  211. console.log("formData", this.formData);
  212. this.$refs.uForm.validate().then((res) => {
  213. if (res) {
  214. if (this.type == 'add') {
  215. addPatient(this.formData).then(res => {
  216. uni.$u.toast('新增成功');
  217. setTimeout(() => {
  218. uni.navigateBack({
  219. delta: 1,
  220. });
  221. }, 1000)
  222. }, err => {
  223. console.log(err);
  224. }).finally(() => {
  225. });
  226. } else {
  227. editPatient(this.formData).then(res => {
  228. uni.$u.toast('修改成功');
  229. setTimeout(() => {
  230. uni.$emit('returnAddress', this.formData);
  231. uni.navigateBack({
  232. delta: 1,
  233. });
  234. }, 1000)
  235. }, err => {
  236. console.log(err);
  237. }).finally(() => {
  238. });
  239. }
  240. }
  241. })
  242. .catch((errors) => {
  243. console.log(",errors", errors);
  244. uni.$u.toast('校验失败');
  245. });
  246. },
  247. getInfo() {
  248. let that = this;
  249. getPatientDetail(that.InfoId).then((res) => {
  250. let data = res.data;
  251. that.formData = data;
  252. this.getSexList()
  253. this.getRelationshipList()
  254. })
  255. .catch((err) => {
  256. console.log(err);
  257. })
  258. },
  259. }
  260. }
  261. </script>
  262. <style scoped lang="scss">
  263. .container {
  264. background-color: #fff;
  265. .form-box {
  266. margin: 20rpx;
  267. padding: 20rpx;
  268. }
  269. .region-info {
  270. display: flex;
  271. align-items: center;
  272. }
  273. .region-txt {
  274. height: 72rpx;
  275. line-height: 1;
  276. width: 500rpx;
  277. padding: 22rpx 18rpx;
  278. border: 1rpx solid #dadbde;
  279. box-sizing: border-box;
  280. border-radius: 8rpx;
  281. }
  282. .region-btn {
  283. margin-left: 10rpx;
  284. padding: 18rpx;
  285. box-sizing: border-box;
  286. border-radius: 8rpx;
  287. background-color: #026EB7;
  288. color: #fff;
  289. }
  290. .footer-box {
  291. position: fixed;
  292. bottom: 0;
  293. display: flex;
  294. align-items: center;
  295. justify-content: space-between;
  296. width: 100%;
  297. padding: 35rpx 30rpx 50rpx;
  298. box-sizing: border-box;
  299. font-size: 28rpx;
  300. background-color: #fff;
  301. box-shadow: 0 -2rpx 30rpx #c5c5c53a;
  302. .btn-box {
  303. width: 100%;
  304. .submit-btn {
  305. display: block;
  306. width: 100%;
  307. height: 60rpx;
  308. line-height: 60rpx;
  309. text-align: center;
  310. color: #fff;
  311. background-color: #026EB7;
  312. border-radius: 50rpx;
  313. }
  314. }
  315. }
  316. }
  317. ::v-deep .input-placeholder {
  318. font-size: 26rpx;
  319. }
  320. </style>