create.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../../../utils/currency"),
  3. CNY = value => currency(value, {
  4. symbol: "¥",
  5. precision: 2
  6. }).format();
  7. Page({
  8. data: {
  9. loading: false,
  10. disabled: true,
  11. showAll: false,
  12. sa_custorderid: '',
  13. orderInfo: {},
  14. form: [{
  15. label: "订单编号",
  16. error: false,
  17. errMsg: "",
  18. type: "text",
  19. value: "",
  20. placeholder: "订单编号",
  21. valueName: "sonum",
  22. required: false,
  23. checking: "base",
  24. disabled: true
  25. },
  26. {
  27. label: "客户",
  28. error: false,
  29. errMsg: "",
  30. type: "text",
  31. value: "",
  32. placeholder: "客户名称",
  33. valueName: "name",
  34. required: false,
  35. checking: "base",
  36. disabled: true
  37. },
  38. {
  39. label: "收款日期",
  40. error: false,
  41. errMsg: "",
  42. type: "date",
  43. value: "",
  44. placeholder: "请选择收款日期",
  45. valueName: "billdate",
  46. required: true,
  47. checking: "base"
  48. },
  49. {
  50. label: "收款金额",
  51. error: false,
  52. errMsg: "",
  53. type: "digit",
  54. value: "",
  55. placeholder: "请输入收款金额(正数或负数)",
  56. valueName: "amount",
  57. required: true,
  58. checking: "base"
  59. },
  60. {
  61. label: "收款类别",
  62. error: false,
  63. errMsg: "",
  64. type: "radio",
  65. value: "订金",
  66. radioList: [{
  67. id: "订金",
  68. name: "订金"
  69. },
  70. {
  71. id: "货款",
  72. name: "货款"
  73. },
  74. {
  75. id: "冲账",
  76. name: "冲账"
  77. },
  78. {
  79. id: "退款",
  80. name: "退款"
  81. }
  82. ],
  83. valueName: "typemx",
  84. required: true,
  85. checking: "base"
  86. },
  87. {
  88. label: "备注",
  89. error: false,
  90. errMsg: "",
  91. type: "textarea",
  92. value: "",
  93. placeholder: "请输入备注",
  94. valueName: "remarks",
  95. required: false,
  96. checking: "base"
  97. }
  98. ],
  99. content: {
  100. sa_custorderid: 0,
  101. sys_enterprise_cashbillid: 0,
  102. billdate: "",
  103. typemx: "",
  104. amount: 0,
  105. remarks: ""
  106. }
  107. },
  108. onLoad(options) {
  109. if (options.sa_custorderid) {
  110. this.setData({
  111. "content.sa_custorderid": options.sa_custorderid,
  112. sa_custorderid: options.sa_custorderid
  113. });
  114. this.getOrderInfoFromPage();
  115. }
  116. // 设置默认收款日期为当天
  117. const today = new Date().toISOString().split('T')[0];
  118. let form = this.data.form;
  119. form.forEach(item => {
  120. if (item.valueName === 'billdate') {
  121. item.value = today;
  122. this.setData({
  123. "content.billdate": today
  124. });
  125. }
  126. });
  127. this.setData({
  128. form
  129. });
  130. },
  131. // 从页面获取订单信息
  132. getOrderInfoFromPage() {
  133. try {
  134. // 通过路由路径查找订单详情页面
  135. const orderDetailPage = getCurrentPages().find(v => v.__route__ == 'CRM/order/detail');
  136. if (orderDetailPage && orderDetailPage.data.detail) {
  137. const orderData = orderDetailPage.data.detail;
  138. this.setData({
  139. orderInfo: orderData
  140. });
  141. // 更新表单数据
  142. let form = this.data.form;
  143. form.forEach(item => {
  144. if (item.valueName === 'sonum') {
  145. item.value = orderData.sonum || '';
  146. }
  147. if (item.valueName === 'name') {
  148. item.value = orderData.name || '';
  149. }
  150. });
  151. this.setData({
  152. form
  153. });
  154. }
  155. } catch (error) {
  156. console.error("获取订单信息失败", error);
  157. }
  158. },
  159. // 提交收款单
  160. submit() {
  161. this.setData({
  162. loading: true
  163. });
  164. let formData = this.selectComponent("#Form").submit();
  165. if (!formData) {
  166. this.setData({
  167. loading: false
  168. });
  169. return;
  170. }
  171. // 验证金额
  172. const amount = parseFloat(formData.amount);
  173. if (isNaN(amount) || amount === 0) {
  174. wx.showToast({
  175. title: '请输入有效的收款金额',
  176. icon: 'none'
  177. });
  178. this.setData({
  179. loading: false
  180. });
  181. return;
  182. }
  183. // 构建请求参数
  184. let content = {
  185. sa_custorderid: this.data.content.sa_custorderid,
  186. sys_enterprise_cashbillid: 0,
  187. billdate: formData.billdate,
  188. typemx: formData.typemx,
  189. amount: amount,
  190. remarks: formData.remarks || ""
  191. };
  192. console.log("创建收款单参数", content);
  193. // 调用创建收款单API
  194. _Http.basic({
  195. id: "2026032016115701",
  196. content
  197. }).then(res => {
  198. console.log('创建收款单结果:', res);
  199. this.setData({
  200. loading: false
  201. });
  202. if (res.code === 1) {
  203. // 获取订单详情页面
  204. const orderDetailPage = getCurrentPages().find(v => v.__route__ == 'CRM/order/detail');
  205. if (orderDetailPage) {
  206. // 更新付款记录列表
  207. orderDetailPage.selectComponent('#PaymentRecord').getList(content.sa_custorderid, true);
  208. // 调用详情页面的获取详情方法更新付款状态
  209. orderDetailPage.getDetail();
  210. }
  211. // 返回上一页
  212. wx.navigateBack({
  213. delta: 1,
  214. success: () => {
  215. // 显示成功提示
  216. wx.showToast({
  217. title: '创建收款单成功',
  218. icon: 'none'
  219. });
  220. }
  221. });
  222. } else {
  223. wx.showToast({
  224. title: res.msg || '创建收款单失败',
  225. icon: 'none'
  226. });
  227. }
  228. }).catch(err => {
  229. console.error('创建收款单失败:', err);
  230. this.setData({
  231. loading: false
  232. });
  233. wx.showToast({
  234. title: '网络错误',
  235. icon: 'none'
  236. });
  237. });
  238. },
  239. interrupt({
  240. detail
  241. }) {
  242. // 处理中断逻辑
  243. },
  244. /* 表单必填项是否完成 */
  245. onConfirm({
  246. detail
  247. }) {
  248. this.setData({
  249. disabled: detail
  250. });
  251. },
  252. onChange(e) {
  253. this.setData({
  254. showAll: e.detail
  255. });
  256. },
  257. closePage() {
  258. wx.navigateBack({
  259. delta: 1
  260. });
  261. }
  262. });