partner.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. myApp.controller("partner", ["$scope", "$http", "$timeout", "NgTableParams", function ($scope, $http, $timeout, NgTableParams) {
  2. var self = this;
  3. $scope.isAdd = true;
  4. $scope.allowUpload = false;
  5. $scope.partner = {};
  6. $scope.kw = "";
  7. $scope.paginationConf = {
  8. currentPage: 1,
  9. itemsPerPage: 10,
  10. pagesLength: 25,
  11. perPageOptions: [10, 15, 20, 30, 50, 100, 200],
  12. rememberPerPage: 'perPageItems',
  13. onChange: function () {
  14. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  15. }
  16. };
  17. this.GetPageData = function (page, size) {
  18. $http.get(`/partner/getpagedata?page=${page}&size=${size}&kw=${$scope.kw}`).then(function (res) {
  19. $scope.paginationConf.totalItems = res.data.TotalCount;
  20. $("div[ng-table-pagination]").remove();
  21. self.tableParams = new NgTableParams({
  22. count: 50000
  23. }, {
  24. filterDelay: 0,
  25. dataset: res.data.Data
  26. });
  27. self.data = res.data.Data;
  28. $timeout(function () {
  29. self.data.forEach(item => {
  30. xmSelect.render({
  31. el: '#category-' + item.Id,
  32. tips: '未选择分类',
  33. prop: {
  34. name: 'Name',
  35. value: 'Id',
  36. children: 'Children',
  37. },
  38. //model: { label: { type: 'text' } },
  39. tree: {
  40. show: true,
  41. strict: false,
  42. expandedKeys: true,
  43. },
  44. filterable: true, //搜索功能
  45. autoRow: true, //选项过多,自动换行
  46. data: $scope.cat,
  47. initValue: (item.CategoryIds || "").split(","),
  48. on: function (data) {
  49. var arr = [];
  50. for (var i = 0; i < data.arr.length; i++) {
  51. arr.push(data.arr[i].Id);
  52. }
  53. $http.post(`/partner/${item.Id}/categories?cids=` + arr.join(",")).then(function (res) {
  54. if (data.status >= 400) {
  55. layer.msg("操作失败");
  56. }
  57. });
  58. }
  59. });
  60. });
  61. }, 1);
  62. });
  63. }
  64. $scope.typesDropdown = xmSelect.render({
  65. el: '#types',
  66. tips: '请选择推广区域',
  67. direction: 'up',
  68. autoRow: true, //选项过多,自动换行
  69. data: [{ name: "轮播图", value: 1 }, { name: "列表项", value: 2 }, { name: "边栏", value: 3 }, { name: "内页", value: 4 }],
  70. on: function (data) {
  71. var arr = [];
  72. for (var i = 0; i < data.arr.length; i++) {
  73. arr.push(data.arr[i].value);
  74. }
  75. $scope.partner.Types = arr.join(",");
  76. }
  77. });
  78. $scope.regionDropdown = xmSelect.render({
  79. el: '#regionMode',
  80. tips: '区域',
  81. model: {
  82. icon: 'hidden',
  83. label: { type: 'text' }
  84. },
  85. radio: true,
  86. clickClose: true,
  87. direction: 'up',
  88. filterable: false, //搜索功能
  89. autoRow: false, //选项过多,自动换行
  90. data: [{ name: "不限", value: 0 }, { name: "以内", value: 1 }, { name: "以外", value: 2 }],
  91. on: function (data) {
  92. if (data.arr.length > 0) {
  93. $scope.partner.RegionMode = data.arr[0].value;
  94. }
  95. }
  96. });
  97. $scope.regionDropdown.setValue([0]);
  98. $scope.getCategory = function () {
  99. $http.get("/category/getcategories").then(function (res) {
  100. var data = res.data;
  101. if (data.Success) {
  102. $scope.cat = data.Data;
  103. $scope.categoryDropdown = xmSelect.render({
  104. el: '#category',
  105. tips: '请选择分类',
  106. prop: {
  107. name: 'Name',
  108. value: 'Id',
  109. children: 'Children',
  110. },
  111. direction: 'up',
  112. tree: {
  113. show: true,
  114. strict: false,
  115. expandedKeys: true,
  116. },
  117. filterable: true, //搜索功能
  118. autoRow: true, //选项过多,自动换行
  119. data: data.Data,
  120. on: function (data) {
  121. var arr = [];
  122. for (var i = 0; i < data.arr.length; i++) {
  123. arr.push(data.arr[i].Id);
  124. }
  125. $scope.partner.CategoryIds = arr.join(",");
  126. }
  127. });
  128. } else {
  129. window.notie.alert({
  130. type: 3,
  131. text: '获取文章分类失败!',
  132. time: 4
  133. });
  134. }
  135. });
  136. }
  137. $scope.getCategory();
  138. $scope.remove = function (partner) {
  139. layer.closeAll();
  140. swal({
  141. title: '确定移除这条广告吗?',
  142. text: partner.Title,
  143. showCancelButton: true,
  144. confirmButtonColor: '#3085d6',
  145. cancelButtonColor: '#d33',
  146. confirmButtonText: '确定',
  147. cancelButtonText: '取消'
  148. }).then(function (isConfirm) {
  149. if (isConfirm) {
  150. $scope.request("/partner/delete/" + partner.Id, null, function (data) {
  151. window.notie.alert({
  152. type: 1,
  153. text: data.Message,
  154. time: 4
  155. });
  156. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  157. });
  158. }
  159. }).catch(swal.noop);
  160. }
  161. $scope.add = function () {
  162. $scope.partner = {
  163. ExpireTime: "2049-12-31 23:59:59"
  164. };
  165. $scope.isAdd = true;
  166. $scope.allowUpload = false;
  167. layer.open({
  168. type: 1,
  169. zIndex: 20,
  170. title: '添加广告推广',
  171. area: (window.screen.width > 650 ? 650 : window.screen.width) + 'px',// '340px'], //宽高
  172. content: $("#edit"),
  173. cancel: function (index, layero) {
  174. setTimeout(function () {
  175. $("#edit").css("display", "none");
  176. }, 500);
  177. return true;
  178. }
  179. });
  180. layui.use('laydate', function () {
  181. var laydate = layui.laydate;
  182. laydate.render({
  183. elem: '#timespan',
  184. type: 'datetime',
  185. calendar: true,
  186. done: function (value, date, endDate) {
  187. $scope.partner.ExpireTime = value;
  188. }
  189. });
  190. });
  191. }
  192. $scope.edit = function (item) {
  193. $scope.partner = angular.copy(item);
  194. $scope.partner.ExpireTime = $scope.partner.ExpireTime == null ? "2049-12-31 23:59:59" : new Date($scope.partner.ExpireTime).Format("yyyy-MM-dd hh:mm:ss");
  195. $scope.isAdd = false;
  196. $scope.allowUpload = false;
  197. layer.closeAll();
  198. $scope.categoryDropdown.setValue((item.CategoryIds || "").split(','));
  199. $scope.typesDropdown.setValue(item.Types.split(','));
  200. $scope.regionDropdown.setValue([item.RegionMode]);
  201. layer.open({
  202. type: 1,
  203. zIndex: 20,
  204. title: '保存广告',
  205. area: (window.screen.width > 650 ? 650 : window.screen.width) + 'px',// '340px'], //宽高
  206. content: $("#edit"),
  207. cancel: function (index, layero) {
  208. setTimeout(function () {
  209. $("#edit").css("display", "none");
  210. }, 500);
  211. return true;
  212. }
  213. });
  214. layui.use('laydate', function () {
  215. var laydate = layui.laydate;
  216. laydate.render({
  217. elem: '#timespan',
  218. type: 'datetime',
  219. calendar: true,
  220. done: function (value, date, endDate) {
  221. $scope.partner.ExpireTime = value;
  222. }
  223. });
  224. });
  225. }
  226. $scope.copy = function (item) {
  227. $scope.partner = angular.copy(item);
  228. delete $scope.partner.Id;
  229. $scope.partner.ExpireTime = $scope.partner.ExpireTime == null ? "2049-12-31 23:59:59" : new Date($scope.partner.ExpireTime).Format("yyyy-MM-dd hh:mm:ss");
  230. $scope.isAdd = true;
  231. $scope.allowUpload = false;
  232. layer.closeAll();
  233. $scope.categoryDropdown.setValue((item.CategoryIds || "").split(','));
  234. $scope.typesDropdown.setValue(item.Types.split(','));
  235. $scope.regionDropdown.setValue([0]);
  236. layer.open({
  237. type: 1,
  238. zIndex: 20,
  239. title: '复制广告推广',
  240. area: (window.screen.width > 650 ? 650 : window.screen.width) + 'px',// '340px'], //宽高
  241. content: $("#edit"),
  242. cancel: function (index, layero) {
  243. setTimeout(function () {
  244. $("#edit").css("display", "none");
  245. }, 500);
  246. return true;
  247. }
  248. });
  249. layui.use('laydate', function () {
  250. var laydate = layui.laydate;
  251. laydate.render({
  252. elem: '#timespan',
  253. type: 'datetime',
  254. calendar: true,
  255. done: function (value, date, endDate) {
  256. $scope.partner.ExpireTime = value;
  257. }
  258. });
  259. });
  260. }
  261. $scope.closeAll = function () {
  262. layer.closeAll();
  263. setTimeout(function () {
  264. $("#edit").css("display", "none");
  265. }, 500);
  266. }
  267. $scope.submit = function (partner) {
  268. if ($scope.isAdd) {
  269. partner.Id = 0;
  270. }
  271. $scope.request("/partner/save", partner, function (data) {
  272. $scope.closeAll();
  273. window.notie.alert({
  274. type: 1,
  275. text: data.Message,
  276. time: 4
  277. });
  278. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  279. $scope.partner.ImageUrl = "";
  280. $scope.partner.Description = "";
  281. $scope.categoryDropdown.setValue([]);
  282. $scope.typesDropdown.setValue([]);
  283. $scope.regionDropdown.setValue([0]);
  284. });
  285. }
  286. $scope.uploadImage = function (field) {
  287. $("#uploadform").ajaxSubmit({
  288. url: "/Upload",
  289. type: "post",
  290. success: function (data) {
  291. document.getElementById("uploadform").reset();
  292. $scope.$apply(function () {
  293. $scope.partner[field] = data.Data;
  294. layer.close(layer.index);
  295. });
  296. }
  297. });
  298. };
  299. $scope.upload = function (field) {
  300. $scope.imgField = field;
  301. layer.open({
  302. type: 1,
  303. zIndex: 20,
  304. title: '上传图片',
  305. area: [(window.screen.width > 300 ? 300 : window.screen.width) + 'px', '80px'], //宽高
  306. content: $("#img-upload"),
  307. cancel: function (index, layero) {
  308. return true;
  309. }
  310. });
  311. }
  312. var _timeout;
  313. $scope.search = function (kw) {
  314. if (_timeout) {
  315. $timeout.cancel(_timeout);
  316. }
  317. _timeout = $timeout(function () {
  318. $scope.kw = kw;
  319. self.GetPageData($scope.paginationConf.currentPage, $scope.paginationConf.itemsPerPage);
  320. _timeout = null;
  321. }, 500);
  322. }
  323. $scope.changeState = function (row) {
  324. $scope.request("/partner/ChangeState/" + row.Id, null, function (data) {
  325. window.notie.alert({
  326. type: 1,
  327. text: data.Message,
  328. time: 4
  329. });
  330. });
  331. }
  332. $scope.detail = function (item) {
  333. $scope.partner = angular.copy(item);
  334. layer.closeAll();
  335. $scope.typesDropdown.setValue(item.Types.split(','));
  336. layer.open({
  337. type: 1,
  338. zIndex: 20,
  339. offset: '50px',
  340. title: item.Title,
  341. area: (window.screen.width > 850 ? 850 : window.screen.width) + 'px',// '340px'], //宽高
  342. content: $("#detail"),
  343. cancel: function (index, layero) {
  344. return true;
  345. }
  346. });
  347. xmSelect.render({
  348. el: '#category-view',
  349. tips: '未选择分类',
  350. disabled: true,
  351. prop: {
  352. name: 'Name',
  353. value: 'Id',
  354. children: 'Children',
  355. },
  356. tree: {
  357. show: true,
  358. strict: false,
  359. expandedKeys: true,
  360. },
  361. autoRow: true, //选项过多,自动换行
  362. data: $scope.cat,
  363. initValue: (item.CategoryIds || "").split(",")
  364. });
  365. xmSelect.render({
  366. el: '#types-view',
  367. disabled: true,
  368. autoRow: true, //选项过多,自动换行
  369. data: [{ name: "轮播图", value: 1 }, { name: "列表项", value: 2 }, { name: "边栏", value: 3 }, { name: "内页", value: 4 }],
  370. initValue: (item.Types || "").split(",")
  371. });
  372. }
  373. $scope.delayShow = function (item) {
  374. $scope.partner = item;
  375. $scope.isAdd = false;
  376. $scope.partner.ExpireTime = new Date($scope.partner.ExpireTime).Format("yyyy-MM-dd hh:mm:ss");
  377. layer.open({
  378. type: 1,
  379. zIndex: 20,
  380. title: "延期广告",
  381. content: $("#delay"),
  382. cancel: function (index, layero) {
  383. return true;
  384. }
  385. });
  386. layui.use('laydate', function () {
  387. var laydate = layui.laydate;
  388. laydate.render({
  389. elem: '.timespan',
  390. type: 'datetime',
  391. calendar: true,
  392. done: function (value, date, endDate) {
  393. $scope.partner.ExpireTime = value;
  394. }
  395. });
  396. });
  397. }
  398. $scope.insight = function (row) {
  399. layer.full(layer.open({
  400. type: 2,
  401. title: '广告《' + row.Title + '》洞察分析',
  402. maxmin: true, //开启最大化最小化按钮
  403. area: ['893px', '100vh'],
  404. content: '/partner/' + row.Id + '/insight'
  405. }));
  406. }
  407. }]);