ProductsView.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import QtQuick 2.15
  2. import QtQuick.Controls 2.15
  3. import QtQuick.Layouts 1.15
  4. import ru.ded.beerlog 1.0
  5. Page {
  6. ProductsViewModel {
  7. id: productsModel
  8. }
  9. RowLayout {
  10. anchors.fill: parent
  11. ListView {
  12. id: productsList
  13. Layout.fillWidth: true
  14. Layout.preferredHeight: parent.height
  15. model: productsModel.products
  16. delegate: ItemDelegate {
  17. width: productsList.width
  18. text: modelData.name
  19. height: spinbox.height
  20. SpinBox {
  21. id: spinbox
  22. width: 150
  23. from: 0
  24. to: 100 * 100
  25. stepSize: 50
  26. anchors.right: parent.right
  27. editable: true
  28. property int decimals: 1
  29. property real realValue: value / 100
  30. validator: DoubleValidator {
  31. bottom: Math.min(spinbox.from, spinbox.to)
  32. top: Math.max(spinbox.from, spinbox.to)
  33. }
  34. textFromValue: function(value, locale) {
  35. return value === 0 ? "" : Number(value / 100).toLocaleString(locale, 'f', spinbox.decimals)
  36. }
  37. valueFromText: function(text, locale) {
  38. return Number.fromLocaleString(locale, text) * 100
  39. }
  40. onRealValueChanged: productsModel.setOrderValue(modelData.id, realValue)
  41. }
  42. }
  43. function reload() {
  44. model = undefined
  45. model = productsModel.products
  46. }
  47. }
  48. ListView {
  49. id: orderList
  50. Layout.minimumWidth: parent.width * 0.3
  51. Layout.preferredHeight: parent.height
  52. model: productsModel.order
  53. delegate: ItemDelegate {
  54. width: orderList.width
  55. text: "%1 x%2".arg(modelData.name).arg(modelData.count.toLocaleString(Qt.locale()))
  56. }
  57. footer: Column {
  58. width: orderList.width
  59. Label {
  60. anchors.right: parent.right
  61. anchors.margins: 10
  62. text: qsTr("Summary: %1").arg(productsModel.orderSum.toLocaleCurrencyString(Qt.locale()))
  63. }
  64. Button {
  65. anchors.right: parent.right
  66. anchors.margins: 10
  67. text: qsTr("Order")
  68. enabled: productsModel.orderSum > 0
  69. onClicked: {
  70. productsModel.submitOrder()
  71. productsList.reload()
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }