hot.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div>
  3. <use-table ref="tbl"></use-table>
  4. <div class="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></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" highlight-current-row>
  25. <!-- <el-table-column label="排序" width="200" align="center">
  26. <template slot-scope="scope">
  27. <el-input-number size="small" :min="1" v-model="scope.row.sort" @change="sortChange(scope.row)" @blur="sortChange(scope.row)"></el-input-number>
  28. </template>
  29. </el-table-column> -->
  30. <el-table-column label="商品" width="330" align="center">
  31. <template slot-scope="scope">
  32. <div class="dflex_vertical_c">
  33. <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>
  34. <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>
  35. <div class="left_just margin_l_10">
  36. <div class="ellipsis">{{ scope.row.name }}</div>
  37. </div>
  38. </div>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="价格" align="center">
  42. <template slot-scope="scope">
  43. <div class="price">{{ scope.row.price}}</div>
  44. <div class="m_price">{{ scope.row.marketPrice}}</div>
  45. </template>
  46. </el-table-column>
  47. <el-table-column label="状态" align="center">
  48. <template slot-scope="scope">
  49. <template v-if="scope.row.state==0">下架</template>
  50. <template v-if="scope.row.state==1">在售</template>
  51. <template v-if="scope.row.state==2">待审核</template>
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="数据统计" align="left" width="150">
  55. <template slot-scope="scope">
  56. <div class="left_just">
  57. <div>已售数:{{ scope.row.saleCnt }}</div>
  58. <div>访问数:{{ scope.row.visitCnt }}</div>
  59. <div>收藏数:{{ scope.row.collectCnt }}</div>
  60. <!-- <div>分享数:{{ scope.row.shareCnt }}</div> -->
  61. </div>
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="热门推荐" align="center">
  65. <template slot-scope="scope">
  66. <el-tooltip :content="scope.row.hot == '1' ? '点击取消热门推荐' : '点击启用热门推荐'" placement="top" :hide-after="1000" :enterable="false" effect="light">
  67. <el-switch
  68. v-model="scope.row.hot"
  69. active-color="#ff6a6c"
  70. inactive-color="#bbb"
  71. active-value="1"
  72. inactive-value="0"
  73. @change="hotChange(scope.row)"
  74. ></el-switch>
  75. </el-tooltip>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="标签" width="220" align="center">
  79. <template slot-scope="scope">
  80. <div class="left_just">
  81. <el-tag effect="plain" class="margin_t_5 margin_r_5" type="info" v-for="(item, i) in scope.row.goodsServiceTags" :key="i">{{ item.tagName }}</el-tag>
  82. </div>
  83. </template>
  84. </el-table-column>
  85. </el-table>
  86. <el-pagination
  87. :current-page="req.page"
  88. :page-sizes="[10, 20, 30, 50, 100]"
  89. :page-size="req.rows"
  90. layout="total, sizes, prev, pager, next, jumper"
  91. :total="tableTotal"
  92. @size-change="sizeChange"
  93. @current-change="currentChange"
  94. ></el-pagination>
  95. <popupsGoods ref="child" @choiceGoods="choiceGoods"></popupsGoods>
  96. </div>
  97. </div>
  98. </template>
  99. <script>
  100. import vCountup from 'vue-countupjs';
  101. import popupsGoods from '@/components/popups_goods';
  102. const __name = 'usemall-goods';
  103. export default {
  104. components: { vCountup, popupsGoods },
  105. data() {
  106. return {
  107. state1: 1,//0下架 1在售 2 待审核
  108. stateObj: {
  109. 待审核: '2',
  110. 销售中: '1',
  111. 已下架: '0',
  112. 全部: ''
  113. },
  114. stateDatas: [],
  115. req: {
  116. hot: 1,
  117. page: 1,
  118. rows: 10,
  119. orderby: 'sort asc',
  120. name: '',
  121. state: ''
  122. },
  123. tblHeight: 0,
  124. tableDatas: [],
  125. tableTotal: 0
  126. };
  127. },
  128. methods: {
  129. loadData(e) {
  130. var _self=this
  131. _self.stateDatas = [];
  132. for (let key in _self.stateObj) {
  133. _self.stateDatas.push({
  134. name: key,
  135. cnt: _self.stateObj[key]
  136. });
  137. }
  138. _self.$axios.get("/goods/admin/list",
  139. {
  140. params:{
  141. 'curPage':_self.req.page,
  142. 'pageSize':_self.req.rows,
  143. 'goodsName':e,//商品名称搜索
  144. 'state':_self.req.state,//商品状态0下架 1在售 2 待审核
  145. 'hot':1,//是否热门;0否1是
  146. },
  147. headers:{
  148. 'Mall-Token': uni.getStorageSync("token")
  149. }
  150. }).then(response => {
  151. let res = response
  152. console.log(res)
  153. if (res.success) {
  154. // if (res.data.list && res.data.list.state) {
  155. // _self.stateDatas = res.data.list.state
  156. // }
  157. res.data.list.forEach(row => {
  158. // row.imgs = [row.imgs];
  159. // row.limited = row.limited + '';
  160. });
  161. _self.tableDatas = res.data.list;
  162. _self.tableTotal = res.data.totalCount;
  163. } else {
  164. }
  165. }).catch(res =>{
  166. });
  167. // await this.$db[__name]
  168. // .where({ hot: 1 })
  169. // .whereif(this.req.state && this.req.state != '全部', { state: this.req.state })
  170. // .whereif(this.req.name, { name: new RegExp(this.req.name) })
  171. // .withgroup({ field: 'state', obj: this.stateObj })
  172. // .totable(this.req)
  173. // .then(res => {
  174. // if (res.code == 200) {
  175. // if (res.datas.group && res.datas.group.datas) {
  176. // this.stateDatas = res.datas.group.datas;
  177. // }
  178. // res.datas.rows.forEach(row => {
  179. // row.imgs = [row.img];
  180. // row.hot = row.hot + '';
  181. // });
  182. // this.tableDatas = res.datas.rows;
  183. // this.tableTotal = res.datas.total;
  184. // }
  185. // });
  186. },
  187. toAdd() {
  188. this.$refs.child.show({
  189. hot: 0
  190. });
  191. },
  192. choiceGoods(datas) {
  193. let ids = datas.map(x => x._id);
  194. if (ids && ids.length > 0) {
  195. // this.$db[__name]
  196. // .where(`in(_id, ${JSON.stringify(ids)})`)
  197. // .update('', { hot: 1 })
  198. // .then(res => {
  199. // if (res.code == 200) this.loadData();
  200. // });
  201. }
  202. },
  203. hotChange(row) {
  204. if(row.hot=='1'){
  205. var type=1
  206. }else if(row.hot=='0'){
  207. var type=0
  208. }
  209. this.$axios.put("/goods/admin/hot-limited-change",
  210. {
  211. "action": "1",//1热门推荐、2限时精选
  212. "goodIds": [row.id],
  213. "type": type//1新增、0取消
  214. },
  215. {
  216. headers:{
  217. 'Mall-Token': uni.getStorageSync("token")
  218. }
  219. }).then(response => {
  220. let res = response
  221. if (res.success) {
  222. this.loadData();
  223. } else {
  224. }
  225. }).catch(res =>{
  226. });
  227. // this.$db[__name].update(row._id, { hot: parseInt(row.hot) }).then(res => {
  228. // if (res.code == 200) this.loadData();
  229. // });
  230. },
  231. sortChange(row) {
  232. if (row.sort == '') {
  233. return;
  234. }
  235. },
  236. cutSta(item) {
  237. this.state1 = item.cnt;
  238. this.req.state = item.cnt;
  239. this.loadData();
  240. },
  241. sizeChange(size) {
  242. this.req.rows = size;
  243. this.loadData();
  244. },
  245. currentChange(current) {
  246. this.req.page = current;
  247. this.loadData();
  248. }
  249. },
  250. created() {
  251. this.loadData();
  252. },
  253. updated() {
  254. if (!this.tblHeight) {
  255. this.tblHeight = this.$refs.tbl.tblHeight;
  256. }
  257. }
  258. };
  259. </script>
  260. <style></style>