addAndEdit.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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. countDown: "", //查重倒计时
  215. },
  216. onLoad(options) {
  217. let siteid = wx.getStorageSync('userMsg').siteid,
  218. form = this.data.form;
  219. if (siteid == 'HY') this.setHY();
  220. if (['NB', 'TZ', 'YOSTEST1'].includes(siteid)) {
  221. form.splice(form.findIndex(v => v.optionNmae == 'scaleunitname') + 1, 0, {
  222. label: "预计签约金额(元)",
  223. error: false,
  224. errMsg: "",
  225. type: "digit",
  226. value: "",
  227. placeholder: "请填写金额",
  228. valueName: "signamount_due",
  229. checking: "base",
  230. required: false
  231. })
  232. this.setData({
  233. form
  234. })
  235. }
  236. if (options.data) {
  237. let data = JSON.parse(options.data);
  238. let disabled = options.disabled == "true";
  239. data.sa_brandid = [data.brandname, [data.sa_brandid]]
  240. this.setData({
  241. disabled: false,
  242. sa_projectid: data.sa_projectid,
  243. form: form.map(v => {
  244. if (v.valueName != 'region') {
  245. v.value = data[v.valueName];
  246. } else {
  247. v.value = data.province ? [data.province, data.city, data.county] : []
  248. };
  249. if (disabled) {
  250. if (['projectname', 'region', 'address'].includes(v.valueName)) v.disabled = true
  251. }
  252. return v
  253. })
  254. });
  255. } else {
  256. //查询默认项目规模单位
  257. this.getUnitname();
  258. }
  259. getApp().globalData.Language.getLanguagePackage(this, options.data ? '编辑项目' : '新建项目');
  260. },
  261. setHY() {
  262. let required = ["预计签约时间", "项目等级", "详细地址", "项目规模"],
  263. remove = ["项目预算(万元)", "总投资额(万元)", "造价(万元)"];
  264. this.setData({
  265. form: this.data.form.filter(v => !remove.includes(v.label)).map(v => {
  266. if (required.includes(v.label)) v.required = true;
  267. // if (v.valueName == 'projectname') v.interrupt = false;
  268. return v
  269. }),
  270. siteid: wx.getStorageSync('userMsg').siteid,
  271. })
  272. },
  273. async interrupt(e) {
  274. let {
  275. data,
  276. form,
  277. temporary
  278. } = e.detail;
  279. if (data.label == "项目名称") {
  280. if (data.value) {
  281. const result = await this.selectComponent("#projectname").queryList(data.value);
  282. if (typeof result == 'string') {
  283. data.errMsg = result;
  284. form[0] = data;
  285. this.setData({
  286. form
  287. })
  288. } else {
  289. if (result) {
  290. data.errMsg = '疑似重复';
  291. form[0] = data;
  292. this.setData({
  293. form
  294. })
  295. } else {
  296. if (data.errMsg) {
  297. data.errMsg = '';
  298. form[0] = data;
  299. this.setData({
  300. form
  301. })
  302. }
  303. }
  304. }
  305. } else {
  306. if (data.errMsg) {
  307. data.errMsg = '';
  308. form[0] = data;
  309. this.setData({
  310. form
  311. })
  312. }
  313. }
  314. }
  315. },
  316. getUnitname() {
  317. _Http.basic({
  318. "classname": "sysmanage.develop.optiontype.optiontype",
  319. "method": "optiontypeselect",
  320. "content": {
  321. pageNumber: 1,
  322. "pageSize": 1,
  323. "typename": "scaleunitname",
  324. "parameter": {
  325. "siteid": wx.getStorageSync('siteP').siteid
  326. }
  327. }
  328. }).then(res => {
  329. console.log("项目规模", res)
  330. if (res.code == '1') {
  331. let index = this.data.form.findIndex(v => v.label == '项目规模单位');
  332. if (index != -1) this.setData({
  333. [`form[${index}].value`]: res.data[0].value
  334. })
  335. }
  336. })
  337. },
  338. /* 表单必填项是否完成 */
  339. onConfirm({
  340. detail
  341. }) {
  342. this.setData({
  343. disabled: detail
  344. })
  345. },
  346. // 是否显示全部
  347. onChange({
  348. detail
  349. }) {
  350. this.setData({
  351. showAll: detail
  352. })
  353. },
  354. /* 查询是否重复 */
  355. async queryRepetition(e) {
  356. let data = this.selectComponent("#Form").query();
  357. /* if (data.projectname == '') return wx.showToast({
  358. title: `您还未填写项目名称`,
  359. icon: "none"
  360. }); */
  361. data.province = data.region[0] || "";
  362. data.city = data.region[1] || "";
  363. data.county = data.region[2] || "";
  364. let res = await this.handleQueryRepetition({
  365. sa_projectid: this.data.sa_projectid,
  366. ...data
  367. });
  368. console.log("查询重复", res)
  369. if (res.code != '1') return wx.showToast({
  370. title: res.msg,
  371. icon: "none"
  372. });
  373. this.setData({
  374. countDown: 6
  375. });
  376. count = setInterval(() => {
  377. let countDown = this.data.countDown;
  378. if (countDown == 0) {
  379. clearInterval(count);
  380. this.setData({
  381. countDown: ""
  382. })
  383. } else {
  384. countDown--;
  385. this.setData({
  386. countDown
  387. })
  388. }
  389. }, 1000)
  390. if (res.total == 0) {
  391. getApp().globalData.Language.showToast('未查询到疑似重复的项目信息')
  392. this.data.repetitionShow = false;
  393. } else {
  394. wx.showToast({
  395. title: getApp().globalData.Language.getMapText('查询到') + res.total + getApp().globalData.Language.getMapText('条疑似重复项目信息'),
  396. icon: "none"
  397. })
  398. if (wx.getStorageSync('userMsg').siteid != 'HY') this.setData({
  399. repetitionShow: true,
  400. repetitionList: res.data.map(v => {
  401. v.chars = v.chars.reduce((acc, item) => ({
  402. ...acc,
  403. ...item
  404. }), {});
  405. v.projectname = v.projectname.split('').map(text => {
  406. let projectname = v.chars.projectname.join("") || ''
  407. return projectname.includes(text) ? {
  408. text,
  409. color: "red"
  410. } : {
  411. text,
  412. color: "#666666"
  413. }
  414. })
  415. return v
  416. }),
  417. })
  418. }
  419. },
  420. repClose() {
  421. if (this.data.isSubmit) {
  422. let that = this;
  423. wx.showModal({
  424. title: getApp().globalData.Language.getMapText('提示'),
  425. content: getApp().globalData.Language.getMapText(this.data.sa_projectid ? '是否继续保存项目' : '是否继续创建项目'),
  426. cancelText: getApp().globalData.Language.getMapText('取消'),
  427. confirmText: getApp().globalData.Language.getMapText(this.data.sa_projectid ? '保存' : '创建'),
  428. complete: (res) => {
  429. if (res.confirm) that.handleSubmit(true);
  430. }
  431. })
  432. }
  433. this.setData({
  434. repetitionShow: false,
  435. isSubmit: false
  436. })
  437. },
  438. /* 处理查重 */
  439. handleQueryRepetition(content) {
  440. return _Http.basic({
  441. "id": 20221208184202,
  442. content
  443. })
  444. },
  445. async submit() {
  446. let data = this.selectComponent("#Form").submit(),
  447. that = this;
  448. data.province = data.region[0] || "";
  449. data.city = data.region[1] || "";
  450. data.county = data.region[2] || "";
  451. data.signamount_due = data.signamount_due || 0;
  452. let query = await this.handleQueryRepetition({
  453. sa_projectid: this.data.sa_projectid,
  454. ...data
  455. });
  456. if (query.total != 0) {
  457. if (this.data.siteid == 'HY') {
  458. wx.showModal({
  459. title: getApp().globalData.Language.getMapText('提示'),
  460. content: getApp().globalData.Language.joint([{
  461. v: '查询到',
  462. t: 1
  463. },
  464. {
  465. v: query.total,
  466. r: '“',
  467. f: "”"
  468. }, {
  469. v: '条疑似重复项目信息,是否确定继续' + this.data.sa_projectid ? '保存' : '创建' + '项目',
  470. t: 1,
  471. }
  472. ]),
  473. cancelText: getApp().globalData.Language.getMapText('取消'),
  474. confirmText: getApp().globalData.Language.getMapText(this.data.sa_projectid ? '保存' : '创建'),
  475. complete: (res) => {
  476. if (res.confirm) that.handleSubmit(true);
  477. }
  478. })
  479. } else {
  480. wx.showToast({
  481. title: getApp().globalData.Language.getMapText('查询到') + query.total + getApp().globalData.Language.getMapText('条疑似重复项目信息'),
  482. icon: "none"
  483. })
  484. this.setData({
  485. repetitionShow: true,
  486. repetitionList: query.data.map(v => {
  487. v.chars = v.chars.reduce((acc, item) => ({
  488. ...acc,
  489. ...item
  490. }), {});
  491. v.projectname = v.projectname.split('').map(text => {
  492. let projectname = v.chars.projectname.join("") || ''
  493. return projectname.includes(text) ? {
  494. text,
  495. color: "red"
  496. } : {
  497. text,
  498. color: "#666666"
  499. }
  500. })
  501. return v
  502. }),
  503. isSubmit: true
  504. })
  505. }
  506. } else {
  507. this.handleSubmit();
  508. }
  509. },
  510. handleSubmit(tag = false) {
  511. this.setData({
  512. loading: true
  513. })
  514. let data = this.selectComponent("#Form").submit();
  515. data.province = data.region[0] || "";
  516. data.city = data.region[1] || "";
  517. data.county = data.region[2] || "";
  518. data.tradefields = [data.tradefields];
  519. data.sa_brandid = data.sa_brandid ? data.sa_brandid[1][0] : 0;
  520. if (data.scale.length != 0 && data.scale == 0) {
  521. this.setData({
  522. loading: false
  523. })
  524. wx.showToast({
  525. title: getApp().globalData.Language.getMapText('项目规模不可为0'),
  526. icon: "none"
  527. })
  528. return;
  529. }
  530. delete(data.region);
  531. _Http.basic({
  532. "id": 20221020144202,
  533. "content": {
  534. sa_projectid: this.data.sa_projectid,
  535. ...data
  536. }
  537. }).then(res => {
  538. this.setData({
  539. loading: false
  540. })
  541. console.log("新建项目", res)
  542. wx.showToast({
  543. title: res.code != '1' ? res.msg : getApp().globalData.Language.getMapText('保存成功'),
  544. icon: "none",
  545. mask: true
  546. })
  547. if (res.code != '1') return;
  548. //绑定疑似重复标签
  549. if (tag) _Http.basic({
  550. "id": 20220929090901,
  551. "content": {
  552. "ownertable": "sa_project",
  553. "ownerid": res.data.sa_projectid,
  554. "datatag": ["疑似重复"]
  555. }
  556. })
  557. setTimeout(() => {
  558. let page = getCurrentPages()[getCurrentPages().length - 2];
  559. if (page.__route__ == 'packageA/project/index') {
  560. wx.redirectTo({
  561. url: '/packageA/project/detail?id=' + res.data.sa_projectid,
  562. })
  563. } else if (page.__route__ == 'packageA/project/detail') {
  564. wx.navigateBack()
  565. page.getDetail();
  566. }
  567. }, 500)
  568. })
  569. }
  570. })