ProductsView.qml 2.9 KB

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