insert.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. const deleteMark = require("../../../../utils/deleteMark"),
  2. _Http = getApp().globalData.http;
  3. let count = null;
  4. Component({
  5. properties: {
  6. endInsert: Function,
  7. type: String,
  8. content: {
  9. type: Object,
  10. value: {
  11. "sat_orderclueid": 0,
  12. "name": "",
  13. "phonenumber": "",
  14. "province": "",
  15. "city": "",
  16. "county": "",
  17. "address": "",
  18. "notes": "",
  19. "cluesource": ""
  20. },
  21. }
  22. },
  23. data: {
  24. region: ['', '', ''], //省市县选择
  25. disabled: true,
  26. loading: false
  27. },
  28. lifetimes: {
  29. ready: function () {
  30. this.isDisabled();
  31. }
  32. },
  33. methods: {
  34. initData() {
  35. let content = this.data.content;
  36. for (let i in content) {
  37. if (content[i] == '-') content[i] = ""
  38. };
  39. this.setData({
  40. content
  41. })
  42. },
  43. /* 提交 */
  44. submit() {
  45. if (this.data.disabled || this.data.loading) return;
  46. if (!deleteMark.CheckPhoneNumber(this.data.content.phonenumber)) return;
  47. const that = this;
  48. if (this.data.type == '新建线索') return this.handleEdit();
  49. wx.showModal({
  50. title: "提示",
  51. content: "是否确认本次修改",
  52. success: ({
  53. confirm
  54. }) => {
  55. if (confirm) that.handleEdit();
  56. }
  57. })
  58. },
  59. handleEdit() {
  60. this.setData({
  61. loading: true
  62. });
  63. _Http.basic({
  64. "classname": "saletool.orderclue.web.orderclue",
  65. "method": "edit",
  66. content: this.data.content
  67. }).then(res => {
  68. this.setData({
  69. loading: false
  70. });
  71. if (res.msg != '成功') return wx.showToast({
  72. title: res.msg,
  73. icon: "none"
  74. });
  75. wx.showToast({
  76. title: '保存成功!',
  77. })
  78. setTimeout(() => {
  79. this.triggerEvent("endInsert");
  80. }, 300);
  81. })
  82. },
  83. /* 输入框输入内容 */
  84. inputChange(e) {
  85. let text = e.type == 'input' ? e.detail.value : e.detail;
  86. text = deleteMark.queryStr(text);
  87. const {
  88. label
  89. } = e.currentTarget.dataset;
  90. this.setData({
  91. ["content." + label]: text
  92. })
  93. if (['phonenumber', 'province', 'cluesource'].includes(label)) this.isDisabled();
  94. },
  95. /* 是否禁用 */
  96. isDisabled() {
  97. clearTimeout(count)
  98. count = setTimeout(() => {
  99. let {
  100. phonenumber,
  101. province,
  102. cluesource
  103. } = this.data.content;
  104. this.setData({
  105. disabled: !(phonenumber && province && cluesource)
  106. })
  107. }, 500);
  108. },
  109. /* 省市县选择器 */
  110. bindRegionChange: function (e) {
  111. let region = e.detail.value;
  112. this.setData({
  113. region,
  114. "content.province": region[0],
  115. "content.city": region[1],
  116. "content.county": region[2],
  117. })
  118. this.isDisabled();
  119. }
  120. }
  121. })