TradeRecordSIM_Admin.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. var ExcelData;
  2. function ConfirmImport() {
  3. $.ajax({
  4. type: "POST",
  5. url: "/Admin/TradeRecord/Import?r=" + Math.random(1),
  6. data: "ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  7. dataType: "text",
  8. success: function (data) {
  9. if (data == "success") {
  10. layer.msg("导入成功", { time: 2000 }, function () {
  11. window.location.reload();
  12. });
  13. } else {
  14. layer.msg(data);
  15. }
  16. }
  17. });
  18. }
  19. function ConfirmImportTrade() {
  20. $.ajax({
  21. type: "POST",
  22. url: "/Admin/TradeRecord/ImportTrade?r=" + Math.random(1),
  23. data: "ExcelData=" + encodeURIComponent(JSON.stringify(ExcelData)),
  24. dataType: "text",
  25. success: function (data) {
  26. if (data == "success") {
  27. layer.msg("导入成功", { time: 2000 }, function () {
  28. window.location.reload();
  29. });
  30. } else {
  31. layer.msg(data);
  32. }
  33. }
  34. });
  35. }
  36. function CheckImport(table, key, loadindex, index) {
  37. $.ajax({
  38. url: "/Admin/TradeRecord/CheckImportV2?r=" + Math.random(1),
  39. data: "key=" + key,
  40. dataType: "json",
  41. success: function (data) {
  42. console.log(data);
  43. if (data.status == 1) {
  44. layer.msg("成功操作" + data.data + "条", {
  45. time: 2000
  46. }, function () {
  47. layer.close(index); //关闭弹层
  48. layer.close(loadindex);
  49. table.reload('LAY-list-manage'); //数据刷新
  50. });
  51. } else if (data.status == 2) {
  52. layer.close(index); //关闭弹层
  53. layer.close(loadindex);
  54. var content = '';
  55. for (var i = 0; i < data.errList.length; i++) {
  56. content += data.errList[i] + '<br/>'
  57. }
  58. layer.alert(content);
  59. } else {
  60. layer.msg(data.data, {
  61. time: 1000
  62. }, function () {
  63. CheckImport(table, key, loadindex, index);
  64. });
  65. }
  66. }
  67. });
  68. }
  69. var excel;
  70. layui.config({
  71. base: '/layuiadmin/' //静态资源所在路径
  72. }).extend({
  73. myexcel: 'layui/lay/modules/excel',
  74. index: 'lib/index' //主入口模块
  75. }).use(['index', 'table', 'excel', 'laydate'], function () {
  76. var $ = layui.$
  77. , form = layui.form
  78. , table = layui.table;
  79. //- 筛选条件-日期
  80. var laydate = layui.laydate;
  81. var layCreateDate = laydate.render({
  82. elem: '#CreateDate',
  83. type: 'date',
  84. range: true,
  85. trigger: 'click',
  86. change: function (value, date, endDate) {
  87. var op = true;
  88. if (date.year == endDate.year && endDate.month - date.month <= 1) {
  89. if (endDate.month - date.month == 1 && endDate.date > date.date) {
  90. op = false;
  91. layCreateDate.hint('日期范围请不要超过1个月');
  92. setTimeout(function () {
  93. $(".laydate-btns-confirm").addClass("laydate-disabled");
  94. }, 1);
  95. }
  96. } else {
  97. op = false;
  98. layCreateDate.hint('日期范围请不要超过1个月');
  99. setTimeout(function () {
  100. $(".laydate-btns-confirm").addClass("laydate-disabled");
  101. }, 1);
  102. }
  103. if (op) {
  104. $('#CreateDate').val(value);
  105. }
  106. }
  107. });
  108. var layTradeDate = laydate.render({
  109. elem: '#TradeDate',
  110. trigger: 'click',
  111. type: 'date',
  112. range: true,
  113. change: function (value, date, endDate) {
  114. var op = true;
  115. if (date.year == endDate.year && endDate.month - date.month <= 2) {
  116. if (endDate.month - date.month == 2 && endDate.date > date.date) {
  117. op = false;
  118. layTradeDate.hint('日期范围请不要超过2个月');
  119. setTimeout(function () {
  120. $(".laydate-btns-confirm").addClass("laydate-disabled");
  121. }, 1);
  122. }
  123. } else {
  124. op = false;
  125. layTradeDate.hint('日期范围请不要超过2个月');
  126. setTimeout(function () {
  127. $(".laydate-btns-confirm").addClass("laydate-disabled");
  128. }, 1);
  129. }
  130. if (op) {
  131. $('#TradeDate').val(value);
  132. }
  133. }
  134. });
  135. //excel导入
  136. excel = layui.excel;
  137. $('#ExcelFile').change(function (e) {
  138. var files = e.target.files;
  139. excel.importExcel(files, {}, function (data) {
  140. ExcelData = data[0].sheet1;
  141. });
  142. });
  143. //监听单元格编辑
  144. table.on('edit(LAY-list-manage)', function (obj) {
  145. var value = obj.value //得到修改后的值
  146. , data = obj.data //得到所在行所有键值
  147. , field = obj.field; //得到字段
  148. if (field == "Sort") {
  149. $.ajax({
  150. type: "POST",
  151. url: "/Admin/TradeRecord/Sort?r=" + Math.random(1),
  152. data: "Id=" + data.Id + "&Sort=" + value,
  153. dataType: "text",
  154. success: function (data) {
  155. }
  156. });
  157. }
  158. });
  159. //激活预览列表数据
  160. table.render({
  161. elem: '#LAY-list-manage'
  162. , url: '/Admin/TradeRecord/IndexDataSIMDo' //模拟接口
  163. , cols: [[
  164. { type: 'checkbox', fixed: 'left' }
  165. , { field: 'iccId', width: 200, title: '广电卡号', sort: true } //广电卡号
  166. , { field: 'orderNo', width: 200, title: '订单编码', sort: true } //订单编码
  167. , { field: 'orderCreateTime', width: 200, title: '订单创建时间', sort: true } //订单创建时间
  168. , { field: 'phoneNo', width: 200, title: '选择号码', sort: true } //选择号码
  169. , { field: 'firstCharge', width: 200, title: '是否有首充', sort: true } //是否有首充
  170. , { field: 'initialChargeAmount', width: 200, title: '首充金额(元)', sort: true } //首充金额(元)
  171. , { field: 'province', width: 200, title: '号码归属省份', sort: true } //号码归属省份
  172. , { field: 'city', width: 200, title: '号码归属地市', sort: true } //号码归属地市
  173. , { field: 'productName', width: 200, title: '商品名称', sort: true } //商品名称
  174. , { field: 'promotionName', width: 200, title: '促销活动名称', sort: true } //促销活动名称
  175. , { field: 'productTypeName', width: 200, title: '商品类型名称', sort: true } //商品类型名称
  176. , { field: 'paidInAmount', width: 200, title: '实付金额', sort: true } //实付金额(元)
  177. , { field: 'orderStatus', width: 200, title: '订单状态', sort: true } //订单状态
  178. , { field: 'activationStatusName', width: 200, title: '激活状态名称', sort: true } //激活状态名称
  179. , { field: 'activationTime', width: 200, title: '激活时间', sort: true } //激活时间
  180. , { field: 'jobId', width: 200, title: 'BOSS员工工号', sort: true } //BOSS员工工号
  181. ]]
  182. , where: {
  183. DateStr: DateStr
  184. }
  185. , page: true
  186. , limit: 30
  187. , height: 'full-' + String($('.layui-card-header').height() + 130)
  188. , text: '对不起,加载出现异常!'
  189. , done: function (res, curr, count) {
  190. $(".layui-none").text("无数据");
  191. }
  192. });
  193. //监听搜索
  194. form.on('submit(LAY-list-front-search)', function (data) {
  195. var field = data.field;
  196. //执行重载
  197. table.reload('LAY-list-manage', {
  198. where: field,
  199. page: {
  200. curr: 1
  201. }
  202. });
  203. });
  204. form.on('submit(LAY-list-front-searchall)', function (data) {
  205. table.reload('LAY-list-manage', {
  206. where: null,
  207. page: {
  208. curr: 1
  209. }
  210. });
  211. });
  212. //事件
  213. var active = {
  214. GetActInfo: function () {
  215. var perContent = layer.open({
  216. type: 2
  217. , title: '获取广电卡激活数据'
  218. , content: 'GetSimTrade'
  219. , maxmin: true
  220. , area: ['500px', '450px']
  221. , btn: ['确定', '取消']
  222. , yes: function (index, layero) {
  223. var iframeWindow = window['layui-layer-iframe' + index]
  224. , submitID = 'LAY-list-front-submit'
  225. , submit = layero.find('iframe').contents().find('#' + submitID);
  226. setTimeout(function () {
  227. layero.find('iframe').contents().find('.layui-tab-item').each(function (i) {
  228. var errObj = $(this).find('.layui-form-danger');
  229. if (errObj.length > 0) {
  230. iframeWindow.element.tabChange('mytabbar', String(i + 1));
  231. submit.click();
  232. }
  233. });
  234. }, 300);
  235. //监听提交
  236. iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
  237. var field = data.field; //获取提交的字段
  238. var userdata = "";
  239. for (var prop in field) {
  240. userdata += prop + "=" + encodeURIComponent(field[prop]) + "&";
  241. }
  242. //提交 Ajax 成功后,静态更新表格中的数据
  243. //$.ajax({});
  244. $.ajax({
  245. type: "POST",
  246. url: "/Admin/TradeRecord/GetSimTradePost?r=" + Math.random(1),
  247. data: userdata,
  248. dataType: "text",
  249. success: function (data) {
  250. layer.close(index); //关闭弹层
  251. if (data == "success") {
  252. layer.msg("提交成功");
  253. } else {
  254. layer.msg(data);
  255. }
  256. }
  257. });
  258. });
  259. submit.trigger('click');
  260. }
  261. });
  262. }
  263. };
  264. $('.layui-btn').on('click', function () {
  265. var type = $(this).data('type');
  266. active[type] ? active[type].call(this) : '';
  267. });
  268. });