goods.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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: 'goods/index' + location.search,
  8. add_url: 'goods/add',
  9. edit_url: 'goods/edit',
  10. del_url: 'goods/del',
  11. multi_url: 'goods/multi',
  12. import_url: 'goods/import',
  13. bind_url: 'goods/bind_goods',
  14. statistics_url: 'goods/goods_statistics',
  15. amount_rank_url: 'goods/goods_buy_rank',
  16. order_amount_rank_url: 'goods/order_amount_rank',
  17. order_num_rank_url: 'goods/order_num_rank',
  18. table: 'goods',
  19. }
  20. });
  21. let extend=$.fn.bootstrapTable.defaults.extend
  22. var table = $("#table");
  23. // 初始化表格
  24. table.bootstrapTable({
  25. url: $.fn.bootstrapTable.defaults.extend.index_url,
  26. pk: 'id',
  27. sortName: 'id',
  28. searchFormVisible:true,
  29. columns: [
  30. [
  31. {checkbox: true},
  32. {field: 'id', title: __('Id')},
  33. {field: 'name', title: __('Name'),formatter: Table.api.formatter.content,width:200},
  34. {field: 'category.name', title: __('分类'),formatter: Table.api.formatter.label,operate: "like"},
  35. {field: 'brand', title: __('Brand')},
  36. //{field: 'amount', title: __('售价'), operate:'BETWEEN'},
  37. //{field: 'amount_kill', title: __('Amount_kill'), operate:'BETWEEN'},
  38. {field: 'is_hot', title: __('Is_hot'),formatter:Table.api.formatter.label,searchList:{0:'否',1:'是'}},
  39. {field: 'is_kill', title: __('Is_kill'),formatter:Table.api.formatter.label,searchList:{0:'否',1:'是'}},
  40. {field: 'status', title: __('状态'),formatter:Table.api.formatter.label,searchList:goodsStatus},
  41. {field: 'num_sell', title: __('Num_sell')},
  42. {field: 'create_time', title: __('Create_time'),formatter: Table.api.formatter.datetime,addClass:'datetimerange'},
  43. //{field: 'update_time', title: __('Update_time'),formatter: Table.api.formatter.datetime,addClass:'datetimerange'},
  44. {field:'',title:'统计',table: table,events: Table.api.events.operate,formatter: Table.api.formatter.buttons,operate: false,
  45. buttons:[
  46. {
  47. name: 'detail',
  48. text: __('商品组合'),
  49. title: __('商品组合'),
  50. classname: 'btn btn-xs btn-primary btn-dialog',
  51. icon: 'fa',
  52. url: extend.bind_url,
  53. callback: function (data) {
  54. },
  55. visible: function (row) {
  56. return table.data('operate-bind_goods');
  57. }
  58. },
  59. {
  60. name: 'detail',
  61. text: __('数据统计'),
  62. title: __('数据统计'),
  63. classname: 'btn btn-xs btn-info btn-dialog',
  64. icon: 'fa',
  65. url: extend.statistics_url,
  66. extend:`data-area='["800px","80%"]'`,
  67. callback: function (data) {
  68. },
  69. visible: function (row) {
  70. return table.data('operate-buy_rank');
  71. }
  72. },
  73. {
  74. name: 'detail',
  75. text: __('采购金额排名'),
  76. title: __('采购金额排名'),
  77. classname: 'btn btn-xs btn-info btn-dialog',
  78. icon: 'fa',
  79. url: extend.amount_rank_url,
  80. extend:`data-area='["800px","80%"]'`,
  81. callback: function (data) {
  82. },
  83. visible: function (row) {
  84. return table.data('operate-buy_rank');
  85. }
  86. },
  87. {
  88. name: 'detail',
  89. text: __('订单金额排名'),
  90. title: __('订单金额排名'),
  91. classname: 'btn btn-xs btn-info btn-dialog',
  92. icon: 'fa',
  93. url: extend.order_amount_rank_url,
  94. extend:`data-area='["800px","80%"]'`,
  95. callback: function (data) {
  96. },
  97. visible: function (row) {
  98. return table.data('operate-order_amount_rank');
  99. }
  100. },
  101. {
  102. name: 'detail',
  103. text: __('订单笔数排名'),
  104. title: __('订单笔数排名'),
  105. classname: 'btn btn-xs btn-info btn-dialog',
  106. icon: 'fa',
  107. url: extend.order_num_rank_url,
  108. extend:`data-area='["800px","80%"]'`,
  109. callback: function (data) {
  110. },
  111. visible: function (row) {
  112. return table.data('operate-order_num_rank');
  113. }
  114. },
  115. ]},
  116. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
  117. ]
  118. ],
  119. onLoadSuccess(){
  120. setTimeout(()=>{
  121. $('.btn-editone').attr('data-area','["800px","90%"]')
  122. },100)
  123. }
  124. });
  125. $(document).on('click','.bindGoods',function (){
  126. let id=$(this).data('id')
  127. Fast.api.open(extend.bind_url+`/id/${id}`,'绑定商品')
  128. })
  129. // 为表格绑定事件
  130. Table.api.bindevent(table);
  131. },
  132. add: function () {
  133. this.editor()
  134. },
  135. edit: function () {
  136. this.editor(1)
  137. },
  138. goods_statistics(){
  139. //Controller.api.bindevent();
  140. Form.events.daterangepicker($('.form'))
  141. $('.doSearch').click(()=>{
  142. layer.load()
  143. })
  144. },
  145. goods_buy_rank(){
  146. Table.api.init()
  147. var table = $("#table");
  148. // 初始化表格
  149. table.bootstrapTable({
  150. url: location.href,
  151. pk: 'id',
  152. sortName: 'id',
  153. searchFormVisible:true,
  154. showExport:false,
  155. commonSearch:true,
  156. search:false,
  157. columns: [
  158. [
  159. {field: 'rank', title: __('排名'),operate:false,},
  160. {field: 'nickname', title: __('用户名'),operate:false,},
  161. {field: 'amount', title: __('金额'),operate:false,},
  162. {field: 'date', title: __('时间'),operate:'range',addClass:'datetimerange',visible:false},
  163. ]
  164. ]
  165. });
  166. Table.api.bindevent(table);
  167. },
  168. order_amount_rank(){
  169. Table.api.init()
  170. var table = $("#table");
  171. // 初始化表格
  172. table.bootstrapTable({
  173. url: location.href,
  174. pk: 'id',
  175. sortName: 'id',
  176. searchFormVisible:true,
  177. showExport:false,
  178. commonSearch:true,
  179. search:false,
  180. columns: [
  181. [
  182. {field: 'rank', title: __('排名'),operate: false,},
  183. {field: 'order_no', title: __('订单号'),operate: false,},
  184. {field: 'nickname', title: __('用户名'),operate: false,},
  185. {field: 'amount', title: __('金额'),operate: false,},
  186. {field: 'date', title: __('时间'),operate:'range',addClass:'datetimerange',visible:false},
  187. ]
  188. ]
  189. });
  190. Table.api.bindevent(table);
  191. },
  192. order_num_rank(){
  193. Table.api.init()
  194. var table = $("#table");
  195. // 初始化表格
  196. table.bootstrapTable({
  197. url: location.href,
  198. pk: 'id',
  199. sortName: 'id',
  200. searchFormVisible:true,
  201. showExport:false,
  202. commonSearch:true,
  203. search:false,
  204. columns: [
  205. [
  206. {field: 'rank', title: __('排名'),operate: false,},
  207. {field: 'nickname', title: __('用户名'),operate: false,},
  208. {field: 'num', title: __('笔数'),operate: false,},
  209. {field: 'date', title: __('时间'),operate:'range',addClass:'datetimerange',visible:false},
  210. ]
  211. ]
  212. });
  213. Table.api.bindevent(table);
  214. },
  215. editor(isEdit){
  216. let app=new Vue({
  217. el:'#app',
  218. data(){
  219. return {
  220. form:{
  221. is_hot:0,
  222. is_kill:0,
  223. is_fix:0,
  224. status:1,
  225. logo:[],
  226. video:null,
  227. },
  228. category:category,
  229. status:status,
  230. }
  231. },
  232. methods:{
  233. addImg(type, index, multiple) {
  234. let that = this;
  235. let ext
  236. if(type==='image'){
  237. ext='image/*'
  238. }else if(type==='video'){
  239. ext='video/mp4'
  240. }
  241. parent.Fast.api.open(`general/attachment/select?mimetype=${ext}&multiple=` + multiple, "选择图片", {
  242. callback: function (data) {
  243. switch (type) {
  244. case "image":
  245. that.form.logo.push(data.url)
  246. break;
  247. case "video":
  248. that.form.video=data.url
  249. break;
  250. }
  251. }
  252. });
  253. return false;
  254. },
  255. delImg(index) {
  256. this.form.logo.splice(index,1)
  257. },
  258. delVideo(){
  259. this.form.video=null
  260. }
  261. }
  262. })
  263. },
  264. api: {
  265. bindevent: function () {
  266. Form.api.bindevent($("form[role=form]"));
  267. }
  268. },
  269. bind_goods(){
  270. Controller.api.bindevent();
  271. $('.skuItem input[type=radio]').change(function (){
  272. getGoods(goods.id,this.value)
  273. })
  274. let getGoods=(goods_id,sku_id)=>{
  275. let idx=layer.load()
  276. $.post('',{e:'get',sku_id,goods_id},function (res){
  277. if(res.data.length) {
  278. $('#c-name').val(res.data.join(','))
  279. }else{
  280. $('#c-name').selectPageClear()
  281. }
  282. $('#c-name').selectPageRefresh();
  283. layer.close(idx)
  284. })
  285. }
  286. $('.firstSku').trigger('click')
  287. }
  288. };
  289. return Controller;
  290. });