contactAdd.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. var util = require('../../utils/util.js')
  2. const app = getApp();
  3. Page({
  4. data: {
  5. customerId:"",
  6. rules: {
  7. contactName: [{ required: true, message: '联系人必填', trigger: 'blur' }],
  8. telephone: [{ required: true, message: '联系人电话必填', trigger: 'blur' }],
  9. },
  10. // 新增/编辑
  11. create: {
  12. dialogStatus: '',
  13. temp: {
  14. contactName: '',
  15. telephone: '',
  16. address: '',
  17. remark: '',
  18. customerId:"",
  19. created: util.getToday(),
  20. },
  21. }
  22. },
  23. onLoad: function (options) {
  24. // 表单初始化
  25. wx.lin.initValidateForm(this)
  26. var id = options.id;
  27. this.setData({
  28. "customerId":id,
  29. ['create.temp.customerId']: id
  30. })
  31. },
  32. //保存
  33. submit:function(e){
  34. var detail_value = e.detail.values
  35. var detail_errors = e.detail.errors
  36. var detail_errors = e.detail.errors
  37. console.log("detail_value",detail_value)
  38. console.log("create.temp",this.data.create.temp)
  39. const submit_data = Object.assign({}, this.data.create.temp, detail_value)
  40. console.log("保存发送:",submit_data)
  41. var send_data = {
  42. "name": "insertContacts" ,
  43. "parammaps": submit_data
  44. }
  45. //验证必填项是否为空
  46. if(submit_data.contactName == ""){
  47. wx.showToast({title: '联系人必填',icon: 'none',duration: 2000})
  48. } else if(submit_data.telephone == ""){
  49. wx.showToast({title: '联系人电话必填',icon: 'none',duration: 2000})
  50. } else {
  51. if( wx.getStorageSync('isLoading') == "true"){
  52. wx.showToast({
  53. title: '正在保存中,请稍等!',
  54. icon: 'none',
  55. duration: 2000
  56. })
  57. } else {
  58. util.postDataByName(send_data, this.getListSuccess)
  59. }
  60. }
  61. },
  62. getListSuccess: function (res) {
  63. console.log('table数据======>', res)
  64. var that = this
  65. var id = this.data.customerId
  66. if (res.msg !== 'fail') {
  67. wx.showToast({
  68. title: '保存成功',
  69. icon: 'success',
  70. duration: 2000,
  71. success: function(){
  72. wx.redirectTo({ url:"../contact/contact?id=" + id})
  73. }
  74. })
  75. } else {
  76. wx.showToast({
  77. title: '保存失败'+res.data,
  78. icon: 'error',
  79. duration: 2000,
  80. })
  81. }
  82. },
  83. onReady: function () {
  84. },
  85. onShow: function () {
  86. },
  87. onHide: function () {
  88. },
  89. onUnload: function () {
  90. },
  91. /**
  92. * 页面相关事件处理函数--监听用户下拉动作
  93. */
  94. onPullDownRefresh: function () {
  95. },
  96. /**
  97. * 页面上拉触底事件的处理函数
  98. */
  99. onReachBottom: function () {
  100. },
  101. onShareAppMessage: function () {
  102. }
  103. })