addProjectOffer.js 11 KB

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