goods.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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/goods/index' + location.search,
  9. add_url: 'service/goods/add',
  10. edit_url: 'service/goods/edit',
  11. multi_url: 'service/goods/multi',
  12. import_url: 'service/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: 'weigh',
  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>
  50. </div>`
  51. return result
  52. }},
  53. {field: 'id', title: __('城市/规格'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  54. let result = '';
  55. if(row.city){
  56. result += `<div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  57. <span style="font-size: 14px;color: #999;">城市</span>
  58. <span style="color: #333333;font-size: 14px;">${row.city}专属</span>
  59. </div>`
  60. }else {
  61. result += `<div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  62. <span style="font-size: 14px;color: #999;">城市</span>
  63. <span style="color: #333333;font-size: 14px;">全国通用</span>
  64. </div>`
  65. }
  66. if(row.spec_type == 1){
  67. result += `
  68. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  69. <span style="font-size: 14px;color: #999;">规格</span>
  70. <span style="color: #6116FF;font-size: 14px;">${row.spec_type_text}</span>
  71. </div>
  72. `
  73. }else {
  74. result += `
  75. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  76. <span style="font-size: 14px;color: #999;">规格</span>
  77. <span style="color: #1677FF;font-size: 14px;">${row.spec_type_text}</span>
  78. </div>
  79. `
  80. }
  81. return result
  82. }},
  83. {field: 'id', title: __('服务者职能'),operate: false,cellStyle: function () {return {css: {"min-width": "200px","max-width": "300px"}}},formatter:function (value,row){
  84. let word = row.skillCateName.split(',')
  85. let result = '<div style="color: #333;font-size: 14px;margin-bottom: 8px;flex-wrap: wrap;display: flex;align-items: center">';
  86. for(let i=0; i < word.length; i++){
  87. result += `<div style="margin: 0 8px 8px;">${word[i]}</div>`
  88. }
  89. result+='</div>'
  90. return result
  91. }},
  92. {field: 'id', title: __('时间设置'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  93. return `
  94. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  95. <span style="font-size: 14px;color: #999;">最早相应</span>
  96. <span style="color: #333;font-size: 14px;">${row.response_hour}小时</span>
  97. </div>
  98. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  99. <span style="font-size: 14px;color: #999;">可约时段</span>
  100. <span style="color: #FF1F2B;font-size: 14px;">${row.start_hour}点-${row.end_hour}点</span>
  101. </div>
  102. `
  103. }},
  104. {field: 'id', title: __('下单设置'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  105. return `
  106. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  107. <span style="font-size: 14px;color: #999;">是否选择出行</span>
  108. <span style="color: #62CB81;font-size: 14px;">${row.is_travel_text}</span>
  109. </div>
  110. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  111. <span style="font-size: 14px;color: #999;">是否选择服务人员</span>
  112. <span style="color: #333;font-size: 14px;">${row.choose_skill_type_text}</span>
  113. </div>
  114. `
  115. }},
  116. {field: 'id', title: __('时间/权重'),operate: false, cellStyle: function () {return {css: {"min-width": "250px"}}},formatter:function (value,row){
  117. return `
  118. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;border-bottom: 1px solid #EEEEEE;">
  119. <span style="font-size: 14px;color: #999;">更新时间</span>
  120. <span style="color: #333;font-size: 14px;">${row.update_time}</span>
  121. </div>
  122. <div style="display: flex;align-items: center;justify-content:space-between;padding: 0 20px;width: 250px;height: 66px;">
  123. <span style="font-size: 14px;color: #999;">权重</span>
  124. <span style="color: #FFA600;font-size: 14px;">${row.weigh}</span>
  125. </div>
  126. `
  127. }},
  128. {checkbox: true,visible: false},
  129. {field: 'id', title: __('Id'),visible: false},
  130. {field: 'name', title: __('Name'), operate: 'LIKE',visible: false},
  131. {field: 'category_id', title: __('Category_id'),visible: false},
  132. {field: 'two_category_id', title: __('Two_category_id'),visible: false},
  133. {field: 'skill_cate_ids', title: __('Skill_cate_ids'),visible: false},
  134. {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1')}, formatter: Table.api.formatter.normal,visible: false},
  135. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image,visible: false},
  136. {field: 'images', title: __('Images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images,visible: false},
  137. {field: 'price', title: __('Price'), operate:'BETWEEN',visible: false},
  138. {field: 'response_hour', title: __('Response_hour'),visible: false},
  139. {field: 'spec_type', title: __('Spec_type'), searchList: {"0":__('Spec_type 0'),"1":__('Spec_type 1')}, formatter: Table.api.formatter.normal,visible: false},
  140. // {field: 'flow_path_images', title: __('Flow_path_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  141. // {field: 'illustrate_images', title: __('Illustrate_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
  142. {field: 'salenums', title: __('Salenums'),visible: false},
  143. {field: 'status', title: __('Status'), searchList: {"normal":__('Status normal'),"hidden":__('Status hidden')}, formatter: Table.api.formatter.status,visible: false},
  144. {field: 'weigh', title: __('Weigh'), operate: false,visible: false},
  145. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
  146. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible: false},
  147. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
  148. buttons: [
  149. {
  150. name: 'up',
  151. title: __('上架'),
  152. text: __('上架'),
  153. classname: 'btn btn-xs btn-detail btn-ajax',
  154. confirm: '确认上架?',
  155. url: function(row){
  156. return 'service/goods/updateGoodsStatus?status=normal&id='+row.id;
  157. },
  158. success: function (data, ret) {
  159. $(".btn-refresh").trigger('click');
  160. },
  161. hidden:function(row){
  162. if(row.status == 'normal'){
  163. return true;
  164. }
  165. }
  166. },
  167. {
  168. name: 'down',
  169. title: __('下架'),
  170. text: __('下架'),
  171. classname: 'btn btn-xs btn-down btn-ajax',
  172. confirm: '确认下架?',
  173. url: function(row){
  174. return 'service/goods/updateGoodsStatus?status=hidden&id='+row.id;
  175. },
  176. success: function (data, ret) {
  177. $(".btn-refresh").trigger('click');
  178. },
  179. hidden:function(row){
  180. if(row.status == 'hidden'){
  181. return true;
  182. }
  183. }
  184. },
  185. {
  186. name: 'list',
  187. title: __('附加项目'),
  188. text: __('附加项目'),
  189. classname: 'btn btn-xs btn-change btn-dialog',
  190. url: function(row){
  191. return 'service/goodsadd/index?goods_id='+row.id;
  192. },
  193. },
  194. {
  195. name: 'edit',
  196. text: __('编辑'),
  197. title: __('编辑'),
  198. classname: 'btn btn-xs btn-status btn-dialog',
  199. icon: 'fa fa-list-o',
  200. url: 'service/goods/edit',
  201. }
  202. ],
  203. formatter: Table.api.formatter.operate}
  204. ]
  205. ]
  206. });
  207. // 为表格绑定事件
  208. Table.api.bindevent(table);
  209. },
  210. add: function () {
  211. let add = new Vue({
  212. el: '#app',
  213. data(){
  214. return {
  215. category_id: '',
  216. two_category_id: '',
  217. spec_type: 0,
  218. choose_skill_type: 0,
  219. categoryList: [{name: '测试',id:1}],
  220. spu: [{
  221. name: '',
  222. info: [{name: ''}]
  223. }],
  224. sku: [],
  225. }
  226. },
  227. watch:{
  228. spu:{
  229. deep: true,
  230. handler(){
  231. let sku = this.combination(this.spu)
  232. let arr = [];
  233. for(let i = 0; i < sku.length; i++){
  234. arr.push({
  235. name: sku[i].join(','),
  236. cost_seconds:'',
  237. price: '',
  238. unit: ''
  239. })
  240. }
  241. this.sku = arr;
  242. }
  243. },
  244. category_id(){
  245. console.log(111)
  246. this.two_category_id = ''
  247. }
  248. },
  249. methods:{
  250. changeCate(){
  251. console.log(1111)
  252. Fast.api.ajax({
  253. url: 'service/goods/category',
  254. loading: true,
  255. data: {
  256. pid: this.category_id
  257. }
  258. }, function (ret, res) {
  259. Fast.api.close();
  260. })
  261. },
  262. changeSpecType(e){
  263. console.log(this.spec_type)
  264. },
  265. addSpuName(){
  266. this.spu.push({
  267. name: '',
  268. info: [{name: ''}]
  269. })
  270. },
  271. delSpuName(index){
  272. this.spu.splice(index,1)
  273. },
  274. delSkuName(key, value){
  275. value.splice(key,1)
  276. },
  277. addSkuName(value){
  278. value.push({name: ''})
  279. },
  280. combination(spu){
  281. let result = [[]];
  282. spu.map(a=>{
  283. var res = [];
  284. result.map(b=>{
  285. a.info.map(c => {
  286. res.push([...b,c.name])
  287. })
  288. })
  289. result = res;
  290. })
  291. return result
  292. }
  293. }
  294. })
  295. Controller.api.bindevent();
  296. },
  297. edit: function () {
  298. let add = new Vue({
  299. el: '#app',
  300. data(){
  301. return {
  302. category_id: '',
  303. two_category_id: '',
  304. spec_type: Config.spec_type,
  305. choose_skill_type: Config.choose_skill_type,
  306. categoryList: [{name: '测试',id:1}],
  307. spu: Config.spec_type === 1 ? Config.spu : [{
  308. name: '',
  309. info: [{name: ''}]
  310. }],
  311. sku: Config.spec_type === 1 ? Config.sku :[],
  312. status: Config.status
  313. }
  314. },
  315. watch:{
  316. spu:{
  317. deep: true,
  318. handler(){
  319. let sku = this.combination(this.spu)
  320. let arr = [];
  321. for(let i = 0; i < sku.length; i++){
  322. arr.push({
  323. name: sku[i].join(','),
  324. cost_seconds:'',
  325. price: '',
  326. unit: ''
  327. })
  328. }
  329. this.sku = arr;
  330. }
  331. },
  332. category_id(){
  333. console.log(111)
  334. this.two_category_id = ''
  335. }
  336. },
  337. methods:{
  338. changeCate(){
  339. console.log(1111)
  340. Fast.api.ajax({
  341. url: 'service/goods/category',
  342. loading: true,
  343. data: {
  344. pid: this.category_id
  345. }
  346. }, function (ret, res) {
  347. Fast.api.close();
  348. })
  349. },
  350. changeSpecType(e){
  351. console.log(this.spec_type)
  352. },
  353. addSpuName(){
  354. this.spu.push({
  355. name: '',
  356. info: [{name: ''}]
  357. })
  358. },
  359. delSpuName(index){
  360. this.spu.splice(index,1)
  361. },
  362. delSkuName(key, value){
  363. value.splice(key,1)
  364. },
  365. addSkuName(value){
  366. value.push({name: ''})
  367. },
  368. combination(spu){
  369. let result = [[]];
  370. spu.map(a=>{
  371. var res = [];
  372. result.map(b=>{
  373. a.info.map(c => {
  374. res.push([...b,c.name])
  375. })
  376. })
  377. result = res;
  378. })
  379. return result
  380. }
  381. }
  382. })
  383. Controller.api.bindevent();
  384. },
  385. api: {
  386. bindevent: function () {
  387. Form.api.bindevent($("form[role=form]"));
  388. }
  389. }
  390. };
  391. return Controller;
  392. });