addProjectOffer.js 11 KB

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