notification.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. Table.api.init({
  5. extend: {
  6. index_url: 'shopro/notification/config/index' + location.search,
  7. add_url: 'shopro/notification/config/add',
  8. edit_url: 'shopro/notification/config/edit',
  9. del_url: 'shopro/notification/config/del',
  10. multi_url: 'shopro/notification/config/multi',
  11. table: 'shopro_notification_config',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url: $.fn.bootstrapTable.defaults.extend.index_url,
  18. pk: 'id',
  19. sortName: 'id',
  20. columns: [
  21. [{
  22. checkbox: true
  23. },
  24. {
  25. field: 'id',
  26. title: __('Id')
  27. },
  28. {
  29. field: 'platform',
  30. title: __('Platform')
  31. },
  32. {
  33. field: 'name',
  34. title: __('Name')
  35. },
  36. {
  37. field: 'event',
  38. title: __('Event')
  39. },
  40. {
  41. field: 'status',
  42. title: __('Status'),
  43. searchList: {
  44. "0": __('Status 0'),
  45. "1": __('Status 1')
  46. },
  47. formatter: Table.api.formatter.status
  48. },
  49. {
  50. field: 'createtime',
  51. title: __('Createtime'),
  52. operate: 'RANGE',
  53. addclass: 'datetimerange',
  54. formatter: Table.api.formatter.datetime
  55. },
  56. {
  57. field: 'updatetime',
  58. title: __('Updatetime'),
  59. operate: 'RANGE',
  60. addclass: 'datetimerange',
  61. formatter: Table.api.formatter.datetime
  62. },
  63. {
  64. field: 'operate',
  65. title: __('Operate'),
  66. table: table,
  67. events: Table.api.events.operate,
  68. formatter: Table.api.formatter.operate
  69. }
  70. ]
  71. ]
  72. });
  73. // 为表格绑定事件
  74. Table.api.bindevent(table);
  75. },
  76. config: function () {
  77. var notification_index = new Vue({
  78. el: "#notification-index",
  79. data() {
  80. return {
  81. tipCloseFlag: true,
  82. notificationDialog: false,
  83. notificationData: [],
  84. notificationForm: {},
  85. editIndex:null,
  86. editPlatform:null
  87. }
  88. },
  89. mounted() {
  90. this.getnotificationData();
  91. },
  92. methods: {
  93. getnotificationData(){
  94. let that=this;
  95. Fast.api.ajax({
  96. url: 'shopro/notification/config',
  97. type:'GET',
  98. loading: true,
  99. data: {}
  100. }, function (ret, res) {
  101. that.notificationData=res.data;
  102. return false;
  103. })
  104. },
  105. tipClose() {
  106. this.tipCloseFlag = false;
  107. },
  108. changeStatua(platform, event, name, status) {
  109. let that = this;
  110. Fast.api.ajax({
  111. url: 'shopro/notification/set_status',
  112. loading: true,
  113. type: "POST",
  114. data: {
  115. platform: platform,
  116. event: event,
  117. name: name,
  118. status: status
  119. }
  120. }, function (ret, res) {
  121. that.getnotificationData();
  122. })
  123. },
  124. fieldDel(index){
  125. this.notificationForm.fields.splice(index,1)
  126. },
  127. notificationClose(type) {
  128. let that = this;
  129. if(this.editPlatform!='email'){
  130. that.notificationForm.template_id=that.notificationForm.template_id.replace(/\s*/g,"");
  131. }
  132. if (type == 'yes') {
  133. let content=JSON.stringify(that.notificationForm)
  134. if(this.editPlatform=='email'){
  135. content=$('#c-content').val()
  136. }
  137. Fast.api.ajax({
  138. url: 'shopro/notification/set_template',
  139. loading: true,
  140. data: {
  141. platform: that.editMsg.platform,
  142. event: that.editMsg.event,
  143. name: that.editMsg.name,
  144. content: content
  145. }
  146. }, function (ret, res) {
  147. that.getnotificationData();
  148. that.notificationDialog = false;
  149. that.notificationForm = {};
  150. that.editMsg={};
  151. })
  152. } else {
  153. that.notificationForm = {};
  154. that.editMsg={};
  155. that.notificationDialog = false;
  156. }
  157. },
  158. edit(index, type) {
  159. this.editMsg=this.notificationData[index][type];
  160. this.notificationForm = JSON.parse(JSON.stringify(this.notificationData[index][type].content_arr));
  161. this.editPlatform=type;
  162. if(this.editPlatform=='email'){
  163. this.$nextTick(callback=>{
  164. Controller.api.bindevent();
  165. $('#c-content').html(this.notificationData[index][type].content)
  166. })
  167. }
  168. this.notificationDialog = true;
  169. },
  170. addfield() {
  171. this.notificationForm.fields.push({
  172. 'name': '',
  173. 'template_field': '',
  174. 'value': '',
  175. });
  176. },
  177. },
  178. })
  179. },
  180. recyclebin: function () {
  181. // 初始化表格参数配置
  182. Table.api.init({
  183. extend: {
  184. 'dragsort_url': ''
  185. }
  186. });
  187. var table = $("#table");
  188. // 初始化表格
  189. table.bootstrapTable({
  190. url: 'shopro/notification/recyclebin' + location.search,
  191. pk: 'id',
  192. sortName: 'id',
  193. columns: [
  194. [{
  195. checkbox: true
  196. },
  197. {
  198. field: 'id',
  199. title: __('Id')
  200. },
  201. {
  202. field: 'deletetime',
  203. title: __('Deletetime'),
  204. operate: 'RANGE',
  205. addclass: 'datetimerange',
  206. formatter: Table.api.formatter.datetime
  207. },
  208. {
  209. field: 'operate',
  210. width: '130px',
  211. title: __('Operate'),
  212. table: table,
  213. events: Table.api.events.operate,
  214. buttons: [{
  215. name: 'Restore',
  216. text: __('Restore'),
  217. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  218. icon: 'fa fa-rotate-left',
  219. url: 'shopro/notification/restore',
  220. refresh: true
  221. },
  222. {
  223. name: 'Destroy',
  224. text: __('Destroy'),
  225. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  226. icon: 'fa fa-times',
  227. url: 'shopro/notification/destroy',
  228. refresh: true
  229. }
  230. ],
  231. formatter: Table.api.formatter.operate
  232. }
  233. ]
  234. ]
  235. });
  236. // 为表格绑定事件
  237. Table.api.bindevent(table);
  238. },
  239. edit: function () {
  240. Controller.api.bindevent();
  241. },
  242. api: {
  243. bindevent: function () {
  244. Form.api.bindevent($("form[role=form]"));
  245. }
  246. }
  247. };
  248. return Controller;
  249. });