instrument-list.js 8.4 KB

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