addAndEdit.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. let _Http = getApp().globalData.http,
  2. count = null;
  3. Page({
  4. data: {
  5. repetitionShow: false,
  6. repetitionList: [],
  7. isSubmit: false,
  8. "sa_projectid": 0,
  9. showAll: false,
  10. form: [{
  11. label: "项目名称",
  12. error: false,
  13. errMsg: "",
  14. type: "textarea",
  15. value: "",
  16. placeholder: "项目名称",
  17. valueName: "projectname",
  18. checking: "base",
  19. required: true
  20. }, {
  21. label: "项目类型",
  22. error: false,
  23. errMsg: "",
  24. type: "option",
  25. optionNmae: "projecttype",
  26. optionType: "radio", //复选 radio 单选
  27. value: "",
  28. placeholder: "选择类型",
  29. valueName: "projecttype",
  30. checking: "base",
  31. required: true
  32. }, {
  33. label: "项目等级",
  34. error: false,
  35. errMsg: "",
  36. type: "option",
  37. optionNmae: "projectgrade",
  38. optionType: "radio", //复选 radio 单选
  39. value: "",
  40. placeholder: "选择项目等级",
  41. valueName: "grade",
  42. checking: "base",
  43. required: false
  44. }, {
  45. label: "省市县",
  46. error: false,
  47. errMsg: "",
  48. type: "region",
  49. value: [],
  50. placeholder: "省/市/县",
  51. valueName: "region",
  52. required: true
  53. }, {
  54. label: "详细地址",
  55. error: false,
  56. errMsg: "",
  57. type: "textarea",
  58. value: "",
  59. placeholder: "详细地址",
  60. valueName: "address",
  61. checking: "base",
  62. required: false
  63. }, {
  64. label: "项目规模",
  65. error: false,
  66. errMsg: "",
  67. type: "textarea",
  68. value: "",
  69. placeholder: "请填写建筑面积(㎡)/吨位(t)",
  70. valueName: "scale",
  71. checking: "base",
  72. required: false
  73. }, {
  74. label: "项目预算(万)",
  75. error: false,
  76. errMsg: "",
  77. type: "digit",
  78. value: "",
  79. placeholder: "请填写金额",
  80. valueName: "budgetary",
  81. checking: "base",
  82. required: false
  83. }, {
  84. label: "总投资额(百万)",
  85. error: false,
  86. errMsg: "",
  87. type: "digit",
  88. value: "",
  89. placeholder: "请填写金额",
  90. valueName: "totalinvestment",
  91. checking: "base",
  92. required: false
  93. }, {
  94. label: "造价(百万)",
  95. error: false,
  96. errMsg: "",
  97. type: "digit",
  98. value: "",
  99. placeholder: "请填写金额",
  100. valueName: "costofconstruction",
  101. checking: "base",
  102. required: false
  103. }, {
  104. label: "预计开工时间",
  105. error: false,
  106. errMsg: "",
  107. type: "date",
  108. fields: "month",
  109. value: "",
  110. placeholder: "预计开工时间",
  111. valueName: "begdate_due",
  112. checking: "base",
  113. required: false
  114. }, {
  115. label: "预计完工时间",
  116. error: false,
  117. errMsg: "",
  118. type: "date",
  119. fields: "month",
  120. value: "",
  121. placeholder: "预计完工时间",
  122. valueName: "enddate_due",
  123. checking: "base",
  124. required: false
  125. },
  126. {
  127. label: "预计签约时间",
  128. error: false,
  129. errMsg: "",
  130. type: "date",
  131. fields: "month",
  132. value: "",
  133. placeholder: "预计签约时间",
  134. valueName: "signdate_due",
  135. checking: "base",
  136. required: false
  137. }, {
  138. label: "领域",
  139. error: false,
  140. errMsg: "",
  141. type: "option",
  142. optionNmae: "tradefield",
  143. optionType: "radio", //复选 radio 单选
  144. value: "",
  145. placeholder: "选择领域",
  146. valueName: "tradefields",
  147. checking: "base",
  148. required: true
  149. }, {
  150. label: "品牌",
  151. error: false,
  152. errMsg: "",
  153. type: "route",
  154. url: "/packageA/select/brand/select",
  155. params: {
  156. "id": 20220924163702,
  157. "content": {
  158. nochace: true,
  159. }
  160. },
  161. query: "&radio=true",
  162. value: "",
  163. placeholder: "选择品牌",
  164. valueName: "sa_brandid",
  165. checking: "base",
  166. required: true
  167. }
  168. ],
  169. disabled: true,
  170. countDown: "", //查重倒计时
  171. },
  172. onLoad(options) {
  173. if (options.data) {
  174. let data = JSON.parse(options.data);
  175. let disabled = options.disabled == "true";
  176. data.sa_brandid = [data.brandname, [data.sa_brandid]]
  177. this.setData({
  178. disabled: false,
  179. sa_projectid: data.sa_projectid,
  180. form: this.data.form.map(v => {
  181. if (v.valueName != 'region') {
  182. v.value = data[v.valueName];
  183. } else {
  184. v.value = data.province ? [data.province, data.city, data.county] : []
  185. };
  186. if (disabled) {
  187. if (['projectname', 'region', 'address'].includes(v.valueName)) v.disabled = true
  188. }
  189. return v
  190. })
  191. })
  192. };
  193. },
  194. /* 表单必填项是否完成 */
  195. onConfirm({
  196. detail
  197. }) {
  198. this.setData({
  199. disabled: detail
  200. })
  201. },
  202. // 是否显示全部
  203. onChange({
  204. detail
  205. }) {
  206. this.setData({
  207. showAll: detail
  208. })
  209. },
  210. /* 查询是否重复 */
  211. async queryRepetition(e) {
  212. let {
  213. projectname,
  214. address
  215. } = this.selectComponent("#Form").query();
  216. if (projectname == '') return wx.showToast({
  217. title: `您还未填写项目名称`,
  218. icon: "none"
  219. });
  220. let res = await this.handleQueryRepetition({
  221. sa_projectid: this.data.sa_projectid,
  222. projectname,
  223. address
  224. });
  225. console.log("查询重复", res)
  226. if (res.msg != '成功') return wx.showToast({
  227. title: res.msg,
  228. icon: "none"
  229. });
  230. this.setData({
  231. countDown: 6
  232. });
  233. count = setInterval(() => {
  234. let countDown = this.data.countDown;
  235. if (countDown == 0) {
  236. clearInterval(count);
  237. this.setData({
  238. countDown: ""
  239. })
  240. } else {
  241. countDown--;
  242. this.setData({
  243. countDown
  244. })
  245. }
  246. }, 1000)
  247. if (res.total == 0) {
  248. wx.showToast({
  249. title: '未查询到疑似重复的项目信息',
  250. icon: "none"
  251. })
  252. } else {
  253. wx.showToast({
  254. title: `查询到${res.total}条疑似重复项目信息`,
  255. icon: "none"
  256. })
  257. this.setData({
  258. repetitionShow: true,
  259. repetitionList: res.data
  260. })
  261. }
  262. },
  263. repClose() {
  264. if (this.data.isSubmit) {
  265. let that = this;
  266. wx.showModal({
  267. title: '提示',
  268. content: `是否继续创建项目`,
  269. complete: (res) => {
  270. if (res.confirm) that.handleSubmit(true);
  271. }
  272. })
  273. }
  274. this.setData({
  275. repetitionShow: false,
  276. isSubmit: false
  277. })
  278. },
  279. /* 处理查重 */
  280. handleQueryRepetition(content) {
  281. return _Http.basic({
  282. "id": 20221208184202,
  283. content
  284. })
  285. },
  286. async submit() {
  287. let data = this.selectComponent("#Form").submit();
  288. let query = await this.handleQueryRepetition({
  289. sa_projectid: this.data.sa_projectid,
  290. projectname: data.projectname,
  291. address: data.address
  292. });
  293. if (query.total != 0) {
  294. wx.showToast({
  295. title: `查询到${query.total}条疑似重复项目信息`,
  296. icon: "none"
  297. })
  298. this.setData({
  299. repetitionShow: true,
  300. repetitionList: query.data,
  301. isSubmit: true
  302. })
  303. } else {
  304. this.handleSubmit();
  305. }
  306. },
  307. handleSubmit(tag = false) {
  308. let data = this.selectComponent("#Form").submit();
  309. if (data.region.length != 0) {
  310. data.province = data.region[0]
  311. data.city = data.region[1]
  312. data.county = data.region[2]
  313. };
  314. data.tradefields = [data.tradefields];
  315. data.sa_brandid = data.sa_brandid[1][0] || 0
  316. delete(data.region);
  317. _Http.basic({
  318. "id": 20221020144202,
  319. "content": {
  320. sa_projectid: this.data.sa_projectid,
  321. ...data
  322. }
  323. }).then(res => {
  324. console.log("新建项目", res)
  325. if (res.msg != '成功') return wx.showToast({
  326. title: res.msg,
  327. icon: "none"
  328. })
  329. wx.showToast({
  330. title: '保存成功',
  331. icon: "none"
  332. })
  333. //绑定疑似重复标签
  334. if (tag) _Http.basic({
  335. "id": 20220929090901,
  336. "content": {
  337. "ownertable": "sa_project",
  338. "ownerid": res.data.sa_projectid,
  339. "datatag": ["疑似重复"]
  340. }
  341. })
  342. setTimeout(() => {
  343. getCurrentPages().forEach(v => {
  344. if (v.getList) v.getList(true);
  345. if (['packageA/project/index', 'packageA/project/search'].includes(v.__route__)) {
  346. if (this.data.sa_projectid == 0) {
  347. v.data.list.push(res.data)
  348. } else {
  349. let i = v.data.list.findIndex(value => value.sa_projectid == this.data.sa_projectid);
  350. if (i != -1) v.data.list[i] = res.data;
  351. }
  352. v.setData({
  353. list: v.data.list
  354. })
  355. } else if (v.__route__ == 'packageA/project/detail') {
  356. wx.navigateBack()
  357. v.getDetail();
  358. }
  359. })
  360. if (this.data.sa_projectid == 0) {
  361. wx.redirectTo({
  362. url: '/packageA/project/detail?sa_projectid=' + res.data.sa_projectid,
  363. })
  364. }
  365. }, tag ? 500 : 300)
  366. })
  367. }
  368. })