addAndEdit.js 9.1 KB

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