addAndEdit.js 16 KB

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