addAndEdit.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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 (wx.getStorageSync('userMsg').siteid == 'HY') this.setHY();
  217. if (options.data) {
  218. wx.setNavigationBarTitle({
  219. title: '编辑项目',
  220. })
  221. let data = JSON.parse(options.data);
  222. let disabled = options.disabled == "true";
  223. data.sa_brandid = [data.brandname, [data.sa_brandid]]
  224. this.setData({
  225. disabled: false,
  226. sa_projectid: data.sa_projectid,
  227. form: this.data.form.map(v => {
  228. if (v.valueName != 'region') {
  229. v.value = data[v.valueName];
  230. } else {
  231. v.value = data.province ? [data.province, data.city, data.county] : []
  232. };
  233. if (disabled) {
  234. if (['projectname', 'region', 'address'].includes(v.valueName)) v.disabled = true
  235. }
  236. return v
  237. })
  238. });
  239. } else {
  240. //查询默认项目规模单位
  241. this.getUnitname();
  242. }
  243. },
  244. setHY() {
  245. let required = ["预计签约时间", "项目等级", "详细地址", "项目规模"],
  246. remove = ["项目预算(万元)", "总投资额(万元)", "造价(万元)"];
  247. this.setData({
  248. form: this.data.form.filter(v => !remove.includes(v.label)).map(v => {
  249. if (required.includes(v.label)) v.required = true;
  250. return v
  251. })
  252. })
  253. },
  254. async interrupt(e) {
  255. let {
  256. data,
  257. form,
  258. temporary
  259. } = e.detail;
  260. if (data.label == "项目名称") {
  261. if (data.value) {
  262. const result = await this.selectComponent("#projectname").queryList(data.value);
  263. console.log(result)
  264. if (result) {
  265. data.errMsg = '疑似重复';
  266. form[0] = data;
  267. this.setData({
  268. form
  269. })
  270. } else {
  271. if (data.errMsg) {
  272. data.errMsg = '';
  273. form[0] = data;
  274. this.setData({
  275. form
  276. })
  277. }
  278. }
  279. } else {
  280. if (data.errMsg) {
  281. data.errMsg = '';
  282. form[0] = data;
  283. this.setData({
  284. form
  285. })
  286. }
  287. }
  288. }
  289. },
  290. getUnitname() {
  291. _Http.basic({
  292. "classname": "sysmanage.develop.optiontype.optiontype",
  293. "method": "optiontypeselect",
  294. "content": {
  295. pageNumber: 1,
  296. "pageSize": 1,
  297. "typename": "scaleunitname",
  298. "parameter": {
  299. "siteid": wx.getStorageSync('siteP').siteid
  300. }
  301. }
  302. }).then(res => {
  303. console.log("项目规模", res)
  304. if (res.msg == '成功') {
  305. let index = this.data.form.findIndex(v => v.label == '项目规模单位');
  306. if (index != -1) this.setData({
  307. [`form[${index}].value`]: res.data[0].value
  308. })
  309. }
  310. })
  311. },
  312. /* 表单必填项是否完成 */
  313. onConfirm({
  314. detail
  315. }) {
  316. this.setData({
  317. disabled: detail
  318. })
  319. },
  320. // 是否显示全部
  321. onChange({
  322. detail
  323. }) {
  324. this.setData({
  325. showAll: detail
  326. })
  327. },
  328. /* 查询是否重复 */
  329. async queryRepetition(e) {
  330. let data = this.selectComponent("#Form").query();
  331. /* if (data.projectname == '') return wx.showToast({
  332. title: `您还未填写项目名称`,
  333. icon: "none"
  334. }); */
  335. data.province = data.region[0] || "";
  336. data.city = data.region[1] || "";
  337. data.county = data.region[2] || "";
  338. let res = await this.handleQueryRepetition({
  339. sa_projectid: this.data.sa_projectid,
  340. ...data
  341. });
  342. console.log("查询重复", res)
  343. if (res.msg != '成功') return wx.showToast({
  344. title: res.msg,
  345. icon: "none"
  346. });
  347. this.setData({
  348. countDown: 6
  349. });
  350. count = setInterval(() => {
  351. let countDown = this.data.countDown;
  352. if (countDown == 0) {
  353. clearInterval(count);
  354. this.setData({
  355. countDown: ""
  356. })
  357. } else {
  358. countDown--;
  359. this.setData({
  360. countDown
  361. })
  362. }
  363. }, 1000)
  364. if (res.total == 0) {
  365. wx.showToast({
  366. title: '未查询到疑似重复的项目信息',
  367. icon: "none"
  368. })
  369. } else {
  370. wx.showToast({
  371. title: `查询到${res.total}条疑似重复项目信息`,
  372. icon: "none"
  373. })
  374. this.setData({
  375. repetitionShow: true,
  376. repetitionList: res.data
  377. })
  378. }
  379. },
  380. repClose() {
  381. if (this.data.isSubmit) {
  382. let that = this;
  383. wx.showModal({
  384. title: '提示',
  385. content: `是否继续创建项目`,
  386. complete: (res) => {
  387. if (res.confirm) that.handleSubmit(true);
  388. }
  389. })
  390. }
  391. this.setData({
  392. repetitionShow: false,
  393. isSubmit: false
  394. })
  395. },
  396. /* 处理查重 */
  397. handleQueryRepetition(content) {
  398. return _Http.basic({
  399. "id": 20221208184202,
  400. content
  401. })
  402. },
  403. async submit() {
  404. let data = this.selectComponent("#Form").submit();
  405. data.province = data.region[0] || "";
  406. data.city = data.region[1] || "";
  407. data.county = data.region[2] || "";
  408. let query = await this.handleQueryRepetition({
  409. sa_projectid: this.data.sa_projectid,
  410. ...data
  411. });
  412. if (query.total != 0) {
  413. wx.showToast({
  414. title: `查询到${query.total}条疑似重复项目信息`,
  415. icon: "none"
  416. })
  417. this.setData({
  418. repetitionShow: true,
  419. repetitionList: query.data,
  420. isSubmit: true
  421. })
  422. } else {
  423. this.handleSubmit();
  424. }
  425. },
  426. handleSubmit(tag = false) {
  427. this.setData({
  428. loading: true
  429. })
  430. let data = this.selectComponent("#Form").submit();
  431. data.province = data.region[0] || "";
  432. data.city = data.region[1] || "";
  433. data.county = data.region[2] || "";
  434. data.tradefields = [data.tradefields];
  435. data.sa_brandid = data.sa_brandid ? data.sa_brandid[1][0] : 0;
  436. if (data.scale.length != 0 && data.scale == 0) {
  437. this.setData({
  438. loading: false
  439. })
  440. wx.showToast({
  441. title: '项目规模不可为0',
  442. icon: "none"
  443. })
  444. return;
  445. }
  446. delete(data.region);
  447. _Http.basic({
  448. "id": 20221020144202,
  449. "content": {
  450. sa_projectid: this.data.sa_projectid,
  451. ...data
  452. }
  453. }).then(res => {
  454. this.setData({
  455. loading: false
  456. })
  457. console.log("新建项目", res)
  458. wx.showToast({
  459. title: res.msg != '成功' ? res.msg : "保存成功",
  460. icon: "none",
  461. mask: true
  462. })
  463. if (res.msg != '成功') return;
  464. //绑定疑似重复标签
  465. if (tag) _Http.basic({
  466. "id": 20220929090901,
  467. "content": {
  468. "ownertable": "sa_project",
  469. "ownerid": res.data.sa_projectid,
  470. "datatag": ["疑似重复"]
  471. }
  472. })
  473. setTimeout(() => {
  474. let page = getCurrentPages()[getCurrentPages().length - 2];
  475. if (page.__route__ == 'packageA/project/index') {
  476. wx.redirectTo({
  477. url: '/packageA/project/detail?id=' + res.data.sa_projectid,
  478. })
  479. } else if (page.__route__ == 'packageA/project/detail') {
  480. wx.navigateBack()
  481. page.getDetail();
  482. }
  483. }, 500)
  484. })
  485. }
  486. })