订单2021-11-15

/*
 * @Author: your name
 * @Date: 2021-08-12 16:55:43
 * @LastEditTime: 2021-08-23 10:07:51
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \hzero-order-32920\packages\hzero-order\src\pages\order-mange\component\DetailPage.js
 */

import { Form, DatePicker, Button, Table, TextField, Lov, Output } from 'choerodon-ui/pro'
import { withRouter } from 'react-router-dom';
import React from 'react'
import intl from "utils/intl";
const DetailPage = (props) => {
    /**
     * @description: 删除行订单
     * @param {*}
     * @return {*}
     */
    const handleDeleteLine = () => {
        props.inLineDS.data.map((item) => {
            if (item.isSelected) {
                const fn = async () => {
                    const res = await props.inLineDS.delete(item)
                    if (res) {
                        props.inDetailHeadDS.query(1)
                        props.tableTotalDS.query(1)
                    }
                }
                fn()
            }
        })
    }
    /**
     * @description: 添加行订单
     * @param {*}
     * @return {*}
     */
    const handleAdd = () => {
        console.log(props.inLineDS);
        const record = props.inLineDS.create({}, 0);
        record.setState('editing', true);
    };
    /**
     * @description: 列订单按钮
     * @param {*}
     * @return {*}
     */
    const buttons = [
        <Button icon="playlist_add"
            onClick={handleAdd}
            key='add'
            disabled={(props.OrderStatus != "NEW" && props.OrderStatus != 'REJECTED')} >
            {intl.get('hzero.common.button.add').d('新增')}</ Button>,
        <Button icon="playlist_add" onClick={handleDeleteLine} key='delete'
            disabled={(props.OrderStatus != "NEW" && props.OrderStatus != 'REJECTED')}>
            {intl.get('hzero.common.button.delete').d('删除')}</Button>
    ]
    /**
     * @description: 编辑行订单
     * @param {*}
     * @return {*}
     */
    const handleEdit = (record) => {
        record.setState('editing', true);
    };
    /**
     * @description: 编辑取消回调函数
     * @param {*}
     * @return {*}
     */   
    const handleCancel = (record) => {
        if (record.status === 'add') {
            props.inLineDS.remove(record);
        } else {
            record.reset();
            record.setState('editing', false);
        }
    };
    /**
     * @description: 计算总金额
     * @param {*}
     * @return {*}
     */    
    const getToTalPrice = () => {
        if(props.inLineDS.records){
              let price = 0;
        for (let item of props.inLineDS.records) {
            if(item.get('unitSellingPrice')&&item.get('orderQuantity') ){
              price += item.get('orderQuantity') * item.get('unitSellingPrice');
            }
         
        }
        return  <span>{price}</span>
       
        }
      else{
          return <span>0</span>
      }
    };
    /**
     * @description: 行订单确认回调
     * @param {*}
     * @return {*}
     */   
    const handleSubmit = async () => {
        //等待验证字段是否符合规范
        const valid = !await props.inLineDS.validate();
        if (valid) {
            alert("输入数据有误,验证不成功,请重新输入")
        }
        else {
            const res = await props.inLineDS.submit();
            if (res) {
                props.inLineDS.query(1);
            }
        }
    };
   
    const columns = [
        { name: 'lineNumber', align: "left", editor: (record) => record.getState('editing') },
        { name: 'itemLOV', editor: (record) => record.getState('editing') },
        { name: 'itemDescription', },
        { name: 'orderQuantityUom' },
        { name: 'orderQuantity', align: "left", editor: (record) => record.getState('editing') },
        { name: 'unitSellingPrice', align: "left", editor: (record) => record.getState('editing') },
        {
            name: 'totalPrice', align: "left", renderer: ({ record }) => {
                //计算行订单金额
                if (record.get("orderQuantity") && record.get("unitSellingPrice")) {
                    return (
                        <p style={{ width: '300px' }}>
                            {record.get("orderQuantity") * record.get("unitSellingPrice")}
                        </p>
                    )
                } else {
                    return (
                        <p style={{ width: '300px' }}>0</p>
                    )
                }
            }
        },
        { name: 'description', editor: (record) => record.getState('editing'), align: "center", },
        {
            header: '操作', align: "center", lock: "right", text: '编辑',
            //操作列回调函数
            renderer: ({ record }) => {
                const btns = [];
                if (record.getState('editing')) {
                    btns.push(
                        <a onClick={handleSubmit} style={{ marginRight: '0.1rem' }}>
                            确认
                        </a>,
                        <a onClick={() => handleCancel(record)}>取消</a>,
                    );
                } else {
                    btns.push(
                        <a
                            onClick={() => handleEdit(record)}
                            disabled={(props.OrderStatus != "NEW" && props.OrderStatus != 'REJECTED')}
                        >
                            编辑
                        </a>,
                    );
                }
                return [<span className="action-link">{btns}</span>];
            }
        }

    ]
    return (
        <div>
            <Form id="basic"
                labelAlign='left'
                useColon={false}
                labelLayout='horizontal'
                columns={3}
                dataSet={props.inDetailHeadDS}
            >
                <TextField name='orderNumber' style={{ width: '300px' }} disabled></TextField>
                <Lov name='companyLOV' style={{ width: '300px' }}
                    disabled={(props.OrderStatus != "NEW" && props.OrderStatus != 'REJECTED')}></Lov>
                <Lov name='customerLOV' style={{ width: '300px' }}
                    disabled={(props.OrderStatus != "NEW" && props.OrderStatus != 'REJECTED')}></Lov>
                <DatePicker name='orderDate' style={{ width: '300px' }} mode='dateTime' min='2020'
                    disabled={(props.OrderStatus != "NEW" && props.OrderStatus != 'REJECTED')}></DatePicker>
                <Output name='orderPrice' disabled renderer={getToTalPrice}></Output>
                <TextField name='orderStatus' style={{ width: '300px' }} disabled></TextField>
            </Form>
            <Table dataSet={props.inLineDS} buttons={buttons} dragColumnAlign="left" key='DetailPage' columns={columns} sortable={true}>
            </Table>
        </div >
    )

}
export default withRouter(DetailPage)

