goods_list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <div>
  3. <use-table ref="tbl"></use-table>
  4. <div class="container container_status dflex_vertical_c">
  5. <div class="item_interval" v-for="(item, i) in stateDatas" :key="i">
  6. <el-button class="badge_txt" :class="{ active: item.cnt == req.state }" size="small" @click="cutSta(item)">{{ item.name }}</el-button>
  7. <!-- <v-countup class="badge" start-value="0" :end-value="item.cnt"></v-countup> -->
  8. </div>
  9. </div>
  10. <div class="container padding_b_0">
  11. <div class="dflex_wrap">
  12. <div class="dflex_vertical_c margin_r_40 margin_b_20">
  13. <div class="search_name">商品名称:</div>
  14. <el-input v-model="req.name" placeholder="请输入" @input="loadData" class="search_input"></el-input>
  15. </div>
  16. <el-button size="mini" class="search_btn margin_b_20 margin_r_40" @click="loadData">搜索</el-button>
  17. </div>
  18. </div>
  19. <div class="container use-table">
  20. <div class="dflex_sb margin_b_15">
  21. <div><el-button class="batch_btn padding0" @click="removes">删除</el-button></div>
  22. <el-button class="add_btn pos_r padding0" icon="iconfont iconxinzeng" @click="toAdd">新增</el-button>
  23. </div>
  24. <el-table :height="tblHeight" :data="tableDatas" @selection-change="selectionChange" highlight-current-row>
  25. <el-table-column type="selection"></el-table-column>
  26. <!-- <el-table-column label="排序" width="200" align="center">
  27. <template slot-scope="scope">
  28. <el-input-number size="small" :min="1" v-model="scope.row.sort" @change="sortChange(scope.row)" @blur="sortChange(scope.row)"></el-input-number>
  29. </template>
  30. </el-table-column> -->
  31. <el-table-column label="商品" width="330" align="center">
  32. <template slot-scope="scope">
  33. <div class="dflex_vertical_c">
  34. <el-image v-if="scope.row.imgs.search(',')==(-1)" style="width: 100px;height: 80px;" :src="scope.row.imgs || require('static/img/noimage.png')" :preview-src-list="scope.row.imgs" fit="contain"></el-image>
  35. <el-image v-else style="width: 100px;height: 80px;" :src="((scope.row.imgs).substring(0, ((scope.row.imgs).indexOf(',')))) || require('static/img/noimage.png')" :preview-src-list="scope.row.imgs" fit="contain"></el-image>
  36. <div class="left_just margin_l_10">
  37. <div class="ellipsis">{{ scope.row.name }}</div>
  38. </div>
  39. </div>
  40. </template>
  41. </el-table-column>
  42. <el-table-column label="价格" align="center">
  43. <template slot-scope="scope">
  44. <div class="price">{{ scope.row.price}}</div>
  45. <div class="m_price">{{ scope.row.marketPrice}}</div>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="限时精选" align="center">
  49. <template slot-scope="scope">
  50. <el-tooltip :content="scope.row.limited == '1' ? '取消限时精选' : '启用限时精选'" placement="top" :hide-after="1000" :enterable="false" effect="light">
  51. <el-switch
  52. v-model="scope.row.limited"
  53. active-color="#ff6a6c"
  54. inactive-color="#bbb"
  55. active-value="1"
  56. inactive-value="0"
  57. @change="limitedChang(scope.row)"
  58. ></el-switch>
  59. </el-tooltip>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="热门推荐" align="center">
  63. <template slot-scope="scope">
  64. <el-tooltip :content="scope.row.hot == '1' ? '取消热门推荐' : '启用热门推荐'" placement="top" :hide-after="1000" :enterable="false" effect="light">
  65. <el-switch
  66. v-model="scope.row.hot"
  67. active-color="#ff6a6c"
  68. inactive-color="#bbb"
  69. active-value="1"
  70. inactive-value="0"
  71. @change="hotChang(scope.row)"
  72. ></el-switch>
  73. </el-tooltip>
  74. </template>
  75. </el-table-column>
  76. <el-table-column label="状态" align="center">
  77. <template slot-scope="scope">
  78. <template v-if="scope.row.state==0">下架</template>
  79. <template v-if="scope.row.state==1">在售</template>
  80. <template v-if="scope.row.state==2">待审核</template>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="数据统计" align="left" width="150">
  84. <template slot-scope="scope">
  85. <div class="left_just">
  86. <div>已售数:{{ scope.row.saleCnt }}</div>
  87. <div>访问数:{{ scope.row.visitCnt }}</div>
  88. <div>收藏数:{{ scope.row.collectCnt }}</div>
  89. <!-- <div>分享数:{{ scope.row.shareCnt }}</div> -->
  90. </div>
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="操作" align="center" fixed="right" width="120">
  94. <template slot-scope="scope">
  95. <div>
  96. <el-tooltip content="上架" placement="top" :hide-after="1000" :enterable="false" effect="light" v-if="scope.row.state == '2'">
  97. <el-button icon="iconfont iconshangjia" circle @click="staUp(scope.row.id)"></el-button>
  98. </el-tooltip>
  99. <el-tooltip content="下架" placement="top" :hide-after="1000" :enterable="false" effect="light" v-if="scope.row.state == '1'">
  100. <el-button icon="iconfont iconxiajia1" circle @click="staOut(scope.row.id)"></el-button>
  101. </el-tooltip>
  102. <el-tooltip content="编辑" placement="top" :hide-after="1000" :enterable="false" effect="light">
  103. <el-button icon="iconfont iconbianji" circle @click="toEdit(scope.row.id)"></el-button>
  104. </el-tooltip>
  105. </div>
  106. <div class="margin_t_10">
  107. <el-tooltip content="删除" placement="top" :hide-after="1000" :enterable="false" effect="light" v-if="scope.row.state == '0' || scope.row.state == '2'">
  108. <el-button icon="iconfont iconshanchu" circle @click="remove(scope.row.id)"></el-button>
  109. </el-tooltip>
  110. <!-- <el-tooltip content="评价" placement="top" :hide-after="1000" :enterable="false" effect="light" v-if="scope.row.state == '1'">
  111. <el-button icon="iconfont iconpingjia1" circle @click="toEvaluate(scope.row.id)"></el-button>
  112. </el-tooltip> -->
  113. <!-- <el-tooltip content="二维码" placement="top" :hide-after="1000" :enterable="false" effect="light" v-if="scope.row.state == '1'"><el-button icon="iconfont iconerweima" circle @click="qrCode"></el-button></el-tooltip> -->
  114. <!-- <el-tooltip content="预览" placement="top" :hide-after="1000" :enterable="false" effect="light" v-if="scope.row.state == '2'">
  115. <el-button icon="el-icon-view" circle @click="preview(scope.row.id)"></el-button>
  116. </el-tooltip> -->
  117. </div>
  118. </template>
  119. </el-table-column>
  120. </el-table>
  121. <el-pagination
  122. :current-page="req.page"
  123. :page-sizes="[10, 20, 30, 50, 100]"
  124. :page-size="req.rows"
  125. layout="total, sizes, prev, pager, next, jumper"
  126. :total="tableTotal"
  127. @size-change="sizeChange"
  128. @current-change="currentChange"
  129. ></el-pagination>
  130. </div>
  131. </div>
  132. </template>
  133. <script>
  134. import vCountup from 'vue-countupjs';
  135. const __name = 'usemall-goods';
  136. const __goodsCategory = 'usemall-goods-category';
  137. import {
  138. goodsOut,
  139. goodsUp,
  140. delgoodpin
  141. } from '@/util/loginJie.js'
  142. export default {
  143. components: { vCountup },
  144. data() {
  145. return {
  146. state: '',//0下架 1在售 2 待审核
  147. classOptions: [],
  148. stateObj: {
  149. 待审核: '2',
  150. 销售中: '1',
  151. 已下架: '0',
  152. 全部: ''
  153. },
  154. stateDatas: [],
  155. req: {
  156. page: 1,
  157. rows: 10,
  158. orderby: 'sort asc',
  159. name: '',
  160. state: ''
  161. },
  162. tblHeight: 0,
  163. tableDatas: [],
  164. tableTotal: 0,
  165. selectDatas: []
  166. };
  167. },
  168. methods: {
  169. loadData(e) {
  170. this.stateDatas = [];
  171. for (let key in this.stateObj) {
  172. this.stateDatas.push({
  173. name: key,
  174. cnt: this.stateObj[key]
  175. });
  176. }
  177. console.log(this.req.page)
  178. this.$axios.get("/goods/admin/list",
  179. {
  180. params:{
  181. 'curPage':this.req.page,
  182. 'pageSize':this.req.rows,
  183. 'goodsName':e,//商品名称搜索
  184. 'state':this.req.state,//商品状态0下架 1在售 2 待审核
  185. 'orderField':'sort',
  186. 'order':'asc'
  187. },
  188. headers:{
  189. 'Mall-Token': uni.getStorageSync("token")
  190. }
  191. }).then(response => {
  192. let res = response
  193. console.log(res)
  194. if (res.success) {
  195. // if (res.datas.group && res.datas.group.datas) {
  196. // this.stateDatas = res.datas.group.state;
  197. // }
  198. // res.data.list.forEach((row, idx) => {
  199. // row.imgs = [row.imgs];
  200. // row.limited = row.limit + '';
  201. // row.hot = row.hot + '';
  202. // });
  203. this.tableDatas = res.data.list;
  204. this.tableTotal = res.data.totalCount;
  205. } else {
  206. }
  207. }).catch(res =>{
  208. });
  209. },
  210. cutSta(item) {
  211. this.state = item.cnt;
  212. this.req.state = item.cnt;
  213. this.loadData();
  214. },
  215. toAdd() {
  216. uni.navigateTo({
  217. url: `/pages/goods/list/goods_list_add_edit?tab=添加商品`,
  218. events: {
  219. refreshData: () => {
  220. this.loadData();
  221. }
  222. }
  223. });
  224. },
  225. staUp(id) {
  226. var data=[id]
  227. var headers={
  228. 'Content-Type': 'application/json; charset=utf-8',
  229. "Mall-Token": uni.getStorageSync('token')
  230. }
  231. this.$confirm('此操作将上架此商品!', '提示', {
  232. confirmButtonText: '确定',
  233. cancelButtonText: '取消',
  234. type: 'warning'
  235. }).then(() => {
  236. goodsUp(data,headers).then((res) => {
  237. if (res.success) {
  238. this.loadData();
  239. }
  240. })
  241. // this.$db[__name].update(id, { state: '销售中' }).then(res => {
  242. // if (res.code == 200) this.loadData();
  243. // });
  244. });
  245. },
  246. staOut(id) {
  247. var data=[id]
  248. var headers={
  249. 'Content-Type': 'application/json; charset=utf-8',
  250. "Mall-Token": uni.getStorageSync('token')
  251. }
  252. this.$confirm('此操作将下架此商品!', '提示', {
  253. confirmButtonText: '确定',
  254. cancelButtonText: '取消',
  255. type: 'warning'
  256. }).then(() => {
  257. goodsOut(data,headers).then((res) => {
  258. if (res.success) {
  259. this.loadData();
  260. }
  261. })
  262. // this.$db[__name].update(id, { state: '已下架' }).then(res => {
  263. // if (res.code == 200) this.loadData();
  264. // });
  265. });
  266. },
  267. toEdit(id) {
  268. uni.navigateTo({
  269. url: `/pages/goods/list/goods_list_add_edit?id=${id}&tab=编辑商品`,
  270. events: {
  271. refreshData: () => {
  272. this.loadData();
  273. }
  274. }
  275. });
  276. },
  277. toEvaluate(id) {
  278. uni.navigateTo({
  279. url: `/pages/goods/list/evaluate_add?id=${id}&tab=添加评价`
  280. });
  281. },
  282. qrCode() {
  283. this.$message('正在开发中...');
  284. },
  285. preview() {
  286. this.$notify.info({
  287. title: '消息',
  288. message: '正在开发中...'
  289. });
  290. },
  291. remove(id) {
  292. var data=[id]
  293. var headers={
  294. 'Content-Type': 'application/json; charset=utf-8',
  295. "Mall-Token": uni.getStorageSync('token')
  296. }
  297. this.$confirm('此操作将永久删除该数据!', '提示', {
  298. confirmButtonText: '确定',
  299. cancelButtonText: '取消',
  300. type: 'warning'
  301. }).then(() => {
  302. delgoodpin(data,headers).then((res) => {
  303. if (res.success) {
  304. this.loadData();
  305. }
  306. })
  307. // this.$db[__name].remove(id).then(res => {
  308. // if (res.code == 200) {
  309. // this.loadData();
  310. // }
  311. // });
  312. });
  313. },
  314. selectionChange(datas) {
  315. this.selectDatas = datas;
  316. },
  317. removes() {
  318. if (this.selectDatas.length <= 0) {
  319. this.$message('请勾选需要删除的数据');
  320. return;
  321. }
  322. let data = this.selectDatas.map(x => x.id);
  323. var headers={
  324. 'Content-Type': 'application/json; charset=utf-8',
  325. "Mall-Token": uni.getStorageSync('token')
  326. }
  327. this.$confirm('此操作将永久删除勾选数据!', '提示', {
  328. confirmButtonText: '确定',
  329. cancelButtonText: '取消',
  330. type: 'warning'
  331. }).then(() => {
  332. delgoodpin(data,headers).then((res) => {
  333. if (res.success) {
  334. this.loadData();
  335. }
  336. })
  337. // this.$db[__name]
  338. // .where({
  339. // id: this.$db.$cmd.in(ids)
  340. // })
  341. // .remove()
  342. // .then(res => {
  343. // if (res.code == 200) {
  344. // this.loadData();
  345. // }
  346. // });
  347. });
  348. },
  349. sortChange(row) {
  350. if (row.sort == '') {
  351. return;
  352. }
  353. this.$db[__name].update(row.id, { sort: row.sort }).then(res => {
  354. if (res.code == 200) this.loadData();
  355. });
  356. },
  357. limitedChang(row) {
  358. if(row.limited=='1'){
  359. var type=1
  360. }else if(row.limited=='0'){
  361. var type=0
  362. }
  363. this.$axios.put("/goods/admin/hot-limited-change",
  364. {
  365. "action": "2",//1热门推荐、2限时精选
  366. "goodIds": [row.id],
  367. "type": type//1新增、0取消
  368. },
  369. {
  370. headers:{
  371. 'Mall-Token': uni.getStorageSync("token")
  372. }
  373. }).then(response => {
  374. let res = response
  375. if (res.success) {
  376. this.loadData();
  377. } else {
  378. }
  379. }).catch(res =>{
  380. });
  381. // this.$db[__name].update(row.id, { limited: parseInt(row.limited) }).then(res => {
  382. // if (res.code == 200) this.loadData();
  383. // });
  384. },
  385. hotChang(row) {
  386. if(row.hot=='1'){
  387. var type=1
  388. }else if(row.hot=='0'){
  389. var type=0
  390. }
  391. this.$axios.put("/goods/admin/hot-limited-change",
  392. {
  393. "action": "1",//1热门推荐、2限时精选
  394. "goodIds": [row.id],
  395. "type": type//1新增、0取消
  396. },
  397. {
  398. headers:{
  399. 'Mall-Token': uni.getStorageSync("token")
  400. }
  401. }).then(response => {
  402. let res = response
  403. if (res.success) {
  404. this.loadData();
  405. } else {
  406. }
  407. }).catch(res =>{
  408. });
  409. // this.$db[__name].update(row.id, { hot: parseInt(row.hot) }).then(res => {
  410. // if (res.code == 200) this.loadData();
  411. // });
  412. },
  413. sizeChange(size) {
  414. this.req.rows = size;
  415. this.loadData();
  416. },
  417. currentChange(current) {
  418. this.req.page = current;
  419. this.loadData();
  420. }
  421. },
  422. created() {
  423. // this.$db[__goodsCategory].totree({ orderby: 'sort asc', startWith: 'pid == ""', loadding: false }).then(res => {
  424. // if (res.code == 200) {
  425. // this.classOptions = res.datas;
  426. // }
  427. // });
  428. this.loadData();
  429. },
  430. updated() {
  431. if (!this.tblHeight) {
  432. this.tblHeight = this.$refs.tbl.tblHeight;
  433. }
  434. }
  435. };
  436. </script>
  437. <style></style>