addOrEdit.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="container">
  3. <view class="box">
  4. <view class="body">
  5. <!-- 姓名区域 -->
  6. <view class="body_box">
  7. <view class="body_box_key">姓名</view>
  8. <view class="body_box_value">
  9. <input class="input" type="text" placeholder="请输入姓名" v-model="name" />
  10. </view>
  11. </view>
  12. <!-- 身份证号区域 -->
  13. <view class="body_box">
  14. <view class="body_box_key">身份证号</view>
  15. <view class="body_box_value">
  16. <input class="input" type="text" placeholder="请输入身份证号" maxlength="18" v-model="identity" />
  17. </view>
  18. </view>
  19. <!-- 联系电话区域 -->
  20. <view class="body_box">
  21. <view class="body_box_key">联系电话</view>
  22. <view class="body_box_value">
  23. <input class="input" type="text" placeholder="请输入联系电话" maxlength="11" v-model="phone" />
  24. </view>
  25. </view>
  26. </view>
  27. <view class="btn" @click="handleSub">确定</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. // 姓名
  36. name: '',
  37. // 身份证号
  38. identity: '',
  39. // 电话
  40. phone: '',
  41. type: '',
  42. id: ''
  43. }
  44. },
  45. onLoad(options) {
  46. // console.log(options)
  47. this.type = options.type
  48. if (options.type === '2') {
  49. // 编辑状态
  50. const info = JSON.parse(options.info)
  51. this.name = info.user_name
  52. this.identity = info.card_number
  53. this.phone = info.user_phone
  54. this.id = info.id
  55. uni.setNavigationBarTitle({
  56. title: '编辑旅客'
  57. })
  58. }
  59. },
  60. methods: {
  61. // 确定按钮点击回调
  62. handleSub() {
  63. const reName = /^[\u4e00-\u9fa5]{2,4}$/
  64. const rePhone = /^[1][3,4,5,7,8,9][0-9]{9}$/
  65. const reIdentity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  66. if (!this.name) {
  67. uni.showToast({
  68. title: '请输入姓名',
  69. icon: 'none',
  70. mask: true
  71. })
  72. return
  73. }
  74. if (!reName.test(this.name)) {
  75. uni.showToast({
  76. title: '姓名格式有误',
  77. icon: 'none'
  78. })
  79. return
  80. }
  81. if (!this.identity) {
  82. uni.showToast({
  83. title: '请输入身份证号',
  84. icon: 'none',
  85. mask: true
  86. })
  87. return
  88. }
  89. if (!reIdentity.test(this.identity)) {
  90. uni.showToast({
  91. title: '身份证号码格式有误',
  92. icon: 'none'
  93. })
  94. return
  95. }
  96. if (!this.phone) {
  97. uni.showToast({
  98. title: '请输入联系电话',
  99. icon: 'none',
  100. mask: true
  101. })
  102. return
  103. }
  104. if (!rePhone.test(this.phone)) {
  105. uni.showToast({
  106. title: '电话号码格式有误',
  107. icon: 'none'
  108. })
  109. return
  110. }
  111. if (this.type === '1') {
  112. // 添加
  113. this.add()
  114. } else {
  115. // 编辑
  116. this.edit()
  117. }
  118. },
  119. // 添加请求
  120. async add() {
  121. const res = await this.$myRequest({
  122. url: '/mhotel/ampAddContact.action',
  123. data: {
  124. userName: uni.getStorageSync('userInfo').user_name,
  125. contactUserName: this.name,
  126. contactUserPhone: this.phone,
  127. contactUserIdNum: this.identity,
  128. userId: uni.getStorageSync('userInfo').id
  129. }
  130. })
  131. // console.log(res)
  132. if (res.code === 200) {
  133. uni.showToast({
  134. title: '添加成功',
  135. icon: 'success',
  136. mask: true
  137. })
  138. setTimeout(() => {
  139. uni.navigateBack(1)
  140. }, 1500)
  141. }
  142. },
  143. // 编辑请求
  144. async edit() {
  145. const res = await this.$myRequest({
  146. url: '/mhotel/ampupdateContact.action',
  147. data: {
  148. contactUserName: this.name,
  149. contactUserPhone: this.phone,
  150. contactUserIdNum: this.identity,
  151. contactId: this.id
  152. }
  153. })
  154. // console.log(res)
  155. if (res.code === 200) {
  156. uni.showToast({
  157. title: '编辑成功',
  158. icon: 'success',
  159. mask: true
  160. })
  161. setTimeout(() => {
  162. uni.navigateBack(1)
  163. }, 1500)
  164. }
  165. }
  166. }
  167. }
  168. </script>
  169. <style lang="scss" scoped>
  170. .container {
  171. display: flex;
  172. flex-direction: column;
  173. height: 100vh;
  174. background-color: #f2f2f2;
  175. .box {
  176. margin-top: 20rpx;
  177. height: calc(100vh - 20rpx);
  178. background-color: #fff;
  179. .body {
  180. box-sizing: border-box;
  181. padding: 0 20rpx;
  182. height: calc(100vh - 236rpx);
  183. background-color: #fff;
  184. .body_box {
  185. display: flex;
  186. align-items: center;
  187. margin-top: 30rpx;
  188. height: 80rpx;
  189. .body_box_key {
  190. width: 152rpx;
  191. color: #808080;
  192. font-size: 28rpx;
  193. }
  194. .body_box_value {
  195. display: flex;
  196. align-items: center;
  197. box-sizing: border-box;
  198. padding: 0 28rpx;
  199. width: 559rpx;
  200. height: 80rpx;
  201. font-size: 28rpx;
  202. border-radius: 15rpx;
  203. background-color: #f2f2f2;
  204. .input {
  205. width: 100%;
  206. }
  207. }
  208. }
  209. }
  210. .btn {
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. margin: 45rpx auto;
  215. width: 710rpx;
  216. height: 96rpx;
  217. font-size: 32rpx;
  218. border-radius: 64rpx;
  219. color: #fff;
  220. background-color: #096562;
  221. }
  222. }
  223. }
  224. </style>