insert.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. "region[0]": content.province,
  42. "region[1]": content.city,
  43. "region[2]": content.county
  44. })
  45. },
  46. /* 提交 */
  47. submit() {
  48. if (this.data.disabled || this.data.loading) return;
  49. if (!deleteMark.CheckPhoneNumber(this.data.content.phonenumber)) return;
  50. const that = this;
  51. if (this.data.type == '新建线索') return this.handleEdit();
  52. wx.showModal({
  53. title: "提示",
  54. content: "是否确认本次修改",
  55. success: ({
  56. confirm
  57. }) => {
  58. if (confirm) that.handleEdit();
  59. }
  60. })
  61. },
  62. handleEdit() {
  63. this.setData({
  64. loading: true
  65. });
  66. _Http.basic({
  67. "classname": "saletool.orderclue.web.orderclue",
  68. "method": "edit",
  69. content: this.data.content
  70. }).then(res => {
  71. this.setData({
  72. loading: false
  73. });
  74. if (res.msg != '成功') return wx.showToast({
  75. title: res.msg,
  76. icon: "none"
  77. });
  78. wx.showToast({
  79. title: '保存成功!',
  80. })
  81. setTimeout(() => {
  82. this.triggerEvent("endInsert");
  83. }, 300);
  84. })
  85. },
  86. /* 输入框输入内容 */
  87. inputChange(e) {
  88. let text = e.type == 'input' ? e.detail.value : e.detail;
  89. text = deleteMark.queryStr(text);
  90. const {
  91. label
  92. } = e.currentTarget.dataset;
  93. this.setData({
  94. ["content." + label]: text
  95. })
  96. if (['phonenumber', 'province', 'cluesource'].includes(label)) this.isDisabled();
  97. },
  98. /* 是否禁用 */
  99. isDisabled() {
  100. clearTimeout(count)
  101. count = setTimeout(() => {
  102. let {
  103. phonenumber,
  104. province,
  105. cluesource
  106. } = this.data.content;
  107. this.setData({
  108. disabled: !(phonenumber && province && cluesource)
  109. })
  110. }, 500);
  111. },
  112. /* 省市县选择器 */
  113. bindRegionChange: function (e) {
  114. let region = e.detail.value;
  115. this.setData({
  116. region,
  117. "content.province": region[0],
  118. "content.city": region[1],
  119. "content.county": region[2],
  120. })
  121. this.isDisabled();
  122. }
  123. }
  124. })