PriceChangeRnav.cshtml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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">{{$t('Product')}}</label>
  6. <label class="price-form-label">{{$t('CurrentPrice')}}</label>
  7. <label class="price-form-label">{{$t('NewPrice')}}</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. //let url = '/api/fuelprice'
  47. //InvokeHttpPost(url, JSON.stringify(this.rows), function (res) {
  48. // vm.showResult = true
  49. // vm.result = res.value
  50. //})
  51. return false
  52. },
  53. GetData() {
  54. var temp = {
  55. "parameters": [
  56. { "name": "pumpId", "value": "-1" }
  57. ]
  58. };
  59. GetDataByAPIS("GetPumpsLayout", temp, "post", function (response) {
  60. console.log(response);
  61. if (response === null || response.length === 0) return;
  62. vm.rows.splice(0, vm.rows.length);
  63. var tempMap = new Map();
  64. response.forEach(function (p) {
  65. p.Nozzles.forEach(function (n) {
  66. if (n.ProductBarcode !== null && !tempMap.has(n.ProductBarcode)) {
  67. tempMap.set(n.ProductBarcode, {
  68. "FuelName": n.ProductName,
  69. "CurrentPrice": n.RealPriceOnPhysicalPump === null ? 0 : n.RealPriceOnPhysicalPump / Math.pow(10, p.AmountDecimalDigits), "NewPrice": null, "ProductBarcode": n.ProductBarcode
  70. });
  71. }
  72. });
  73. });
  74. tempMap.forEach(function (value, key) {
  75. vm.rows.push(value);
  76. });
  77. vm.receiveData = true;
  78. tempMap.clear();
  79. });
  80. },
  81. ChangeFuelPrice() {
  82. if (vm.rows.length === 0) return;
  83. var resultMap = new Map();
  84. //var succeed = false;
  85. if (vm.currentIndex > vm.rows.length - 1 ||
  86. vm.rows[vm.currentIndex].NewPrice === null || vm.rows[vm.currentIndex].NewPrice === "") {
  87. vm.currentIndex++;
  88. if (vm.currentIndex < vm.rows.length) vm.ChangeFuelPrice();
  89. else {
  90. vm.showResult = true;
  91. vm.GetData();
  92. }
  93. return;
  94. }
  95. var tempPara = new Array();
  96. tempPara.push(vm.rows[vm.currentIndex].ProductBarcode);
  97. tempPara.push(vm.rows[vm.currentIndex].NewPrice * 1);
  98. GetDataByAPIS("ChangeFuelPriceAsync", tempPara, "post", function (response) {
  99. if (response === null || response.length === 0) {
  100. resultMap.set(vm.rows[vm.currentIndex].ProductBarcode, false);
  101. } else {
  102. vm.result = true;
  103. resultMap.set(vm.rows[vm.currentIndex].ProductBarcode, true);
  104. }
  105. vm.currentIndex++;
  106. if (vm.currentIndex < vm.rows.length) {
  107. vm.ChangeFuelPrice();
  108. }
  109. else{
  110. vm.showResult = true;
  111. //vm.result = succeed;
  112. vm.GetData();
  113. }
  114. })
  115. //vm.rows.forEach(function (value) {
  116. // if (value.NewPrice === null || value.NewPrice === "") {
  117. // resultMap.set(value.ProductBarcode, false);
  118. // return;
  119. // }
  120. // var tempPara = new Array();
  121. // tempPara.push(value.ProductBarcode);
  122. // tempPara.push(value.NewPrice*1);
  123. // GetDataByAPIS("ChangeFuelPriceAsync", tempPara, "post", function (response) {
  124. // if (response === null || response.length === 0) {
  125. // resultMap.set(value.ProductBarcode, false);
  126. // } else {
  127. // succeed = true;
  128. // resultMap.set(value.ProductBarcode, true);
  129. // }
  130. // if (resultMap.size === vm.rows.length) {
  131. // vm.showResult = true;
  132. // vm.result = succeed;
  133. // vm.GetData();
  134. // }
  135. // })
  136. //});
  137. }
  138. },
  139. mounted: function () {
  140. console.log("test");
  141. this.GetData();
  142. //let url = '/api/fuelprice'
  143. //InvokeHttpGet(url, function (res) {
  144. // vm.receive(res)
  145. // vm.receiveData = true
  146. //})
  147. }
  148. })
  149. </script>