index.js:

/*
 * @Author: your name
 * @Date: 2021-08-12 16:55:43
 * @LastEditTime: 2021-08-23 14:44:04
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \hzero-order-32920\packages\hzero-order\src\pages\order-mange\component\index.js
 */
import React, { useState } from 'react';
import { PageHeaderWrapper } from 'hzero-boot/lib/components/Page';
import CreatePage from './CreatePage';
import DetailPage from './DetailPage';
import { Button, DataSet, Icon } from 'choerodon-ui/pro';
import intl from "utils/intl";
import notification from 'utils/notification'
import { totalDS } from '../store/totalDS'
import { detailHeadDS } from '../store/detailHeadDS'
import { lineDS } from '../store/lineDS'
import { closeTab } from 'utils/menuTab';

const index = (props) => {
    if (props.location.query) {
        var [OrderStatus, setOrderStatus] = useState(props.location.query.record.data.orderStatus)
        /**
         * @description: 定义头订单,行订单ds
         * @param {*}
         * @return {*}
         */       
        var inDetailHeadDS = new DataSet(detailHeadDS(props.location.query.record.data.soHeaderId))
        var inLineDS = new DataSet(lineDS(props.location.query.record.data.soHeaderId))
        /**
         * @description: 处理头订单确认信息
         * @param {*}
         * @return {*}
         */       
        var handleListSubmit = async () => {
            if (inLineDS) {
                const res = await inDetailHeadDS.submit();
                if (res) {
                    const fn = async () => {
                        await inDetailHeadDS.query(1)
                        inLineDS.query(1)
                    }
                    fn()
                }
            }
            
            else {
                notification.warn({
                    message: "还没添加行订单"
                })
            }
        };
        /**
         * @description: 更改头订单状态为已提交的函数
         * @param {*}
         * @return {*}
         */      
        var handleStatusToSubmited = () => {
            notification.info({
                message: '正在处理,请勿重复点击',
            });
            if (inLineDS.records[0]) {
                const fn = async () => {
                    inDetailHeadDS.records[0].set("orderStatus", "SUBMITED");
                    const res = await inDetailHeadDS.submit();
                    if (res) {
                        setOrderStatus('SUBMITED')
                        // back()
                        inDetailHeadDS.query(1)
                        inLineDS.query(1)
                        tableTotalDS.query(1)
                    }
                }
                fn()
            }
            else {
                notification.warning({
                    message: "还没添加行订单"
                })
            }
        }
        /**
         * @description:删除头订单
         * @param {*}
         * @return {*}
         */    
        var handleDeleteList = async () => {
            const res = await inDetailHeadDS.delete(inDetailHeadDS.current)
            if (res) {
                back()
                inDetailHeadDS.query(1)
                tableTotalDS.query(1)
            }
        }

    }
    /**
     * @description: 定义订单管理列表的ds和新增页面的ds,和新增数据的record
     * @param {*}
     * @return {*}
     */    
    const tableTotalDS = new DataSet(totalDS())
    const newHeadDS = new DataSet(detailHeadDS())
    const currentRecord = newHeadDS.create({});
    const back = () => {
        props.history.push({ pathname: '/hzero-order-32920/list' })
        closeTab('/hzero-order-32920/detail')
        tableTotalDS.query(1)
    }
    /**
     * @description: 新订单保存按钮,同时跳转路由
     * @param {*}
     * @return {*}
     */    
    const handleNewListSubmit = async () => {
        notification.info({
            message: '正在处理,请勿重复点击',
        });
        const res = await newHeadDS.submit()
        if (res) {
            props.history.push({
                pathname: '/hzero-order-32920/toDetail', query: { record: newHeadDS.records[0] }
            })
        }
    };
    
    return (props.location.query ?
        <PageHeaderWrapper
            title={<div><Icon type="arrow_back" onClick={back} style={{ cursor: 'pointer', width: '20px', position: 'relative', top: '-2px' }} />订单详情</div>}
            header={
                <div>
                    <Button onClick={handleListSubmit}>{intl.get(`hzero.common.button.save`).d('保存')}</Button>,
                    <Button
                        onClick={handleStatusToSubmited}
                        disabled={(OrderStatus != "NEW" && OrderStatus != 'REJECTED')}>
                        {intl.get('hzero.common.button.submit').d('提交')}</Button>,
                    <Button
                        onClick={handleDeleteList}
                        disabled={(OrderStatus != "NEW" && OrderStatus != 'REJECTED')}>
                        {intl.get('hzero.common.button.delete').d('删除')}</Button></div>}
        >
            <DetailPage record={props.location.query.record} OrderStatus={OrderStatus} inDetailHeadDS={inDetailHeadDS} inLineDS={inLineDS} tableTotalDS={tableTotalDS} />
        </PageHeaderWrapper >
        :
        <PageHeaderWrapper title={<div><Icon type="arrow_back" onClick={back} style={{ cursor: 'pointer', width: '20px', position: 'relative', top: '-2px' }} />新增订单页面</div>}
            header={<Button onClick={handleNewListSubmit}>{intl.get(`hzero.common.button.save`).d('保存')}</Button>}>
            <CreatePage record={currentRecord} newHeadDS={newHeadDS} />
        </PageHeaderWrapper>)
};

