addAndEdit.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. let _Http = getApp().globalData.http,
  2. count = null;
  3. Page({
  4. data: {
  5. "sa_projectid": 0,
  6. showAll: false,
  7. form: [{
  8. label: "项目名称",
  9. error: false,
  10. errMsg: "",
  11. type: "textarea",
  12. value: "",
  13. placeholder: "项目名称",
  14. valueName: "projectname",
  15. checking: "base",
  16. required: true
  17. }, {
  18. label: "项目类型",
  19. error: false,
  20. errMsg: "",
  21. type: "option",
  22. optionNmae: "projecttype",
  23. optionType: "radio", //复选 radio 单选
  24. value: "",
  25. placeholder: "选择类型",
  26. valueName: "projecttype",
  27. checking: "base",
  28. required: true
  29. }, {
  30. label: "项目等级",
  31. error: false,
  32. errMsg: "",
  33. type: "option",
  34. optionNmae: "projectgrade",
  35. optionType: "radio", //复选 radio 单选
  36. value: "",
  37. placeholder: "选择项目等级",
  38. valueName: "grade",
  39. checking: "base",
  40. required: false
  41. }, {
  42. label: "地区",
  43. error: false,
  44. errMsg: "",
  45. type: "region",
  46. value: [],
  47. placeholder: "所属地区 省/市/区",
  48. valueName: "region",
  49. required: false
  50. }, {
  51. label: "详细地址",
  52. error: false,
  53. errMsg: "",
  54. type: "textarea",
  55. value: "",
  56. placeholder: "详细地址",
  57. valueName: "address",
  58. checking: "base",
  59. required: false
  60. }, {
  61. label: "项目规模",
  62. error: false,
  63. errMsg: "",
  64. type: "textarea",
  65. value: "",
  66. placeholder: "项目规模",
  67. valueName: "scale",
  68. checking: "base",
  69. required: false
  70. }, {
  71. label: "项目预算",
  72. error: false,
  73. errMsg: "",
  74. type: "number",
  75. value: "",
  76. placeholder: "项目预算",
  77. valueName: "budgetary",
  78. checking: "base",
  79. required: false
  80. }, {
  81. label: "预计签约金额",
  82. error: false,
  83. errMsg: "",
  84. type: "number",
  85. value: "",
  86. placeholder: "预计签约金额",
  87. valueName: "signamount_due",
  88. checking: "base",
  89. required: false
  90. }, {
  91. label: "预计签约月份",
  92. error: false,
  93. errMsg: "",
  94. type: "date",
  95. fields: "month",
  96. value: "",
  97. placeholder: "预计签约月份",
  98. valueName: "signdate_due",
  99. checking: "base",
  100. required: false
  101. }],
  102. disabled: true,
  103. countDown: "", //查重倒计时
  104. },
  105. onLoad(options) {
  106. if (options.data) {
  107. let data = JSON.parse(options.data);
  108. this.setData({
  109. disabled: false,
  110. sa_projectid: data.sa_projectid,
  111. form: this.data.form.map(v => {
  112. if (v.valueName != 'region') {
  113. v.value = data[v.valueName];
  114. } else {
  115. v.value = data.province ? [data.province, data.city, data.county] : []
  116. }
  117. return v
  118. })
  119. })
  120. }
  121. },
  122. /* 表单必填项是否完成 */
  123. onConfirm({
  124. detail
  125. }) {
  126. this.setData({
  127. disabled: detail
  128. })
  129. },
  130. // 是否显示全部
  131. onChange({
  132. detail
  133. }) {
  134. this.setData({
  135. showAll: detail
  136. })
  137. },
  138. /* 查询是否重复 */
  139. async queryRepetition(e) {
  140. let {
  141. projectname,
  142. address
  143. } = this.selectComponent("#Form").query();
  144. if (projectname == '') return wx.showToast({
  145. title: `您还未填写项目名称`,
  146. icon: "none"
  147. });
  148. let res = await this.handleQueryRepetition({
  149. projectname,
  150. address
  151. });
  152. console.log("查询重复", res)
  153. if (res.msg != '成功') return wx.showToast({
  154. title: res.msg,
  155. icon: "none"
  156. });
  157. this.setData({
  158. countDown: 6
  159. });
  160. count = setInterval(() => {
  161. let countDown = this.data.countDown;
  162. if (countDown == 0) {
  163. clearInterval(count);
  164. this.setData({
  165. countDown: ""
  166. })
  167. } else {
  168. countDown--;
  169. this.setData({
  170. countDown
  171. })
  172. }
  173. }, 1000)
  174. if (res.total == 0) {
  175. wx.showToast({
  176. title: '未查询到疑似重复的项目信息',
  177. icon: "none"
  178. })
  179. } else {
  180. wx.showToast({
  181. title: `查询到${res.total}条疑似重复项目信息`,
  182. icon: "none"
  183. })
  184. }
  185. },
  186. /* 处理查重 */
  187. handleQueryRepetition(content) {
  188. return _Http.basic({
  189. "id": 20221208184202,
  190. content
  191. })
  192. },
  193. async submit() {
  194. let data = this.selectComponent("#Form").submit();
  195. if (data.region.length != 0) {
  196. data.province = data.region[0]
  197. data.city = data.region[1]
  198. data.county = data.region[2]
  199. };
  200. delete(data.region);
  201. let query = await this.handleQueryRepetition({
  202. projectname: data.projectname,
  203. address: data.address
  204. });
  205. if (query.total != 0) await new Promise((resolve, reject) => {
  206. wx.showModal({
  207. title: '提示',
  208. content: `查询到${query.total}条疑似重复项目信息 是否确认继续新建`,
  209. complete: (res) => {
  210. if (res.cancel) reject()
  211. if (res.confirm) resolve(true);
  212. }
  213. })
  214. })
  215. _Http.basic({
  216. "id": 20221020144202,
  217. "content": {
  218. sa_projectid: this.data.sa_projectid,
  219. ...data
  220. }
  221. }).then(res => {
  222. console.log("新建客户", res)
  223. if (res.msg != '成功') return wx.showToast({
  224. title: res.msg,
  225. icon: "none"
  226. })
  227. wx.showToast({
  228. title: '保存成功',
  229. icon: "none"
  230. })
  231. //绑定疑似重复标签
  232. if (query.total != 0) _Http.basic({
  233. "id": 20220929090901,
  234. "content": {
  235. "ownertable": "sa_project",
  236. "ownerid": res.data.sa_projectid,
  237. "datatag": ["疑似重复"]
  238. }
  239. })
  240. setTimeout(() => {
  241. getCurrentPages().forEach(v => {
  242. if (v.getList) v.getList(true);
  243. if (['packageA/project/index', 'packageA/project/search'].includes(v.__route__)) {
  244. if (this.data.sa_projectid == 0) {
  245. v.data.list.push(res.data)
  246. } else {
  247. let i = v.data.list.findIndex(value => value.sa_projectid == this.data.sa_projectid);
  248. if (i != -1) v.data.list[i] = res.data;
  249. }
  250. v.setData({
  251. list: v.data.list
  252. })
  253. } else if (v.__route__ == 'packageA/project/detail') {
  254. wx.navigateBack()
  255. v.getDetail();
  256. }
  257. })
  258. if (this.data.sa_projectid == 0) {
  259. wx.redirectTo({
  260. url: '/packageA/project/detail?sa_projectid=' + res.data.sa_projectid,
  261. })
  262. }
  263. }, query.total != 0 ? 300 : 500)
  264. })
  265. },
  266. })