addContacts.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view class="pages">
  3. <div class="form-input">
  4. <u-input v-model="form.name" placeholder="请输入名称" border="bottom"></u-input>
  5. <u-input v-model="form.phone" placeholder="请输入手机号" border="bottom"></u-input>
  6. </div>
  7. <div class="form-btn">
  8. <u-button type="primary" @click="save">添加</u-button>
  9. </div>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. form: {
  17. name: '',
  18. phone: ''
  19. }
  20. }
  21. },
  22. methods: {
  23. save() {
  24. if (this.form.name == '') {
  25. this.$u.toast('请输入名称')
  26. return
  27. }
  28. if (this.form.phone == '') {
  29. this.$u.toast('请输入手机号')
  30. return
  31. }
  32. //返回上一页并添加联系人
  33. let pages = getCurrentPages(); //获取所有页面栈实例列表
  34. let nowPage = pages[pages.length - 1]; //当前页页面实例
  35. let prevPage = pages[pages.length - 2]; //上一页页面实例
  36. console.log(prevPage.$vm.contactsList);
  37. prevPage.$vm.contactsList.push(this.form);
  38. uni.navigateBack(1)
  39. // this.$u.post('/api/contacts/add',this.form).then(res => {
  40. // if(res.code == 0){
  41. // this.$u.toast('添加成功')
  42. // setTimeout(() => {
  43. // uni.navigateBack({
  44. // delta: 1
  45. // })
  46. // }, 1000);
  47. // }
  48. // })
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. .pages {
  55. width: 100%;
  56. height: 100vh;
  57. background: #f5f5f5;
  58. }
  59. .form-input {
  60. background: #fff;
  61. padding: 10px;
  62. }
  63. .form-btn{}
  64. </style>