export default index;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用python中的pymsql完成如下:表结构与数据创建 1. 建立 `users` 表和 `orders` 表。 `users` 表有用户ID、用户名、年龄字段,(id,name,age) `orders` 表有订单ID、订单日期、订单金额,用户id字段。(id,order_date,amount,user_id) 2 两表的id作为主键,`orders` 表用户id为users的外键 3 插入数据 `users` (1, '张三', 18), (2, '李四', 20), (3, '王五', 22), (4, '赵六', 25), (5, '钱七', 28); `orders` (1, '2021-09-01', 500, 1), (2, '2021-09-02', 1000, 2), (3, '2021-09-03', 600, 3), (4, '2021-09-04', 800, 4), (5, '2021-09-05', 1500, 5), (6, '2021-09-06', 1200, 3), (7, '2021-09-07', 2000, 1), (8, '2021-09-08', 300, 2), (9, '2021-09-09', 700, 5), (10, '2021-09-10', 900, 4); 查询语句 1. 查询订单总金额 2. 查询所有用户的平均年龄,并将结果四舍五入保留两位小数。 3. 查询订单总数最多的用户的姓名和订单总数。 4. 查询所有不重复的年龄。 5. 查询订单日期在2021年9月1日至9月4日之间的订单总金额。 6. 查询年龄不大于25岁的用户的订单数量,并按照降序排序。 7. 查询订单总金额排名前3的用户的姓名和订单总金额。 8. 查询订单总金额最大的用户的姓名和订单总金额。 9. 查询订单总金额最小的用户的姓名和订单总金额。 10. 查询所有名字中含有“李”的用户,按照名字升序排序。 11. 查询所有年龄大于20岁的用户,按照年龄降序排序,并只显示前5条记录。 12. 查询每个用户的订单数量和订单总金额,并按照总金额降序排序。
06-03

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值