addAndEdit.js 15 KB

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