goods_classify.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <div>
  3. <use-table ref="tbl"></use-table>
  4. <div class="container padding_b_0">
  5. <!-- <div class="dflex_wrap">
  6. <div class="dflex_vertical_c margin_r_40 margin_b_20">
  7. <div class="search_name">分类名称:</div>
  8. <el-input v-model="req.name" placeholder="请输入" class="search_input" @input="loadData"></el-input>
  9. </div>
  10. <el-button size="mini" class="search_btn margin_b_20 margin_r_40" @click="loadData">搜索</el-button>
  11. </div> -->
  12. </div>
  13. <div class="container use-table">
  14. <div class="dflex_sb margin_b_15">
  15. <div></div>
  16. <el-button class="add_btn pos_r padding0" icon="iconfont iconxinzeng" @click="toAdd">新增</el-button>
  17. </div>
  18. <el-table :height="tblHeight" :data="tableDatas" row-key="id" :tree-props="{ children: 'childCategory', hasChildren: 'hasChildren' }">
  19. <el-table-column prop="name" label="分类名称" width="120"></el-table-column>
  20. <el-table-column label="排序" width="200" align="center">
  21. <template slot-scope="scope">
  22. <el-input-number size="small" :min="1" v-model="scope.row.sort" @change="sortChange(scope.row)" @blur="sortChange(scope.row)"></el-input-number>
  23. </template>
  24. </el-table-column>
  25. <el-table-column prop="id" label="分类ID" align="center" width="250"></el-table-column>
  26. <el-table-column label="图片" align="center">
  27. <template slot-scope="scope">
  28. <el-image style="width: 100px; height: 80px;" :preview-src-list="scope.row.imgs" :src="scope.row.icon || require('static/img/noimage.png')" fit="contain"></el-image>
  29. </template>
  30. </el-table-column>
  31. <!-- <el-table-column prop="create_time" label="创建时间" align="center"></el-table-column> -->
  32. <el-table-column label="状态" align="center">
  33. <template slot-scope="scope">
  34. <el-tooltip :content="scope.row.state == '0' ? '点击启用' : '点击禁用'" placement="top" :hide-after="1000" :enterable="false" effect="light">
  35. <el-switch
  36. v-model="scope.row.state"
  37. active-color="#ff6a6c"
  38. inactive-color="#bbb"
  39. active-value="1"
  40. inactive-value="0"
  41. @change="stateChange(scope.row)"
  42. ></el-switch>
  43. </el-tooltip>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="操作" align="center">
  47. <template slot-scope="scope">
  48. <el-tooltip content="编辑" placement="top" :hide-after="1000" :enterable="false" effect="light">
  49. <el-button type="text" icon="iconfont iconbianji" class="bbb" @click="toEdit(scope.row)"></el-button>
  50. </el-tooltip>
  51. <el-tooltip content="删除" placement="top" :hide-after="1000" :enterable="false" effect="light">
  52. <el-button type="text" icon="iconfont iconshanchu" class="bbb" @click="remove(scope.row.id)"></el-button>
  53. </el-tooltip>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. import {
  62. delgoodslei
  63. } from '@/util/loginJie.js'
  64. const __name = 'usemall-goods-category';
  65. export default {
  66. data() {
  67. return {
  68. req: {
  69. page: 1,
  70. rows: 500,
  71. orderby: 'sort asc',
  72. name: ''
  73. },
  74. tblHeight: 0,
  75. tableDatas: [],
  76. allTableDatas: [],
  77. now_date:'',//当前时间
  78. };
  79. },
  80. methods: {
  81. loadData() {
  82. this.req.startWith = "pid == ''";
  83. if (this.req.name) {
  84. this.req.startWith = "/"+ this.req.name +"/.test(name)";
  85. }
  86. this.$axios.get("/goodsCategory/admin/list",
  87. {
  88. params:{
  89. },
  90. headers:{
  91. "Mall-Token": uni.getStorageSync('token')
  92. }
  93. }).then(response => {
  94. let res = response
  95. console.log(res)
  96. if (res.success) {
  97. let datas = [];
  98. res.data.forEach((row, idx) => {
  99. row.imgs = [row.icon];
  100. });
  101. res.data.forEach((row, idx) => {
  102. if (row.pid && res.data.find(x => x.id == row.pid)) {
  103. return;
  104. }
  105. datas.push(row);
  106. });
  107. this.tableDatas = res.data;
  108. } else {
  109. }
  110. }).catch(res =>{
  111. });
  112. // this.$db[__name]
  113. // .totree(this.req)
  114. // .then(res => {
  115. // if (res.code == 200) {
  116. // let datas = [];
  117. // res.datas.forEach((row, idx) => {
  118. // row.create_time = new Date(row.create_time).format();
  119. // if (row.children && row.children.length > 0) {
  120. // row.children.forEach(c => {
  121. // c.create_time = new Date(c.create_time).format();
  122. // });
  123. // }
  124. // row.imgs = [row.img];
  125. // });
  126. // res.datas.forEach((row, idx) => {
  127. // if (row.pid && res.datas.find(x => x._id == row.pid)) {
  128. // return;
  129. // }
  130. // datas.push(row);
  131. // });
  132. // this.tableDatas = datas;
  133. // }
  134. // });
  135. },
  136. toAdd() {
  137. uni.navigateTo({
  138. url: `/pages/goods/classify/goods_classify_add_edit?tab=添加分类`,
  139. events: {
  140. refreshData: () => {
  141. this.loadData();
  142. }
  143. }
  144. });
  145. },
  146. toEdit(row) {
  147. uni.navigateTo({
  148. url: `/pages/goods/classify/goods_classify_add_edit?id=${row.id}
  149. &tab=编辑分类&name=${row.name}&pid=${row.pid}
  150. &sort=${row.sort}&icon=${row.icon}&level=${row.level}
  151. &state=${row.state}`,
  152. events: {
  153. refreshData: () => {
  154. this.loadData();
  155. }
  156. }
  157. });
  158. },
  159. remove(id) {
  160. var data=[id]
  161. var headers={
  162. 'Content-Type': 'application/json; charset=utf-8',
  163. "Mall-Token": uni.getStorageSync('token')
  164. }
  165. this.$confirm('此操作将永久删除该数据!', '提示', {
  166. confirmButtonText: '确定',
  167. cancelButtonText: '取消',
  168. type: 'warning'
  169. }).then(() => {
  170. delgoodslei(data,headers).then((res) => {
  171. if (res.success) {
  172. this.loadData();
  173. }
  174. }).catch((err)=>{
  175. this.$confirm(err.message)
  176. })
  177. // this.$db[__name].remove(id).then(res => {
  178. // if (res.code == 200) {
  179. // this.loadData();
  180. // }
  181. // });
  182. });
  183. },
  184. stateChange(row) {
  185. this.$axios.put("/goodsCategory/admin/update",
  186. {
  187. 'createBy':row.createBy,//创建人
  188. 'createTime':row.createTime,//创建时间
  189. 'updateBy':uni.getStorageSync("nickName"),//更新人
  190. 'updateTime':this.now_date,//更新时间
  191. "name": row.name,
  192. "icon": row.icon,
  193. "level": row.level,
  194. "pid": row.pid,
  195. 'sort':row.sort,//排序
  196. 'state':row.state,
  197. 'id':row.id
  198. },
  199. {
  200. headers:{
  201. 'Mall-Token': uni.getStorageSync("token")
  202. }
  203. }).then(response => {
  204. let res = response
  205. if (res.success) {
  206. this.loadData()
  207. } else {
  208. alert(res.message)
  209. }
  210. })
  211. },
  212. sortChange(row) {
  213. if (row.sort == '') {
  214. return;
  215. }
  216. this.$axios.put("/goodsCategory/admin/update",
  217. {
  218. 'createBy':row.createBy,//创建人
  219. 'createTime':row.createTime,//创建时间
  220. 'updateBy':uni.getStorageSync("nickName"),//更新人
  221. 'updateTime':this.now_date,//更新时间
  222. "name": row.name,
  223. "icon": row.icon,
  224. "level": row.level,
  225. "pid": row.pid,
  226. 'sort':row.sort,//排序
  227. 'state':row.state,
  228. 'id':row.id
  229. },
  230. {
  231. headers:{
  232. 'Mall-Token': uni.getStorageSync("token")
  233. }
  234. }).then(response => {
  235. let res = response
  236. if (res.success) {
  237. this.loadData()
  238. } else {
  239. alert(res.message)
  240. }
  241. })
  242. },
  243. //获取当前时间
  244. getNowDate() {
  245. var _this = this;
  246. // this.timer = setInterval(function() {
  247. var aData = new Date();
  248. var month = aData.getMonth() < 9 ? "0" + (aData.getMonth() + 1) : aData.getMonth() + 1;
  249. var date = aData.getDate() <= 9 ? "0" + aData.getDate() : aData.getDate();
  250. var date2 = aData.getDate() <= 9 ? "0" + (aData.getDate()-1) : (aData.getDate()-1);
  251. var Hour = aData.getHours() <= 9 ? "0" + (aData.getHours()) : aData.getHours();
  252. var Miunte = aData.getMinutes() <= 9 ? "0" + (aData.getMinutes()) : aData.getMinutes();
  253. var Seconds = aData.getSeconds() <= 9 ? "0" + (aData.getSeconds()) : aData.getSeconds();
  254. // console.log(aData.getTime())
  255. _this.now_date = aData.getFullYear() + "-" + month + "-" + date + ' '+ Hour +":"+ Miunte +":"+ Seconds;
  256. // console.log(aData.getFullYear() + "-" + month + "-" + date2)昨天
  257. // }, 86400000);
  258. },
  259. },
  260. created() {
  261. this.loadData();
  262. },
  263. updated() {
  264. if (!this.tblHeight) {
  265. this.tblHeight = this.$refs.tbl.tblHeight;
  266. }
  267. }
  268. };
  269. </script>
  270. <style ></style>