insert.js 3.7 KB

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