addSetclientOffer.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. const _Http = getApp().globalData.http,
  2. getTime = require("../../utils/getTime");
  3. let sa_quotedpriceid = 0,
  4. quotedpricenotes = [],
  5. address = "";
  6. Page({
  7. data: {
  8. loading: false,
  9. showAll: false,
  10. form: [{
  11. label: "客户",
  12. error: false,
  13. errMsg: "",
  14. type: "route",
  15. url: "/packageA/contract/add/setclient/select",
  16. value: "",
  17. params: {
  18. "id": 20220920083901,
  19. "content": {
  20. "pageNumber": 1,
  21. "pageSize": 20,
  22. "where": {
  23. "condition": "",
  24. "type": 19,
  25. "sa_projectid": ""
  26. }
  27. },
  28. },
  29. interrupt: true,
  30. query: "&radio=true&idname=sys_enterpriseid",
  31. placeholder: "选择客户",
  32. valueName: "sys_enterpriseid",
  33. checking: "base",
  34. required: true
  35. }, {
  36. label: "产品系列",
  37. error: false,
  38. errMsg: "",
  39. type: "option",
  40. optionNmae: "itemtype",
  41. optionType: "checkbox", //复选 radio 单选
  42. value: "",
  43. placeholder: "请选择产品系列",
  44. valueName: "itemtype",
  45. checking: "base",
  46. required: true
  47. }, {
  48. label: "折扣(%)",
  49. error: false,
  50. errMsg: "",
  51. hint: "请输入0-100%",
  52. type: "digit",
  53. value: "",
  54. placeholder: "请填写折扣(%)",
  55. valueName: "discountrate", //绑定的字段名称
  56. required: false, //必填
  57. checking: `^(100|\\d{0,2})(\\.\\d{1,2})?$`, //0-100%
  58. slot: "discountrate"
  59. }, {
  60. label: "报价日期",
  61. error: false,
  62. errMsg: "",
  63. type: "date",
  64. value: getTime.formatTime(new Date(), '-').split(' ')[0] + "",
  65. placeholder: "报价日期",
  66. valueName: "billdate",
  67. checking: "base",
  68. required: false
  69. }, {
  70. label: "有效期",
  71. error: false,
  72. errMsg: "",
  73. type: "dateRange",
  74. value: [getTime.formatTime(new Date(), '-').split(' ')[0] + "", ""],
  75. placeholder: ['生效日期', '截止日期'],
  76. valueName: "invaliddate",
  77. checking: "base",
  78. required: true
  79. }, {
  80. label: "备注",
  81. error: false,
  82. errMsg: "",
  83. type: "textarea",
  84. value: "",
  85. placeholder: "报价单说明",
  86. valueName: "remarks",
  87. required: false, //必填
  88. }],
  89. disabled: true
  90. },
  91. onLoad(options) {
  92. if (options.data) {
  93. let data = JSON.parse(options.data);
  94. let form = this.data.form;
  95. sa_quotedpriceid = data.sa_quotedpriceid || 0;
  96. quotedpricenotes = data.quotedpricenotes || [];
  97. address = data.address || "";
  98. data.discountrate = data.discountrate == 1 ? 100 : (data.discountrate * 100).toFixed(2);
  99. data.sys_enterpriseid = [data.enterprisename, [data.sys_enterpriseid]];
  100. form = form.map(v => {
  101. if (v.valueName == "invaliddate") {
  102. v.value = [data.begdate, data.enddate]
  103. } else {
  104. v.value = data[v.valueName] || "";
  105. }
  106. return v
  107. })
  108. form.splice(1, 0, {
  109. label: "联系人",
  110. error: false,
  111. errMsg: "",
  112. type: "route",
  113. url: "/packageA/select/contacts/select",
  114. value: [data.contactsname, [data.sys_phonebookid]],
  115. params: {
  116. "id": "20240614151004",
  117. "version": 1,
  118. "content": {
  119. nocache: true,
  120. "sys_enterpriseid": data.sys_enterpriseid[1][0],
  121. sa_projectid: 0,
  122. "where": {
  123. "condition": "",
  124. "workaddress": 0
  125. }
  126. }
  127. },
  128. query: "&radio=true&idname=sys_phonebookid",
  129. placeholder: "选择客户联系人",
  130. valueName: "sys_phonebookid",
  131. checking: "base",
  132. required: false
  133. });
  134. form.splice(6, 0, {
  135. label: "业务员",
  136. error: false,
  137. errMsg: "",
  138. type: "route",
  139. url: "/packageA/select/contacts/select",
  140. value: [data.name, [data.saler_hrid]],
  141. params: {
  142. "id": "20230306144402",
  143. "content": {
  144. nocache: true,
  145. "type": 1, //type:1客户2:项目
  146. "sys_enterpriseid": data.sys_enterpriseid[1][0],
  147. "where": {
  148. "condition": ""
  149. }
  150. }
  151. },
  152. query: "&radio=true&idname=hrid",
  153. placeholder: "选择业务员",
  154. valueName: "saler_hrid",
  155. checking: "base",
  156. required: true
  157. });
  158. this.setData({
  159. form
  160. });
  161. this.selectComponent("#Form").confirm();
  162. }
  163. },
  164. /* 打断处理form */
  165. interrupt(e) {
  166. let {
  167. data,
  168. form,
  169. temporary
  170. } = e.detail;
  171. console.log("处理", data, form, temporary)
  172. if (temporary.item.value[0] == data.value[0]) return wx.navigateBack();
  173. temporary.item.value = data.value;
  174. if (temporary.item.valueName == "sys_enterpriseid") {
  175. //联系人
  176. let contacts = {
  177. label: "联系人",
  178. error: false,
  179. errMsg: "",
  180. type: "route",
  181. url: "/packageA/select/contacts/select",
  182. value: "",
  183. params: {
  184. "id": "20240614151004",
  185. "version": 1,
  186. "content": {
  187. nocache: true,
  188. "sys_enterpriseid": data.value[1][0],
  189. sa_projectid: 0,
  190. "where": {
  191. "condition": "",
  192. "workaddress": 0
  193. }
  194. }
  195. },
  196. query: "&radio=true",
  197. placeholder: "选择客户联系人",
  198. query: "&radio=true&idname=sys_phonebookid",
  199. valueName: "sys_phonebookid",
  200. checking: "base",
  201. required: false
  202. };
  203. form.splice(1, form[1].label == "联系人" ? 1 : 0, contacts);
  204. //业务员
  205. let hr = {
  206. label: "业务员",
  207. error: false,
  208. errMsg: "",
  209. type: "route",
  210. url: "/packageA/select/contacts/select",
  211. value: "",
  212. params: {
  213. "id": "20230306144402",
  214. "content": {
  215. nocache: true,
  216. "type": 1, //type:1客户2:项目
  217. "sys_enterpriseid": data.value[1][0],
  218. "where": {
  219. "condition": ""
  220. }
  221. }
  222. },
  223. query: "&radio=true&idname=hrid",
  224. placeholder: "选择业务员",
  225. valueName: "saler_hrid",
  226. checking: "base",
  227. required: true
  228. };
  229. form.splice(6, form[6].label == "业务员" ? 1 : 0, hr);
  230. }
  231. form[temporary.index] = temporary.item;
  232. wx.navigateBack()
  233. this.setData({
  234. form
  235. })
  236. },
  237. submit() {
  238. this.setData({
  239. loading: true
  240. })
  241. let content = {
  242. ...this.selectComponent("#Form").submit(),
  243. "sa_projectid": 0, //项目id
  244. projectname: "",
  245. sa_quotedpriceid,
  246. quotedpricenotes,
  247. address
  248. };
  249. content.sys_enterpriseid = content.sys_enterpriseid[1] ? content.sys_enterpriseid[1][0] : 0;
  250. content.sys_phonebookid = content.sys_phonebookid[1] ? content.sys_phonebookid[1][0] : 0;
  251. content.saler_hrid = content.saler_hrid[1] ? content.saler_hrid[1][0] : 0;
  252. content.discountrate = (content.discountrate / 100).toFixed(4) || 1;
  253. content.begdate = content.invaliddate[0];
  254. content.enddate = content.invaliddate[1];
  255. delete(content.invaliddate)
  256. _Http.basic({
  257. "id": 20221020164803,
  258. "version": 1,
  259. content
  260. }).then(res => {
  261. console.log("添加客户报价单", res)
  262. this.setData({
  263. loading: false
  264. })
  265. wx.showToast({
  266. title: res.msg != '成功' ? res.msg : '保存成功',
  267. icon: "none"
  268. })
  269. if (res.msg != '成功') return;
  270. setTimeout(() => {
  271. let pages = getCurrentPages(),
  272. page = pages[pages.length - 2];
  273. if (page.__route__ == 'packageA/offers/detail') {
  274. page.getDetail(true);
  275. wx.navigateBack()
  276. } else {
  277. if (['packageA/setclient/detail', 'packageA/publicCustomer/detail'].includes(page.__route__)) {
  278. let model = page.selectComponent("#Offers");
  279. model.getList(model.data.sys_enterpriseid, true);
  280. }
  281. wx.redirectTo({
  282. url: '/packageA/offers/detail?sa_quotedpriceid=' + res.data.sa_quotedpriceid
  283. })
  284. }
  285. }, 300)
  286. })
  287. },
  288. // 是否显示全部
  289. onChange({
  290. detail
  291. }) {
  292. this.setData({
  293. showAll: detail
  294. })
  295. },
  296. /* 表单必填项是否完成 */
  297. onConfirm({
  298. detail
  299. }) {
  300. this.setData({
  301. disabled: detail
  302. })
  303. }
  304. })