addAndEdit.js 11 KB

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