addProjectOffer.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. accessory: true,
  12. form: [{
  13. label: "项目",
  14. error: false,
  15. errMsg: "",
  16. type: "route",
  17. url: "/packageA/select/project/select",
  18. value: "",
  19. params: {
  20. "id": 20221020143503,
  21. content: {
  22. nocache: true,
  23. "type": 1,
  24. "where": {
  25. "condition": "",
  26. }
  27. },
  28. },
  29. interrupt: true,
  30. query: "&radio=true",
  31. placeholder: "选择项目",
  32. valueName: "sa_projectid",
  33. checking: "base",
  34. required: true
  35. }, {
  36. label: "报价金额(元)",
  37. error: false,
  38. errMsg: "",
  39. type: "digit",
  40. value: "",
  41. placeholder: "请填写金额",
  42. valueName: "quotedpriceamount",
  43. checking: "twoDecimalPlaces",
  44. required: true
  45. }, {
  46. label: "产品系列",
  47. error: false,
  48. errMsg: "",
  49. type: "option",
  50. optionNmae: "itemtype",
  51. optionType: "checkbox", //复选 radio 单选
  52. value: "",
  53. placeholder: "请选择产品系列",
  54. valueName: "itemtype",
  55. checking: "base",
  56. required: true
  57. }, {
  58. label: "折扣(%)",
  59. error: false,
  60. errMsg: "",
  61. hint: "请输入0-100%",
  62. type: "digit",
  63. value: "",
  64. placeholder: "请填写折扣(%)",
  65. valueName: "discountrate", //绑定的字段名称
  66. required: false, //必填
  67. checking: `^(100|\\d{0,2})(\\.\\d{1,2})?$`, //0-100%
  68. slot: "discountrate"
  69. }, {
  70. label: "报价日期",
  71. error: false,
  72. errMsg: "",
  73. type: "date",
  74. value: getTime.formatTime(new Date(), '-').split(' ')[0],
  75. placeholder: "报价日期",
  76. valueName: "billdate",
  77. checking: "base",
  78. required: false
  79. }, {
  80. label: "有效期",
  81. error: false,
  82. errMsg: "",
  83. type: "dateRange",
  84. value: [getTime.formatTime(new Date(), '-').split(' ')[0] + "", getTime.formatTime(new Date(Date.now() + (86400000 * 30)), '-').split(' ')[0] + ""],
  85. placeholder: ['生效日期', '截止日期'],
  86. valueName: "invaliddate",
  87. checking: "base",
  88. required: true
  89. }, {
  90. label: "备注",
  91. error: false,
  92. errMsg: "",
  93. type: "textarea",
  94. value: "",
  95. placeholder: "报价单说明",
  96. valueName: "remarks",
  97. required: false, //必填
  98. }],
  99. disabled: true
  100. },
  101. changeState({
  102. detail
  103. }) {
  104. this.setData({
  105. loading: detail
  106. })
  107. },
  108. onLoad(options) {
  109. let form = this.data.form;
  110. /* 项目商机进入 */
  111. if (options.sa_projectid) {
  112. let data = JSON.parse(options.sa_projectid);
  113. if (data.sa_projectid) {
  114. form[0].value = data.sa_projectid;
  115. form[0].disabled = true;
  116. source = 1;
  117. form.splice(1, 0, {
  118. label: "选择客户",
  119. error: false,
  120. errMsg: "",
  121. type: "route",
  122. url: "/packageA/select/setclient/select",
  123. value: "",
  124. params: {
  125. id: 20221027143702,
  126. "content": {
  127. nocache: true,
  128. "sa_projectid": data.sa_projectid[1][0],
  129. "where": {
  130. "condition": ""
  131. }
  132. },
  133. },
  134. query: "&radio=true&idname=sys_enterpriseid",
  135. placeholder: "选择客户",
  136. valueName: "sys_enterpriseid",
  137. checking: "base",
  138. required: true,
  139. interrupt: true
  140. });
  141. //业务员
  142. form.splice(form.findIndex(v => v.label == '备注'), 0, {
  143. label: "业务员",
  144. error: false,
  145. errMsg: "",
  146. type: "route",
  147. url: "/packageA/select/contacts/select",
  148. value: "",
  149. params: {
  150. "id": "20230306144402",
  151. "content": {
  152. nocache: true,
  153. "type": 2, //type:1客户2:项目
  154. "sa_projectid": data.sa_projectid[1][0],
  155. "where": {
  156. "condition": ""
  157. }
  158. }
  159. },
  160. query: "&radio=true&idname=hrid",
  161. placeholder: "选择业务员",
  162. valueName: "saler_hrid",
  163. checking: "base",
  164. required: true
  165. });
  166. };
  167. this.setData({
  168. disabled: false,
  169. form
  170. });
  171. };
  172. if (options.data) {
  173. let data1 = JSON.parse(options.data);
  174. sa_quotedpriceid = data1.sa_quotedpriceid;
  175. quotedpricenotes = data1.quotedpricenotes;
  176. address = data1.address;
  177. data1.sa_projectid = [data1.projectname, [data1.sa_projectid]]
  178. data1.discountrate = data1.discountrate == 1 ? 100 : (data1.discountrate * 100).toFixed(2)
  179. form = form.map(v => {
  180. if (v.valueName == "invaliddate") {
  181. v.value = [data1.begdate, data1.enddate]
  182. } else {
  183. v.value = data1[v.valueName] || "";
  184. if (v.valueName == "quotedpriceamount") v.disabled = data1.iseditamount == 0
  185. }
  186. return v
  187. })
  188. form.splice(1, 0, {
  189. label: "选择客户",
  190. error: false,
  191. errMsg: "",
  192. type: "route",
  193. url: "/packageA/select/setclient/select",
  194. value: [data1.enterprisename, [data1.sys_enterpriseid]],
  195. params: {
  196. id: 20221027143702,
  197. "content": {
  198. nocache: true,
  199. "sa_projectid": data1.sa_projectid[1][0],
  200. "where": {
  201. "condition": ""
  202. }
  203. },
  204. },
  205. interrupt: true,
  206. query: "&radio=true&idname=sys_enterpriseid",
  207. placeholder: "选择客户",
  208. valueName: "sys_enterpriseid",
  209. checking: "base",
  210. required: true,
  211. interrupt: true
  212. });
  213. form.splice(2, 0, {
  214. label: "联系人",
  215. error: false,
  216. errMsg: "",
  217. type: "route",
  218. url: "/packageA/select/contacts/select",
  219. value: [data1.contactsname, [data1.sys_phonebookid]],
  220. params: {
  221. "id": "20240614151004",
  222. "content": {
  223. nocache: true,
  224. "sys_enterpriseid": data1.sys_enterpriseid,
  225. sa_projectid: data1.sa_projectid[1][0],
  226. pageNumber: 1,
  227. pageSize: 10,
  228. pageTotal: 1,
  229. "where": {
  230. "condition": "",
  231. "workaddress": 0
  232. }
  233. }
  234. },
  235. query: "&radio=true&idname=sys_phonebookid",
  236. placeholder: "选择客户联系人",
  237. valueName: "sys_phonebookid",
  238. checking: "base",
  239. required: true
  240. });
  241. form.splice(form.findIndex(v => v.label == '备注'), 0, {
  242. label: "业务员",
  243. error: false,
  244. errMsg: "",
  245. type: "route",
  246. url: "/packageA/select/contacts/select",
  247. value: [data1.name, [data1.saler_hrid]],
  248. params: {
  249. "id": "20230306144402",
  250. "content": {
  251. nocache: true,
  252. "type": 2, //type:1客户2:项目
  253. "sa_projectid": data1.sa_projectid[1][0],
  254. "where": {
  255. "condition": ""
  256. }
  257. }
  258. },
  259. query: "&radio=true&idname=hrid",
  260. placeholder: "选择业务员",
  261. valueName: "saler_hrid",
  262. checking: "base",
  263. required: true
  264. });
  265. this.setData({
  266. form,
  267. accessory: false
  268. })
  269. } else {
  270. _Http.basic({
  271. "classname": "sysmanage.develop.optiontype.optiontype",
  272. "method": "optiontypeselect",
  273. "content": {
  274. "pageNumber": 1,
  275. "pageSize": 1,
  276. "typename": "itemtype",
  277. "parameter": {
  278. "siteid": wx.getStorageSync('siteP').siteid
  279. }
  280. },
  281. }).then(res => {
  282. console.log(res)
  283. if (res.code == 1 && res.data.length) {
  284. this.data.form[this.data.form.findIndex(v => v.label == '产品系列')].value = [res.data[0].value]
  285. this.setData({
  286. form: this.data.form
  287. })
  288. }
  289. })
  290. }
  291. getApp().globalData.Language.getLanguagePackage(this, '项目报价');
  292. },
  293. /* 打断处理form */
  294. interrupt(e) {
  295. let {
  296. data,
  297. form,
  298. temporary
  299. } = e.detail;
  300. if (temporary.item.value[0] == data.value[0]) return wx.navigateBack();
  301. let obj = {};
  302. temporary.item.value = data.value;
  303. switch (temporary.item.valueName) {
  304. case "sa_projectid":
  305. obj = {
  306. label: "选择客户",
  307. error: false,
  308. errMsg: "",
  309. type: "route",
  310. url: "/packageA/select/setclient/select",
  311. value: "",
  312. params: {
  313. id: 20221027143702,
  314. "content": {
  315. nocache: true,
  316. "sa_projectid": data.value[1][0],
  317. "where": {
  318. "condition": ""
  319. }
  320. },
  321. },
  322. interrupt: true,
  323. query: "&radio=true&idname=sys_enterpriseid",
  324. placeholder: "选择客户",
  325. valueName: "sys_enterpriseid",
  326. checking: "base",
  327. required: true
  328. };
  329. form.splice(1, form[1].label == "选择客户" ? 1 : 0, obj);
  330. address = data.item.province + data.item.city + data.item.county + data.item.address
  331. //业务员
  332. let hr = {
  333. label: "业务员",
  334. error: false,
  335. errMsg: "",
  336. type: "route",
  337. url: "/packageA/select/contacts/select",
  338. value: "",
  339. params: {
  340. "id": "20230306144402",
  341. "content": {
  342. nocache: true,
  343. "type": 2, //type:1客户2:项目
  344. "sa_projectid": data.value[1][0],
  345. "where": {
  346. "condition": ""
  347. }
  348. }
  349. },
  350. query: "&radio=true&idname=hrid",
  351. placeholder: "选择业务员",
  352. valueName: "saler_hrid",
  353. checking: "base",
  354. required: true
  355. };
  356. form.splice(form.findIndex(v => v.label == '备注'), form.some(v => v.label == '业务员') ? 1 : 0, hr);
  357. break;
  358. case "sys_enterpriseid":
  359. obj = {
  360. label: "联系人",
  361. error: false,
  362. errMsg: "",
  363. type: "route",
  364. url: "/packageA/select/contacts/select",
  365. value: "",
  366. params: {
  367. "id": "20240614151004",
  368. "content": {
  369. nocache: true,
  370. "sys_enterpriseid": data.value[1][0],
  371. sa_projectid: form.find(v => v.valueName == 'sys_enterpriseid').params.content.sa_projectid,
  372. pageNumber: 1,
  373. pageSize: 10,
  374. pageTotal: 1,
  375. "where": {
  376. "condition": "",
  377. "workaddress": 0
  378. }
  379. }
  380. },
  381. query: "&radio=true&idname=sys_phonebookid",
  382. placeholder: "选择客户联系人",
  383. valueName: "sys_phonebookid",
  384. checking: "base",
  385. required: true
  386. };
  387. form.splice(2, form.some(v => v.label == '联系人') ? 1 : 0, obj);
  388. break;
  389. }
  390. form[temporary.index] = temporary.item;
  391. wx.navigateBack()
  392. this.setData({
  393. form
  394. })
  395. },
  396. /* 绑定媒体 */
  397. insertImgEdit({
  398. detail
  399. }) {
  400. this.handleFileLink(detail)
  401. },
  402. handleFileLink(attachmentids, ownertable = "temporary", ownerid = 1, data) {
  403. _Http.basic({
  404. "classname": "system.attachment.Attachment",
  405. "method": "createFileLink",
  406. "content": {
  407. ownertable,
  408. ownerid,
  409. usetype: 'default',
  410. attachmentids
  411. }
  412. }).then(res => {
  413. console.log('跟进记录绑定附件', res)
  414. if (res.code != '1') return wx.showToast({
  415. title: res.msg,
  416. icon: "none"
  417. })
  418. if (ownertable == 'temporary') {
  419. this.selectComponent("#Yl_files").handleFiles(res.data)
  420. } else {
  421. if (res.data.length) data.attinfos = res.data;
  422. this.changeItem(data)
  423. setTimeout(() => {
  424. wx.navigateBack()
  425. }, 500)
  426. }
  427. })
  428. },
  429. changeItem(data) {
  430. this.setData({
  431. loading: false
  432. })
  433. let pages = getCurrentPages(),
  434. page = pages[pages.length - 2];
  435. if (page.__route__ == 'packageA/offers/detail') {
  436. page.getDetail(true);
  437. wx.navigateBack()
  438. } else {
  439. if (page.__route__ == 'packageA/offers/index') {
  440. page.getList(true);
  441. } else if (page.__route__ == 'packageA/project/detail') {
  442. let model = page.selectComponent("#Offers");
  443. model.getList(model.data.sa_projectid, true);
  444. }
  445. wx.redirectTo({
  446. url: '/packageA/offers/detail?sa_quotedpriceid=' + data.sa_quotedpriceid
  447. })
  448. }
  449. },
  450. submit() {
  451. this.setData({
  452. loading: true
  453. })
  454. let content = {
  455. ...this.selectComponent("#Form").submit(),
  456. sa_quotedpriceid,
  457. quotedpricenotes,
  458. address,
  459. source
  460. };
  461. content.sys_enterpriseid = content.sys_enterpriseid[1] ? content.sys_enterpriseid[1][0] : 0;
  462. content.projectname = content.sa_projectid[0] || "";
  463. content.sa_projectid = content.sa_projectid[1] ? content.sa_projectid[1][0] : 0;
  464. content.sys_phonebookid = content.sys_phonebookid ? content.sys_phonebookid[1][0] : 0;
  465. content.discountrate = (content.discountrate / 100).toFixed(4) || 1;
  466. content.saler_hrid = content.saler_hrid[1] ? content.saler_hrid[1][0] : 0;
  467. content.begdate = content.invaliddate[0];
  468. content.enddate = content.invaliddate[1];
  469. delete(content.invaliddate)
  470. _Http.basic({
  471. "id": 20221020164803,
  472. "version": 1,
  473. content
  474. }).then(res => {
  475. console.log("添加项目报价单", res)
  476. wx.showToast({
  477. title: res.code != '1' ? res.msg : getApp().globalData.Language.getMapText('保存成功'),
  478. icon: "none",
  479. mask: true
  480. })
  481. if (res.code != '1') return this.setData({
  482. loading: false
  483. });
  484. try {
  485. let attachmentids = this.selectComponent("#Yl_files").getFiles().attachmentids;
  486. if (attachmentids.length) return this.handleFileLink(attachmentids, 'sa_quotedprice', res.data.sa_quotedpriceid, res.data);
  487. } catch (error) {
  488. }
  489. setTimeout(() => {
  490. this.changeItem(res.data)
  491. }, 500)
  492. })
  493. },
  494. // 是否显示全部
  495. onChange({
  496. detail
  497. }) {
  498. this.setData({
  499. showAll: detail
  500. })
  501. },
  502. /* 表单必填项是否完成 */
  503. onConfirm({
  504. detail
  505. }) {
  506. this.setData({
  507. disabled: detail
  508. })
  509. }
  510. })