addAndEdit.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. interrupt: true,
  23. permit: true, //无视errMsg 运行提交
  24. }, {
  25. label: "项目类型",
  26. error: false,
  27. errMsg: "",
  28. type: "option",
  29. optionNmae: "projecttype",
  30. optionType: "radio", //复选 radio 单选
  31. value: "",
  32. placeholder: "选择类型",
  33. valueName: "projecttype",
  34. checking: "base",
  35. required: true
  36. }, {
  37. label: "项目方阶段",
  38. error: false,
  39. errMsg: "",
  40. type: "option",
  41. optionNmae: "squarestage",
  42. optionType: "radio", //复选 radio 单选
  43. value: "",
  44. placeholder: "选择项目方阶段",
  45. valueName: "squarestage",
  46. checking: "base",
  47. required: false
  48. }, {
  49. label: "项目等级",
  50. error: false,
  51. errMsg: "",
  52. type: "option",
  53. optionNmae: "projectgrade",
  54. optionType: "radio", //复选 radio 单选
  55. value: "",
  56. placeholder: "选择项目等级",
  57. valueName: "grade",
  58. checking: "base",
  59. required: false
  60. }, {
  61. label: "省市县",
  62. error: false,
  63. errMsg: "",
  64. type: "region",
  65. value: [],
  66. placeholder: "省/市/县",
  67. valueName: "region",
  68. required: true
  69. }, {
  70. label: "详细地址",
  71. error: false,
  72. errMsg: "",
  73. type: "textarea",
  74. value: "",
  75. placeholder: "详细地址",
  76. valueName: "address",
  77. checking: "base",
  78. required: false
  79. }, {
  80. label: "项目规模",
  81. error: false,
  82. errMsg: "",
  83. type: "digit",
  84. value: "",
  85. placeholder: "请填写数值",
  86. valueName: "scale",
  87. checking: "base",
  88. required: false
  89. }, {
  90. label: "项目规模单位",
  91. error: false,
  92. errMsg: "",
  93. type: "option",
  94. optionNmae: "scaleunitname",
  95. optionType: "radio", //复选 radio 单选
  96. value: "",
  97. placeholder: "选择单位",
  98. valueName: "unitname",
  99. required: false
  100. }, {
  101. label: "项目预算(万元)",
  102. error: false,
  103. errMsg: "",
  104. type: "digit",
  105. value: "",
  106. placeholder: "请填写金额",
  107. valueName: "budgetary",
  108. checking: "base",
  109. required: false
  110. }, {
  111. label: "总投资额(万元)",
  112. error: false,
  113. errMsg: "",
  114. type: "digit",
  115. value: "",
  116. placeholder: "请填写金额",
  117. valueName: "totalinvestment",
  118. checking: "base",
  119. required: false
  120. }, {
  121. label: "造价(万元)",
  122. error: false,
  123. errMsg: "",
  124. type: "digit",
  125. value: "",
  126. placeholder: "请填写金额",
  127. valueName: "costofconstruction",
  128. checking: "base",
  129. required: false
  130. }, {
  131. label: "预计开工时间",
  132. error: false,
  133. errMsg: "",
  134. type: "date",
  135. fields: "month",
  136. value: "",
  137. placeholder: "预计开工时间",
  138. valueName: "begdate_due",
  139. checking: "base",
  140. required: false
  141. }, {
  142. label: "预计完工时间",
  143. error: false,
  144. errMsg: "",
  145. type: "date",
  146. fields: "month",
  147. value: "",
  148. placeholder: "预计完工时间",
  149. valueName: "enddate_due",
  150. checking: "base",
  151. required: false
  152. },
  153. {
  154. label: "预计签约时间",
  155. error: false,
  156. errMsg: "",
  157. type: "date",
  158. fields: "month",
  159. value: "",
  160. placeholder: "预计签约时间",
  161. valueName: "signdate_due",
  162. checking: "base",
  163. required: false
  164. }, {
  165. label: "领域",
  166. error: false,
  167. errMsg: "",
  168. type: "option",
  169. optionNmae: "tradefield",
  170. optionType: "radio", //复选 radio 单选
  171. value: "",
  172. placeholder: "选择领域",
  173. valueName: "tradefield",
  174. checking: "base",
  175. required: true
  176. }, {
  177. label: "品牌",
  178. error: false,
  179. errMsg: "",
  180. type: "route",
  181. url: "/packageA/select/brand/select",
  182. params: {
  183. "id": 20220924163702,
  184. "content": {
  185. nochace: true,
  186. }
  187. },
  188. query: "&radio=true",
  189. value: "",
  190. placeholder: "选择品牌",
  191. valueName: "sa_brandid",
  192. checking: "base",
  193. required: false
  194. }, {
  195. label: "品牌是否由提报方植入",
  196. error: false,
  197. errMsg: "",
  198. hint: "",
  199. type: "radio",
  200. value: "",
  201. radioList: [{
  202. id: '1',
  203. name: '是'
  204. }, {
  205. id: '0',
  206. name: '否'
  207. }],
  208. valueName: "isfillbrangd", //绑定的字段名称
  209. required: false, //必填
  210. direction: "horizontal"
  211. }
  212. ],
  213. countDown: "", //查重倒计时
  214. },
  215. onLoad(options) {
  216. if (options.data) {
  217. let data = JSON.parse(options.data);
  218. let disabled = options.disabled == "true";
  219. data.sa_brandid = [data.brandname, [data.sa_brandid]]
  220. this.setData({
  221. disabled: false,
  222. sa_projectid: data.sa_projectid,
  223. form: this.data.form.map(v => {
  224. if (v.valueName != 'region') {
  225. v.value = data[v.valueName];
  226. } else {
  227. v.value = data.province ? [data.province, data.city, data.county] : []
  228. };
  229. if (disabled) {
  230. if (['projectname', 'region', 'address'].includes(v.valueName)) v.disabled = true
  231. }
  232. return v
  233. })
  234. });
  235. } else {
  236. //查询默认项目规模单位
  237. this.getUnitname();
  238. }
  239. },
  240. async interrupt(e) {
  241. let {
  242. data,
  243. form,
  244. temporary
  245. } = e.detail;
  246. if (data.label == "项目名称") {
  247. if (data.value) {
  248. const result = await this.selectComponent("#projectname").queryList(data.value);
  249. console.log(result)
  250. if (result) {
  251. data.errMsg = '疑似重复';
  252. form[0] = data;
  253. this.setData({
  254. form
  255. })
  256. } else {
  257. if (data.errMsg) {
  258. data.errMsg = '';
  259. form[0] = data;
  260. this.setData({
  261. form
  262. })
  263. }
  264. }
  265. } else {
  266. if (data.errMsg) {
  267. data.errMsg = '';
  268. form[0] = data;
  269. this.setData({
  270. form
  271. })
  272. }
  273. }
  274. }
  275. },
  276. getUnitname() {
  277. _Http.basic({
  278. "classname": "sysmanage.develop.optiontype.optiontype",
  279. "method": "optiontypeselect",
  280. "content": {
  281. pageNumber: 1,
  282. "pageSize": 1,
  283. "typename": "scaleunitname",
  284. "parameter": {
  285. "siteid": wx.getStorageSync('siteP').siteid
  286. }
  287. }
  288. }).then(res => {
  289. console.log("项目规模", res)
  290. if (res.msg == '成功') {
  291. let index = this.data.form.findIndex(v => v.label == '项目规模单位');
  292. if (index != -1) this.setData({
  293. [`form[${index}].value`]: res.data[0].value
  294. })
  295. }
  296. })
  297. },
  298. /* 表单必填项是否完成 */
  299. onConfirm({
  300. detail
  301. }) {
  302. this.setData({
  303. disabled: detail
  304. })
  305. },
  306. // 是否显示全部
  307. onChange({
  308. detail
  309. }) {
  310. this.setData({
  311. showAll: detail
  312. })
  313. },
  314. /* 查询是否重复 */
  315. async queryRepetition(e) {
  316. let data = this.selectComponent("#Form").query();
  317. /* if (data.projectname == '') return wx.showToast({
  318. title: `您还未填写项目名称`,
  319. icon: "none"
  320. }); */
  321. data.province = data.region[0] || "";
  322. data.city = data.region[1] || "";
  323. data.county = data.region[2] || "";
  324. let res = await this.handleQueryRepetition({
  325. sa_projectid: this.data.sa_projectid,
  326. ...data
  327. });
  328. console.log("查询重复", res)
  329. if (res.msg != '成功') return wx.showToast({
  330. title: res.msg,
  331. icon: "none"
  332. });
  333. this.setData({
  334. countDown: 6
  335. });
  336. count = setInterval(() => {
  337. let countDown = this.data.countDown;
  338. if (countDown == 0) {
  339. clearInterval(count);
  340. this.setData({
  341. countDown: ""
  342. })
  343. } else {
  344. countDown--;
  345. this.setData({
  346. countDown
  347. })
  348. }
  349. }, 1000)
  350. if (res.total == 0) {
  351. wx.showToast({
  352. title: '未查询到疑似重复的项目信息',
  353. icon: "none"
  354. })
  355. } else {
  356. wx.showToast({
  357. title: `查询到${res.total}条疑似重复项目信息`,
  358. icon: "none"
  359. })
  360. this.setData({
  361. repetitionShow: true,
  362. repetitionList: res.data
  363. })
  364. }
  365. },
  366. repClose() {
  367. if (this.data.isSubmit) {
  368. let that = this;
  369. wx.showModal({
  370. title: '提示',
  371. content: `是否继续创建项目`,
  372. complete: (res) => {
  373. if (res.confirm) that.handleSubmit(true);
  374. }
  375. })
  376. }
  377. this.setData({
  378. repetitionShow: false,
  379. isSubmit: false
  380. })
  381. },
  382. /* 处理查重 */
  383. handleQueryRepetition(content) {
  384. return _Http.basic({
  385. "id": 20221208184202,
  386. content
  387. })
  388. },
  389. async submit() {
  390. let data = this.selectComponent("#Form").submit();
  391. data.province = data.region[0] || "";
  392. data.city = data.region[1] || "";
  393. data.county = data.region[2] || "";
  394. let query = await this.handleQueryRepetition({
  395. sa_projectid: this.data.sa_projectid,
  396. ...data
  397. });
  398. if (query.total != 0) {
  399. wx.showToast({
  400. title: `查询到${query.total}条疑似重复项目信息`,
  401. icon: "none"
  402. })
  403. this.setData({
  404. repetitionShow: true,
  405. repetitionList: query.data,
  406. isSubmit: true
  407. })
  408. } else {
  409. this.handleSubmit();
  410. }
  411. },
  412. handleSubmit(tag = false) {
  413. this.setData({
  414. loading: true
  415. })
  416. let data = this.selectComponent("#Form").submit();
  417. data.province = data.region[0] || "";
  418. data.city = data.region[1] || "";
  419. data.county = data.region[2] || "";
  420. data.tradefields = [data.tradefields];
  421. data.sa_brandid = data.sa_brandid ? data.sa_brandid[1][0] : 0;
  422. delete(data.region);
  423. _Http.basic({
  424. "id": 20221020144202,
  425. "content": {
  426. sa_projectid: this.data.sa_projectid,
  427. ...data
  428. }
  429. }).then(res => {
  430. this.setData({
  431. loading: false
  432. })
  433. console.log("新建项目", res)
  434. wx.showToast({
  435. title: res.msg != '成功' ? res.msg : "保存成功",
  436. icon: "none",
  437. mask: true
  438. })
  439. if (res.msg != '成功') return;
  440. //绑定疑似重复标签
  441. if (tag) _Http.basic({
  442. "id": 20220929090901,
  443. "content": {
  444. "ownertable": "sa_project",
  445. "ownerid": res.data.sa_projectid,
  446. "datatag": ["疑似重复"]
  447. }
  448. })
  449. setTimeout(() => {
  450. let page = getCurrentPages()[getCurrentPages().length - 2];
  451. if (page.__route__ == 'packageA/project/index') {
  452. wx.redirectTo({
  453. url: '/packageA/project/detail?id=' + res.data.sa_projectid,
  454. })
  455. } else if (page.__route__ == 'packageA/project/detail') {
  456. wx.navigateBack()
  457. page.getDetail();
  458. }
  459. }, 500)
  460. })
  461. }
  462. })