form.vue 8.4 KB

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