index.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('component/com-add-cat',__DIR__);
  4. ComponentHelper::loadComponentView('com-export-dialog');
  5. ?>
  6. <style>
  7. </style>
  8. <div id="app" v-cloak>
  9. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  10. <div slot="header">
  11. <span>商品列表</span>
  12. <div style="float: right; margin: -5px 0">
  13. <el-button type="primary" size="small" @click="handle('edit')">添加商品</el-button>
  14. </div>
  15. </div>
  16. <div class="table-body">
  17. <el-tabs v-model="activeName" @tab-click="handleClick">
  18. <el-tab-pane v-for="item in tabs" :key="item.value" :label="item.name" :name="item.value">
  19. <el-form :inline="true" :model="search_data" size="small" class="demo-form-inline">
  20. <el-form-item>
  21. <el-button size="small" @click="$refs.cats.openDialog()">分类筛选</el-button>
  22. <el-button size="small" v-if="search_data.cats && search_data.cats.length > 0" type="danger" @click="clearCat">清除分类</el-button>
  23. </el-form-item>
  24. <el-form-item >
  25. <el-date-picker style="margin-top: 1px;" size="small" @change="changeTime" v-model="datetime" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
  26. </el-form-item>
  27. <el-form-item label="">
  28. <el-input size="small" placeholder="请输入商品名称" v-model="search_data.goods_name"></el-input>
  29. </el-form-item>
  30. <el-form-item label="">
  31. <el-input size="small" placeholder="请输入商品ID精准搜索" v-model="search_data.goods_id"></el-input>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="primary" @click="search">搜索</el-button>
  35. <el-button type="danger" @click="clearSearch" v-if="show_clear_search_btn">清除条件</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <template >
  39. <el-button @click="upDown(1)" size="mini">批量上架</el-button>
  40. <el-button @click="upDown(0)" size="mini">批量下架</el-button>
  41. </template>
  42. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%" @sort-change="sortChange" @selection-change="handleSelectionChange">
  43. <el-table-column type="selection" align="center" width="60"></el-table-column>
  44. <el-table-column label="ID" prop="id" align="center"></el-table-column>
  45. <el-table-column prop="sort" label="排序" width="150">
  46. <template slot-scope="scope">
  47. <div v-if="sort_id != scope.row.id">
  48. <el-tooltip class="item" effect="dark" content="排序" placement="top">
  49. <span>{{scope.row.sort}}</span>
  50. </el-tooltip>
  51. <el-button class="edit-sort" type="text" @click="edit(scope.row,'sort')">
  52. <img src="resources/img/mall/order/edit.png" alt="">
  53. </el-button>
  54. </div>
  55. <div style="display: flex;align-items: center" v-else>
  56. <el-input style="min-width: 70px" type="number" size="mini" class="change" v-model="sort" autocomplete="off"></el-input>
  57. <el-button class="change-quit" type="text" style="color: #F56C6C;padding: 0 5px" icon="el-icon-error" circle @click="cancelEdit('sort')"></el-button>
  58. <el-button class="change-success" type="text" style="margin-left: 0;color: #67C23A;padding: 0 5px" icon="el-icon-success" circle @click="handle('sort',scope.row)">
  59. </el-button>
  60. </div>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="分类" align="center">
  64. <template slot-scope="scope">
  65. <div class="goods-cat">
  66. <el-tag v-if="scope.row.cats && scope.row.cats.length > 0" size="mini">
  67. {{scope.row.cats[0].name}}
  68. </el-tag>
  69. <el-tooltip v-if="scope.row.cats && scope.row.cats.length > 1" placement="top">
  70. <div slot="content">
  71. <span v-for="item in scope.row.cats" :key="item.id">{{item.name}}&nbsp;</span>
  72. </div>
  73. <span>...</span>
  74. </el-tooltip>
  75. </div>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="商品名称" min-width="200" prop="goods_name" align="center">
  79. <template slot-scope="scope">
  80. <div flex="cross:center">
  81. <div style="margin-right: 10px;">
  82. <el-image style="width: 50px; height: 50px;border-radius: 5px;" :src="scope.row.cover_pic"></el-image>
  83. </div>
  84. <div v-if="goods_name_id != scope.row.id">
  85. <el-tooltip class="item" effect="dark" content="商品名称" placement="top">
  86. <span>{{scope.row.goods_name}}</span>
  87. </el-tooltip>
  88. <el-button class="edit-sort" type="text" @click="edit(scope.row,'goods_name')">
  89. <img src="resources/img/mall/order/edit.png" alt="">
  90. </el-button>
  91. </div>
  92. <div style="display: flex;align-items: center" v-else>
  93. <el-input style="min-width: 70px" size="mini" class="change" v-model="goods_name" autocomplete="off"></el-input>
  94. <el-button class="change-quit" type="text" style="color: #F56C6C;padding: 0 5px" icon="el-icon-error" circle @click="cancelEdit('goods_name')"></el-button>
  95. <el-button class="change-success" type="text" style="margin-left: 0;color: #67C23A;padding: 0 5px" icon="el-icon-success" circle @click="handle('goods_name',scope.row)">
  96. </el-button>
  97. </div>
  98. </div>
  99. </template>
  100. </el-table-column>
  101. <el-table-column label="售价" prop="price" align="center" sortable="false">
  102. <template slot-scope="scope">
  103. <div size="small">{{scope.row.price}}</div>
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="库存" prop="stock" align="center" sortable="false">
  107. <template slot-scope="scope">
  108. <div size="small" style="color: red;" v-if="scope.row.stock<=scope.row.stock_warning">{{scope.row.stock}}</div>
  109. <div size="small" v-else>{{scope.row.stock}}</div>
  110. </template>
  111. </el-table-column>
  112. <el-table-column label="审核状态" prop="check_status" align="center">
  113. <template slot-scope="scope">
  114. <div size="small" v-if="scope.row.check_status == 1">已通过</div>
  115. <div size="small" v-if="scope.row.check_status == 2">不通过</div>
  116. <div size="small" v-if="scope.row.check_status == 0">审核中</div>
  117. </template>
  118. </el-table-column>
  119. <el-table-column label="审核备注" prop="check_status" align="center">
  120. <template slot-scope="scope">
  121. <div size="small" v-if="scope.row.check_status == 2">{{scope.row.check_remark}}</div>
  122. </template>
  123. </el-table-column>
  124. <el-table-column label="状态" prop="is_on_sale" align="center">
  125. <template slot-scope="scope">
  126. <div size="small" v-if="scope.row.is_on_sale == 1">上架</div>
  127. <div size="small" v-if="scope.row.is_on_sale == 0">下架</div>
  128. </template>
  129. </el-table-column>
  130. <el-table-column label="类型" prop="goods_type" align="center">
  131. <template slot-scope="scope">
  132. <div size="small" v-if="scope.row.goods_type == 1">实体商品</div>
  133. <div size="small" v-if="scope.row.goods_type == 2">虚拟商品</div>
  134. <div size="small" v-if="scope.row.goods_type == 3">预约商品</div>
  135. </template>
  136. </el-table-column>
  137. <el-table-column label="创建时间" width="160" prop="created_at" align="center">
  138. <template slot-scope="scope">
  139. <div size="small">{{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  140. </template>
  141. </el-table-column>
  142. <el-table-column label="操作" min-width="300" align="center">
  143. <template slot-scope="scope">
  144. <template v-if="scope.row.addons_name!=''">
  145. <el-tooltip class="item" effect="dark" content="该商品正在参与营销活动,暂不可操作" placement="left-start">
  146. <el-tag size="small" type="warning">{{scope.row.addons_name}}</el-tag>
  147. </el-tooltip>
  148. </template>
  149. <template v-else="group_buy_active_arr[scope.row.id]">
  150. <el-button type="text" @click="handle('edit',scope.row)">编辑</el-button>
  151. <el-button type="text" @click="handle('destroy',scope.row)">删除</el-button>
  152. <el-button type="text" @click="handle('is_on_sale',scope.row)">
  153. <span size="small" v-if="scope.row.is_on_sale == 0">上架</span>
  154. <span size="small" v-if="scope.row.is_on_sale == 1">下架</span>
  155. </el-button>
  156. <el-button type="text" @click="handle('model',scope.row)">模式</el-button>
  157. </template>
  158. </template>
  159. </el-table-column>
  160. </el-table>
  161. <div style="text-align: right;margin: 20px 0;">
  162. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  163. </div>
  164. </el-tab-pane>
  165. </el-tabs>
  166. </div>
  167. </el-card>
  168. <!-- 分类筛选 -->
  169. <com-add-cat ref="cats" :new-cats="search_data.cats" @select="selectCat" :mch_id="mch_id"></com-add-cat>
  170. </div>
  171. <script>
  172. const app = new Vue({
  173. el: '#app',
  174. data() {
  175. return {
  176. goods_name: '',
  177. goods_id: '',
  178. tabs: [{
  179. name: '全部',
  180. value: 'all'
  181. },
  182. {
  183. name: '审核中',
  184. value: 'checking'
  185. },
  186. {
  187. name: '销售中',
  188. value: 'onsale'
  189. },
  190. {
  191. name: '下架中',
  192. value: 'offline'
  193. },
  194. {
  195. name: '售罄',
  196. value: 'sell-out'
  197. },
  198. ],
  199. activeName: 'all',
  200. list: [],
  201. listLoading: false,
  202. page: 1,
  203. pageCount: 0,
  204. mch_id: 0, // 这个地方不知道要怎么获取
  205. searchCats: [],
  206. datetime: [],
  207. search_data: { // 筛选条件
  208. type: null,
  209. cats: [],
  210. start: null,
  211. end: null,
  212. goods_id: null,
  213. goods_name: null,
  214. },
  215. sort: 0,
  216. sort_id: 0,
  217. goods_name_id: 0,
  218. export_url: 'mall/goods/export-excel',
  219. export_list:{},
  220. group_buy_active_arr:{},
  221. chooseList:[],
  222. sign:''
  223. };
  224. },
  225. mounted: function() {
  226. this.getList();
  227. },
  228. created() {
  229. this.sign = getQuery('sign')
  230. },
  231. computed: {
  232. show_clear_search_btn: function() {
  233. return !isEmpty(this.search_data.cats) || !isEmpty(this.search_data.start) ||
  234. !isEmpty(this.search_data.end) || !isEmpty(this.search_data.goods_id) ||
  235. !isEmpty(this.search_data.goods_name);
  236. }
  237. },
  238. methods: {
  239. selectCat(arr) {
  240. this.search_data.cats = [];
  241. arr.forEach(it => this.search_data.cats.push(it.id))
  242. this.getList()
  243. },
  244. clearCat() { // 清除分类
  245. this.search_data.cats = []
  246. this.getList()
  247. },
  248. changeTime(e) {
  249. // console.log(e)
  250. this.search_data.start = e[0]
  251. this.search_data.end = e[1]
  252. },
  253. handleClick(res) { //标签页切换
  254. if (this.search_data.status == this.activeName) return;
  255. this.search_data.type = this.activeName;
  256. this.getList();
  257. },
  258. sortChange(row) {
  259. if (row.prop) {
  260. this.search_data.sort_field = row.prop;
  261. this.search_data.sort_type = row.order == "descending" ? 'desc' : 'asc';
  262. } else {
  263. this.search_data.sort_prop = null;
  264. this.search_data.sort_type = null;
  265. }
  266. this.getList();
  267. },
  268. search() {
  269. this.page = 1;
  270. this.getList();
  271. },
  272. clearSearch() {
  273. this.search_data.cats = [];
  274. this.search_data.start = null;
  275. this.search_data.end = null;
  276. this.search_data.goods_id = null;
  277. this.search_data.goods_name = null;
  278. this.datetime = [];
  279. this.getList();
  280. },
  281. handle(type, data = null) {
  282. let id = data ? parseInt(data.id) : '';
  283. switch (type) {
  284. case 'edit':
  285. let params = {
  286. r: 'mch/client/goods/edit'
  287. };
  288. if (id) params = Object.assign(params, {
  289. id: id,
  290. sign:this.sign
  291. });
  292. navigateTo(params);
  293. break;
  294. case 'model':// 模式跳转
  295. param = {
  296. r: 'mch/client/goods/goods-model'
  297. };
  298. if (id) param = Object.assign(param, {
  299. id: id,
  300. sign:this.sign
  301. });
  302. navigateTo(param);
  303. break;
  304. case 'destroy':
  305. param = {id: data.id,type};
  306. this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {type: 'warning'}).then(() => {this.send(param)})
  307. break;
  308. case 'sort':
  309. param = {
  310. id: id,
  311. sort: this.sort,
  312. type
  313. };
  314. this.send(param);
  315. break;
  316. case 'goods_name':
  317. param = {
  318. id: id,
  319. goods_name: this.goods_name,
  320. type
  321. };
  322. this.send(param);
  323. break;
  324. case 'is_on_sale':
  325. param = {
  326. id: id,
  327. is_on_sale: data.is_on_sale == 0 ? 1 : 0,
  328. type
  329. };
  330. operate_type = data.is_on_sale == 0 ? '上架' : '下架';
  331. this.$confirm('是否'+operate_type+'该商品?', '警告', {type: 'warning'}).then(() => {this.send(param)})
  332. break;
  333. }
  334. this.cancelEdit(type);
  335. },
  336. send(params) {
  337. let self = this;
  338. request({
  339. params: {
  340. r: 'mch/client/goods/index',
  341. },
  342. method: 'post',
  343. data: params
  344. }).then(e => {
  345. if (e.data.code == 0) {
  346. self.$message.success(e.data.msg);
  347. self.getList();
  348. } else {
  349. self.$message.error(e.data.msg);
  350. }
  351. }).catch(e => {
  352. console.log(e);
  353. });
  354. },
  355. edit(row, type) {
  356. switch (type) {
  357. case 'sort':
  358. this.sort = row.sort;
  359. this.sort_id = row.id;
  360. break;
  361. case 'goods_name':
  362. this.goods_name_id = row.id;
  363. this.goods_name = row.goods_name;
  364. break;
  365. }
  366. },
  367. cancelEdit(type) {
  368. switch (type) {
  369. case 'sort':
  370. this.sort = 0;
  371. this.sort_id = 0;
  372. break;
  373. case 'goods_name':
  374. this.goods_name = '';
  375. this.goods_name_id = 0;
  376. break;
  377. }
  378. },
  379. searchClick() {
  380. this.page = 1;
  381. this.getList();
  382. },
  383. pagination(currentPage) {
  384. let self = this;
  385. self.page = currentPage;
  386. self.getList();
  387. },
  388. // 获取商品列表
  389. getList() {
  390. let self = this;
  391. let basic_params = {
  392. r: 'mch/client/goods/index',
  393. page: self.page,
  394. };
  395. params = Object.assign(basic_params, this.search_data);
  396. if (self.listLoading == false) {
  397. self.listLoading = true;
  398. request({
  399. params: params,
  400. method: 'get',
  401. }).then(e => {
  402. self.listLoading = false;
  403. if (e.data.code == 0) {
  404. self.list = e.data.data.list;
  405. self.group_buy_active_arr = e.data.data.group_buy_active_arr;
  406. self.pageCount = e.data.data.page_count;
  407. this.export_list = e.data.data.export_list;
  408. } else {
  409. self.$message.error(e.data.msg);
  410. }
  411. }).catch(e => {
  412. self.$message.error(e.data.msg);
  413. self.listLoading = false;
  414. });
  415. }
  416. },
  417. // 全选单前页
  418. handleSelectionChange(val) {
  419. let self = this;
  420. self.chooseList = [];
  421. val.forEach(function (item) {
  422. self.chooseList.push(item.id);
  423. })
  424. },
  425. checkChooseList() {
  426. if (this.isAllChecked) {
  427. this.dialogTitle = '已选所有商品';
  428. return true;
  429. }
  430. if (this.chooseList.length > 0) {
  431. this.dialogTitle = '已选商品' + this.chooseList.length + '种';
  432. return true;
  433. }
  434. this.$message.warning('请先勾选要设置的商品');
  435. return false;
  436. },
  437. upDown(command) {
  438. let self = this;
  439. if (!self.checkChooseList()) {
  440. return false;
  441. }
  442. let text = this.isAllChecked ? '警告:批量' + (command === 1 ? '上架' : '下架') + '所有商品?' : '批量' + (command === 1 ? '上架' : '下架') + ',是否继续';
  443. this.$confirm(text, '警告', {type: 'warning'}).then(() => {
  444. request({
  445. params: {
  446. r: 'mch/client/goods/batch-change-status',
  447. },
  448. method: 'post',
  449. data: {
  450. ids: this.chooseList,
  451. status: command,
  452. },
  453. }).then(e => {
  454. if (e.data.code == 0) {
  455. self.$message.success(e.data.msg);
  456. self.getList();
  457. } else {
  458. self.$message.error(e.data.msg);
  459. }
  460. }).catch(e => {
  461. console.log(e);
  462. });
  463. });
  464. },
  465. }
  466. });
  467. </script>