addOrEdit.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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="请输入身份证号" 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. if (!this.name) {
  64. uni.showToast({
  65. title: '请输入姓名',
  66. icon: 'none',
  67. mask: true
  68. })
  69. return
  70. }
  71. if (!this.identity) {
  72. uni.showToast({
  73. title: '请输入身份证号',
  74. icon: 'none',
  75. mask: true
  76. })
  77. return
  78. }
  79. if (!this.phone) {
  80. uni.showToast({
  81. title: '请输入联系电话',
  82. icon: 'none',
  83. mask: true
  84. })
  85. return
  86. }
  87. if (this.type === '1') {
  88. // 添加
  89. this.add()
  90. } else {
  91. // 编辑
  92. this.edit()
  93. }
  94. },
  95. // 添加请求
  96. async add() {
  97. const res = await this.$myRequest({
  98. url: '/mhotel/ampAddContact.action',
  99. data: {
  100. userName: uni.getStorageSync('userInfo').user_name,
  101. contactUserName: this.name,
  102. contactUserPhone: this.phone,
  103. contactUserIdNum: this.identity,
  104. userId: uni.getStorageSync('userInfo').id
  105. }
  106. })
  107. // console.log(res)
  108. if (res.code === 200) {
  109. uni.showToast({
  110. title: '添加成功',
  111. icon: 'success',
  112. mask: true
  113. })
  114. setTimeout(() => {
  115. uni.navigateBack(1)
  116. }, 1500)
  117. }
  118. },
  119. // 编辑请求
  120. async edit() {
  121. const res = await this.$myRequest({
  122. url: '/mhotel/ampupdateContact.action',
  123. data: {
  124. contactUserName: this.name,
  125. contactUserPhone: this.phone,
  126. contactUserIdNum: this.identity,
  127. contactId: this.id
  128. }
  129. })
  130. console.log(res)
  131. if (res.code === 200) {
  132. uni.showToast({
  133. title: '编辑成功',
  134. icon: 'success',
  135. mask: true
  136. })
  137. setTimeout(() => {
  138. uni.navigateBack(1)
  139. }, 1500)
  140. }
  141. }
  142. }
  143. }
  144. </script>
  145. <style lang="scss" scoped>
  146. .container {
  147. display: flex;
  148. flex-direction: column;
  149. height: 100vh;
  150. background-color: #f2f2f2;
  151. .box {
  152. margin-top: 20rpx;
  153. height: calc(100vh - 20rpx);
  154. background-color: #fff;
  155. .body {
  156. box-sizing: border-box;
  157. padding: 0 20rpx;
  158. height: calc(100vh - 236rpx);
  159. background-color: #fff;
  160. .body_box {
  161. display: flex;
  162. align-items: center;
  163. margin-top: 30rpx;
  164. height: 80rpx;
  165. .body_box_key {
  166. width: 152rpx;
  167. color: #808080;
  168. font-size: 28rpx;
  169. }
  170. .body_box_value {
  171. display: flex;
  172. align-items: center;
  173. box-sizing: border-box;
  174. padding: 0 28rpx;
  175. width: 559rpx;
  176. height: 80rpx;
  177. font-size: 28rpx;
  178. border-radius: 15rpx;
  179. background-color: #f2f2f2;
  180. .input {
  181. width: 100%;
  182. }
  183. }
  184. }
  185. }
  186. .btn {
  187. display: flex;
  188. justify-content: center;
  189. align-items: center;
  190. margin: 45rpx auto;
  191. width: 710rpx;
  192. height: 96rpx;
  193. font-size: 32rpx;
  194. border-radius: 64rpx;
  195. color: #fff;
  196. background-color: #096562;
  197. }
  198. }
  199. }
  200. </style>