user_order.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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: 'user_order/index' + location.search,
  8. add_url: 'user_order/add',
  9. edit_url: 'user_order/edit',
  10. del_url: 'user_order/del',
  11. multi_url: 'user_order/multi',
  12. import_url: 'user_order/import',
  13. table: 'user_order',
  14. }
  15. });
  16. var table = $("#table");
  17. let statusList = await $.getJSON('user_order/status')
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. searchFormVisible:true,
  23. sortName: 'id',
  24. columns: [
  25. [
  26. //{checkbox: true},
  27. {field: 'id', title: __('Id')},
  28. {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
  29. {field: 'no', title: __('订单号'), operate: '='},
  30. {field: 'from_city', title: __('From_city')},
  31. {field: 'to_city', title: __('To_city')},
  32. {
  33. field: 'images',
  34. title: __('Images'),
  35. operate: false,
  36. events: Table.api.events.image,
  37. formatter: Table.api.formatter.images
  38. },
  39. {field: 'real_amount', title: __('Real_amount'), operate: 'BETWEEN'},
  40. {field: 'discount_amount', title: __('Coupon_amount'), operate: 'BETWEEN'},
  41. {
  42. field: 'status',
  43. title: __('Status'),
  44. searchList: statusList,
  45. formatter: Table.api.formatter.label
  46. },
  47. {field: 'created_at', title: __('Created_at'), formatter: Table.api.formatter.datetime,operate: 'RANGE',addclass: 'datetimerange'},
  48. {
  49. field: 'operate',
  50. title: __('Operate'),
  51. table: table,
  52. events: Table.api.events.operate,
  53. formatter: Table.api.formatter.buttons,
  54. buttons:[
  55. {
  56. name: 'detail',
  57. text: __('详情'),
  58. title: __('详情'),
  59. classname: 'btn btn-xs btn-primary btn-dialog btn-detail',
  60. icon: 'fa fa-list',
  61. url: 'user_order/edit',
  62. callback: function (data) {
  63. //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  64. $('.btn-refresh').trigger('click')
  65. },
  66. visible: function (row) {
  67. //返回true时按钮显示,返回false隐藏
  68. return true;
  69. }
  70. },
  71. {
  72. name: 'send_detail',
  73. text: __('运送详情'),
  74. title: __('运送详情'),
  75. classname: 'btn btn-xs btn-primary btn-dialog btn-send_detail',
  76. icon: 'fa fa-list',
  77. url: 'user_order/send_detail',
  78. callback: function (data) {
  79. //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  80. },
  81. visible: function (row) {
  82. //返回true时按钮显示,返回false隐藏
  83. return $('#table').data('operate-send_detail')===1;
  84. }
  85. },
  86. {
  87. name: 'remark',
  88. text: __('备注'),
  89. title: __('备注'),
  90. classname: 'btn btn-xs btn-danger btn-click',
  91. icon: 'fa fa-wikipedia-w',
  92. url: 'user_order/remark',
  93. click: function (data) {
  94. let _this=this
  95. layer.prompt({
  96. formType: 2,
  97. title: '请填写备注',
  98. area: ['500px', '150px'],
  99. btnAlign: 'c',
  100. yes: function(index, layero){
  101. // 获取文本框输入的值
  102. var value = layero.find(".layui-layer-input").val();
  103. if (value) {
  104. let load=layer.load(2)
  105. $.post(_this.href,{remark:value,ids:data.id},function (res) {
  106. if(res.code===1) {
  107. $('.btn-refresh').trigger('click')
  108. layer.msg('操作成功')
  109. layer.close(index)
  110. }else{
  111. layer.alert(res.msg)
  112. }
  113. layer.close(load)
  114. })
  115. } else {
  116. layer.alert("输入值为空!");
  117. }
  118. }
  119. })
  120. },
  121. visible: function (row) {
  122. //返回true时按钮显示,返回false隐藏
  123. return $('#table').data('operate-send_detail')===1;
  124. }
  125. },
  126. {
  127. name: 'delete',
  128. text: __('删除'),
  129. title: __('删除'),
  130. classname: 'btn btn-xs btn-danger btn-click',
  131. icon: 'fa fa-delicious',
  132. url: 'user_order/delete',
  133. click: function (data) {
  134. let _this=this
  135. layer.confirm('确认删除吗?',function (){
  136. let load=layer.load(2)
  137. $.post(_this.href,{},function (res) {
  138. if(res.code===1){
  139. layer.msg('删除成功')
  140. $('.btn-refresh').trigger('click')
  141. }else{
  142. layer.msg(res.msg)
  143. }
  144. layer.close(load)
  145. })
  146. })
  147. },
  148. visible: function (row) {
  149. //返回true时按钮显示,返回false隐藏
  150. return $('#table').data('operate-delete')===1 && row.status===80;
  151. }
  152. },
  153. {
  154. name: 'delete',
  155. text: __('驳回此订单'),
  156. title: __('驳回此订单'),
  157. classname: 'btn btn-xs btn-info btn-click',
  158. icon: 'fa fa-delicious',
  159. url: 'user_order/cancel',
  160. click: function (data) {
  161. let _this=this
  162. layer.confirm('确认驳回吗?',function (){
  163. let load=layer.load(2)
  164. $.post(_this.href,{},function (res) {
  165. if(res.code===1){
  166. layer.msg('驳回成功')
  167. $('.btn-refresh').trigger('click')
  168. }else{
  169. layer.msg(res.msg)
  170. }
  171. layer.close(load)
  172. })
  173. })
  174. },
  175. visible: function (row) {
  176. //返回true时按钮显示,返回false隐藏
  177. return $('#table').data('operate-cancel')===1 && row.status===1;
  178. }
  179. },
  180. ],
  181. }
  182. ]
  183. ],
  184. onLoadSuccess:function(data){
  185. $('#turnover').text(data.turnover)
  186. // 这里就是数据渲染结束后的回调函数
  187. $(".btn-detail,.btn-send_detail").data("area", ['1000px','100%']);
  188. $(".btn-detail,.btn-send_detail").data("shade", [0.5,"#000"]);
  189. }
  190. });
  191. // 为表格绑定事件
  192. Table.api.bindevent(table);
  193. },
  194. add: function () {
  195. Controller.api.bindevent();
  196. },
  197. edit: function () {
  198. Controller.api.bindevent();
  199. $('.deal_remark').click(function (){
  200. let id=$(this).data('id')
  201. layer.open({
  202. content:'请选择操作',
  203. btn:['立即结算','拒绝结算','取消操作'],
  204. yes:function (idx){
  205. $.post('user_order/deal_settle',{ids:id,status:1},function (res) {
  206. if(res.code===1) {
  207. Fast.api.close({})
  208. layer.msg('操作成功')
  209. layer.close(idx)
  210. window.location.reload()
  211. }else{
  212. layer.alert(res.msg)
  213. }
  214. })
  215. },
  216. btn2:function (idx){
  217. $.post('user_order/deal_settle',{ids:id,status:2},function (res) {
  218. if(res.code===1) {
  219. Fast.api.close({})
  220. layer.msg('操作成功')
  221. layer.close(idx)
  222. window.location.reload()
  223. }else{
  224. layer.alert(res.msg)
  225. }
  226. })
  227. },
  228. btn3:function (idx){
  229. layer.close(idx)
  230. }
  231. })
  232. })
  233. $('.deal_refund').click(function (){
  234. let id=$(this).data('id')
  235. layer.open({
  236. content:'请选择操作',
  237. btn:['同意退款','拒绝退款','取消操作'],
  238. yes:function (idx){
  239. $.post('user_order/deal_refund',{ids:id,status:1},function (res) {
  240. if(res.code===1) {
  241. Fast.api.close({})
  242. layer.msg('操作成功')
  243. layer.close(idx)
  244. window.location.reload()
  245. }else{
  246. layer.alert(res.msg)
  247. }
  248. })
  249. },
  250. btn2:function (idx){
  251. $.post('user_order/deal_refund',{ids:id,status:2},function (res) {
  252. if(res.code===1) {
  253. Fast.api.close({})
  254. layer.msg('操作成功')
  255. layer.close(idx)
  256. window.location.reload()
  257. }else{
  258. layer.alert(res.msg)
  259. }
  260. })
  261. },
  262. btn3:function (idx){
  263. layer.close(idx)
  264. }
  265. })
  266. })
  267. },
  268. api: {
  269. bindevent: function () {
  270. Form.api.bindevent($("form[role=form]"));
  271. }
  272. }
  273. };
  274. return Controller;
  275. });