orders.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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: 'orders/index' + location.search,
  8. add_url: 'orders/add',
  9. edit_url: 'orders/edit',
  10. del_url: 'orders/del',
  11. multi_url: 'orders/multi',
  12. import_url: 'orders/import',
  13. table: 'orders',
  14. }
  15. });
  16. var table = $("#table");
  17. let s=JSON.parse(JSON.stringify(status))
  18. s[40]='售后'
  19. // 初始化表格
  20. table.bootstrapTable({
  21. url: $.fn.bootstrapTable.defaults.extend.index_url,
  22. pk: 'id',
  23. sortName: 'id',
  24. searchFormVisible:true,
  25. search:false,
  26. columns: [
  27. [
  28. {checkbox: true},
  29. {field: 'id', title: __('Id')},
  30. {field: 'order_no', title: __('Order_no'),operate: 'like',},
  31. {field: 'status', title: __('Status'),formatter(status,order,index){
  32. /*if(status===0 && order.voucher && order.voucher.status===0){
  33. return `<span class="label label-default">待审核</span>`
  34. }*/
  35. let s=Table.api.formatter.status.call(this,status,order,index)
  36. let info=[]
  37. order.info.forEach(item=>{
  38. if(item.refund && item.refund.is_pass && info.indexOf(item.refund.refund_type_text)===-1){
  39. info.push(item.refund.refund_type_text)
  40. }
  41. })
  42. if(info.length){
  43. s+=`<div><a class="text-danger">${info.join(',')}</a></div>`
  44. }
  45. return s
  46. },searchList:s},
  47. {field: 'user.nickname', title: __('下单用户'),operate: 'like',formatter:Table.api.formatter.normal},
  48. {field: 'info', title: __('商品信息'),operate: false,formatter(info, order, index) {
  49. let a=[];
  50. info.forEach(item=>{
  51. a.push(`<div class="">商品:${item.goods_name},规格:${item.sku_name},数量:${item.num},安装量:${item.num_install},金额:${item.amount_pay}</div>`)
  52. })
  53. return Table.api.formatter.content.call(this,a.join('<br/>'),order,index)
  54. }},
  55. {field: 'amount_total', title: __('Amount_total'), operate:'BETWEEN'},
  56. {field: 'amount_pay', title: __('Amount_pay'), operate:'BETWEEN'},
  57. /* {field: 'amount_install', title: __('Amount_install'), operate:'BETWEEN'},
  58. {field: 'num', title: __('Num'),operate: 'between'},
  59. {field: 'num_install', title: __('Num_install'),operate: 'between'},*/
  60. {field: 'admin.nickname', title: __('销售人员'), operate:'like'},
  61. {field: 'tax_link', title: __('发票状态'), operate:'=',searchList: {'NULL':'未开票','NOT NULL':'已开票'},formatter(a){
  62. if(a){
  63. return `<span class="label label-success">已开票</span>`
  64. }
  65. return `<span class="label label-default">未开票</span>`
  66. }},
  67. {field: 'create_time', title: __('Create_time'),addClass:'datetimerange',formatter: Table.api.formatter.datetime,operate: 'range'},
  68. //{field: 'update_time', title: __('Update_time'),addClass:'datetimerange',formatter: Table.api.formatter.datetime,operate: 'range'},
  69. {field: 'pay_type', title: __('Pay_type'),formatter: Table.api.formatter.label,searchList:payTypes},
  70. {field: 'pay_time', title: __('支付时间'),addClass:'datetimerange',formatter: Table.api.formatter.datetime,operate: 'range'},
  71. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.buttons,buttons:[
  72. {
  73. name: 'edit',
  74. text: __('发货'),
  75. title: __('发货'),
  76. classname: 'btn btn-xs btn-info btn-dialog',
  77. icon: 'fa',
  78. url: 'orders/send',
  79. callback: function (data) {
  80. //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  81. $('.btn-refresh').trigger('click')
  82. },
  83. visible: function (row) {
  84. //返回true时按钮显示,返回false隐藏
  85. return row.status===5 && table.data('operate-send');
  86. }
  87. },
  88. {
  89. name: 'edit',
  90. text: __('已收款'),
  91. title: __('已收款'),
  92. classname: 'btn btn-xs btn-info btn-ajax',
  93. icon: 'fa',
  94. url: 'orders/payed',
  95. confirm:'确认已收款?',
  96. success: function (data) {
  97. $('.btn-refresh').trigger('click')
  98. },
  99. visible: function (row) {
  100. //返回true时按钮显示,返回false隐藏
  101. return row.status===0 && table.data('operate-payed') && row.pay_type===6
  102. }
  103. },
  104. {
  105. name: 'edit',
  106. text: __('订单详情'),
  107. title: __('订单详情'),
  108. classname: 'btn btn-xs btn-info btn-detail btn-dialog',
  109. icon: 'fa fa-outdent',
  110. url: 'orders/detail',
  111. extend:'data-area=\'["1200px","100%"]\'',
  112. callback: function (data) {
  113. //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  114. $('.btn-refresh').trigger('click')
  115. },
  116. visible: function (row) {
  117. //返回true时按钮显示,返回false隐藏
  118. return table.data('operate-detail');
  119. }
  120. },
  121. {
  122. name: 'edit',
  123. text: __('上传发票'),
  124. title: __('上传发票'),
  125. classname: 'btn btn-xs btn-warning btn-dialog',
  126. icon: 'fa',
  127. url: 'orders/tax',
  128. callback: function (data) {
  129. //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  130. $('.btn-refresh').trigger('click')
  131. },
  132. visible: function (row) {
  133. //返回true时按钮显示,返回false隐藏
  134. return !row.tax_link && row.tax && table.data('operate-tax');
  135. }
  136. },
  137. {
  138. name: 'edit',
  139. text: __('查看物流'),
  140. title: __('查看物流'),
  141. classname: 'btn btn-xs btn-warning btn-dialog',
  142. icon: 'fa',
  143. url: 'orders/logistics',
  144. callback: function (data) {
  145. //Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  146. $('.btn-refresh').trigger('click')
  147. },
  148. extend: `data-area='["800px","80%"]'`,
  149. visible: function (row) {
  150. //返回true时按钮显示,返回false隐藏
  151. return table.data('operate-logistics') && row.logistics && row.logistics.trans_no;
  152. }
  153. },
  154. /*{
  155. name: 'edit',
  156. text: __('电子面单'),
  157. title: __('电子面单'),
  158. classname: 'btn btn-xs btn-success btn-dialog',
  159. icon: 'fa',
  160. url: 'orders/md',
  161. callback: function (data) {
  162. $('.btn-refresh').trigger('click')
  163. },
  164. extend: `data-area='["800px","80%"]'`,
  165. visible: function (row) {
  166. //返回true时按钮显示,返回false隐藏
  167. return table.data('operate-md') && row.logistics && row.logistics.trans_no;
  168. }
  169. },*/
  170. ]}
  171. ]
  172. ],
  173. onLoadSuccess(a) {
  174. $('.btn-export').attr('href',a.link)
  175. }
  176. });
  177. $('.btn-export').click(function (){
  178. })
  179. // 为表格绑定事件
  180. Table.api.bindevent(table);
  181. },
  182. add: function () {
  183. Controller.api.bindevent();
  184. },
  185. send: function () {
  186. Controller.api.bindevent();
  187. $(document).on("change", "#c-name", function(){
  188. //后续操作
  189. var address_id = $(this).val();
  190. if(!address_id){
  191. $('#province1').fadeOut();
  192. $('#province2').fadeOut();
  193. return false;
  194. }
  195. $.ajax({
  196. url: 'orders/is_same_city',
  197. data: {address_id: $(this).val(),order_id:$('#order_id').val()},
  198. dataType: 'json',
  199. cache: false,
  200. success: function (row) {
  201. if(!row.code){
  202. Toastr.error(row.msg);
  203. }
  204. if(row.data.type == 1){
  205. $('#province1').fadeIn();
  206. $('#province2').fadeOut();
  207. }
  208. if(row.data.type == 0){
  209. $('#province1').fadeOut();
  210. $('#province2').fadeIn();
  211. }
  212. }, error: function () {
  213. Toastr.error(__('Network error'));
  214. }
  215. });
  216. });
  217. },
  218. tax: function () {
  219. Controller.api.bindevent();
  220. },
  221. api: {
  222. bindevent: function () {
  223. Form.api.bindevent($("form[role=form]"));
  224. }
  225. },
  226. md(){
  227. $('.btn-print').click(function (){
  228. Fast.api.ajax({},(res)=>{
  229. console.log(res)
  230. })
  231. })
  232. },
  233. detail: function () {
  234. // 初始化表格参数配置
  235. Table.api.init({
  236. extend: {
  237. index_url: location.pathname + location.search,
  238. refund_detail_url:'order_info_refund/audit'
  239. }
  240. });
  241. var table = $("#table");
  242. // 初始化表格
  243. table.bootstrapTable({
  244. url: $.fn.bootstrapTable.defaults.extend.index_url,
  245. pk: 'id',
  246. sortName: 'id',
  247. commonSearch:false,
  248. search:false,
  249. pagination:false,
  250. columns: [
  251. [
  252. {field: 'id', title: __('Id')},
  253. {field: 'logo', title: __('商品图片'),formatter: Table.api.formatter.image,events:Table.api.events.image,operate: false},
  254. {field: 'goods_name', title: __('商品名称'),operate: false,formatter(name,orderInfo,index){
  255. let a=[]
  256. a.push(`<div>${name}</div>`)
  257. if(orderInfo.refund){
  258. a.push(`<div>
  259. <a class="label label-default btnViewRefund" data-id="${orderInfo.refund.id}">售后详情</a>
  260. <span class="label label-danger">${refundStatus[orderInfo.refund.refund_status]}</span>
  261. </div>`)
  262. }
  263. return a.join('')
  264. },width:200},
  265. {field: 'sku_name', title: __('商品规格'),operate: false},
  266. {field: 'amount_pay', title: __('Amount_total'), operate:'BETWEEN'},
  267. {field: 'amount_goods_real', title: __('商品金额'), operate:'BETWEEN'},
  268. {field: 'amount_install', title: __('Amount_install'), operate:'BETWEEN'},
  269. {field: 'num', title: __('购买数量'),operate: 'between'},
  270. {field: 'num_install', title: __('安装数量'),operate: 'between'},
  271. //{field: 'refund.refund_status', title: __('售后'),operate: 'eq',formatter: Table.api.formatter.label,searchList:refundStatus},
  272. ]
  273. ],
  274. onLoadSuccess(){
  275. setTimeout(()=>{
  276. $('.btn-detail').data('area',["500px","900px"])
  277. },200)
  278. }
  279. });
  280. // 为表格绑定事件
  281. Table.api.bindevent(table);
  282. $(document).on('click','.btnViewRefund',function (){
  283. let id=$(this).data('id')
  284. parent.Fast.api.open(`${$.fn.bootstrapTable.defaults.extend.refund_detail_url}?ids=${id}`,'售后详情')
  285. })
  286. },
  287. };
  288. return Controller;
  289. });