addProjectOffer.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. value: "",
  13. params: {
  14. id: 20221020143502,
  15. content: {
  16. nocache: true,
  17. "type": 0,
  18. "isExport": 0,
  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: "number",
  48. value: "",
  49. placeholder: "请填写折扣(%)",
  50. valueName: "discountrate", //绑定的字段名称
  51. required: false, //必填
  52. checking: `^([1-9]?\\d|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.splice(1, 0, {
  93. label: "选择客户",
  94. error: false,
  95. errMsg: "",
  96. type: "route",
  97. url: "/packageA/select/setclient/select",
  98. value: "",
  99. params: {
  100. id: 20221027143702,
  101. "content": {
  102. nocache: true,
  103. "sa_projectid": data.sa_projectid[1][0],
  104. "where": {
  105. "condition": ""
  106. }
  107. },
  108. },
  109. query: "&radio=true&idname=sys_enterpriseid",
  110. placeholder: "选择客户",
  111. valueName: "sys_enterpriseid",
  112. checking: "base",
  113. required: true
  114. })
  115. };
  116. this.setData({
  117. disabled: false,
  118. form
  119. })
  120. }
  121. },
  122. /* 打断处理form */
  123. interrupt(e) {
  124. let {
  125. data,
  126. form,
  127. temporary
  128. } = e.detail;
  129. console.log("处理", data, form, temporary)
  130. if (temporary.item.value[0] == data.value[0]) return wx.navigateBack();
  131. let obj = {};
  132. temporary.item.value = data.value;
  133. switch (temporary.item.valueName) {
  134. case "sa_projectid":
  135. obj = {
  136. label: "选择客户",
  137. error: false,
  138. errMsg: "",
  139. type: "route",
  140. url: "/packageA/select/setclient/select",
  141. value: "",
  142. params: {
  143. id: 20221027143702,
  144. "content": {
  145. nocache: true,
  146. "sa_projectid": data.value[1][0],
  147. "where": {
  148. "condition": ""
  149. }
  150. },
  151. },
  152. interrupt: true,
  153. query: "&radio=true&idname=sys_enterpriseid",
  154. placeholder: "选择客户",
  155. valueName: "sys_enterpriseid",
  156. checking: "base",
  157. required: true
  158. };
  159. form.splice(1, form[1].label == "选择客户" ? 1 : 0, obj);
  160. this.setData({
  161. address: data.item.province + data.item.city + data.item.county + data.item.address
  162. })
  163. break;
  164. case "sys_enterpriseid":
  165. obj = {
  166. label: "联系人",
  167. error: false,
  168. errMsg: "",
  169. type: "route",
  170. url: "/packageA/select/contacts/select",
  171. value: "",
  172. params: {
  173. "id": "20221022165503",
  174. "content": {
  175. nocache: true,
  176. "sys_enterpriseid": data.value[1][0],
  177. pageNumber: 1,
  178. pageSize: 10,
  179. pageTotal: 1,
  180. "where": {
  181. "condition": "",
  182. "workaddress": 0
  183. }
  184. }
  185. },
  186. query: "&radio=true",
  187. placeholder: "选择客户联系人",
  188. valueName: "contactsid",
  189. checking: "base",
  190. required: false
  191. };
  192. form.splice(2, form[2].label == "联系人" ? 1 : 0, obj);
  193. break;
  194. }
  195. form[temporary.index] = temporary.item;
  196. wx.navigateBack()
  197. this.setData({
  198. form
  199. })
  200. },
  201. submit() {
  202. let content = {
  203. ...this.selectComponent("#Form").submit(),
  204. sa_quotedpriceid: 0
  205. };
  206. content.sys_enterpriseid = content.sys_enterpriseid[1] ? content.sys_enterpriseid[1][0] : 0;
  207. content.projectname = content.sa_projectid[0] || "";
  208. content.sa_projectid = content.sa_projectid[1] ? content.sa_projectid[1][0] : 0;
  209. content.contactsid = content.contactsid ? content.contactsid[1][0] : 0;
  210. content.discountrate = (content.discountrate / 100).toFixed(4) || 1;
  211. content.begdate = content.invaliddate[0];
  212. content.enddate = content.invaliddate[1];
  213. content.address = this.data.address;
  214. delete(content.invaliddate)
  215. _Http.basic({
  216. "id": 20221020164803,
  217. "version": 1,
  218. content
  219. }).then(res => {
  220. console.log("添加项目报价单", res)
  221. wx.showToast({
  222. title: res.msg != '成功' ? res.msg : '保存成功',
  223. icon: "none"
  224. })
  225. if (res.msg != '成功') return;
  226. setTimeout(() => {
  227. let pages = getCurrentPages(),
  228. page = pages[pages.length - 2];
  229. if (page.__route__ == 'packageA/offers/index') {
  230. page.getList(true);
  231. } else if (page.__route__ == 'packageA/project/detail') {
  232. let model = page.selectComponent("#Offers");
  233. model.getList(model.data.sa_projectid, true);
  234. }
  235. wx.redirectTo({
  236. url: '/packageA/offers/detail?sa_quotedpriceid=' + res.data.sa_quotedpriceid
  237. })
  238. }, 300)
  239. })
  240. },
  241. // 是否显示全部
  242. onChange({
  243. detail
  244. }) {
  245. this.setData({
  246. showAll: detail
  247. })
  248. },
  249. /* 表单必填项是否完成 */
  250. onConfirm({
  251. detail
  252. }) {
  253. this.setData({
  254. disabled: detail
  255. })
  256. }
  257. })