mobile_flow.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'mobile_flow/index' + location.search,
  8. add_url: 'mobile_flow/add',
  9. edit_url: 'mobile_flow/edit',
  10. del_url: 'mobile_flow/del',
  11. multi_url: 'mobile_flow/multi',
  12. import_url: 'mobile_flow/import',
  13. batch: 'mobile_flow/batch',
  14. table: 'mobile',
  15. cancel_discount: 'mobile_flow/cancelsetdiscount',
  16. set_discount: 'mobile_flow/setdiscount',
  17. }
  18. });
  19. var table = $("#table");
  20. // 初始化表格
  21. table.bootstrapTable({
  22. url: $.fn.bootstrapTable.defaults.extend.index_url,
  23. pk: 'id',
  24. sortName: 'id',
  25. search:false,
  26. searchFormVisible:true,
  27. columns: [
  28. [
  29. {checkbox: true},
  30. {field: 'id', title: __('Id')},
  31. {field: 'no', title: __('手机号'),operate: "LIKE"},
  32. {field: 'province', title: __('省份')},
  33. {field: 'city', title: __('归属地')},
  34. {field: 'name', 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. {field: 'summary', title: __('简介'),operate: "like",formatter: Table.api.formatter.content,width: 200},
  39. {field: 'info.describe', title: __('套餐信息'),operate: "like",formatter: Table.api.formatter.content,width: 200},
  40. {field: 'remark', title: __('备注'), operate:'like'},
  41. {field: 'is_hold', title: __('状态'),formatter: Table.api.formatter.normal,searchList:{0:'正常',1:'预占'}},
  42. {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  43. {field: 'create_time', title: __('上架时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  44. {field: 'sort', title: __('Sort'),operate: "BETWEEN"},
  45. {field: 'admin_id', title: __('上传用户'),operate: "="},
  46. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[]},
  47. ]
  48. ]
  49. });
  50. let setStatus=function (_this,field) {
  51. let a=layer.load()
  52. $.post('mobile/batch',{id:_this.attr('data-id'),status:_this.attr('data-value')?0:1,field:field},function (res){
  53. if(res.code){
  54. _this.attr('data-value',res.data.status)
  55. if(res.data.status){
  56. _this.find('i').removeClass('fa-flip-horizontal text-gray')
  57. }else{
  58. _this.find('i').addClass('fa-flip-horizontal text-gray')
  59. }
  60. }else{
  61. layer.msg('操作失败')
  62. }
  63. layer.close(a)
  64. })
  65. }
  66. $(document).on('click','.btn-change-top',function (){
  67. setStatus($(this),'top_time')
  68. })
  69. $(document).on('click','.btn-change-rec',function (){
  70. setStatus($(this),'rec_time')
  71. })
  72. $(document).on('click','.btn-set-discount',function (){
  73. let set=$(this).data('set')
  74. let select=table.bootstrapTable('getSelections'),
  75. a=[]
  76. if(!select.length){
  77. return
  78. }
  79. select.forEach(item=>{
  80. a.push(item.id)
  81. })
  82. if(!set){
  83. $.post($.fn.bootstrapTable.defaults.extend.cancel_discount,{ids:a},function (){
  84. layer.msg('操作成功')
  85. $('.btn-refresh').trigger('click')
  86. })
  87. }else{
  88. Fast.api.open($.fn.bootstrapTable.defaults.extend.set_discount+`/ids/${a.join(',')}`,'设置特价',{
  89. close(){
  90. $('.btn-refresh').trigger('click')
  91. }
  92. })
  93. }
  94. })
  95. // 为表格绑定事件
  96. Table.api.bindevent(table);
  97. },
  98. add: function () {
  99. Controller.api.bindevent();
  100. },
  101. edit: function () {
  102. Controller.api.bindevent();
  103. },
  104. setdiscount(){
  105. Controller.api.bindevent();
  106. $(document).on('click','#activity_forever input',function (){
  107. if(this.value==0){
  108. $('input[name="row[activity_time_end]"]').attr('disabled',false)
  109. }else{
  110. $('input[name="row[activity_time_end]"]').attr('disabled',true)
  111. }
  112. })
  113. },
  114. api: {
  115. bindevent: function () {
  116. Form.api.bindevent($("form[role=form]"));
  117. }
  118. },
  119. takeit(){
  120. Controller.api.bindevent();
  121. $('.kill-discount-radio').change(function (){
  122. let amount=$('#c-amount_base').val(),
  123. dis=this.value
  124. let total=amount*dis
  125. $('#c-amount_kill').val(total.toFixed(2))
  126. })
  127. $('.kill-discount').bind('input propertychange',function (){
  128. let amount=$('#c-amount_base').val(),
  129. dis=this.value
  130. let total=amount*dis/10
  131. $('#c-amount_kill').val(total.toFixed(2))
  132. })
  133. }
  134. };
  135. return Controller;
  136. });