PriceChangeRnav.cshtml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. 
  2. <div id="PriceChangeDiv">
  3. <form action="" method="post" class="config-form">
  4. <div class="config-form-group">
  5. <label class="price-form-label">油品</label>
  6. <label class="price-form-label">当前价格(元)</label>
  7. <label class="price-form-label">新价格(元)</label>
  8. </div>
  9. <div v-for="r in rows" class="config-form-group">
  10. <label class="price-form-label">{{ r.FuelName }}</label>
  11. <label class="price-form-label">{{ r.CurrentPrice }}</label>
  12. <input class="price-form-input" oninput="value=value.match(/[0-9]{1,10}\.?[0-9]{0,6}/)" v-model="r.NewPrice" />
  13. </div>
  14. <div class="config-form-submit-group">
  15. <label :class="showResult ? (result ? 'config-form-result' : 'config-form-result-fail') : 'color-transparent'">{{ result ? '提交完成' : '提交失败' }}</label>
  16. </div>
  17. <div class="config-form-submit-group" v-if="receiveData">
  18. <label class="config-form-label"></label>
  19. <button class="config-form-submit" type="button" @@click="submit(event)" id="FuelChange" />
  20. </div>
  21. </form>
  22. </div>
  23. <script type="text/javascript">
  24. var vm = new Vue({
  25. el: '#PriceChangeDiv',
  26. i18n,
  27. data: {
  28. //rows: { "1": { "FuelName": "0#", "CurrentPrice": 0.0, "NewPrice": null }, "2": { "FuelName": "98#", "CurrentPrice": 0.0, "NewPrice": null } },
  29. rows: [],
  30. receiveData: false,
  31. showResult: false,
  32. result: false,
  33. currentIndex:0
  34. },
  35. methods: {
  36. receive(resdata) {
  37. resdata = JSON.parse(resdata)
  38. this.rows = resdata
  39. },
  40. submit(e) {
  41. if (!confirm("确定要继续吗?")) {
  42. return
  43. }
  44. this.currentIndex = 0;
  45. this.ChangeFuelPrice();
  46. return false
  47. },
  48. GetData() {
  49. var temp = {
  50. "parameters": [
  51. { "name": "pumpId", "value": "-1" }
  52. ]
  53. };
  54. GetDataByAPIS("GetPumpsLayout", temp, "post", function (response) {
  55. console.log("GetPumpsLayout", response);
  56. if (response === null || response.length === 0) return;
  57. vm.rows.splice(0, vm.rows.length);
  58. var tempMap = new Map();
  59. response.forEach(function (p) {
  60. p.Nozzles.forEach(function (n) {
  61. if (n.ProductBarcode !== null && !tempMap.has(n.ProductBarcode)) {
  62. tempMap.set(n.ProductBarcode, {
  63. "FuelName": n.ProductName,
  64. "CurrentPrice": n.RealPriceOnPhysicalPump === null ? 0 : n.RealPriceOnPhysicalPump / Math.pow(10, p.AmountDecimalDigits), "NewPrice": null, "ProductBarcode": n.ProductBarcode
  65. });
  66. }
  67. });
  68. });
  69. tempMap.forEach(function (value, key) {
  70. vm.rows.push(value);
  71. });
  72. vm.receiveData = true;
  73. tempMap.clear();
  74. });
  75. },
  76. ChangeFuelPrice() {
  77. if (vm.rows.length === 0) return;
  78. var resultMap = new Map();
  79. //var succeed = false;
  80. if (vm.currentIndex > vm.rows.length - 1 ||
  81. vm.rows[vm.currentIndex].NewPrice === null || vm.rows[vm.currentIndex].NewPrice === "") {
  82. vm.currentIndex++;
  83. if (vm.currentIndex < vm.rows.length) vm.ChangeFuelPrice();
  84. else {
  85. vm.showResult = true;
  86. vm.GetData();
  87. }
  88. return;
  89. }
  90. var tempPara = new Array();
  91. tempPara.push(vm.rows[vm.currentIndex].ProductBarcode);
  92. tempPara.push(vm.rows[vm.currentIndex].NewPrice * 1);
  93. GetDataByAPIS("ChangeFuelPriceAsync", tempPara, "post", function (response) {
  94. if (response === null || response.length === 0) {
  95. resultMap.set(vm.rows[vm.currentIndex].ProductBarcode, false);
  96. } else {
  97. vm.result = true;
  98. resultMap.set(vm.rows[vm.currentIndex].ProductBarcode, true);
  99. }
  100. vm.currentIndex++;
  101. if (vm.currentIndex < vm.rows.length) {
  102. vm.ChangeFuelPrice();
  103. }
  104. else{
  105. vm.showResult = true;
  106. //vm.result = succeed;
  107. vm.GetData();
  108. }
  109. })
  110. //vm.rows.forEach(function (value) {
  111. // if (value.NewPrice === null || value.NewPrice === "") {
  112. // resultMap.set(value.ProductBarcode, false);
  113. // return;
  114. // }
  115. // var tempPara = new Array();
  116. // tempPara.push(value.ProductBarcode);
  117. // tempPara.push(value.NewPrice*1);
  118. // GetDataByAPIS("ChangeFuelPriceAsync", tempPara, "post", function (response) {
  119. // if (response === null || response.length === 0) {
  120. // resultMap.set(value.ProductBarcode, false);
  121. // } else {
  122. // succeed = true;
  123. // resultMap.set(value.ProductBarcode, true);
  124. // }
  125. // if (resultMap.size === vm.rows.length) {
  126. // vm.showResult = true;
  127. // vm.result = succeed;
  128. // vm.GetData();
  129. // }
  130. // })
  131. //});
  132. }
  133. },
  134. mounted: function () {
  135. this.GetData();
  136. }
  137. })
  138. </script>