mobile.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: async function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'mobile/index' + location.search,
  8. add_url: 'mobile/add',
  9. edit_url: 'mobile/edit',
  10. del_url: 'mobile/del',
  11. multi_url: 'mobile/multi',
  12. import_url: 'mobile/import',
  13. batch: 'mobile/batch',
  14. table: 'mobile',
  15. cancel_discount: 'mobile/cancelsetdiscount',
  16. set_discount: 'mobile/setdiscount',
  17. }
  18. });
  19. var table = $("#table");
  20. let status = await $.getJSON('mobile/status')
  21. // 初始化表格
  22. table.bootstrapTable({
  23. url: $.fn.bootstrapTable.defaults.extend.index_url,
  24. pk: 'id',
  25. sortName: 'id',
  26. search: false,
  27. searchFormVisible: true,
  28. columns: [
  29. [
  30. {checkbox: true},
  31. {field: 'id', title: __('Id')},
  32. {field: 'no', title: __('手机号'), operate: "LIKE"},
  33. {field: 'province', title: __('Province')},
  34. {field: 'city', title: __('归属地')},
  35. {field: 'network', title: __('运营商'), formatter: Table.api.formatter.label},
  36. {field: 'proxy.nickname', title: __('代理商'), formatter: Table.api.formatter.label},
  37. {field: 'brand', title: __('卡品牌'), formatter: Table.api.formatter.label},
  38. {
  39. field: 'rules', title: __('规律'), searchList: Object.keys(filters), formatter(a) {
  40. return a.join('<br>')
  41. }
  42. },
  43. {
  44. field: 'info.describe',
  45. title: __('套餐信息'),
  46. operate: "like",
  47. formatter: Table.api.formatter.content,
  48. width: 300
  49. },
  50. {field: 'amount_original', title: __('Amount_original'), operate: 'BETWEEN'},
  51. {field: 'amount_di', title: __('底价'), operate: 'BETWEEN'},
  52. {field: 'amount_base', title: __('Amount'), operate: 'BETWEEN'},
  53. {field: 'amount_charge', title: __('预存话费'), operate: 'BETWEEN'},
  54. {field: 'remark', title: __('备注'), operate: 'like'},
  55. {
  56. field: 'top_time',
  57. title: __('Top_time'),
  58. operate: 'RANGE',
  59. addclass: 'datetimerange',
  60. autocomplete: false,
  61. formatter(a, b, c) {
  62. return `<a data-toggle="switcher" class="btn-switcher btn-change-top" data-id="${b.id}" data-value="${a ? a : ''}">
  63. <i class="fa fa-toggle-on text-success ${a ? '' : 'fa-flip-horizontal text-gray'} fa-2x"></i>
  64. </a>`
  65. }
  66. },
  67. {
  68. field: 'rec_time',
  69. title: __('Rec_time'),
  70. operate: 'RANGE',
  71. addclass: 'datetimerange',
  72. autocomplete: false,
  73. formatter(a, b, c) {
  74. return `<a data-toggle="switcher" class="btn-switcher btn-change-rec" data-id="${b.id}" data-value="${a ? a : ''}">
  75. <i class="fa fa-toggle-on text-success ${a ? '' : 'fa-flip-horizontal text-gray'} fa-2x"></i>
  76. </a>`
  77. }
  78. },
  79. //{field: 'is_hold', title: __('预占'),formatter: Table.api.formatter.toggle,searchList:{0:'否',1:'是'}},
  80. {
  81. field: 'buttons',
  82. width: "120px",
  83. title: __('操作'),
  84. table: table,
  85. events: Table.api.events.operate,
  86. operate: false,
  87. formatter: Table.api.formatter.buttons,
  88. buttons: [
  89. {
  90. name: 'detail',
  91. text: __('预占'),
  92. title: __('预占'),
  93. classname: 'btn btn-xs btn-info btn-dialog',
  94. url: 'mobile/takeit',
  95. callback: function (data) {
  96. },
  97. visible: function (row) {
  98. return true;
  99. }
  100. },
  101. {
  102. name: 'detail',
  103. text: __('记录'),
  104. title: __('记录'),
  105. classname: 'btn btn-xs btn-info btn-dialog',
  106. url: 'mobile_price_log/index?a=1',
  107. callback: function (data) {
  108. },
  109. visible: function (row) {
  110. return true;
  111. }
  112. },
  113. ]
  114. },
  115. {field: 'status', title: __('状态'), formatter: Table.api.formatter.label, searchList: status},
  116. {
  117. field: 'update_time',
  118. title: __('Update_time'),
  119. operate: 'RANGE',
  120. addclass: 'datetimerange',
  121. autocomplete: false,
  122. formatter: Table.api.formatter.datetime
  123. },
  124. {
  125. field: 'create_time',
  126. title: __('上架时间'),
  127. operate: 'RANGE',
  128. addclass: 'datetimerange',
  129. autocomplete: false,
  130. formatter: Table.api.formatter.datetime
  131. },
  132. {field: 'sort', title: __('Sort'), operate: "BETWEEN"},
  133. {field: 'hold_chan', title: __('预占通道'), operate: "="},
  134. {field: 'hold_user', title: __('预占用户ID'), operate: "="},
  135. {field: 'admin_id', title: __('上传用户'), operate: "="},
  136. /*{field: 'name', title: __('Name')},
  137. {field: 'type', title: __('Type'),formatter: Table.api.formatter.label,searchList:no_type},
  138. {field: 'amount_exists', title: __('Amount_exists'), operate:'BETWEEN'},
  139. {field: 'amount_base', title: __('Amount_base'), operate:'BETWEEN'},
  140. {field: 'summary', title: __('Summary')},
  141. {field: 'saled', title: __('Saled'),formatter: Table.api.formatter.label,searchList:{0:'否',1:'是'}},
  142. {field: 'is_activity', title: __('Is_activity'),formatter: Table.api.formatter.label,searchList:{0:'否',1:'是'}},
  143. {field: 'activity_time_end', title: __('Activity_time_end'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  144. {field: 'sort', title: __('Sort'),operate: "BETWEEN"},*/
  145. {
  146. field: 'operate',
  147. title: __('Operate'),
  148. table: table,
  149. events: Table.api.events.operate,
  150. formatter: Table.api.formatter.operate,
  151. buttons: [
  152. {
  153. name: 'detail',
  154. text: __('取消预占'),
  155. title: __('取消预占'),
  156. classname: 'btn btn-xs btn-info btn-ajax',
  157. url: 'mobile/cancel_hold',
  158. callback: function (data) {
  159. },
  160. visible: function (row) {
  161. return row.is_hold === 1;
  162. }
  163. },
  164. {
  165. name: 'detail',
  166. text: __('记录'),
  167. title: __('记录'),
  168. classname: 'btn btn-xs btn-info btn-dialog',
  169. url: 'mobile_price_log/index?a=1',
  170. callback: function (data) {
  171. },
  172. visible: function (row) {
  173. return true;
  174. }
  175. },
  176. ]
  177. },
  178. ]
  179. ]
  180. });
  181. let setStatus = function (_this, field) {
  182. let a = layer.load()
  183. $.post('mobile/batch', {
  184. id: _this.attr('data-id'),
  185. status: _this.attr('data-value') ? 0 : 1,
  186. field: field
  187. }, function (res) {
  188. if (res.code) {
  189. _this.attr('data-value', res.data.status)
  190. if (res.data.status) {
  191. _this.find('i').removeClass('fa-flip-horizontal text-gray')
  192. } else {
  193. _this.find('i').addClass('fa-flip-horizontal text-gray')
  194. }
  195. } else {
  196. layer.msg('操作失败')
  197. }
  198. layer.close(a)
  199. })
  200. }
  201. $(document).on('click', '.btn-change-top', function () {
  202. setStatus($(this), 'top_time')
  203. })
  204. $(document).on('click', '.btn-change-rec', function () {
  205. setStatus($(this), 'rec_time')
  206. })
  207. $(document).on('click', '.btn-set-discount', function () {
  208. let set = $(this).data('set')
  209. let select = table.bootstrapTable('getSelections'),
  210. a = []
  211. if (!select.length) {
  212. return
  213. }
  214. select.forEach(item => {
  215. a.push(item.id)
  216. })
  217. if (!set) {
  218. $.post($.fn.bootstrapTable.defaults.extend.cancel_discount, {ids: a}, function () {
  219. layer.msg('操作成功')
  220. $('.btn-refresh').trigger('click')
  221. })
  222. } else {
  223. Fast.api.open($.fn.bootstrapTable.defaults.extend.set_discount + `/ids/${a.join(',')}`, '设置特价', {
  224. close() {
  225. $('.btn-refresh').trigger('click')
  226. }
  227. })
  228. }
  229. })
  230. // 为表格绑定事件
  231. Table.api.bindevent(table);
  232. },
  233. add: function () {
  234. Controller.api.bindevent();
  235. },
  236. edit: function () {
  237. Controller.api.bindevent();
  238. $('.kill-discount-radio').change(function (){
  239. let amount=$('#c-amount_base').val(),
  240. dis=this.value
  241. let total=amount*dis
  242. $('#c-amount_kill').val(total.toFixed(2))
  243. })
  244. $('.kill-discount').bind('input propertychange',function (){
  245. let amount=$('#c-amount_base').val(),
  246. dis=this.value
  247. let total=amount*dis/10
  248. $('#c-amount_kill').val(total.toFixed(2))
  249. })
  250. },
  251. setdiscount(){
  252. Controller.api.bindevent();
  253. $(document).on('click','#activity_forever input',function (){
  254. if(this.value==0){
  255. $('input[name="row[activity_time_end]"]').attr('disabled',false)
  256. }else{
  257. $('input[name="row[activity_time_end]"]').attr('disabled',true)
  258. }
  259. })
  260. },
  261. api: {
  262. bindevent: function () {
  263. Form.api.bindevent($("form[role=form]"));
  264. }
  265. },
  266. takeit(){
  267. Controller.api.bindevent();
  268. $('.kill-discount-radio').change(function (){
  269. let amount=$('#c-amount_base').val(),
  270. dis=this.value
  271. let total=amount*dis
  272. $('#c-amount_kill').val(total.toFixed(2))
  273. })
  274. $('.kill-discount').bind('input propertychange',function (){
  275. let amount=$('#c-amount_base').val(),
  276. dis=this.value
  277. let total=amount*dis/10
  278. $('#c-amount_kill').val(total.toFixed(2))
  279. })
  280. }
  281. };
  282. return Controller;
  283. });