instrument-list.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. "use strict";
  2. console.log(123);
  3. var productList = new Vue({
  4. el: '#productList',
  5. data: {
  6. name: 'supplier-instrument-list',
  7. refreshType: '',
  8. hidden: '',
  9. visibilityChange: '',
  10. listRecord: 0,
  11. shopId: GLOBAL_SHOP_ID || 0,
  12. listQuery: {
  13. commodityType: 2,
  14. productId: '',
  15. name: '',
  16. auditStatus: '',
  17. typeId: '',
  18. pageNum: 1,
  19. pageSize: 10
  20. },
  21. pageInput: 1,
  22. pageTotal: 0,
  23. productList: [],
  24. productTypeList: [],
  25. categoryKeyMap: {
  26. name: 'typeName',
  27. value: 'typeId'
  28. },
  29. auditStatusList: [
  30. {
  31. name: '全部',
  32. value: '',
  33. },
  34. {
  35. name: '待审核',
  36. value: 1,
  37. },
  38. {
  39. name: '审核通过',
  40. value: 2,
  41. },
  42. {
  43. name: '审核未通过',
  44. value: 3,
  45. }
  46. ]
  47. },
  48. computed: {
  49. pageTotal: function pageTotal() {
  50. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  51. return total > 0 ? total : 1;
  52. },
  53. showPageBtn: function showPageBtn() {
  54. var total = Math.ceil(this.listRecord / this.listQuery.pageSize);
  55. total = total > 0 ? total : 1;
  56. var index = this.listQuery.pageNum,
  57. arr = [];
  58. if (total <= 6) {
  59. for (var i = 1; i <= total; i++) {
  60. arr.push(i);
  61. }
  62. return arr;
  63. }
  64. if (index <= 3) return [1, 2, 3, 4, 5, 0, total];
  65. if (index >= total - 2) return [1, 0, total - 4, total - 3, total - 2, total - 1, total];
  66. return [1, 0, index - 2, index - 1, index, index + 1, index + 2, 0, total];
  67. }
  68. },
  69. filters: {
  70. // 时间格式化
  71. formatDate: function formatDate(date) {
  72. if (!date) return '---';
  73. return dateFormat(new Date(date));
  74. }
  75. },
  76. created: function created() {
  77. this.getArticleList();
  78. this.fetchArticleCatagory();
  79. },
  80. mounted: function mounted() {
  81. window.name = this.name;
  82. $('.navLayout').find('.navList').removeClass("on").find('.con').hide().find('a').removeClass("on");
  83. $('.navLayout').find('.navList').eq(3).addClass("on").find('.con').show().find('a').eq(1).addClass("on");
  84. },
  85. methods: {
  86. // 获取文章列表
  87. getArticleList: function getArticleList() {
  88. var that = this;
  89. this.listQuery.shopId = this.shopId;
  90. SupplierApi.GetShopBaikeProductList(this.listQuery, function (res) {
  91. console.log(res);
  92. if (res.code === 0) {
  93. that.listRecord = res.data.total;
  94. that.productList = res.data.list;
  95. that.pageTotal = res.data.pages;
  96. } else {
  97. CAIMEI.Alert(res.msg, '确定', false);
  98. }
  99. });
  100. },
  101. //表格操作按钮点击
  102. clickOption: function clickOption(product, type) {
  103. var handles = {
  104. 1: this.toEdit,
  105. 2: this.changeStatus,
  106. 3: this.toDetail,
  107. 4: this.handleDelete
  108. };
  109. handles[type](product);
  110. },
  111. //跳转编辑页面
  112. toEdit: function toEdit(product) {
  113. localStorage.setItem('productId', product.productId);
  114. window.open('/supplier/encyclopedia/instrument-edit.html');
  115. },
  116. //修改状态
  117. changeStatus: function changeStatus(product) {
  118. var newStatus = 1;
  119. if (product.status === 1) {
  120. newStatus = 0;
  121. }
  122. SupplierApi.ShopBaikeProductStatusUpdate({
  123. productId: product.productId,
  124. shopId: this.shopId,
  125. status: newStatus
  126. }, function (res) {
  127. if (res.code === 0) {
  128. // 不刷新数据更新
  129. product.status = newStatus;
  130. CAIMEI.dialog('修改状态成功!');
  131. } else {
  132. CAIMEI.dialog('修改状态失败!');
  133. }
  134. });
  135. },
  136. //查看
  137. toDetail: function toDetail(product) {
  138. if (product.auditStatus !== 2) return CAIMEI.dialog('请等待审核通过后查看!');
  139. if (!product.status) return CAIMEI.dialog('请未启后查看!');
  140. window.open('/encyclopedia/product-' + product.productId + '.html');
  141. },
  142. // 跳转添加文章页面
  143. handleAddArticle: function handleAddArticle() {
  144. window.open('/supplier/encyclopedia/instrument-edit.html');
  145. },
  146. // 查询文章列表
  147. handleSearchList: function handleSearchList() {
  148. this.listQuery.pageNum = 1;
  149. this.getArticleList();
  150. },
  151. // 获取文章列表
  152. fetchArticleCatagory: function fetchArticleCatagory() {
  153. var that = this;
  154. SupplierApi.ShopBaikeProductTypeList({ commodityType: 1 }, function (res) {
  155. if (res.code === 0) {
  156. that.productTypeList = res.data;
  157. } else {
  158. CAIMEI.Alert(res.msg, '确定', false);
  159. }
  160. });
  161. },
  162. //删除确认
  163. handleDelete: function handleDelete(product) {
  164. var that = this;
  165. var params = {
  166. content: '确认删除该商品信息?',
  167. cancelBtnText: '取消',
  168. confitmBtnText: '删除'
  169. };
  170. CAIMEI.Popup(params, function () {
  171. that.productDelete(product);
  172. });
  173. },
  174. // 删除文章
  175. productDelete: function productDelete(product) {
  176. var that = this;
  177. SupplierApi.ShopBaikeProductDelete({
  178. productId: product.productId
  179. }, function (res) {
  180. if (res.code === 0) {
  181. that.getArticleList();
  182. CAIMEI.dialog('删除文章成功!');
  183. } else {
  184. CAIMEI.dialog('删除文章失败!');
  185. }
  186. });
  187. },
  188. //页码跳转
  189. toPagination: function toPagination(pageNum) {
  190. if (pageNum <= this.pageTotal) {
  191. this.listQuery.pageNum = pageNum; // console.log('页码跳转');
  192. this.getArticleList();
  193. $('html ,body').animate({scrollTop: 0}, 400, 'linear'); // 页面置顶
  194. }
  195. },
  196. // 输入框设置页码
  197. checkNum: function checkNum() {
  198. if (this.pageInput > this.pageTotal) {
  199. this.pageInput = this.pageTotal;
  200. } else if (this.pageInput < 1) {
  201. this.pageInput = 1;
  202. }
  203. },
  204. cateSelectChange(data) {
  205. console.log(data);
  206. this.listQuery.typeId = data.typeId;
  207. this.getArticleList()
  208. },
  209. auditStatusChange(data){
  210. this.listQuery.auditStatus = data.value
  211. this.getArticleList()
  212. }
  213. }
  214. });