goods.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form','vue'], function ($, undefined, Backend, Table, Form, Vue) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. dragsort_url: '',
  8. index_url: 'service/shop/goods/index' + location.search,
  9. add_url: 'service/shop/goods/add',
  10. edit_url: 'service/shop/goods/edit',
  11. multi_url: 'service/shop/goods/multi',
  12. import_url: 'service/shop/goods/import',
  13. table: 'service_goods',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'updatetime',
  22. fixedColumns: true,
  23. fixedRightNumber: 1,
  24. columns: [
  25. [
  26. {field: 'id', title: __('商品信息'),operate: false,cellStyle: function () {return {css: {"min-width": "200px"}}},formatter:function (value,row){
  27. let result = `<div style="display: flex;align-items: center">
  28. <img src="${row.image}" alt="" style="width: 92px;height: 92px;">
  29. <div style="flex: 1;margin-left: 20px;">
  30. <div style="width: 100%;display: flex;align-items: center;justify-content: space-between">
  31. <div style="color: #333;font-size: 14px;margin-right: 10px;font-weight:bold;">${row.name}</div>`;
  32. if(row.status == 'normal'){
  33. result += `<div style="background: #FFF7E6;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;color: #FFA600;margin-right: 10px;font-size:12px;">已上架</div>`
  34. }else {
  35. result += `<div style="background: #F7F7F7;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;color: #A4A9B7;margin-right: 10px;font-size:12px;">已下架</div>`
  36. }
  37. result += `
  38. <div style="flex:1"></div>
  39. <div style="color: #E4484B;font-size: 14px;">¥${row.price}</div>
  40. <div style="background: rgba(248, 118, 121, 0.10);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;margin-left: 8px;color:rgba(248, 118, 121, 1);"><span style="color: rgba(248, 118, 121, 1)">ID:</span>${row.id}</div>
  41. </div>
  42. <div style="color: #666;font-size: 12px;text-align: left;margin: 10px 0;">${row.tag_name}</div>
  43. <div style="display: flex;align-items: center;">
  44. <div style="background: #F0FAF3;height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;color: #62CB81;margin-right: 10px;font-size:12px;">${row.categoryName}/${row.twoCategoryName}</div>
  45. <div style="background: rgba(97, 22, 255, 0.07);height: 26px;display: flex;align-items: center;padding: 0 8px;border-radius: 13px;color: rgba(97, 22, 255, 1);margin-right: 10px;font-size:12px;">${row.to_shop_text}</div>
  46. <div></div>
  47. <div style="color: #999;font-size: 12px;">销量:${row.salenums}</div>
  48. </div>
  49. <div style="display: flex;align-items: center;margin-top: 8px;width: 100%;">
  50. <div style="width: 100%;background: #EFF5FF;display: flex;align-items: center;padding: 8px;border-radius: 6px;color: #1677FF;"><span style="color: #999999">所属商家:</span>${row.shopname}</div>
  51. </div>
  52. </div>
  53. </div>`
  54. return result
  55. }},
  56. {field: 'id', title: __('城市/规格'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  57. let result = '';
  58. if(row.city){
  59. result += `<div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  60. <span style="font-size: 14px;color: #999;">城市</span>
  61. <span style="color: #333333;font-size: 14px;">${row.city}专属</span>
  62. </div>`
  63. }else {
  64. result += `<div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  65. <span style="font-size: 14px;color: #999;">城市</span>
  66. <span style="color: #333333;font-size: 14px;">全国通用</span>
  67. </div>`
  68. }
  69. if(row.spec_type == 1){
  70. result += `
  71. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  72. <span style="font-size: 14px;color: #999;">规格</span>
  73. <span style="color: #6116FF;font-size: 14px;">${row.spec_type_text}</span>
  74. </div>
  75. `
  76. }else {
  77. result += `
  78. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  79. <span style="font-size: 14px;color: #999;">规格</span>
  80. <span style="color: #1677FF;font-size: 14px;">${row.spec_type_text}</span>
  81. </div>
  82. `
  83. }
  84. return result
  85. }},
  86. {field: 'id', title: __('服务者职能'),operate: false,cellStyle: function () {return {css: {"min-width": "200px","max-width": "300px"}}},formatter:function (value,row){
  87. let word = row.skillCateName.split(',')
  88. let result = '<div style="color: #333;font-size: 14px;margin-bottom: 8px;flex-wrap: wrap;display: flex;align-items: center">';
  89. for(let i=0; i < word.length; i++){
  90. result += `<div style="margin: 0 8px 8px;">${word[i]}</div>`
  91. }
  92. result+='</div>'
  93. return result
  94. }},
  95. {field: 'id', title: __('时间设置'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  96. return `
  97. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  98. <span style="font-size: 14px;color: #999;">最早相应</span>
  99. <span style="color: #333;font-size: 14px;">${row.response_hour}小时</span>
  100. </div>
  101. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  102. <span style="font-size: 14px;color: #999;">可约时段</span>
  103. <span style="color: #FF1F2B;font-size: 14px;">${row.start_hour}点-${row.end_hour}点</span>
  104. </div>
  105. `
  106. }},
  107. {field: 'id', title: __('下单设置'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  108. return `
  109. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  110. <span style="font-size: 14px;color: #999;">是否选择出行</span>
  111. <span style="color: #62CB81;font-size: 14px;">${row.is_travel_text}</span>
  112. </div>
  113. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  114. <span style="font-size: 14px;color: #999;">是否选择服务人员</span>
  115. <span style="color: #333;font-size: 14px;">${row.choose_skill_type_text}</span>
  116. </div>
  117. `
  118. }},
  119. {field: 'id', title: __('状态'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  120. let result = ` <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  121. <span style="font-size: 14px;color: #999;">审核结果</span>
  122. <span style="color: #62CB81;font-size: 14px;">${row.shop_state_text}</span>
  123. </div>`
  124. if(row.shop_state == -1){
  125. result += `
  126. <div style="display: flex;align-items: flex-start;justify-content:space-between;width: 250px;height: 66px;white-space:normal;padding:20px 20px 0;border-top: 1px solid #EEEEEE;">
  127. <div style="font-size: 14px;color: #999;flex-shrink:0;">拒绝原因</div>
  128. <div style="color: #FF1F2B;font-size: 14px;text-align:left;margin-left:20px">${row.note}</div>
  129. </div>`
  130. }
  131. return result
  132. }},
  133. {field: 'id', title: __('时间/权重'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  134. return `
  135. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  136. <span style="font-size: 14px;color: #999;">更新时间</span>
  137. <span style="color: #333;font-size: 14px;">${row.update_time}</span>
  138. </div>
  139. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  140. <span style="font-size: 14px;color: #999;">权重</span>
  141. <span style="color: #FFA600;font-size: 14px;">${row.weigh}</span>
  142. </div>
  143. `
  144. }},
  145. {checkbox: true,visible: false},
  146. {field: 'id', title: __('Id'),visible: false},
  147. {field: 'name', title: __('Name'), operate: 'LIKE',visible: false},
  148. {field: 'category_id', title: __('Category_id'),visible: false},
  149. {field: 'two_category_id', title: __('Two_category_id'),visible: false},
  150. {field: 'skill_cate_ids', title: __('Skill_cate_ids'), operate: 'LIKE',visible: false},
  151. {field: 'shop_id', title: __('Shop_id'),visible: false},
  152. {field: 'shop_user_id', title: __('Shop_user_id'),visible: false},
  153. {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal,visible: false},
  154. {field: 'to_shop', title: __('To_shop'), searchList: {"door":__('To_shop door'),"shop":__('To_shop shop')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label,visible: false},
  155. {field: 'is_travel', title: __('Is_travel'), searchList: {"0":__('Is_travel 0'),"1":__('Is_travel 1')}, formatter: Table.api.formatter.normal,visible: false},
  156. {field: 'tag_name', title: __('Tag_name'), operate: 'LIKE',visible: false},
  157. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
  158. {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images,visible: false},
  159. {field: 'price', title: __('Price'), operate:'BETWEEN',visible: false},
  160. {field: 'cost_seconds', title: __('Cost_seconds'),visible: false},
  161. {field: 'response_hour', title: __('Response_hour'),visible: false},
  162. {field: 'spec_type', title: __('Spec_type'), searchList: {"0":__('Spec_type 0'),"1":__('Spec_type 1')}, formatter: Table.api.formatter.normal,visible: false},
  163. {field: 'choose_skill_type', title: __('Choose_skill_type'), searchList: {"0":__('Choose_skill_type 0'),"1":__('Choose_skill_type 1')}, formatter: Table.api.formatter.normal,visible: false},
  164. {field: 'flow_path_images', title: __('Flow_path_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images,visible: false},
  165. {field: 'illustrate_images', title: __('Illustrate_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images,visible: false},
  166. {field: 'salenums', title: __('Salenums'),visible: false},
  167. {field: 'shop_state', title: __('Shop_state'), searchList: {"0":__('Shop_state 0'),"1":__('Shop_state 1'),"-1":__('Shop_state -1')}, formatter: Table.api.formatter.normal,visible: false},
  168. {field: 'status', title: __('Status'), searchList: {"normal":__('Status normal'),"hidden":__('Status hidden')}, formatter: Table.api.formatter.status,visible: false},
  169. {field: 'note', title: __('Note'), operate: 'LIKE',visible: false},
  170. {field: 'weigh', title: __('Weigh'), operate: false,visible: false},
  171. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
  172. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
  173. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  174. buttons: [
  175. {
  176. name: 'agree',
  177. text: __('审核通过'),
  178. title: __('审核通过'),
  179. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  180. url: 'service/shop/goods/agree',
  181. success: function (data, ret) {
  182. $(".btn-refresh").trigger('click');
  183. },
  184. hidden:function(row){
  185. if(row.shop_state !== 0){
  186. return true;
  187. }
  188. },
  189. },
  190. {
  191. name: 'refuse',
  192. text: __('审核拒绝'),
  193. title: __('审核拒绝'),
  194. classname: 'btn btn-xs btn-danger btn-dialog',
  195. url: function(row){
  196. return 'service/shop/goods/refuse?ids='+row.id;
  197. },
  198. hidden:function(row){
  199. if(row.shop_state !== 0){
  200. return true;
  201. }
  202. },
  203. },
  204. {
  205. name: 'up',
  206. title: __('上架'),
  207. text: __('上架'),
  208. classname: 'btn btn-xs btn-detail btn-ajax',
  209. confirm: '确认上架?',
  210. url: function(row){
  211. return 'service/goods/updateGoodsStatus?status=normal&id='+row.id;
  212. },
  213. success: function (data, ret) {
  214. $(".btn-refresh").trigger('click');
  215. },
  216. visible:function(row){
  217. if(row.shop_state == 1 && row.status == 'hidden'){
  218. return true;
  219. }
  220. }
  221. },
  222. {
  223. name: 'down',
  224. title: __('下架'),
  225. text: __('下架'),
  226. classname: 'btn btn-xs btn-down btn-ajax',
  227. confirm: '确认下架?',
  228. url: function(row){
  229. return 'service/goods/updateGoodsStatus?status=hidden&id='+row.id;
  230. },
  231. success: function (data, ret) {
  232. $(".btn-refresh").trigger('click');
  233. },
  234. error: function (data, ret) {
  235. console.log(data, ret);
  236. Layer.alert(ret.msg);
  237. return false;
  238. },
  239. visible:function(row){
  240. if(row.shop_state == 1 && row.status == 'normal'){
  241. return true;
  242. }
  243. }
  244. },
  245. {
  246. name: 'list',
  247. title: __('附加项目'),
  248. text: __('附加项目'),
  249. classname: 'btn btn-xs btn-change btn-dialog',
  250. url: function(row){
  251. return 'service/goodsadd/index?goods_id='+row.id;
  252. },
  253. },
  254. {
  255. name: 'edit',
  256. text: __('编辑'),
  257. title: __('编辑'),
  258. classname: 'btn btn-xs btn-status btn-dialog',
  259. icon: 'fa fa-list-o',
  260. url: 'service/shop/goods/edit',
  261. },
  262. {
  263. name: 'del',
  264. text: __('删除'),
  265. title: __('删除'),
  266. classname: 'btn btn-xs btn-cancel btn-dialog',
  267. icon: 'fa fa-list-o',
  268. url: 'service/shop/goods/del',
  269. }
  270. ],formatter: Table.api.formatter.operate}
  271. ]
  272. ]
  273. });
  274. // 为表格绑定事件
  275. Table.api.bindevent(table);
  276. },
  277. recyclebin: function () {
  278. // 初始化表格参数配置
  279. Table.api.init({
  280. extend: {
  281. 'dragsort_url': ''
  282. }
  283. });
  284. var table = $("#table");
  285. // 初始化表格
  286. table.bootstrapTable({
  287. url: 'service/shop/goods/recyclebin' + location.search,
  288. pk: 'id',
  289. sortName: 'id',
  290. columns: [
  291. [
  292. {checkbox: true},
  293. {field: 'id', title: __('Id')},
  294. {field: 'name', title: __('Name'), align: 'left'},
  295. {
  296. field: 'deletetime',
  297. title: __('Deletetime'),
  298. operate: 'RANGE',
  299. addclass: 'datetimerange',
  300. formatter: Table.api.formatter.datetime
  301. },
  302. {
  303. field: 'operate',
  304. width: '140px',
  305. title: __('Operate'),
  306. table: table,
  307. events: Table.api.events.operate,
  308. buttons: [
  309. {
  310. name: 'Restore',
  311. text: __('Restore'),
  312. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  313. icon: 'fa fa-rotate-left',
  314. url: 'service/shop/goods/restore',
  315. refresh: true
  316. },
  317. {
  318. name: 'Destroy',
  319. text: __('Destroy'),
  320. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  321. icon: 'fa fa-times',
  322. url: 'service/shop/goods/destroy',
  323. refresh: true
  324. }
  325. ],
  326. formatter: Table.api.formatter.operate
  327. }
  328. ]
  329. ]
  330. });
  331. // 为表格绑定事件
  332. Table.api.bindevent(table);
  333. },
  334. agree: function () {
  335. $(document).on('click', '.btn-embossed', function () {
  336. parent.$(".btn-refresh").trigger('click');
  337. });
  338. Controller.api.bindevent();
  339. },
  340. refuse: function () {
  341. $(document).on('click', '.btn-embossed', function () {
  342. parent.$(".btn-refresh").trigger('click');
  343. });
  344. Controller.api.bindevent();
  345. },
  346. add: function () {
  347. Controller.api.bindevent();
  348. },
  349. edit: function () {
  350. let add = new Vue({
  351. el: '#app',
  352. data(){
  353. return {
  354. category_id: '',
  355. two_category_id: '',
  356. spec_type: Config.spec_type,
  357. choose_skill_type: Config.choose_skill_type,
  358. categoryList: [{name: '测试',id:1}],
  359. spu: Config.spec_type === 1 ? Config.spu : [{
  360. name: '',
  361. info: [{name: ''}]
  362. }],
  363. sku: Config.spec_type === 1 ? Config.sku :[],
  364. status: Config.status
  365. }
  366. },
  367. watch:{
  368. spu:{
  369. deep: true,
  370. handler(){
  371. let sku = this.combination(this.spu)
  372. let arr = [];
  373. for(let i = 0; i < sku.length; i++){
  374. arr.push({
  375. name: sku[i].join(','),
  376. cost_seconds:'',
  377. price: ''
  378. })
  379. }
  380. this.sku = arr;
  381. }
  382. },
  383. category_id(){
  384. console.log(111)
  385. this.two_category_id = ''
  386. }
  387. },
  388. methods:{
  389. changeCate(){
  390. console.log(1111)
  391. Fast.api.ajax({
  392. url: 'service/goods/category',
  393. loading: true,
  394. data: {
  395. pid: this.category_id
  396. }
  397. }, function (ret, res) {
  398. Fast.api.close();
  399. })
  400. },
  401. changeSpecType(e){
  402. console.log(this.spec_type)
  403. },
  404. addSpuName(){
  405. this.spu.push({
  406. name: '',
  407. info: [{name: ''}]
  408. })
  409. },
  410. delSpuName(index){
  411. this.spu.splice(index,1)
  412. },
  413. delSkuName(key, value){
  414. value.splice(key,1)
  415. },
  416. addSkuName(value){
  417. value.push({name: ''})
  418. },
  419. combination(spu){
  420. let result = [[]];
  421. spu.map(a=>{
  422. var res = [];
  423. result.map(b=>{
  424. a.info.map(c => {
  425. res.push([...b,c.name])
  426. })
  427. })
  428. result = res;
  429. })
  430. return result
  431. }
  432. }
  433. })
  434. Controller.api.bindevent();
  435. },
  436. api: {
  437. bindevent: function () {
  438. Form.api.bindevent($("form[role=form]"));
  439. }
  440. }
  441. };
  442. return Controller;
  443. });