addAndEdit.js 19 KB

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