addProjectOffer.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. const _Http = getApp().globalData.http,
  2. getTime = require("../../utils/getTime");
  3. let source = 0,
  4. sa_quotedpriceid = 0,
  5. quotedpricenotes = [],
  6. address = "";
  7. Page({
  8. data: {
  9. loading: false,
  10. showAll: false,
  11. form: [{
  12. label: "项目",
  13. error: false,
  14. errMsg: "",
  15. type: "route",
  16. url: "/packageA/select/project/select",
  17. value: "",
  18. params: {
  19. "id": 20221020143503,
  20. content: {
  21. nocache: true,
  22. "type": 1,
  23. "where": {
  24. "condition": "",
  25. }
  26. },
  27. },
  28. interrupt: true,
  29. query: "&radio=true",
  30. placeholder: "选择项目",
  31. valueName: "sa_projectid",
  32. checking: "base",
  33. required: true
  34. }, {
  35. label: "产品系列",
  36. error: false,
  37. errMsg: "",
  38. type: "option",
  39. optionNmae: "itemtype",
  40. optionType: "checkbox", //复选 radio 单选
  41. value: "",
  42. placeholder: "请选择产品系列",
  43. valueName: "itemtype",
  44. checking: "base",
  45. required: true
  46. }, {
  47. label: "折扣(%)",
  48. error: false,
  49. errMsg: "",
  50. hint: "请输入0-100%",
  51. type: "digit",
  52. value: "",
  53. placeholder: "请填写折扣(%)",
  54. valueName: "discountrate", //绑定的字段名称
  55. required: false, //必填
  56. checking: `^(100|\\d{0,2})(\\.\\d{1,2})?$`, //0-100%
  57. slot: "discountrate"
  58. }, {
  59. label: "报价日期",
  60. error: false,
  61. errMsg: "",
  62. type: "date",
  63. value: getTime.formatTime(new Date(), '-').split(' ')[0],
  64. placeholder: "报价日期",
  65. valueName: "billdate",
  66. checking: "base",
  67. required: false
  68. }, {
  69. label: "有效期",
  70. error: false,
  71. errMsg: "",
  72. type: "dateRange",
  73. value: [getTime.formatTime(new Date(), '-').split(' ')[0], ""],
  74. placeholder: ['生效日期', '截止日期'],
  75. valueName: "invaliddate",
  76. checking: "base",
  77. required: true
  78. }, {
  79. label: "备注",
  80. error: false,
  81. errMsg: "",
  82. type: "textarea",
  83. value: "",
  84. placeholder: "报价单说明",
  85. valueName: "remarks",
  86. required: false, //必填
  87. }],
  88. disabled: true
  89. },
  90. onLoad(options) {
  91. let form = this.data.form;
  92. /* 项目商机进入 */
  93. if (options.sa_projectid) {
  94. let data = JSON.parse(options.sa_projectid);
  95. if (data.sa_projectid) {
  96. form[0].value = data.sa_projectid;
  97. form[0].disabled = true;
  98. source = 1;
  99. form.splice(1, 0, {
  100. label: "选择客户",
  101. error: false,
  102. errMsg: "",
  103. type: "route",
  104. url: "/packageA/select/setclient/select",
  105. value: "",
  106. params: {
  107. id: 20221027143702,
  108. "content": {
  109. nocache: true,
  110. "sa_projectid": data.sa_projectid[1][0],
  111. "where": {
  112. "condition": ""
  113. }
  114. },
  115. },
  116. query: "&radio=true&idname=sys_enterpriseid",
  117. placeholder: "选择客户",
  118. valueName: "sys_enterpriseid",
  119. checking: "base",
  120. required: true
  121. });
  122. //业务员
  123. form.splice(6, 0, {
  124. label: "业务员",
  125. error: false,
  126. errMsg: "",
  127. type: "route",
  128. url: "/packageA/select/contacts/select",
  129. value: "",
  130. params: {
  131. "id": "20230306144402",
  132. "content": {
  133. nocache: true,
  134. "type": 2, //type:1客户2:项目
  135. "sa_projectid": data.sa_projectid[1][0],
  136. "where": {
  137. "condition": ""
  138. }
  139. }
  140. },
  141. query: "&radio=true&idname=hrid",
  142. placeholder: "选择业务员",
  143. valueName: "saler_hrid",
  144. checking: "base",
  145. required: true
  146. });
  147. };
  148. this.setData({
  149. disabled: false,
  150. form
  151. });
  152. };
  153. if (options.data) {
  154. let data1 = JSON.parse(options.data);
  155. sa_quotedpriceid = data1.sa_quotedpriceid;
  156. quotedpricenotes = data1.quotedpricenotes;
  157. address = data1.address;
  158. data1.sa_projectid = [data1.projectname, [data1.sa_projectid]]
  159. data1.discountrate = data1.discountrate == 1 ? 100 : (data1.discountrate * 100).toFixed(2)
  160. form = form.map(v => {
  161. if (v.valueName == "invaliddate") {
  162. v.value = [data1.begdate, data1.enddate]
  163. } else {
  164. v.value = data1[v.valueName] || "";
  165. }
  166. return v
  167. })
  168. form.splice(1, 0, {
  169. label: "选择客户",
  170. error: false,
  171. errMsg: "",
  172. type: "route",
  173. url: "/packageA/select/setclient/select",
  174. value: [data1.enterprisename, [data1.sys_enterpriseid]],
  175. params: {
  176. id: 20221027143702,
  177. "content": {
  178. nocache: true,
  179. "sa_projectid": data1.sa_projectid[1][0],
  180. "where": {
  181. "condition": ""
  182. }
  183. },
  184. },
  185. interrupt: true,
  186. query: "&radio=true&idname=sys_enterpriseid",
  187. placeholder: "选择客户",
  188. valueName: "sys_enterpriseid",
  189. checking: "base",
  190. required: true
  191. });
  192. form.splice(2, 0, {
  193. label: "联系人",
  194. error: false,
  195. errMsg: "",
  196. type: "route",
  197. url: "/packageA/select/contacts/select",
  198. value: [data1.contactsname, [data1.contactsid]],
  199. params: {
  200. "id": "20221022165503",
  201. "content": {
  202. nocache: true,
  203. "sys_enterpriseid": data1.sys_enterpriseid,
  204. pageNumber: 1,
  205. pageSize: 10,
  206. pageTotal: 1,
  207. "where": {
  208. "condition": "",
  209. "workaddress": 0
  210. }
  211. }
  212. },
  213. query: "&radio=true",
  214. placeholder: "选择客户联系人",
  215. valueName: "contactsid",
  216. checking: "base",
  217. required: false
  218. });
  219. form.splice(6, 0, {
  220. label: "业务员",
  221. error: false,
  222. errMsg: "",
  223. type: "route",
  224. url: "/packageA/select/contacts/select",
  225. value: [data1.name, [data1.saler_hrid]],
  226. params: {
  227. "id": "20230306144402",
  228. "content": {
  229. nocache: true,
  230. "type": 2, //type:1客户2:项目
  231. "sa_projectid": data1.sa_projectid[1][0],
  232. "where": {
  233. "condition": ""
  234. }
  235. }
  236. },
  237. query: "&radio=true&idname=hrid",
  238. placeholder: "选择业务员",
  239. valueName: "saler_hrid",
  240. checking: "base",
  241. required: true
  242. });
  243. this.setData({
  244. form,
  245. })
  246. }
  247. },
  248. /* 打断处理form */
  249. interrupt(e) {
  250. let {
  251. data,
  252. form,
  253. temporary
  254. } = e.detail;
  255. console.log("处理", data, form, temporary)
  256. if (temporary.item.value[0] == data.value[0]) return wx.navigateBack();
  257. let obj = {};
  258. temporary.item.value = data.value;
  259. switch (temporary.item.valueName) {
  260. case "sa_projectid":
  261. obj = {
  262. label: "选择客户",
  263. error: false,
  264. errMsg: "",
  265. type: "route",
  266. url: "/packageA/select/setclient/select",
  267. value: "",
  268. params: {
  269. id: 20221027143702,
  270. "content": {
  271. nocache: true,
  272. "sa_projectid": data.value[1][0],
  273. "where": {
  274. "condition": ""
  275. }
  276. },
  277. },
  278. interrupt: true,
  279. query: "&radio=true&idname=sys_enterpriseid",
  280. placeholder: "选择客户",
  281. valueName: "sys_enterpriseid",
  282. checking: "base",
  283. required: true
  284. };
  285. form.splice(1, form[1].label == "选择客户" ? 1 : 0, obj);
  286. address = data.item.province + data.item.city + data.item.county + data.item.address
  287. //业务员
  288. let hr = {
  289. label: "业务员",
  290. error: false,
  291. errMsg: "",
  292. type: "route",
  293. url: "/packageA/select/contacts/select",
  294. value: "",
  295. params: {
  296. "id": "20230306144402",
  297. "content": {
  298. nocache: true,
  299. "type": 2, //type:1客户2:项目
  300. "sa_projectid": data.value[1][0],
  301. "where": {
  302. "condition": ""
  303. }
  304. }
  305. },
  306. query: "&radio=true&idname=hrid",
  307. placeholder: "选择业务员",
  308. valueName: "saler_hrid",
  309. checking: "base",
  310. required: true
  311. };
  312. form.splice(6, form[6].label == "业务员" ? 1 : 0, hr);
  313. break;
  314. case "sys_enterpriseid":
  315. obj = {
  316. label: "联系人",
  317. error: false,
  318. errMsg: "",
  319. type: "route",
  320. url: "/packageA/select/contacts/select",
  321. value: "",
  322. params: {
  323. "id": "20221022165503",
  324. "content": {
  325. nocache: true,
  326. "sys_enterpriseid": data.value[1][0],
  327. pageNumber: 1,
  328. pageSize: 10,
  329. pageTotal: 1,
  330. "where": {
  331. "condition": "",
  332. "workaddress": 0
  333. }
  334. }
  335. },
  336. query: "&radio=true",
  337. placeholder: "选择客户联系人",
  338. valueName: "contactsid",
  339. checking: "base",
  340. required: false
  341. };
  342. form.splice(2, form[2].label == "联系人" ? 1 : 0, obj);
  343. break;
  344. }
  345. form[temporary.index] = temporary.item;
  346. wx.navigateBack()
  347. this.setData({
  348. form
  349. })
  350. },
  351. submit() {
  352. this.setData({
  353. loading: true
  354. })
  355. let content = {
  356. ...this.selectComponent("#Form").submit(),
  357. sa_quotedpriceid,
  358. quotedpricenotes,
  359. address,
  360. source
  361. };
  362. content.sys_enterpriseid = content.sys_enterpriseid[1] ? content.sys_enterpriseid[1][0] : 0;
  363. content.projectname = content.sa_projectid[0] || "";
  364. content.sa_projectid = content.sa_projectid[1] ? content.sa_projectid[1][0] : 0;
  365. content.contactsid = content.contactsid ? content.contactsid[1][0] : 0;
  366. content.discountrate = (content.discountrate / 100).toFixed(4) || 1;
  367. content.saler_hrid = content.saler_hrid[1] ? content.saler_hrid[1][0] : 0;
  368. content.begdate = content.invaliddate[0];
  369. content.enddate = content.invaliddate[1];
  370. delete(content.invaliddate)
  371. _Http.basic({
  372. "id": 20221020164803,
  373. "version": 1,
  374. content
  375. }).then(res => {
  376. this.setData({
  377. loading: false
  378. })
  379. console.log("添加项目报价单", res)
  380. wx.showToast({
  381. title: res.msg != '成功' ? res.msg : '保存成功',
  382. icon: "none"
  383. })
  384. if (res.msg != '成功') return;
  385. setTimeout(() => {
  386. let pages = getCurrentPages(),
  387. page = pages[pages.length - 2];
  388. if (page.__route__ == 'packageA/offers/detail') {
  389. page.getDetail(true);
  390. wx.navigateBack()
  391. } else {
  392. if (page.__route__ == 'packageA/offers/index') {
  393. page.getList(true);
  394. } else if (page.__route__ == 'packageA/project/detail') {
  395. let model = page.selectComponent("#Offers");
  396. model.getList(model.data.sa_projectid, true);
  397. }
  398. wx.redirectTo({
  399. url: '/packageA/offers/detail?sa_quotedpriceid=' + res.data.sa_quotedpriceid
  400. })
  401. }
  402. }, 300)
  403. })
  404. },
  405. // 是否显示全部
  406. onChange({
  407. detail
  408. }) {
  409. this.setData({
  410. showAll: detail
  411. })
  412. },
  413. /* 表单必填项是否完成 */
  414. onConfirm({
  415. detail
  416. }) {
  417. this.setData({
  418. disabled: detail
  419. })
  420. }
  421. })