addAndEdit.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. "sa_projectid": 0,
  5. showAll: false,
  6. form: [{
  7. label: "项目名称",
  8. error: false,
  9. errMsg: "",
  10. type: "textarea",
  11. value: "",
  12. placeholder: "项目名称",
  13. valueName: "projectname",
  14. checking: "base",
  15. required: true
  16. }, {
  17. label: "项目类型",
  18. error: false,
  19. errMsg: "",
  20. type: "option",
  21. optionNmae: "projecttype",
  22. optionType: "radio", //复选 radio 单选
  23. value: "",
  24. placeholder: "选择类型",
  25. valueName: "projecttype",
  26. checking: "base",
  27. required: true
  28. }, {
  29. label: "项目等级",
  30. error: false,
  31. errMsg: "",
  32. type: "option",
  33. optionNmae: "projectgrade",
  34. optionType: "radio", //复选 radio 单选
  35. value: "",
  36. placeholder: "选择项目等级",
  37. valueName: "grade",
  38. checking: "base",
  39. required: false
  40. }, {
  41. label: "地区",
  42. error: false,
  43. errMsg: "",
  44. type: "region",
  45. value: [],
  46. placeholder: "所属地区 省/市/区",
  47. valueName: "region",
  48. required: false
  49. }, {
  50. label: "详细地址",
  51. error: false,
  52. errMsg: "",
  53. type: "textarea",
  54. value: "",
  55. placeholder: "详细地址",
  56. valueName: "address",
  57. checking: "base",
  58. required: false
  59. }, {
  60. label: "项目规模",
  61. error: false,
  62. errMsg: "",
  63. type: "textarea",
  64. value: "",
  65. placeholder: "项目规模",
  66. valueName: "scale",
  67. checking: "base",
  68. required: false
  69. }, {
  70. label: "项目预算",
  71. error: false,
  72. errMsg: "",
  73. type: "number",
  74. value: "",
  75. placeholder: "项目预算",
  76. valueName: "budgetary",
  77. checking: "base",
  78. required: false
  79. }, {
  80. label: "预计签约金额",
  81. error: false,
  82. errMsg: "",
  83. type: "number",
  84. value: "",
  85. placeholder: "预计签约金额",
  86. valueName: "signamount_due",
  87. checking: "base",
  88. required: false
  89. }, {
  90. label: "预计签约月份",
  91. error: false,
  92. errMsg: "",
  93. type: "date",
  94. fields: "month",
  95. value: "",
  96. placeholder: "预计签约月份",
  97. valueName: "signdate_due",
  98. checking: "base",
  99. required: false
  100. }],
  101. disabled: true
  102. },
  103. onLoad(options) {
  104. if (options.data) {
  105. let data = JSON.parse(options.data);
  106. this.setData({
  107. disabled: false,
  108. sa_projectid: data.sa_projectid,
  109. form: this.data.form.map(v => {
  110. if (v.valueName != 'region') {
  111. v.value = data[v.valueName];
  112. } else {
  113. v.value = data.province ? [data.province, data.city, data.county] : []
  114. }
  115. return v
  116. })
  117. })
  118. }
  119. },
  120. /* 表单必填项是否完成 */
  121. onConfirm({
  122. detail
  123. }) {
  124. this.setData({
  125. disabled: detail
  126. })
  127. },
  128. // 是否显示全部
  129. onChange({
  130. detail
  131. }) {
  132. this.setData({
  133. showAll: detail
  134. })
  135. },
  136. submit() {
  137. let data = this.selectComponent("#Form").submit();
  138. if (data.region.length != 0) {
  139. data.province = data.region[0]
  140. data.city = data.region[1]
  141. data.county = data.region[2]
  142. };
  143. delete(data.region);
  144. _Http.basic({
  145. "id": 20221020144202,
  146. "content": {
  147. sa_projectid: this.data.sa_projectid,
  148. ...data
  149. }
  150. }).then(res => {
  151. console.log("新建客户", res)
  152. if (res.msg != '成功') return wx.showToast({
  153. title: res.msg,
  154. icon: "none"
  155. })
  156. wx.showToast({
  157. title: '保存成功',
  158. icon: "none"
  159. })
  160. setTimeout(() => {
  161. wx.navigateBack()
  162. getCurrentPages().forEach(v => {
  163. if (v.getList) v.getList(true);
  164. if (['packageA/project/index', 'packageA/project/search'].includes(v.__route__)) {
  165. if (this.data.sa_projectid == 0) {
  166. v.data.list.push(res.data)
  167. } else {
  168. let i = v.data.list.findIndex(value => value.sa_projectid == this.data.sa_projectid);
  169. if (i != -1) v.data.list[i] = res.data;
  170. }
  171. v.setData({
  172. list: v.data.list
  173. })
  174. } else if (v.__route__ == 'packageA/project/detail') {
  175. v.getDetail();
  176. }
  177. })
  178. if (this.data.sa_projectid == 0) {
  179. wx.navigateTo({
  180. url: '/packageA/project/detail?sa_projectid=' + res.data.sa_projectid,
  181. })
  182. }
  183. }, 300)
  184. })
  185. },
  186. })