goods_list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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. } from '@/util/loginJie.js'
  141. export default {
  142. components: { vCountup },
  143. data() {
  144. return {
  145. state: '',//0下架 1在售 2 待审核
  146. classOptions: [],
  147. stateObj: {
  148. 待审核: '2',
  149. 销售中: '1',
  150. 已下架: '0',
  151. 全部: ''
  152. },
  153. stateDatas: [],
  154. req: {
  155. page: 1,
  156. rows: 10,
  157. orderby: 'sort asc',
  158. name: '',
  159. state: ''
  160. },
  161. tblHeight: 0,
  162. tableDatas: [],
  163. tableTotal: 0,
  164. selectDatas: []
  165. };
  166. },
  167. methods: {
  168. loadData(e) {
  169. this.stateDatas = [];
  170. for (let key in this.stateObj) {
  171. this.stateDatas.push({
  172. name: key,
  173. cnt: this.stateObj[key]
  174. });
  175. }
  176. console.log(this.req.page)
  177. this.$axios.get("/goods/admin/list",
  178. {
  179. params:{
  180. 'curPage':this.req.page,
  181. 'pageSize':this.req.rows,
  182. 'goodsName':e,//商品名称搜索
  183. 'state':this.req.state,//商品状态0下架 1在售 2 待审核
  184. 'orderField':'sort',
  185. 'order':'asc'
  186. },
  187. headers:{
  188. 'Mall-Token': uni.getStorageSync("token")
  189. }
  190. }).then(response => {
  191. let res = response
  192. console.log(res)
  193. if (res.success) {
  194. // if (res.datas.group && res.datas.group.datas) {
  195. // this.stateDatas = res.datas.group.state;
  196. // }
  197. // res.data.list.forEach((row, idx) => {
  198. // row.imgs = [row.imgs];
  199. // row.limited = row.limit + '';
  200. // row.hot = row.hot + '';
  201. // });
  202. this.tableDatas = res.data.list;
  203. this.tableTotal = res.data.totalCount;
  204. } else {
  205. }
  206. }).catch(res =>{
  207. });
  208. },
  209. cutSta(item) {
  210. this.state = item.cnt;
  211. this.req.state = item.cnt;
  212. this.loadData();
  213. },
  214. toAdd() {
  215. uni.navigateTo({
  216. url: `/pages/goods/list/goods_list_add_edit?tab=添加商品`,
  217. events: {
  218. refreshData: () => {
  219. this.loadData();
  220. }
  221. }
  222. });
  223. },
  224. staUp(id) {
  225. var data=[id]
  226. var headers={
  227. 'Content-Type': 'application/json; charset=utf-8',
  228. "Mall-Token": uni.getStorageSync('token')
  229. }
  230. this.$confirm('此操作将上架此商品!', '提示', {
  231. confirmButtonText: '确定',
  232. cancelButtonText: '取消',
  233. type: 'warning'
  234. }).then(() => {
  235. goodsUp(data,headers).then((res) => {
  236. if (res.success) {
  237. this.loadData();
  238. }
  239. })
  240. // this.$db[__name].update(id, { state: '销售中' }).then(res => {
  241. // if (res.code == 200) this.loadData();
  242. // });
  243. });
  244. },
  245. staOut(id) {
  246. var data=[id]
  247. var headers={
  248. 'Content-Type': 'application/json; charset=utf-8',
  249. "Mall-Token": uni.getStorageSync('token')
  250. }
  251. this.$confirm('此操作将下架此商品!', '提示', {
  252. confirmButtonText: '确定',
  253. cancelButtonText: '取消',
  254. type: 'warning'
  255. }).then(() => {
  256. goodsOut(data,headers).then((res) => {
  257. if (res.success) {
  258. this.loadData();
  259. }
  260. })
  261. // this.$db[__name].update(id, { state: '已下架' }).then(res => {
  262. // if (res.code == 200) this.loadData();
  263. // });
  264. });
  265. },
  266. toEdit(id) {
  267. uni.navigateTo({
  268. url: `/pages/goods/list/goods_list_add_edit?id=${id}&tab=编辑商品`,
  269. events: {
  270. refreshData: () => {
  271. this.loadData();
  272. }
  273. }
  274. });
  275. },
  276. toEvaluate(id) {
  277. uni.navigateTo({
  278. url: `/pages/goods/list/evaluate_add?id=${id}&tab=添加评价`
  279. });
  280. },
  281. qrCode() {
  282. this.$message('正在开发中...');
  283. },
  284. preview() {
  285. this.$notify.info({
  286. title: '消息',
  287. message: '正在开发中...'
  288. });
  289. },
  290. remove(id) {
  291. var data=[id]
  292. var headers={
  293. 'Content-Type': 'application/json; charset=utf-8',
  294. "Mall-Token": uni.getStorageSync('token')
  295. }
  296. this.$confirm('此操作将永久删除该数据!', '提示', {
  297. confirmButtonText: '确定',
  298. cancelButtonText: '取消',
  299. type: 'warning'
  300. }).then(() => {
  301. delLunbo(data,headers).then((res) => {
  302. if (res.success) {
  303. this.loadData();
  304. }
  305. })
  306. // this.$db[__name].remove(id).then(res => {
  307. // if (res.code == 200) {
  308. // this.loadData();
  309. // }
  310. // });
  311. });
  312. },
  313. selectionChange(datas) {
  314. this.selectDatas = datas;
  315. },
  316. removes() {
  317. if (this.selectDatas.length <= 0) {
  318. this.$message('请勾选需要删除的数据');
  319. return;
  320. }
  321. let data = this.selectDatas.map(x => x.id);
  322. var headers={
  323. 'Content-Type': 'application/json; charset=utf-8',
  324. "Mall-Token": uni.getStorageSync('token')
  325. }
  326. this.$confirm('此操作将永久删除勾选数据!', '提示', {
  327. confirmButtonText: '确定',
  328. cancelButtonText: '取消',
  329. type: 'warning'
  330. }).then(() => {
  331. delLunbo(data,headers).then((res) => {
  332. if (res.success) {
  333. this.loadData();
  334. }
  335. })
  336. // this.$db[__name]
  337. // .where({
  338. // id: this.$db.$cmd.in(ids)
  339. // })
  340. // .remove()
  341. // .then(res => {
  342. // if (res.code == 200) {
  343. // this.loadData();
  344. // }
  345. // });
  346. });
  347. },
  348. sortChange(row) {
  349. if (row.sort == '') {
  350. return;
  351. }
  352. this.$db[__name].update(row.id, { sort: row.sort }).then(res => {
  353. if (res.code == 200) this.loadData();
  354. });
  355. },
  356. limitedChang(row) {
  357. if(row.limited=='1'){
  358. var type=1
  359. }else if(row.limited=='0'){
  360. var type=0
  361. }
  362. this.$axios.put("/goods/admin/hot-limited-change",
  363. {
  364. "action": "2",//1热门推荐、2限时精选
  365. "goodIds": [row.id],
  366. "type": type//1新增、0取消
  367. },
  368. {
  369. headers:{
  370. 'Mall-Token': uni.getStorageSync("token")
  371. }
  372. }).then(response => {
  373. let res = response
  374. if (res.success) {
  375. this.loadData();
  376. } else {
  377. }
  378. }).catch(res =>{
  379. });
  380. // this.$db[__name].update(row.id, { limited: parseInt(row.limited) }).then(res => {
  381. // if (res.code == 200) this.loadData();
  382. // });
  383. },
  384. hotChang(row) {
  385. if(row.hot=='1'){
  386. var type=1
  387. }else if(row.hot=='0'){
  388. var type=0
  389. }
  390. this.$axios.put("/goods/admin/hot-limited-change",
  391. {
  392. "action": "1",//1热门推荐、2限时精选
  393. "goodIds": [row.id],
  394. "type": type//1新增、0取消
  395. },
  396. {
  397. headers:{
  398. 'Mall-Token': uni.getStorageSync("token")
  399. }
  400. }).then(response => {
  401. let res = response
  402. if (res.success) {
  403. this.loadData();
  404. } else {
  405. }
  406. }).catch(res =>{
  407. });
  408. // this.$db[__name].update(row.id, { hot: parseInt(row.hot) }).then(res => {
  409. // if (res.code == 200) this.loadData();
  410. // });
  411. },
  412. sizeChange(size) {
  413. this.req.rows = size;
  414. this.loadData();
  415. },
  416. currentChange(current) {
  417. this.req.page = current;
  418. this.loadData();
  419. }
  420. },
  421. created() {
  422. // this.$db[__goodsCategory].totree({ orderby: 'sort asc', startWith: 'pid == ""', loadding: false }).then(res => {
  423. // if (res.code == 200) {
  424. // this.classOptions = res.datas;
  425. // }
  426. // });
  427. this.loadData();
  428. },
  429. updated() {
  430. if (!this.tblHeight) {
  431. this.tblHeight = this.$refs.tbl.tblHeight;
  432. }
  433. }
  434. };
  435. </script>
  436. <style></style>