addAndEdit.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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: "digit",
  70. value: "",
  71. placeholder: "请填写数值",
  72. valueName: "scale",
  73. checking: "base",
  74. required: false
  75. }, {
  76. label: "项目规模单位",
  77. error: false,
  78. errMsg: "",
  79. type: "option",
  80. optionNmae: "scaleunitname",
  81. optionType: "radio", //复选 radio 单选
  82. value: "",
  83. placeholder: "选择单位",
  84. valueName: "unitname",
  85. required: false
  86. }, {
  87. label: "项目预算(万元)",
  88. error: false,
  89. errMsg: "",
  90. type: "digit",
  91. value: "",
  92. placeholder: "请填写金额",
  93. valueName: "budgetary",
  94. checking: "base",
  95. required: false
  96. }, {
  97. label: "总投资额(万元)",
  98. error: false,
  99. errMsg: "",
  100. type: "digit",
  101. value: "",
  102. placeholder: "请填写金额",
  103. valueName: "totalinvestment",
  104. checking: "base",
  105. required: false
  106. }, {
  107. label: "造价(万元)",
  108. error: false,
  109. errMsg: "",
  110. type: "digit",
  111. value: "",
  112. placeholder: "请填写金额",
  113. valueName: "costofconstruction",
  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: "begdate_due",
  125. checking: "base",
  126. required: false
  127. }, {
  128. label: "预计完工时间",
  129. error: false,
  130. errMsg: "",
  131. type: "date",
  132. fields: "month",
  133. value: "",
  134. placeholder: "预计完工时间",
  135. valueName: "enddate_due",
  136. checking: "base",
  137. required: false
  138. },
  139. {
  140. label: "预计签约时间",
  141. error: false,
  142. errMsg: "",
  143. type: "date",
  144. fields: "month",
  145. value: "",
  146. placeholder: "预计签约时间",
  147. valueName: "signdate_due",
  148. checking: "base",
  149. required: false
  150. }, {
  151. label: "领域",
  152. error: false,
  153. errMsg: "",
  154. type: "option",
  155. optionNmae: "tradefield",
  156. optionType: "radio", //复选 radio 单选
  157. value: "",
  158. placeholder: "选择领域",
  159. valueName: "tradefield",
  160. checking: "base",
  161. required: true
  162. }, {
  163. label: "品牌",
  164. error: false,
  165. errMsg: "",
  166. type: "route",
  167. url: "/packageA/select/brand/select",
  168. params: {
  169. "id": 20220924163702,
  170. "content": {
  171. nochace: true,
  172. }
  173. },
  174. query: "&radio=true",
  175. value: "",
  176. placeholder: "选择品牌",
  177. valueName: "sa_brandid",
  178. checking: "base",
  179. required: false
  180. }
  181. ],
  182. countDown: "", //查重倒计时
  183. },
  184. onLoad(options) {
  185. if (options.data) {
  186. let data = JSON.parse(options.data);
  187. let disabled = options.disabled == "true";
  188. data.sa_brandid = [data.brandname, [data.sa_brandid]]
  189. this.setData({
  190. disabled: false,
  191. sa_projectid: data.sa_projectid,
  192. form: this.data.form.map(v => {
  193. if (v.valueName != 'region') {
  194. v.value = data[v.valueName];
  195. } else {
  196. v.value = data.province ? [data.province, data.city, data.county] : []
  197. };
  198. if (disabled) {
  199. if (['projectname', 'region', 'address'].includes(v.valueName)) v.disabled = true
  200. }
  201. return v
  202. })
  203. });
  204. } else {
  205. //查询默认项目规模单位
  206. this.getUnitname();
  207. }
  208. },
  209. getUnitname() {
  210. _Http.basic({
  211. "classname": "sysmanage.develop.optiontype.optiontype",
  212. "method": "optiontypeselect",
  213. "content": {
  214. pageNumber: 1,
  215. "pageSize": 1,
  216. "typename": "scaleunitname",
  217. "parameter": {
  218. "siteid": wx.getStorageSync('siteP').siteid
  219. }
  220. }
  221. }).then(res => {
  222. console.log("项目规模", res)
  223. if (res.msg == '成功') {
  224. let index = this.data.form.findIndex(v => v.label == '项目规模单位');
  225. if (index != -1) this.setData({
  226. [`form[${index}].value`]: res.data[0].value
  227. })
  228. }
  229. })
  230. },
  231. /* 表单必填项是否完成 */
  232. onConfirm({
  233. detail
  234. }) {
  235. this.setData({
  236. disabled: detail
  237. })
  238. },
  239. // 是否显示全部
  240. onChange({
  241. detail
  242. }) {
  243. this.setData({
  244. showAll: detail
  245. })
  246. },
  247. /* 查询是否重复 */
  248. async queryRepetition(e) {
  249. let data = this.selectComponent("#Form").query();
  250. /* if (data.projectname == '') return wx.showToast({
  251. title: `您还未填写项目名称`,
  252. icon: "none"
  253. }); */
  254. data.province = data.region[0] || "";
  255. data.city = data.region[1] || "";
  256. data.county = data.region[2] || "";
  257. let res = await this.handleQueryRepetition({
  258. sa_projectid: this.data.sa_projectid,
  259. ...data
  260. });
  261. console.log("查询重复", res)
  262. if (res.msg != '成功') return wx.showToast({
  263. title: res.msg,
  264. icon: "none"
  265. });
  266. this.setData({
  267. countDown: 6
  268. });
  269. count = setInterval(() => {
  270. let countDown = this.data.countDown;
  271. if (countDown == 0) {
  272. clearInterval(count);
  273. this.setData({
  274. countDown: ""
  275. })
  276. } else {
  277. countDown--;
  278. this.setData({
  279. countDown
  280. })
  281. }
  282. }, 1000)
  283. if (res.total == 0) {
  284. wx.showToast({
  285. title: '未查询到疑似重复的项目信息',
  286. icon: "none"
  287. })
  288. } else {
  289. wx.showToast({
  290. title: `查询到${res.total}条疑似重复项目信息`,
  291. icon: "none"
  292. })
  293. this.setData({
  294. repetitionShow: true,
  295. repetitionList: res.data
  296. })
  297. }
  298. },
  299. repClose() {
  300. if (this.data.isSubmit) {
  301. let that = this;
  302. wx.showModal({
  303. title: '提示',
  304. content: `是否继续创建项目`,
  305. complete: (res) => {
  306. if (res.confirm) that.handleSubmit(true);
  307. }
  308. })
  309. }
  310. this.setData({
  311. repetitionShow: false,
  312. isSubmit: false
  313. })
  314. },
  315. /* 处理查重 */
  316. handleQueryRepetition(content) {
  317. return _Http.basic({
  318. "id": 20221208184202,
  319. content
  320. })
  321. },
  322. async submit() {
  323. let data = this.selectComponent("#Form").submit();
  324. data.province = data.region[0] || "";
  325. data.city = data.region[1] || "";
  326. data.county = data.region[2] || "";
  327. let query = await this.handleQueryRepetition({
  328. sa_projectid: this.data.sa_projectid,
  329. ...data
  330. });
  331. if (query.total != 0) {
  332. wx.showToast({
  333. title: `查询到${query.total}条疑似重复项目信息`,
  334. icon: "none"
  335. })
  336. this.setData({
  337. repetitionShow: true,
  338. repetitionList: query.data,
  339. isSubmit: true
  340. })
  341. } else {
  342. this.handleSubmit();
  343. }
  344. },
  345. handleSubmit(tag = false) {
  346. this.setData({
  347. loading: true
  348. })
  349. let data = this.selectComponent("#Form").submit();
  350. data.province = data.region[0] || "";
  351. data.city = data.region[1] || "";
  352. data.county = data.region[2] || "";
  353. data.tradefields = [data.tradefields];
  354. data.sa_brandid = data.sa_brandid ? data.sa_brandid[1][0] : 0;
  355. delete(data.region);
  356. _Http.basic({
  357. "id": 20221020144202,
  358. "content": {
  359. sa_projectid: this.data.sa_projectid,
  360. ...data
  361. }
  362. }).then(res => {
  363. this.setData({
  364. loading: false
  365. })
  366. console.log("新建项目", res)
  367. wx.showToast({
  368. title: res.msg != '成功' ? res.msg : "保存成功",
  369. icon: "none",
  370. mask: true
  371. })
  372. if (res.msg != '成功') return;
  373. //绑定疑似重复标签
  374. if (tag) _Http.basic({
  375. "id": 20220929090901,
  376. "content": {
  377. "ownertable": "sa_project",
  378. "ownerid": res.data.sa_projectid,
  379. "datatag": ["疑似重复"]
  380. }
  381. })
  382. setTimeout(() => {
  383. let page = getCurrentPages()[getCurrentPages().length - 2];
  384. if (page.__route__ == 'packageA/project/index') {
  385. wx.redirectTo({
  386. url: '/packageA/project/detail?id=' + res.data.sa_projectid,
  387. })
  388. } else if (page.__route__ == 'packageA/project/detail') {
  389. wx.navigateBack()
  390. page.getDetail();
  391. }
  392. }, 500)
  393. })
  394. }
  395. })