wshare.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view>
  3. <scroll-view scroll-x class="bg-white nav text-center solid-bottom echo-fixed-top">
  4. <view class="cu-item" :class="item.id==cateid?'text-red cur':''" v-for="(item, index) in catelist" :key="item.id" @tap="tabSelect" :data-id="item.id">
  5. {{item.title}}
  6. </view>
  7. </scroll-view>
  8. <view class="echo-fixed-top-empty"></view>
  9. <view class="cu-list grid col-2 no-border padding-lr">
  10. <block v-for="(item,index) in plist" :key="index">
  11. <view class="cu-item">
  12. <view class="padding-lr-sm" @tap="getWorkerImage(item.id)">
  13. <view class="bg-img" :style="'background-image:url(' + item.tilpic + ');'"></view>
  14. <view class="padding-tb-xs text-cut">{{item.title}}</view>
  15. </view>
  16. </view>
  17. </block>
  18. </view>
  19. <uni-load-more :status="pstatus"></uni-load-more>
  20. <view class="echo-fixed-top-empty"></view>
  21. <view class="text-center text-gray padding-tb-sm solids-top bg-white" style="position: fixed; bottom: 0rpx; width: 100%;">
  22. <button class="cu-btn margin-lr-xs" :class="modal.texttil=='title'?'line-red':'line-grey'" @tap="changeTexttil('title')">企业名称</button>
  23. <button class="cu-btn margin-lr-xs" :class="modal.texttil=='address'?'line-red':'line-grey'" @tap="changeTexttil('address')">详细地址</button>
  24. <button class="cu-btn margin-lr-xs" :class="modal.texttil=='mobile'?'line-red':'line-grey'" @tap="changeTexttil('mobile')">联系电话</button>
  25. </view>
  26. <view class="cu-modal" :class="modal.name=='shareWorkerpicModal'?'show':''" @tap="hideModal">
  27. <view class="cu-dialog picmodal" @tap.stop="">
  28. <view class="bg-img">
  29. <image mode="widthFix" :src="modal.workerpic"></image>
  30. <view class="cu-bar justify-end text-white picmodalclose">
  31. <view class="action" @tap="hideModal">
  32. <text class="cuIcon-close "></text>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="cu-bar bg-white margin-top-xs">
  37. <view class="action margin-0 flex-sub solid-left" @tap="saveImage">保存到相册</view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
  45. var _this;
  46. export default {
  47. components: {
  48. uniLoadMore
  49. },
  50. data() {
  51. return {
  52. cateid: 0,
  53. catelist: [],
  54. pstatus: 'more',
  55. ppage: 1,
  56. psize: 20,
  57. plist: [],
  58. modal: {
  59. name: null,
  60. texttil: "title",
  61. workerpic: ""
  62. }
  63. };
  64. },
  65. onLoad: function() {
  66. _this = this;
  67. _this.userinfo = uni.getStorageSync('userinfo') || false;
  68. _this.workerinfo = uni.getStorageSync('workerinfo') || false;
  69. if (_this.workerinfo === false) {
  70. uni.reLaunch({
  71. url: "/pages/my/my"
  72. });
  73. return false;
  74. }
  75. _this.$req.ajax({
  76. path: "worker/pagewshare",
  77. data: {}
  78. }).then((data) => {
  79. _this.catelist = data.catelist;
  80. _this.getMore();
  81. }).catch((err) => {
  82. uni.showModal({
  83. title: '信息提示',
  84. content: err,
  85. showCancel: false
  86. });
  87. });
  88. },
  89. onPullDownRefresh: function() {
  90. _this.ppage = 1;
  91. _this.pstatus = 'more';
  92. _this.plist = [];
  93. _this.getMore();
  94. },
  95. onReachBottom: function() {
  96. if (_this.pstatus !== 'more') {
  97. return;
  98. }
  99. _this.getMore();
  100. },
  101. methods: {
  102. tabSelect: function(e) {
  103. _this.cateid = e.currentTarget.dataset.id;
  104. _this.pageRefresh();
  105. },
  106. pageRefresh: function() {
  107. _this.pstatus = 'more';
  108. _this.ppage = 1;
  109. _this.plist = [];
  110. _this.getMore();
  111. },
  112. getMore: function() {
  113. _this.$req.ajax({
  114. path: "worker/listwshare",
  115. data: {
  116. ppage: _this.ppage,
  117. psize: _this.psize,
  118. cateid: _this.cateid
  119. }
  120. }).then((data) => {
  121. _this.pstatus = data.pstatus;
  122. _this.plist = _this.plist.concat(data.plist);
  123. _this.ppage += 1;
  124. uni.stopPullDownRefresh();
  125. }).catch((err) => {
  126. uni.showModal({
  127. title: '信息提示',
  128. content: err,
  129. showCancel: false
  130. });
  131. });
  132. },
  133. changeTexttil: function(texttil) {
  134. _this.modal.texttil = texttil;
  135. },
  136. getWorkerImage: function(shareid) {
  137. var texttil = _this.modal.texttil=='title' ? _this.workerinfo.title : ( _this.modal.texttil=='address' ? _this.workerinfo.address : _this.workerinfo.mobile );
  138. _this.$req.ajax({
  139. title: "推广海报生成中...",
  140. path: "worker/getworkerimage",
  141. data: {
  142. shareid: shareid,
  143. userid: _this.userinfo.id,
  144. workerid: _this.workerinfo.id,
  145. texttil: texttil
  146. }
  147. }).then((data) => {
  148. _this.modal.workerpic = data.workerpic;
  149. _this.modal.name = "shareWorkerpicModal";
  150. }).catch((err) => {
  151. uni.showModal({
  152. title: '温馨提示',
  153. content: err,
  154. showCancel: false
  155. });
  156. });
  157. },
  158. saveImage: function() {
  159. uni.downloadFile({
  160. url: _this.modal.workerpic, //仅为示例,并非真实的资源
  161. success: (res) => {
  162. if (res.statusCode === 200) {
  163. uni.saveImageToPhotosAlbum({
  164. filePath: res.tempFilePath,
  165. success: function() {
  166. uni.showModal({
  167. title: '信息提示',
  168. content: "已保存到手机相册,注意查收。",
  169. showCancel: false
  170. });
  171. }
  172. });
  173. }
  174. }
  175. });
  176. },
  177. hideModal: function() {
  178. _this.modal.name = null;
  179. },
  180. }
  181. }
  182. </script>
  183. <style>
  184. .cu-item .bg-img{ width: 100%; height: 390rpx; background-position: center top; }
  185. .picmodal{ width: 540rpx; background-color: transparent; }
  186. .picmodal image{ width: 100%; }
  187. .picmodal .bg-img{ position: relative; }
  188. .picmodalclose{ position: absolute; top: 0rpx; right: 0rpx; }
  189. </style>