mobile_flow.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','clipboard'], function ($, undefined, Backend, Table, Form,clipboard) {
  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. sort_url: 'mobile_flow/sort',
  11. // del_url: 'mobile_flow/del',
  12. multi_url: 'mobile_flow/multi',
  13. multi_down_url: 'mobile_flow/multi_down',
  14. multi_up_url: 'mobile_flow/multi_up',
  15. import_url: 'mobile_flow/import',
  16. batch: 'mobile_flow/batch',
  17. table: 'mobile',
  18. }
  19. });
  20. let tableData=[]
  21. let clip=new clipboard('.btn-copy-obj',{
  22. text:function (a){
  23. let idx=$(a).data('row-index'),
  24. row=tableData[idx]
  25. return `${location.origin}/build/#/data-traffic-detail/${row.id}`
  26. }
  27. })
  28. clip.on('success',function (){
  29. parent.layer.msg('复制成功')
  30. })
  31. $('.btn-multi_down').click(function (){
  32. parent.layer.confirm('确定要下架吗?',(idx)=>{
  33. let ids=[]
  34. table.bootstrapTable('getSelections').forEach(item=>{
  35. ids.push(item.id)
  36. })
  37. let a=parent.layer.load()
  38. $.ajax($.fn.bootstrapTable.defaults.extend.multi_down_url,{
  39. data:{ids},
  40. type:'post',
  41. success({code,msg}){
  42. if(code){
  43. parent.layer.msg('操作成功')
  44. $('.btn-refresh').trigger('click')
  45. }else{
  46. parent.layer.alert(msg)
  47. }
  48. },
  49. complete(){
  50. parent.layer.close(a)
  51. }
  52. })
  53. parent.layer.close(idx)
  54. })
  55. })
  56. $('.btn-multi_up').click(function (){
  57. parent.layer.confirm('确定要上架吗?',(idx)=>{
  58. let ids=[]
  59. table.bootstrapTable('getSelections').forEach(item=>{
  60. ids.push(item.id)
  61. })
  62. let a=parent.layer.load()
  63. $.ajax($.fn.bootstrapTable.defaults.extend.multi_up_url,{
  64. data:{ids},
  65. type:'post',
  66. success({code,msg}){
  67. if(code){
  68. parent.layer.msg('操作成功')
  69. $('.btn-refresh').trigger('click')
  70. }else{
  71. parent.layer.alert(msg)
  72. }
  73. },
  74. complete(){
  75. parent.layer.close(a)
  76. }
  77. })
  78. parent.layer.close(idx)
  79. })
  80. });
  81. var table = $("#table");
  82. table.on('post-common-search.bs.table', function (event, table) {
  83. var form = $("form", table.$commonsearch);
  84. $("input[name='proxy_id']", form).addClass("selectpage").data("source", "auth/admin/index2").data("params",{"custom[proxy]":"0","custom[sub]":"1"}).data("primaryKey", "nickname").data("field", "nickname").data("orderBy", "id asc");
  85. Form.events.cxselect(form);
  86. Form.events.selectpage(form);
  87. });
  88. $(".btn-add").data("area", ["100%","100%"]);
  89. // 初始化表格
  90. table.bootstrapTable({
  91. url: $.fn.bootstrapTable.defaults.extend.index_url,
  92. pk: 'id',
  93. sortName: 'id',
  94. search:false,
  95. searchFormVisible:true,
  96. columns: [
  97. [
  98. {checkbox: true},
  99. {field: 'id', title: __('Id')},
  100. //{field: 'proxy_role', title: __('站点选择'),visible:false,searchable:true,operate:false,searchList:{1:"主站", 2:"本店"},defaultValue:1},
  101. {field: 'proxy_id', title: __('代理商')},
  102. {field: 'product_no', title: __('产品编码')},
  103. {field: 'name', title: __('商品名称'),operate: 'like',formatter(a,mobile){
  104. let arr=[]
  105. arr.push(`<div class="break-words" style="display:flex;align-items:center;">`)
  106. if(mobile.logo) {
  107. let logo=mobile.logo.split(',')[0]
  108. arr.push(`<div><img src="${logo}" class="view-image" alt="" style="width: 50px;height: 50px;object-fit: cover"/></div>`)
  109. }
  110. arr.push(`<div>${a}</div>`)
  111. arr.push(`</div>`)
  112. return arr.join('')
  113. },align:'left',valign:'top'},
  114. {
  115. field: 'brand',
  116. title: __('运营商'),
  117. formatter: Table.api.formatter.label,
  118. custom:{'flow_limit_yd':'success', 'flow_limit_lt':'danger', 'flow_limit_dx':'info', 'flow_limit_gd':'success'},
  119. searchList:brands,
  120. operate: 'like'
  121. },
  122. {field: 'summary', title: __('商品简介'),operate: "like",formatter: Table.api.formatter.content,width: 200},
  123. {field: 'amount_base', title: __('售价'), operate:'BETWEEN'},
  124. {field: 'stock_num', title: __('库存'), operate:'BETWEEN'},
  125. {field: 'sort', title: __('排序'), operate:'BETWEEN',formatter(a, mobile) {
  126. return `<input class="flow-change-sort" value="${a}" style="width: 100px;" onfocus="$(this).select()" data-id="${mobile.id}">`
  127. }},
  128. {field: 'create_time', title: __('上架时间'), operate:'RANGE', addclass:'datetimerange', autocomplete:false,formatter: Table.api.formatter.datetime},
  129. {field:'status',title:'系统售卖状态',formatter: Table.api.formatter.label,searchList:flow_status,defaultValue:0,},
  130. // {field:'proxy_status',title:'展示状态',formatter: Table.api.formatter.label,searchList:flow_status,defaultValue:(superAdmin ? null : 0),visible:(superAdmin ? false : true),searchable:(superAdmin ? false : true)},
  131. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function(value, row, index){
  132. // return Table.api.formatter.operate;
  133. var that = $.extend({}, this);
  134. var table = $(that.table).clone(true);
  135. if(row.editAuth == false){
  136. $(table).data("operate-edit", null);
  137. that.table = table;
  138. }
  139. if(row.delAuth == false){
  140. $(table).data("operate-del", null);
  141. that.table = table;
  142. }
  143. return Table.api.formatter.operate.call(that, value, row, index);
  144. },buttons:[
  145. {
  146. name: 'detail',
  147. title: __('复制链接'),
  148. text: __('复制链接'),
  149. classname: 'btn btn-xs btn-info btn-copy-obj',
  150. click: function (data,row) {
  151. },
  152. visible: function (row) {
  153. return true;
  154. }
  155. },
  156. {
  157. name: 'detail',
  158. text: __('复制商品'),
  159. title: __('复制商品'),
  160. classname: 'btn btn-xs btn-info btn-ajax',
  161. url: 'mobile_flow/copy_goods',
  162. refresh: true,
  163. visible: function (row) {
  164. return true;
  165. }
  166. },
  167. ]},
  168. ]
  169. ],
  170. onLoadSuccess(a){
  171. tableData=a.rows
  172. $(".btn-editone").data("area", ["100%","100%"]);
  173. }
  174. });
  175. $(document).on('blur','.flow-change-sort',function (){
  176. let id=$(this).data('id')
  177. let idx=layer.load()
  178. Fast.api.ajax({
  179. url: $.fn.bootstrapTable.defaults.extend.sort_url,
  180. data:{id,sort:this.value}
  181. },()=>{
  182. // $('.btn-refresh').trigger('click')
  183. layer.close(idx)
  184. },(res)=>{
  185. layer.close(idx)
  186. })
  187. })
  188. $(document).on('click','.view-image',function (){
  189. layer.photos({
  190. photos:{
  191. data:[
  192. {
  193. src:this.src
  194. }
  195. ]
  196. }
  197. })
  198. })
  199. $('.tab-first[data-value="0"]').trigger('click')
  200. // 为表格绑定事件
  201. Table.api.bindevent(table);
  202. },
  203. add: function () {
  204. Controller.api.bindevent();
  205. $('#c-logo').change(function (){
  206. let images=this.value?this.value.split(','):[]
  207. if(images.length>5){
  208. $(this).val(images.slice(0,5).join(','))
  209. parent.layer.msg('最多上传5张图片')
  210. }
  211. })
  212. },
  213. edit: function () {
  214. Controller.api.bindevent();
  215. },
  216. api: {
  217. bindevent: function () {
  218. Form.api.bindevent($("form[role=form]"));
  219. }
  220. },
  221. };
  222. return Controller;
  223. });