customers.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view>
  3. <!--components/customers/customers.wxml-->
  4. <!-- 新客专享 -->
  5. <template name="New_customers">
  6. <view class="pdlr20">
  7. <view class="mt20 bgfff r10" v-if="customersList&&customersList.products.length > 0">
  8. <navigator hover-class="none" :url="'/activity/newbornZone/newbornZone' + url" class="head">
  9. <view class="titleNav pdlr20 dflex" v-if="customersTemplate.titleType==1">
  10. {{customersTemplate.titleCon}}
  11. <image src="/static/pages/images/more.png" class="more"></image>
  12. </view>
  13. <image lazy-load="true" v-if="customersTemplate.titleType==2"
  14. :src="customersTemplate.titleCon + '?x-oss-process=style/w750-auto'" mode="widthFix"
  15. class="imgtit"></image>
  16. </navigator>
  17. <goodsList :pageList="customersList" :about="about" :merchant="web" :type="'4'" :typeName="'新客'">
  18. </goodsList>
  19. <!-- <view class="pintuan pdlr20">
  20. <view v-for="(item, index) in customersList" :key="index" class="li">
  21. <view class="dflex">
  22. <view class="pinimgs" @tap="goUrl" :data-url="'activity/newbornDetails/newbornDetails?acid=' + item.id + '&id=' + item.productId + '' +web">
  23. <image :src="item.pic" mode="aspectFit" class="pinimg"></image>
  24. </view>
  25. <view class="pininfo flex ">
  26. <view class="proname" @tap="goUrl" :data-url="'activity/newbornDetails/newbornDetails?acid=' + item.id + '&id=' + item.productId + '' + web">
  27. {{item.productName}}</view>
  28. <view :class="'endtime ' + (item.start? '' : 'wei')">{{item.start ? '距结束': '距开始'}} {{item.times}}</view>
  29. <view class="del" v-if="item.marketPrice!=0&&item.marketPrice>item.money" @tap="goUrl" :data-url="'activity/newbornDetails/newbornDetails?acid=' + item.id + '&id=' + item.productId + '' + web">
  30. ¥{{item.marketPrice}}</view>
  31. <view class="operate dflex">
  32. <view class="price" @tap="goUrl" :data-url="'activity/newbornDetails/newbornDetails?acid=' + item.id + '&id=' + item.productId + '' + web">
  33. 新客价¥<text>{{item.money}}</text></view>
  34. <view class="add-cart">
  35. <view class="remind mbglinear dflex" v-if="item.start" @tap="goUrl" :data-url="'activity/newbornDetails/newbornDetails?acid=' + item.id + '&id=' + item.productId + '' + web">立即抢购</view>
  36. <block v-else>
  37. <view class="remind mbggreen dflex" v-if="item.isRemind" @tap="cancelActivityRemind" :data-index="index" data-type="5" :data-id="item.id">取消预约</view>
  38. <view class="remind mbggreen dflex" @tap="addActivityRemind" :data-index="index" data-type="5" :data-id="item.id" v-else>
  39. <icon class="iconfont icon-yugao"></icon>预约提醒
  40. </view>
  41. </block>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </view> -->
  48. </view>
  49. </view>
  50. </template>
  51. </view>
  52. </template>
  53. <script>
  54. // components/customers/customers.js
  55. const route = require("../../utils/route.js");
  56. const utils = require("../../utils/util.js");
  57. const mes = require("../../utils/requestmessage.js");
  58. const req = require("../../utils/request.js");
  59. const app = getApp();
  60. import goodsList from "../../components/goodsList/goodsList";
  61. export default {
  62. data() {
  63. return {};
  64. },
  65. components: {
  66. goodsList
  67. },
  68. props: {
  69. customersList: Object, //{backgroundColor:背景颜色,displayStyle: 样式模板,lineNumber:每行几个,products:产品列表}
  70. url: String, //跳转地址
  71. web: String, //跳转地址
  72. customersTemplate: Object, //新客后台配置
  73. about: Object //参数配置
  74. },
  75. watch: {
  76. },
  77. methods: {
  78. getRqeDatas() {
  79. let that = this; // 新客
  80. let customers = that.homeTemplate.filter(it => it.module == that.templateType.module_customers);
  81. if (customers && customers.length > 0 && customers[0].state == 0) {
  82. that.setData({
  83. customersTemplate: customers[0]
  84. });
  85. this.customersListFun(customers[0]);
  86. }
  87. },
  88. //新客
  89. customersListFun(customersTemplate) {
  90. let _ts = this;
  91. _ts.clearAllTimer(4);
  92. if (this.merchant && this.merchant.type == 5 || this.shopId && this.merchantId) {
  93. let from = {
  94. page: this.page,
  95. limit: customersTemplate.number,
  96. type: 6,
  97. merchantId: this.merchant.merchantDTO.id,
  98. sid: this.merchant.id
  99. };
  100. if (this.shopId && this.merchantId) from.merchantId = this.merchantId, from.sid = this.shopId;
  101. route.getShopeList(from, res => {
  102. res = res.list.map(it => {
  103. it.isRemind = it.remindId;
  104. return it;
  105. });
  106. let arrObjFilter = res.filter(ele => ele.end == false);
  107. this.setData({
  108. customersList: arrObjFilter
  109. });
  110. _ts.initGroupTimer(4);
  111. });
  112. }
  113. if (this.merchant && this.merchant.type != 5) {
  114. route.getAcitve({
  115. page: 1,
  116. limit: customersTemplate.number,
  117. type: 4,
  118. tag: 'home'
  119. }, data => {
  120. data = data.map(it => {
  121. it.isRemind = it.remindId;
  122. return it;
  123. });
  124. let arrObjFilter = data.filter(ele => ele.end == false);
  125. _ts.setData({
  126. customersList: arrObjFilter
  127. });
  128. _ts.initGroupTimer(4);
  129. });
  130. }
  131. },
  132. initGroupTimer(type) {
  133. //社区拼图定时器
  134. let _ts = this;
  135. let list = [];
  136. if (type == 4) list = this.customersList;
  137. if (list && list.length > 0) {
  138. // let activityGroup = this.data.activityGroup;
  139. for (let i = 0, len = list.length; i < len; i++) {
  140. let group = list[i];
  141. let nowTime = new Date(group.nowTime.replace(/-/g, '/')).getTime();
  142. let startTime = new Date(group.startTime.replace(/-/g, '/')).getTime();
  143. let endTime = new Date(group.endTime.replace(/-/g, '/')).getTime();
  144. if (!group.start) endTime = startTime;
  145. let times = parseInt((endTime - nowTime) / 1000);
  146. let timer = setInterval(() => {
  147. times--;
  148. let data = {};
  149. if (times === 0) {
  150. //重新加载列表
  151. if (type == 4) data['customersList[' + i + '].end'] = true;
  152. clearInterval(timer);
  153. } else {
  154. let n = utils.formatDayTimes(times);
  155. if (type == 4) data['customersList[' + i + '].times'] = n;
  156. }
  157. _ts.setData(data);
  158. }, 1000);
  159. if (type == 4) this.customersList[i]['timer'] = timer; // let fs = [];
  160. // fs['activityGroup[' + i + '].timer'] = timer;
  161. // _ts.setData(fs);
  162. }
  163. }
  164. },
  165. clearAllTimer(type) {
  166. if (type == 4) this.customersList.forEach(it => clearInterval(it.timer));
  167. },
  168. goUrl(event) {
  169. //跳转链接
  170. let url = event.currentTarget.dataset.url;
  171. app.globalData.openPage(url);
  172. },
  173. cancelActivityRemind(event) {
  174. const index = event.currentTarget.dataset.index;
  175. const id = event.currentTarget.dataset.id;
  176. const type = event.currentTarget.dataset.type;
  177. if (req.header.appId == 'ZQ1VK5oc17I387E') {
  178. } else {
  179. route.cancelActivityRemind({
  180. id: id
  181. }, res => {
  182. req.msg('取消提醒成功');
  183. let data = {};
  184. if (type == 5) data['customersList[' + index + '].isRemind'] = false;
  185. this.setData(data);
  186. });
  187. }
  188. },
  189. addActivityRemind(event) {
  190. const index = event.currentTarget.dataset.index;
  191. const id = event.currentTarget.dataset.id;
  192. const type = event.currentTarget.dataset.type;
  193. route.addActivityRemind({
  194. activityId: id
  195. }, res => {
  196. mes.remind().then(res => res);
  197. // mes.remind().then(res=>res)
  198. // mes.requsetmessage()
  199. req.msg('订阅提醒成功');
  200. let data = {};
  201. if (type == 5) data['customersList[' + index + '].isRemind'] = true;
  202. this.setData(data);
  203. });
  204. }
  205. }
  206. };
  207. </script>
  208. <style>
  209. @import "./customers.css";
  210. </style>