addProjectOffer.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. const _Http = getApp().globalData.http,
  2. getTime = require("../../utils/getTime");
  3. Page({
  4. data: {
  5. showAll: false,
  6. form: [{
  7. label: "项目",
  8. error: false,
  9. errMsg: "",
  10. type: "route",
  11. url: "/packageA/select/project/select",
  12. radio: true,
  13. value: "",
  14. params: {
  15. id: 20221020143502,
  16. content: {
  17. nocache: true,
  18. "type": 0,
  19. "pageNumber": 1,
  20. "pageSize": 20,
  21. "isExport": 0,
  22. "where": {
  23. "condition": "",
  24. }
  25. },
  26. },
  27. placeholder: "选择项目",
  28. valueName: "sa_projectid",
  29. checking: "base",
  30. required: true
  31. }, {
  32. label: "报价日期",
  33. error: false,
  34. errMsg: "",
  35. type: "date",
  36. value: getTime.formatTime(new Date(), '-').split(' ')[0],
  37. placeholder: "报价日期",
  38. valueName: "billdate",
  39. checking: "base",
  40. required: false
  41. }, {
  42. label: "有效期",
  43. error: false,
  44. errMsg: "",
  45. type: "dateRange",
  46. value: [getTime.formatTime(new Date(), '-').split(' ')[0], ""],
  47. placeholder: ['生效日期', '截止日期'],
  48. valueName: "invaliddate",
  49. checking: "base",
  50. required: true
  51. }],
  52. "content": {
  53. "sa_quotedpriceid": 0, //报价单id
  54. "sa_projectid": 0, //项目id
  55. "contactsid": 0, //联系人id
  56. "sys_enterpriseid": 0, //合作客户ID
  57. "invaliddate": "", //有效截止日期
  58. "billdate": "", //报价日期
  59. discountrate: "",
  60. remarks: "",
  61. projectname: "",
  62. address: ""
  63. },
  64. disabled: true
  65. },
  66. onLoad(options) {
  67. if (options.data) {
  68. let data = JSON.parse(options.data);
  69. let form = this.data.form;
  70. if (data.sa_projectid) {
  71. form[0].value = data.sa_projectid;
  72. form.splice(1, 0, {
  73. label: "选择客户",
  74. error: false,
  75. errMsg: "",
  76. type: "route",
  77. url: "/packageA/select/setclient/select",
  78. radio: true,
  79. value: "",
  80. params: {
  81. id: 20221027143702,
  82. "content": {
  83. nocache: true,
  84. "sa_projectid": data.sa_projectid[1][0],
  85. "pageNumber": 1,
  86. "pageSize": 20,
  87. "where": {
  88. "condition": ""
  89. }
  90. },
  91. },
  92. placeholder: "选择客户",
  93. valueName: "sys_enterpriseid",
  94. checking: "base",
  95. required: true
  96. })
  97. };
  98. this.setData({
  99. disabled: false,
  100. form
  101. })
  102. }
  103. },
  104. /* 打断处理form */
  105. interrupt(e) {
  106. let {
  107. data,
  108. form
  109. } = e.detail;
  110. console.log("处理", data, form)
  111. //选择客户
  112. if (data.valueName == "sa_projectid") {
  113. let obj = {
  114. label: "选择客户",
  115. error: false,
  116. errMsg: "",
  117. type: "route",
  118. url: "/packageA/select/setclient/select",
  119. radio: true,
  120. value: "",
  121. params: {
  122. id: 20221027143702,
  123. "content": {
  124. nocache: true,
  125. "sa_projectid": data.value[1][0],
  126. "pageNumber": 1,
  127. "pageSize": 20,
  128. "where": {
  129. "condition": ""
  130. }
  131. },
  132. },
  133. placeholder: "选择客户",
  134. valueName: "sys_enterpriseid",
  135. checking: "base",
  136. required: true
  137. };
  138. if (form[1].label == "选择客户") {
  139. form[1] = obj
  140. } else {
  141. form.splice(1, 0, obj)
  142. }
  143. this.setData({
  144. form
  145. })
  146. } else if (data.valueName == "sys_enterpriseid") {
  147. let obj = {
  148. label: "联系人",
  149. error: false,
  150. errMsg: "",
  151. type: "route",
  152. url: "/packageA/select/contacts/select",
  153. model: "#Form",
  154. value: "",
  155. radio: true,
  156. params: {
  157. "id": "20221022165503",
  158. "version": 1,
  159. "content": {
  160. "sys_enterpriseid": data.value[1][0],
  161. "where": {
  162. "condition": "",
  163. "workaddress": 0
  164. }
  165. }
  166. },
  167. placeholder: "选择客户联系人",
  168. valueName: "contactsid",
  169. checking: "base",
  170. required: false
  171. };
  172. if (form[2].label == "联系人") {
  173. form[2] = obj
  174. } else {
  175. form.splice(2, 0, obj)
  176. }
  177. this.setData({
  178. form
  179. })
  180. }
  181. },
  182. submit() {
  183. let content = {
  184. ...this.data.content,
  185. ...this.selectComponent("#Form").submit()
  186. };
  187. console.log(content)
  188. content.sys_enterpriseid = content.sys_enterpriseid[1][0] || '';
  189. content.sa_projectid = content.sa_projectid[1][0] || '';
  190. content.contactsid = content.contactsid ? content.contactsid[1][0] : '';
  191. content.begdate = content.invaliddate[0];
  192. content.enddate = content.invaliddate[1];
  193. delete(content.invaliddate)
  194. _Http.basic({
  195. "id": 20221020164803,
  196. "version": 1,
  197. content
  198. }).then(res => {
  199. console.log("添加项目报价单", res)
  200. wx.showToast({
  201. title: res.msg != '成功' ? res.msg : '保存成功',
  202. icon: "none"
  203. })
  204. if (res.msg != '成功') return;
  205. setTimeout(() => {
  206. let pages = getCurrentPages(),
  207. page = pages[pages.length - 2];
  208. if (page.__route__ == 'packageA/offers/index') {
  209. page.getList(true);
  210. } else if (page.__route__ == 'packageA/project/detail') {
  211. let model = page.selectComponent("#Offers");
  212. model.getList(model.data.sa_projectid, true);
  213. }
  214. wx.redirectTo({
  215. url: '/packageA/offers/detail?sa_quotedpriceid=' + res.data.sa_quotedpriceid
  216. })
  217. }, 300)
  218. })
  219. },
  220. // 是否显示全部
  221. onChange({
  222. detail
  223. }) {
  224. this.setData({
  225. showAll: detail
  226. })
  227. },
  228. /* 表单必填项是否完成 */
  229. onConfirm({
  230. detail
  231. }) {
  232. this.setData({
  233. disabled: detail
  234. })
  235. }
  236. })