| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- const _Http = getApp().globalData.http,
- currency = require("../../../../utils/currency"),
- CNY = value => currency(value, {
- symbol: "¥",
- precision: 2
- }).format();
- Page({
- data: {
- loading: false,
- disabled: true,
- showAll: false,
- sa_custorderid: '',
- orderInfo: {},
- form: [{
- label: "订单编号",
- error: false,
- errMsg: "",
- type: "text",
- value: "",
- placeholder: "订单编号",
- valueName: "sonum",
- required: false,
- checking: "base",
- disabled: true
- },
- {
- label: "客户",
- error: false,
- errMsg: "",
- type: "text",
- value: "",
- placeholder: "客户名称",
- valueName: "name",
- required: false,
- checking: "base",
- disabled: true
- },
- {
- label: "收款日期",
- error: false,
- errMsg: "",
- type: "date",
- value: "",
- placeholder: "请选择收款日期",
- valueName: "billdate",
- required: true,
- checking: "base"
- },
- {
- label: "收款金额",
- error: false,
- errMsg: "",
- type: "digit",
- value: "",
- placeholder: "请输入收款金额(正数或负数)",
- valueName: "amount",
- required: true,
- checking: "base"
- },
- {
- label: "收款类别",
- error: false,
- errMsg: "",
- type: "radio",
- value: "订金",
- radioList: [{
- id: "订金",
- name: "订金"
- },
- {
- id: "货款",
- name: "货款"
- },
- {
- id: "冲账",
- name: "冲账"
- },
- {
- id: "退款",
- name: "退款"
- }
- ],
- valueName: "typemx",
- required: true,
- checking: "base"
- },
- {
- label: "备注",
- error: false,
- errMsg: "",
- type: "textarea",
- value: "",
- placeholder: "请输入备注",
- valueName: "remarks",
- required: false,
- checking: "base"
- }
- ],
- content: {
- sa_custorderid: 0,
- sys_enterprise_cashbillid: 0,
- billdate: "",
- typemx: "",
- amount: 0,
- remarks: ""
- }
- },
- onLoad(options) {
- if (options.sa_custorderid) {
- this.setData({
- "content.sa_custorderid": options.sa_custorderid,
- sa_custorderid: options.sa_custorderid
- });
- this.getOrderInfoFromPage();
- }
- // 设置默认收款日期为当天
- const today = new Date().toISOString().split('T')[0];
- let form = this.data.form;
- form.forEach(item => {
- if (item.valueName === 'billdate') {
- item.value = today;
- this.setData({
- "content.billdate": today
- });
- }
- });
- this.setData({
- form
- });
- },
- // 从页面获取订单信息
- getOrderInfoFromPage() {
- try {
- // 通过路由路径查找订单详情页面
- const orderDetailPage = getCurrentPages().find(v => v.__route__ == 'CRM/order/detail');
- if (orderDetailPage && orderDetailPage.data.detail) {
- const orderData = orderDetailPage.data.detail;
- this.setData({
- orderInfo: orderData
- });
- // 更新表单数据
- let form = this.data.form;
- form.forEach(item => {
- if (item.valueName === 'sonum') {
- item.value = orderData.sonum || '';
- }
- if (item.valueName === 'name') {
- item.value = orderData.name || '';
- }
- });
- this.setData({
- form
- });
- }
- } catch (error) {
- console.error("获取订单信息失败", error);
- }
- },
- // 提交收款单
- submit() {
- this.setData({
- loading: true
- });
- let formData = this.selectComponent("#Form").submit();
- if (!formData) {
- this.setData({
- loading: false
- });
- return;
- }
- // 验证金额
- const amount = parseFloat(formData.amount);
- if (isNaN(amount) || amount === 0) {
- wx.showToast({
- title: '请输入有效的收款金额',
- icon: 'none'
- });
- this.setData({
- loading: false
- });
- return;
- }
- // 构建请求参数
- let content = {
- sa_custorderid: this.data.content.sa_custorderid,
- sys_enterprise_cashbillid: 0,
- billdate: formData.billdate,
- typemx: formData.typemx,
- amount: amount,
- remarks: formData.remarks || ""
- };
- console.log("创建收款单参数", content);
- // 调用创建收款单API
- _Http.basic({
- id: "2026032016115701",
- content
- }).then(res => {
- console.log('创建收款单结果:', res);
- this.setData({
- loading: false
- });
- if (res.code === 1) {
- // 获取订单详情页面
- const orderDetailPage = getCurrentPages().find(v => v.__route__ == 'CRM/order/detail');
- if (orderDetailPage) {
- // 更新付款记录列表
- orderDetailPage.selectComponent('#PaymentRecord').getList(content.sa_custorderid, true);
- // 调用详情页面的获取详情方法更新付款状态
- orderDetailPage.getDetail();
- }
- // 返回上一页
- wx.navigateBack({
- delta: 1,
- success: () => {
- // 显示成功提示
- wx.showToast({
- title: '创建收款单成功',
- icon: 'none'
- });
- }
- });
- } else {
- wx.showToast({
- title: res.msg || '创建收款单失败',
- icon: 'none'
- });
- }
- }).catch(err => {
- console.error('创建收款单失败:', err);
- this.setData({
- loading: false
- });
- wx.showToast({
- title: '网络错误',
- icon: 'none'
- });
- });
- },
- interrupt({
- detail
- }) {
- // 处理中断逻辑
- },
- /* 表单必填项是否完成 */
- onConfirm({
- detail
- }) {
- this.setData({
- disabled: detail
- });
- },
- onChange(e) {
- this.setData({
- showAll: e.detail
- });
- },
- closePage() {
- wx.navigateBack({
- delta: 1
- });
- }
- });
|