addAndEdit.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. ],
  139. disabled: true,
  140. countDown: "", //查重倒计时
  141. },
  142. onLoad(options) {
  143. console.log(options)
  144. if (options.data) {
  145. let data = JSON.parse(options.data);
  146. let disabled = options.disabled == "true";
  147. console.log(disabled)
  148. this.setData({
  149. disabled: false,
  150. sa_projectid: data.sa_projectid,
  151. form: this.data.form.map(v => {
  152. if (v.valueName != 'region') {
  153. v.value = data[v.valueName];
  154. } else {
  155. v.value = data.province ? [data.province, data.city, data.county] : []
  156. };
  157. if (disabled) {
  158. if (['projectname', 'region', 'address'].includes(v.valueName)) v.disabled = true
  159. }
  160. return v
  161. })
  162. })
  163. }
  164. },
  165. /* 表单必填项是否完成 */
  166. onConfirm({
  167. detail
  168. }) {
  169. this.setData({
  170. disabled: detail
  171. })
  172. },
  173. // 是否显示全部
  174. onChange({
  175. detail
  176. }) {
  177. this.setData({
  178. showAll: detail
  179. })
  180. },
  181. /* 查询是否重复 */
  182. async queryRepetition(e) {
  183. let {
  184. projectname,
  185. address
  186. } = this.selectComponent("#Form").query();
  187. if (projectname == '') return wx.showToast({
  188. title: `您还未填写项目名称`,
  189. icon: "none"
  190. });
  191. let res = await this.handleQueryRepetition({
  192. sa_projectid: this.data.sa_projectid,
  193. projectname,
  194. address
  195. });
  196. console.log("查询重复", res)
  197. if (res.msg != '成功') return wx.showToast({
  198. title: res.msg,
  199. icon: "none"
  200. });
  201. this.setData({
  202. countDown: 6
  203. });
  204. count = setInterval(() => {
  205. let countDown = this.data.countDown;
  206. if (countDown == 0) {
  207. clearInterval(count);
  208. this.setData({
  209. countDown: ""
  210. })
  211. } else {
  212. countDown--;
  213. this.setData({
  214. countDown
  215. })
  216. }
  217. }, 1000)
  218. if (res.total == 0) {
  219. wx.showToast({
  220. title: '未查询到疑似重复的项目信息',
  221. icon: "none"
  222. })
  223. } else {
  224. wx.showToast({
  225. title: `查询到${res.total}条疑似重复项目信息`,
  226. icon: "none"
  227. })
  228. this.setData({
  229. repetitionShow: true,
  230. repetitionList: res.data
  231. })
  232. }
  233. },
  234. repClose() {
  235. if (this.data.isSubmit) {
  236. let that = this;
  237. wx.showModal({
  238. title: '提示',
  239. content: `是否继续创建项目`,
  240. complete: (res) => {
  241. if (res.confirm) that.handleSubmit(true);
  242. }
  243. })
  244. }
  245. this.setData({
  246. repetitionShow: false,
  247. isSubmit: false
  248. })
  249. },
  250. /* 处理查重 */
  251. handleQueryRepetition(content) {
  252. return _Http.basic({
  253. "id": 20221208184202,
  254. content
  255. })
  256. },
  257. async submit() {
  258. let data = this.selectComponent("#Form").submit();
  259. let query = await this.handleQueryRepetition({
  260. sa_projectid: this.data.sa_projectid,
  261. projectname: data.projectname,
  262. address: data.address
  263. });
  264. if (query.total != 0) {
  265. wx.showToast({
  266. title: `查询到${query.total}条疑似重复项目信息`,
  267. icon: "none"
  268. })
  269. this.setData({
  270. repetitionShow: true,
  271. repetitionList: query.data,
  272. isSubmit: true
  273. })
  274. } else {
  275. this.handleSubmit();
  276. }
  277. },
  278. handleSubmit(tag = false) {
  279. let data = this.selectComponent("#Form").submit();
  280. if (data.region.length != 0) {
  281. data.province = data.region[0]
  282. data.city = data.region[1]
  283. data.county = data.region[2]
  284. };
  285. delete(data.region);
  286. _Http.basic({
  287. "id": 20221020144202,
  288. "content": {
  289. sa_projectid: this.data.sa_projectid,
  290. ...data
  291. }
  292. }).then(res => {
  293. console.log("新建项目", res)
  294. if (res.msg != '成功') return wx.showToast({
  295. title: res.msg,
  296. icon: "none"
  297. })
  298. wx.showToast({
  299. title: '保存成功',
  300. icon: "none"
  301. })
  302. //绑定疑似重复标签
  303. if (tag) _Http.basic({
  304. "id": 20220929090901,
  305. "content": {
  306. "ownertable": "sa_project",
  307. "ownerid": res.data.sa_projectid,
  308. "datatag": ["疑似重复"]
  309. }
  310. })
  311. setTimeout(() => {
  312. getCurrentPages().forEach(v => {
  313. if (v.getList) v.getList(true);
  314. if (['packageA/project/index', 'packageA/project/search'].includes(v.__route__)) {
  315. if (this.data.sa_projectid == 0) {
  316. v.data.list.push(res.data)
  317. } else {
  318. let i = v.data.list.findIndex(value => value.sa_projectid == this.data.sa_projectid);
  319. if (i != -1) v.data.list[i] = res.data;
  320. }
  321. v.setData({
  322. list: v.data.list
  323. })
  324. } else if (v.__route__ == 'packageA/project/detail') {
  325. wx.navigateBack()
  326. v.getDetail();
  327. }
  328. })
  329. if (this.data.sa_projectid == 0) {
  330. wx.redirectTo({
  331. url: '/packageA/project/detail?sa_projectid=' + res.data.sa_projectid,
  332. })
  333. }
  334. }, tag ? 500 : 300)
  335. })
  336. }
  337. })