change_industry.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // 模拟数据
  2. var data = {
  3. "data": {
  4. "area": {
  5. "安徽": [],
  6. "福建": ['福州市', '莆田市'],
  7. "广东": [],
  8. },
  9. "buyset": {
  10. "areacount": 1,
  11. "buyerclasscount": 3,
  12. "citys": {
  13. "贵州": 2,
  14. "广东": 2,
  15. "广西": 2,
  16. "福建": 1,
  17. }
  18. },
  19. "industry": [
  20. "安监",
  21. // "保监"
  22. ],
  23. "isTrial": false
  24. },
  25. "errMsg": "",
  26. "success": true
  27. }
  28. var buyCount = data.data.buyset.buyerclasscount;//已购买的行业数量 -1是全部行业,正数为购买的行业数量
  29. var array = data.data.industry;//已选择的行业(数组)
  30. var result = [];//声明一个空数组为选择结果
  31. // 初始化行业数据,渲染到页面
  32. function initData() {
  33. if (data.data.isTrial) {
  34. $('.update_tips').text("已超出现订单购买范围,需购买")
  35. }
  36. buyCount = data.data.buyset.buyerclasscount;//已购买的行业数量 -1是全部行业,正数为购买的行业数量
  37. array = data.data.industry;//已选择的行业(数组)
  38. /* 已购买过的行业 */
  39. if (buyCount == -1) {
  40. $('.result_name').html('全部行业')
  41. $('.alr_purchase').hide()
  42. } else {
  43. $('.result_name').html(buyCount + '个行业')
  44. }
  45. /* 已选择的行业 数组为空时即选择的全部行业 不为空时对应选择的结果 */
  46. if (array.length == 0) {
  47. $('.result_count').html('全部行业');
  48. $('.industry_item.whole').addClass('active')
  49. } else {
  50. $('.result_count').html(array.length + '个行业');
  51. $('.industry_item:not(.whole)').each(function () {
  52. var text = $(this).text().trim()
  53. for (var i = 0; i < array.length; i++) {
  54. var element = array[i];
  55. if (element == text) {
  56. $(this).addClass('active')
  57. }
  58. }
  59. })
  60. }
  61. resultCount();
  62. }
  63. // 实时改变选择结果
  64. function resultCount() {
  65. $('.result_count').empty();
  66. var count = $('.list').find('.industry_item.active:not(.whole)').length;
  67. if ($('.industry_item.whole').hasClass('active')) {
  68. $('.result_count').html('全部行业');
  69. result = [];
  70. if (buyCount != -1) {
  71. $('.update_tips').show();
  72. } else {
  73. $('.update_tips').hide();
  74. }
  75. } else {
  76. var buttons = $('.select-area-box .list button:not(.whole)');
  77. var canChangeArr = [];
  78. buttons.each(function () {
  79. if ($(this).hasClass('active')) {
  80. canChangeArr.push($(this).text())
  81. }
  82. })
  83. if (count > buyCount && buyCount != -1) {
  84. $('.update_tips').show();
  85. } else {
  86. $('.update_tips').hide();
  87. }
  88. if(count>0){
  89. $('.result_count').html(count + '个行业');
  90. }else {
  91. $('.result_count').html("");
  92. }
  93. if ($('.list').find('.industry_item.active:not(.whole)').length === 0) {
  94. $('.save-btn').prop('disabled', true)
  95. } else {
  96. $('.save-btn').prop('disabled', false)
  97. }
  98. result = canChangeArr;
  99. }
  100. }
  101. $(function () {
  102. // 公共资源交易介绍提示框
  103. $('#showTips').click(function (e) {
  104. e.stopPropagation();
  105. $('#js_dialog').show()
  106. });
  107. // 匹配未分类行业提示框
  108. $('#matchTips').click(function (e) {
  109. e.stopPropagation();
  110. $('#match_dialog').show()
  111. });
  112. $('.know').click(function () {
  113. $('#js_dialog').hide()
  114. $('#match_dialog').hide()
  115. })
  116. // 点击导航跳转
  117. $("body").on('click', '.slide a', function () {
  118. var s = $(this).html()
  119. if (s == '#') {
  120. return;
  121. }
  122. document.querySelector('#' + s).scrollIntoView({
  123. block: 'center'
  124. });
  125. })
  126. // 选择全部行业
  127. $('.industry_item.whole').on('click', function () {
  128. $(this).addClass('active').parents('.list').find('.industry_item:not(.whole)').removeClass('active');
  129. resultCount();
  130. showNeedPopver(false)
  131. })
  132. // 选择非全部行业
  133. $('.industry_item:not(.whole)').on('click', function (e) {
  134. $('.industry_item.whole').removeClass('active');
  135. $(this).toggleClass('active');
  136. showNeedPopver(false)
  137. if ($(this).hasClass('active')) {
  138. showNeedPopver(true, e)
  139. }
  140. resultCount();
  141. })
  142. /* ---S 行业推荐弹窗 @date 2021/4/1 ---*/
  143. // 监听页面滚动事件
  144. $('.form').scroll(function() {
  145. showNeedPopver(false)
  146. });
  147. // 原始数据集合
  148. var needPopverTipMap = [
  149. ['教育', '学校'],
  150. ['卫健委', '医疗'],
  151. ['交通', '运输物流'],
  152. ['工信', '信息技术', '电信行业'],
  153. ['农业', '农林牧渔'],
  154. ['住建', '建筑业'],
  155. ['城管', '市政'],
  156. ['人行', '金融业']
  157. ]
  158. // 常量化索引
  159. var nowSelectIndex = -1
  160. var allNeedTipIndexMap = {}
  161. needPopverTipMap.map(function (v, index) {
  162. v.map(function (s) {
  163. allNeedTipIndexMap[s] = index
  164. })
  165. })
  166. // 获取提示文字
  167. function getNeedPopverTip (str) {
  168. str = str.trim()
  169. var findIndex = allNeedTipIndexMap[str]
  170. if (typeof findIndex === 'number') {
  171. nowSelectIndex = findIndex
  172. var outTip = needPopverTipMap[findIndex].filter(function (v) {
  173. return v !== str
  174. })
  175. return '根据您的选择,推荐添加【'+ outTip.join(',') +'】'
  176. } else {
  177. nowSelectIndex = -1
  178. return ''
  179. }
  180. }
  181. // 控制提示框
  182. function showNeedPopver (show, e) {
  183. if (show) {
  184. var nowStr = getNeedPopverTip($(e.target).text())
  185. if (nowStr !== '') {
  186. var tipDom = $('.add_alert')
  187. tipDom.show().attr('data-index', allNeedTipIndexMap[$(e.target).text()])
  188. tipDom.find('.add_option').text(nowStr)
  189. // 计算及调整显示位置
  190. var computeCoordinateForPop = {
  191. w: tipDom[0].offsetWidth,
  192. h: tipDom[0].offsetHeight
  193. }
  194. var nowSelectDom = $(e.target)
  195. var computeCoordinateForNow = {
  196. w: nowSelectDom[0].offsetWidth,
  197. h: nowSelectDom[0].offsetHeight,
  198. t: nowSelectDom.offset().top,
  199. l: nowSelectDom.offset().left
  200. }
  201. var isTop = e.clientY <= (document.documentElement.clientHeight / 2)
  202. var isLeft = e.clientX <= (document.documentElement.clientWidth / 2)
  203. var cententValue = (document.body.offsetWidth - computeCoordinateForPop.w) / 2
  204. tipDom.css({
  205. top: isTop ? (computeCoordinateForNow.t + computeCoordinateForNow.h + 8) : (computeCoordinateForNow.t - computeCoordinateForPop.h - 8),
  206. left: isLeft ? computeCoordinateForNow.l : cententValue
  207. })
  208. var arrowDom = tipDom.find('.triangle')
  209. arrowDom.css({
  210. top: isTop ? '-14px' : 'initial',
  211. bottom: !isTop ? '-14px' : 'initial',
  212. transform: isTop ? 'rotate(180deg)' : 'rotate(0)',
  213. left: isLeft ? (computeCoordinateForNow.l + 'px') : (computeCoordinateForNow.l - computeCoordinateForNow.w / 2) + 'px'
  214. })
  215. } else {
  216. return showNeedPopver(false)
  217. }
  218. } else {
  219. $('.add_alert').hide()
  220. }
  221. }
  222. // 弹窗取消按钮
  223. $('.btn_cancel').on('click', showNeedPopver.bind(this, false))
  224. // 弹窗确定按钮
  225. $('.btn_confirm').on('click',function(){
  226. showNeedPopver(false)
  227. var buttons = $('.select-area-box .list button')
  228. buttons.each(function () {
  229. var btnStr = $(this).text()
  230. var tempD = $(this)
  231. if (nowSelectIndex !== -1) {
  232. needPopverTipMap[nowSelectIndex].map(function (v) {
  233. if (btnStr === v) {
  234. tempD.addClass('active')
  235. }
  236. })
  237. }
  238. })
  239. resultCount();
  240. $('.add_toast').fadeIn()
  241. setTimeout(function() {
  242. $('.add_toast').fadeOut()
  243. }, 1500)
  244. })
  245. /* ---E 行业推荐弹窗 @date 2021/4/1 ---*/
  246. // 重置按钮事件
  247. $('.reset-btn').on('click', function () {
  248. $('.list').find('.industry_item').removeClass('active');
  249. $('.update_tips').hide();
  250. initData();
  251. showNeedPopver(false)
  252. })
  253. // 确认按钮事件
  254. $('.save-btn').on('click', function () {
  255. data.data.industry = result
  256. var params = {
  257. area: JSON.stringify(data.data.area),
  258. industry: data.data.industry.join(',')
  259. }
  260. // 超级订阅新套餐 修改订阅条件需要提交后台保存, 因是共用页面,为不影响其他页面逻辑,url加上参数进行判断
  261. if (getParam('header') === 'save') {
  262. let url = ''
  263. if(getParam('subvip') === 'free') {
  264. url = '/subscribepay/vipsubscribe/freeSaveChange'
  265. } else {
  266. url = '/subscribepay/vipsubscribe/saveChange'
  267. }
  268. $DoPost(url, params, function (res) {
  269. if (res.data && res.data.doSuccess) {
  270. weui.toast('修改成功', {
  271. duration: 2000,
  272. className: 'custom-toast',
  273. callback: function() {
  274. history.back()
  275. }
  276. });
  277. } else {
  278. weui.toast(res.errMsg, {
  279. duration: 2000,
  280. className: 'custom-toast'
  281. });
  282. }
  283. })
  284. } else {
  285. sessionStorage.setItem('sub_vip_state', JSON.stringify(data.data))
  286. history.back()
  287. }
  288. })
  289. function getDataWitXHR() {
  290. $DoPost('/subscribepay/vipsubscribe/getSubBuyMsg', {}, function (res) {
  291. if (!res.success) return;
  292. data.data = res.data;
  293. res.data.oldArea = res.data.area;
  294. res.data.oldIndustry = res.data.industry;
  295. sessionStorage.setItem('sub_vip_state', JSON.stringify(res.data));
  296. initData();
  297. })
  298. }
  299. var subVipState = sessionStorage.getItem('sub_vip_state')
  300. if (subVipState && !getParam('header')) {
  301. data.data = JSON.parse(subVipState)
  302. initData();
  303. } else {
  304. getDataWitXHR()
  305. }
  306. })