addAndEdit.js 18 KB

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