ProductsView.qml 2.8 KB

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