addAndEdit.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  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 (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.code == '1') {
  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.code != '1') 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. getApp().globalData.Language.showToast('未查询到疑似重复的项目信息')
  366. this.data.repetitionShow = false;
  367. } else {
  368. wx.showToast({
  369. title: getApp().globalData.Language.getMapText('查询到') + res.total + getApp().globalData.Language.getMapText('条疑似重复项目信息'),
  370. icon: "none"
  371. })
  372. if (wx.getStorageSync('userMsg').siteid != 'HY') this.setData({
  373. repetitionShow: true,
  374. repetitionList: res.data
  375. })
  376. }
  377. },
  378. repClose() {
  379. if (this.data.isSubmit) {
  380. let that = this;
  381. wx.showModal({
  382. title: getApp().globalData.Language.getMapText('提示'),
  383. content: getApp().globalData.Language.getMapText('是否继续创建项目'),
  384. cancelText: getApp().globalData.Language.getMapText('取消'),
  385. confirmText: getApp().globalData.Language.getMapText('创建'),
  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. that = this;
  406. data.province = data.region[0] || "";
  407. data.city = data.region[1] || "";
  408. data.county = data.region[2] || "";
  409. let query = await this.handleQueryRepetition({
  410. sa_projectid: this.data.sa_projectid,
  411. ...data
  412. });
  413. if (query.total != 0) {
  414. if (this.data.siteid == 'HY') {
  415. wx.showModal({
  416. title: getApp().globalData.Language.getMapText('提示'),
  417. content: getApp().globalData.Language.joint([{
  418. v: '查询到',
  419. t: 1
  420. },
  421. {
  422. v: query.total,
  423. r: '“',
  424. f: "”"
  425. }, {
  426. v: '条疑似重复项目信息,是否确定继续创建项目',
  427. t: 1,
  428. }
  429. ]),
  430. cancelText: getApp().globalData.Language.getMapText('取消'),
  431. confirmText: getApp().globalData.Language.getMapText('创建'),
  432. complete: (res) => {
  433. if (res.confirm) that.handleSubmit(true);
  434. }
  435. })
  436. } else {
  437. wx.showToast({
  438. title: getApp().globalData.Language.getMapText('查询到') + query.total + getApp().globalData.Language.getMapText('条疑似重复项目信息'),
  439. icon: "none"
  440. })
  441. this.setData({
  442. repetitionShow: true,
  443. repetitionList: query.data,
  444. isSubmit: true
  445. })
  446. }
  447. } else {
  448. this.handleSubmit();
  449. }
  450. },
  451. handleSubmit(tag = false) {
  452. this.setData({
  453. loading: true
  454. })
  455. let data = this.selectComponent("#Form").submit();
  456. data.province = data.region[0] || "";
  457. data.city = data.region[1] || "";
  458. data.county = data.region[2] || "";
  459. data.tradefields = [data.tradefields];
  460. data.sa_brandid = data.sa_brandid ? data.sa_brandid[1][0] : 0;
  461. if (data.scale.length != 0 && data.scale == 0) {
  462. this.setData({
  463. loading: false
  464. })
  465. wx.showToast({
  466. title: getApp().globalData.Language.getMapText('项目规模不可为0'),
  467. icon: "none"
  468. })
  469. return;
  470. }
  471. delete(data.region);
  472. _Http.basic({
  473. "id": 20221020144202,
  474. "content": {
  475. sa_projectid: this.data.sa_projectid,
  476. ...data
  477. }
  478. }).then(res => {
  479. this.setData({
  480. loading: false
  481. })
  482. console.log("新建项目", res)
  483. wx.showToast({
  484. title: res.code != '1' ? res.msg : getApp().globalData.Language.getMapText('保存成功'),
  485. icon: "none",
  486. mask: true
  487. })
  488. if (res.code != '1') return;
  489. //绑定疑似重复标签
  490. if (tag) _Http.basic({
  491. "id": 20220929090901,
  492. "content": {
  493. "ownertable": "sa_project",
  494. "ownerid": res.data.sa_projectid,
  495. "datatag": ["疑似重复"]
  496. }
  497. })
  498. setTimeout(() => {
  499. let page = getCurrentPages()[getCurrentPages().length - 2];
  500. if (page.__route__ == 'packageA/project/index') {
  501. wx.redirectTo({
  502. url: '/packageA/project/detail?id=' + res.data.sa_projectid,
  503. })
  504. } else if (page.__route__ == 'packageA/project/detail') {
  505. wx.navigateBack()
  506. page.getDetail();
  507. }
  508. }, 500)
  509. })
  510. }
  511. })