Currency.cshtml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. @using ShwasherSys.Authorization.Permissions
  2. @using ShwasherSys.BasicInfo
  3. @using ShwasherSys.Models.Layout
  4. @using ShwasherSys.Models.Modal
  5. @{
  6. /**/
  7. ViewBag.ActiveMenu = PermissionNames.PagesBasicInfoCurrency; //The menu item will be active for this page.
  8. ViewBag.Title = "货币汇率信息管理";
  9. // List<SelectListItem> classification = ViewBag.Classification;
  10. //var regionInfo = ViewBag.RegionInfo;
  11. List<Currency> loCurrency = ViewBag.Currency;
  12. }
  13. @section styles
  14. {
  15. <style>
  16. .form-group-sm > div {
  17. margin-bottom: 1rem;
  18. }
  19. .toRate {
  20. border: 1px solid rebeccapurple;
  21. border-radius: 4px;
  22. padding: 3px 10px;
  23. margin-top: 3px;
  24. }
  25. .toRate:after, .toRate:before {
  26. display: table;
  27. content: " ";
  28. }
  29. .toRate:after {
  30. clear: both;
  31. }
  32. label.error {
  33. bottom: 4px;
  34. right: -45px;
  35. }
  36. </style>
  37. }
  38. <div class="table-box mr-4 iwb-bootstrap-table">
  39. @Html.Action("ToolMenu", "Layout", new { pageName = ViewBag.ActiveMenu })
  40. <table id="table"
  41. data-url="/api/services/app/Currency/GetAll"
  42. data-striped="true" data-id-field="id" data-unique-id="id"
  43. data-method="post"
  44. data-side-pagination="server"
  45. data-content-type="application/x-www-form-urlencoded; charset=UTF-8"
  46. data-cache="false"
  47. data-pagination="true" data-page-size="30" data-page-number="1" data-page-list="[30,50,100,200]" data-pagination-detail-h-align="right" data-pagination-h-align="left"
  48. data-query-params="QueryParams"
  49. data-response-handler="ResponseHandler"
  50. data-click-to-select="true"
  51. data-single-select="true">
  52. <thead>
  53. <tr class="row" id="header">
  54. <th data-field="state" data-checkbox="true"></th>
  55. <th data-align="center" data-field="id">货币代码</th>
  56. <th data-align="center" data-field="currencyName">货币名称</th>
  57. </tr>
  58. </thead>
  59. </table>
  60. </div>
  61. @section modal{
  62. <section>
  63. <!--Main Modal-->
  64. <div class="modal fade" id="modal" role="dialog" tabindex="-1" aria-labelledby="ModalLabel" aria-hidden="true">
  65. <div class="modal-dialog modal-dialog-centered" role="document">
  66. <div class="modal-content">
  67. @*@Html.Partial("Modals/_ModalHeader", new ModalHeaderViewModel("办公场所"))
  68. @{
  69. var inputs = new List<InputViewModel>
  70. {
  71. new InputViewModel("id", displayName: "货币代码"),
  72. new InputViewModel("currencyName", displayName: "货币名称").SetOuterAfter("<div class=\"form-group-sm\" style=\"float: right;right:15px;\"><button type=\"button\" class=\"btn btn-sm btn-info\" style=\"width:100%; background-color: #583d9c;border-color: #583d9c;\" onclick=\"AddRate()\">增加换算汇率</button></div>"),
  73. };
  74. //var specials = new List<SpecialInputModel>();
  75. }
  76. @Html.Partial("Modals/_ModalBody", new ModalBodyViewModel(inputs))
  77. @Html.Partial("Modals/_ModalFooter", "0")*@
  78. <div class="modal-header" style="cursor: move;">
  79. <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span aria-hidden="true">×</span></button>
  80. <h4 class="modal-title">
  81. <span class="modal-title-span">添加</span>
  82. <span>货币信息</span>
  83. </h4>
  84. </div>
  85. <div class="modal-body container-fluid" style="padding-top: 15px;padding-bottom: 0;">
  86. <form class="pr-3 pl-3 form-horizontal " id="form">
  87. <div class="form-group-sm">
  88. <label class="iwb-label col-md-2 control-label iwb-label-required" for="id">货币代码</label>
  89. <div class="col-md-10">
  90. <input class="form-control" id="id" name="id" type="text" required="" placeholder="请输入货币代码..." value="" style="">
  91. </div>
  92. </div>
  93. <div class="form-group-sm">
  94. <label class="iwb-label col-md-2 control-label iwb-label-required" for="currencyName">货币名称</label>
  95. <div class="col-md-10">
  96. <input class="form-control" id="currencyName" name="currencyName" type="text" required="" placeholder="请输入货币名称..." value="" style="">
  97. </div>
  98. </div>
  99. <div class="form-group-sm" style="margin-right: 15px;text-align: right"><button type="button" class="btn btn-sm btn-info" style="width:20%; background-color: #583d9c;border-color: #583d9c;" onclick="AddRate()">增加换算汇率</button></div>
  100. </form>
  101. </div>
  102. <div class="modal-footer" style="text-align: center;">
  103. <button type="button" class="btn btn-default waves-effect" data-dismiss="modal" style="min-width:100px;background: #FFFFFF;border: 1px solid #DDDDDD;">取消</button>
  104. <button type="button" class="btn btn-success save-btn waves-effect" style="min-width:100px;background-color: #678ceb;border: 1px solid #678ceb;">保存</button>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </section>
  110. }
  111. @section scripts
  112. {
  113. <script src="~/Content/Plugins/select2/js/select2tree.js"></script>
  114. @*<script src="~/Content/Plugins/kindeditor/kindeditor-all.js"></script>
  115. <script src="~/Content/Plugins/kindeditor/lang/zh-CN.js"></script>*@
  116. <script type="text/javascript">
  117. //var exId = "";
  118. var allCurrency = [];
  119. $(function() {
  120. //show完毕前执行
  121. @{
  122. foreach (var currency in loCurrency)
  123. {
  124. <text>
  125. allCurrency.push({ Id: "@currency.Id", CurrencyName: "@currency.CurrencyName" });
  126. </text>
  127. }
  128. }
  129. LoadTable();
  130. var funs = window.funs || { none: function() { console.log("No type"); } };
  131. funs["btnUpdate"] = function(url) { BtnUpdate(url); };
  132. funs["btnCreate"] = function(url) { BtnCreate(url); };
  133. });
  134. function BtnCreate(url) {
  135. console.log("Create");
  136. $(".toRate").remove();
  137. exId = "";
  138. OpenModal({
  139. modaltitle: window.opCreate,
  140. //data: getFormData(),
  141. url: url,
  142. //success: function(res) {
  143. // allCurrency.push({ Id: res.id, CurrencyName: res.currencyName });
  144. // $("#modal").modal("hide");
  145. // RefreshTable($("#table"));
  146. //},
  147. save: function() {
  148. SaveAjax({
  149. url: url,
  150. data: getFormData(),
  151. success: function(res) {
  152. allCurrency.push({ Id: res.id, CurrencyName: res.currencyName });
  153. $("#modal").modal("hide");
  154. RefreshTable($("#table"));
  155. }
  156. });
  157. }
  158. });
  159. }
  160. function BtnUpdate(url) {
  161. var row = $("#table").bootstrapTable("getSelections")[0];
  162. if (row) {
  163. $(".toRate").remove();
  164. SaveAjax({
  165. url: window.appUrl + 'Currency/GetDtoById?id=' + row.id,
  166. isValidate: false,
  167. isAlert:false,
  168. success: function (res) {
  169. console.log(res);
  170. OpenModal({
  171. modaltitle: window.opUpdate,
  172. data: row,
  173. url: url,
  174. readonly: "id",
  175. save: function() {
  176. SaveAjax({
  177. url: url,
  178. data: getFormData(),
  179. success: function(res) {
  180. $("#modal").modal("hide");
  181. RefreshTable($("#table"));
  182. }
  183. });
  184. }
  185. });
  186. var rs = res.currencyExchangeRates;
  187. rs.forEach(function(v, i) {
  188. AddRate();
  189. $('.toRate:eq(' + i +') [name="toCurrencyId"]').val(v.toCurrencyId).select2();
  190. $('.toRate:eq(' + i +') [name="exchangeRate"]').val(v.exchangeRate);
  191. });
  192. }
  193. });
  194. }
  195. }
  196. //function BtnUpdate(url) {
  197. // console.log("Update");
  198. // var row = $("#table").bootstrapTable("getSelections")[0];
  199. // if (row) {
  200. // abp.ajax({
  201. // contentType: 'application/x-www-form-urlencoded',
  202. // url: "/api/services/app/Regions/GetRegionSelectStrs",
  203. // success: function(res) {
  204. // $("#regionID").empty().html(res);
  205. // //var url = $($this).data("url") + "";
  206. // OpenModal({
  207. // modaltitle: window.opUpdate,
  208. // data: row,
  209. // url: url,
  210. // readonly: "id",
  211. // select2tree: "regionID"
  212. // });
  213. // }
  214. // });
  215. // } else {
  216. // abp.message.warn(abp.localization.localize("ChooseOneToOp"));
  217. // }
  218. //}
  219. function AddRate() {
  220. var str = ' <div class="toRate">';
  221. str += '<label class="iwb-label col-md-2 control-label iwb-label-required" for="currencyName">货币名称</label>';
  222. str += ' <div class="col-md-3">';
  223. str +=
  224. ' <select class="form-control" name="toCurrencyId" type="text" placeholder="请输入货币名称..." value="" style="width: 100%; ">';
  225. str += getOptions() + ' </select>';
  226. str += '</div>';
  227. str += '<label class="iwb-label col-md-2 control-label iwb-label-required" for="currencyName">汇率</label>';
  228. str += '<div class="col-md-3">';
  229. str +=
  230. '<input class="form-control" name="exchangeRate" type="number" min="0" placeholder="请输入汇率..." value="" style="">';
  231. str += '</div>';
  232. str += ' <div class="col-md-2">';
  233. str +=
  234. ' <button type="button" class="btn btn-sm btn-danger" style="width:90%; " onclick="DeleteRate(this)">删除</button>';
  235. str += ' </div>';
  236. str += '</div>';
  237. $("#form").append(str);
  238. }
  239. function DeleteRate(that) {
  240. $(that).closest('.toRate').remove();
  241. }
  242. function getOptions() {
  243. var options = "";
  244. allCurrency.forEach(function(v, i) {
  245. options += '<option value="' + v.Id + '">' + v.CurrencyName + '</option>';
  246. });
  247. return options;
  248. }
  249. function getFormData() {
  250. var d = {
  251. Id: $("#form #id").val(),
  252. CurrencyName: $("#form #currencyName").val(),
  253. CurrencyExchangeRates: []
  254. };
  255. var rates = $('.toRate');
  256. console.log(rates);
  257. for (var i =0; i < rates.length; i++) {
  258. //console.log($('.toRate:nth-of-type(' + i + ') [name="toCurrencyId"]'));
  259. //console.log($('.toRate:nth-of-type(' + i + ')'));
  260. d.CurrencyExchangeRates[i] = {
  261. ToCurrencyId: $('.toRate:eq('+i+') [name="toCurrencyId"]').val(),
  262. ExchangeRate: $('.toRate:eq(' + i +') [name="exchangeRate"]').val()
  263. }
  264. }
  265. //rates.forEach(function(v, i) {
  266. // d.CurrencyExchangeRates[i] = {
  267. // ToCurrencyId: $(v + ' [name="toCurrencyId"]').val(),
  268. // ExchangeRate: $(v + ' [name="exchangeRate"]').val()
  269. // }
  270. //});
  271. //console.log(d);
  272. return d;
  273. }
  274. </script>
  275. }