goods.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. search: false,
  7. commonSearch: true,
  8. searchFormVisible: true,
  9. extend: {
  10. index_url: 'goods/index' + location.search,
  11. add_url: 'goods/add',
  12. edit_url: 'goods/edit',
  13. del_url: 'goods/del',
  14. multi_url: 'goods/multi',
  15. import_url: 'goods/import',
  16. table: 'goods',
  17. merge_url: 'goods/merge',
  18. buy_url: 'goods/buy',
  19. }
  20. });
  21. var table = $("#table");
  22. let mergeAuth=table.data('merge-set')===1;
  23. let buyAuth=table.data('buy-set')===1;
  24. $(document).on('click','.btn-merge-set',function (){
  25. Fast.api.open($.fn.bootstrapTable.defaults.extend.merge_url+`/ids/${$(this).data('id')}`,'合成设置')
  26. })
  27. $(document).on('click','.btn-buy-set',function (){
  28. Fast.api.open($.fn.bootstrapTable.defaults.extend.buy_url+`/ids/${$(this).data('id')}`,'提前购买设置')
  29. })
  30. //给添加按钮添加`data-area`属性
  31. // 初始化表格
  32. table.bootstrapTable({
  33. url: $.fn.bootstrapTable.defaults.extend.index_url,
  34. pk: 'id',
  35. sortName: 'id',
  36. fixedColumns: true,
  37. fixedRightNumber: 1,
  38. columns: [
  39. [
  40. {field: 'id', title: __('Id'), operate: false},
  41. {field: 'name', title: __('Name'), operate: 'LIKE'},
  42. {field: 'goodscategory.name', title: __('Goodscategory.name'), operate: false},
  43. {field: 'goods_category_id', title: __('Goodscategory.name'), visible:false,searchList: $.getJSON('goods_category/list')},
  44. {field: 'author.name', title: __('Author.name'), operate: false},
  45. {field: 'author_id', title: __('Author.name'),visible:false,searchList: $.getJSON('author/list')},
  46. {field: 'network.name', title: __('Network.name'), operate: false},
  47. {field: 'network_id', title: __('Network.name'), visible:false,searchList: $.getJSON('network/list')},
  48. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  49. // {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  50. {field: 'price', title: __('Price'), operate:false},
  51. // {field: 'desc', title: __('Desc'), operate: 'LIKE'},
  52. // {field: 'attribute', title: __('Attribute'), operate: false},
  53. // {field: 'contract', title: __('Contract'), operate: 'LIKE'},
  54. {field: 'meta_data', title: __('Meta_data'), operate: 'LIKE'},
  55. {field: 'order', title: __('Order'), operate: false},
  56. {field: 'stock', title: __('Stock'), operate: false},
  57. {field: 'sales', title: __('Sales'), operate: false},
  58. {field: 'surplus', title: __('Surplus'), operate: false},
  59. {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  60. // {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
  61. {field: 'is_show', title: __('Is_show'), searchList: {"0":__('Is_show 0'),"1":__('Is_show 1')}, formatter: Table.api.formatter.normal},
  62. {
  63. field:'',
  64. title:'合成',
  65. operate: false,
  66. formatter(aa,info){
  67. let a=[],names=[]
  68. info.merge.forEach(item=>{
  69. if(item.goods) {
  70. names.push(`${item.goods.name}(${item.num})`)
  71. }
  72. })
  73. a.push(`<div>开启合成:${info.merge_open?`<span class="text-red">是</span>`:'否'}</div>`)
  74. a.push(`<div>所需藏品:<div style="color: #00caff">${names.join('<br>')}</div></div>`)
  75. if(mergeAuth) {
  76. a.push(`<div><a class="btn btn-success btn-sm btn-merge-set" data-id="${info.id}">设置</a></div>`)
  77. }
  78. return a.join('')
  79. },
  80. align:'left',
  81. valign:'top',
  82. },
  83. {
  84. field:'',
  85. title:'提前购买',
  86. operate: false,
  87. formatter(aa,info){
  88. let a=[],names=[]
  89. info.buy.forEach(item=>{
  90. if(item.goods) {
  91. names.push(`${item.goods.name}(${item.num})`)
  92. }
  93. })
  94. let open=''
  95. if(info.buy_type===0){
  96. open='未开启'
  97. }else if(info.buy_type===1){
  98. open='提前购买'
  99. }else if(info.buy_type===2){
  100. open='空头'
  101. }
  102. a.push(`<div>开启方式:${open}</div>`)
  103. a.push(`<div>时间:${info.buy_before_time}</div>`)
  104. a.push(`<div>限购:${info.buy_before_user_limit||0}</div>`)
  105. a.push(`<div style="color: #00caff;">所需藏品:${names.join('')}</div>`)
  106. if(buyAuth) {
  107. a.push(`<div><a class="btn btn-success btn-sm btn-buy-set" data-id="${info.id}">设置</a></div>`)
  108. }
  109. return a.join('')
  110. },
  111. align:'left',
  112. valign:'top',
  113. },
  114. {field:'merge_open',operate: '=',title:'开启合成',searchList: {0:'未开启',1:'开启'},visible: false},
  115. // {field: 'is_home', title: __('Is_home'), searchList: {"0":__('Is_home 0'),"1":__('Is_home 1')}, formatter: Table.api.formatter.normal},
  116. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
  117. /* buttons:[
  118. {
  119. name: 'merge',
  120. text: '合成设置',
  121. title: '合成设置',
  122. classname: 'btn btn-primary btn-dialog btn-sm',
  123. url: 'goods/merge',
  124. visible:function(row){
  125. return $('#table').data('merge-set')===1; //或者return false
  126. },
  127. callback: function (data) {
  128. $(".btn-refresh").trigger("click");
  129. }
  130. }
  131. ]*/
  132. }
  133. ]
  134. ]
  135. });
  136. // 为表格绑定事件
  137. Table.api.bindevent(table);
  138. },
  139. add: function () {
  140. Controller.api.bindevent();
  141. },
  142. edit: function () {
  143. Controller.api.bindevent();
  144. },
  145. merge: function () {
  146. Controller.api.bindevent();
  147. $('.btn-add-goods').click(function (){
  148. goodsNum++
  149. let a=$('#goodsTemp').html()
  150. a=a.replace(/\$key/gi,goodsNum)
  151. $('.form-group-add-btn-field').before(a)
  152. Controller.api.bindevent();
  153. })
  154. $(document).on('click','.goods-one-delete',function (){
  155. $(this).parents('.goods-one').remove()
  156. })
  157. },
  158. buy: function () {
  159. Controller.api.bindevent();
  160. },
  161. api: {
  162. bindevent: function () {
  163. Form.api.bindevent($("form[role=form]"));
  164. }
  165. }
  166. };
  167. return Controller;
  168. });