shareGift.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. // pages/share/share.js
  2. var app = getApp();
  3. var cardList = [
  4. { id: 1, src: 'images/sendCards/send_cards_1.jpg', intro: '生日快乐' },
  5. { id: 2, src: 'images/sendCards/send_cards_2.jpg', intro: '很高兴遇见你' },
  6. { id: 3, src: 'images/sendCards/send_cards_3.jpg', intro: '多谢关照' },
  7. { id: 4, src: 'images/sendCards/send_cards_4.jpg', intro: '感谢有你' },
  8. { id: 5, src: 'images/sendCards/send_cards_5.jpg', intro: '欢度国庆' },
  9. { id: 6, src: 'images/sendCards/send_cards_6.jpg', intro: '清凉一夏' },
  10. { id: 7, src: 'images/sendCards/send_cards_7.jpg', intro: '新春快乐' },
  11. { id: 8, src: 'images/sendCards/send_cards_8.jpg', intro: '有空长聚' },
  12. { id: 9, src: 'images/sendCards/send_cards_9.jpg', intro: '有你真好' }
  13. ];
  14. Page({
  15. onShareAppMessage: function (res) {
  16. var that = this;
  17. var host = getApp().globalData.servsers;
  18. var un_id = getApp().globalData.un_id;
  19. if (this.data.msg == '' || this.data.msg == undefined) {
  20. this.setData({
  21. msg: '小小心意'
  22. })
  23. }
  24. if (res.from === 'button') {
  25. // 来自页面内转发按钮
  26. console.log("11:" + res.target)
  27. }
  28. var time = Util.formatTime(new Date()); //获赠时间
  29. var shareTime = Date.parse(new Date());//分享时间
  30. shareTime = shareTime / 1000;
  31. var pages = getCurrentPages();
  32. var currPage = pages[pages.length - 1]; //当前页面
  33. var prevPage = pages[pages.length - 2]; //上一个页面
  34. var cardSrc = that.data.cardSrc;
  35. var src = that.data.src;
  36. if (cardSrc) {
  37. this.setData({
  38. src: cardSrc
  39. })
  40. }
  41. var newCarts = JSON.stringify(that.data.goodsList);
  42. newCarts = newCarts.replace(/&/g, "zss");
  43. var shareNum = that.data.shareNum;
  44. return {
  45. title: that.data.msg,
  46. path: '/pages/awaitState/awaitState?src=' + that.data.src + '&msg=' + that.data.msg + '&url=' + that.data.userInfo.avatarUrl + '&name=' + that.data.userInfo.nickName + '&order_number=' + that.data.order_number + '&order_userid=' + that.data.order_userid + "&time=" + time + "&uploadImg=" + that.data.uploadImgList + "&goodsName=" + that.data.goodsNme + "&goodsNum=" + that.data.goodsNum + "&goodsList=" + newCarts + "&shareTime=" + shareTime + '&order_number_send=6' + shareTime,
  47. imageUrl: this.data.src,
  48. success: function (res) {
  49. that.setData({
  50. addGiftListClick: true
  51. })
  52. console.log('成功' + res);
  53. that.setData({
  54. shareNum: 1
  55. })
  56. //消息模版:存储模板消息使用的form_id
  57. wx.request({
  58. url: host + "userapi/insertadduserwxsend",
  59. data: {
  60. user_id: un_id,
  61. form_id_dz: that.data.formId,
  62. order_number: '6' + shareTime,//6开头的单号
  63. },
  64. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  65. header: {
  66. 'Accept': 'application/json'
  67. },
  68. success: function (res) {
  69. if (res == null || res.data == null) {
  70. console.error('网络请求失败');
  71. return;
  72. }
  73. }
  74. })
  75. console.log("order_number_send2:" + that.data.order_number_send);
  76. //插入到分享礼物表【仅有 分享订单号 分享时间(字符串) 分享标志位 三个字段】
  77. wx.request({
  78. url: host + "orderapi/insertorderlink",
  79. data: {
  80. order_number: that.data.order_number,//拆分后的订单号
  81. order_timeno: shareTime,
  82. order_linkFlag: 0
  83. },
  84. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  85. header: {
  86. 'Accept': 'application/json'
  87. },
  88. success: function (res) {
  89. if (res == null || res.data == null) {
  90. console.error('网络请求失败');
  91. return;
  92. }
  93. }
  94. })
  95. if (un_id != undefined && un_id != '' && un_id != null) {
  96. console.log("order_number_send3:" + that.data.order_number_send);
  97. //更改"收到礼物表"标志位
  98. wx.request({
  99. url: host + "giftapi/updateReceive_flag",
  100. data: {
  101. order_number: that.data.order_number,
  102. order_number_gift: that.data.order_number_send
  103. },
  104. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  105. header: {
  106. 'Accept': 'application/json'
  107. },
  108. success: function (res) {
  109. if (res == null || res.data == null) {
  110. console.error('网络请求失败');
  111. return;
  112. }
  113. }
  114. })
  115. //对应插入"送出礼物表"
  116. wx.request({
  117. url: host + "giftapi/insertUserGiftSend",
  118. data: {
  119. userId: un_id,
  120. giftImg: that.data.src,
  121. giftMsg: that.data.msg,
  122. fromUserHead: that.data.userInfo.avatarUrl,
  123. fromUserName: that.data.userInfo.nickName,
  124. orderNumber: that.data.order_number,
  125. orderNumberGift: "6" + shareTime,
  126. cTime: time,
  127. giftOtherImg: that.data.uploadImgList
  128. },
  129. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  130. header: {
  131. 'Accept': 'application/json'
  132. },
  133. success: function (res) {
  134. var preFlag = that.data.flag;
  135. if (preFlag == '1') {//来自礼物详情页【awaitState】
  136. wx.redirectTo({
  137. url: '/pages/mineGiftList/mineGiftList?isSelectNew=1',
  138. })
  139. } else {
  140. prevPage.setData({
  141. isSelect :1,
  142. goosdListnew:{},
  143. goosdListnew2:{}
  144. })
  145. prevPage.onShow();
  146. wx.navigateBack({
  147. delta: 1
  148. })
  149. }
  150. if (res == null || res.data == null) {
  151. console.error('网络请求失败');
  152. return;
  153. }
  154. }
  155. });
  156. }
  157. },
  158. fail: function (res) {
  159. console.log('shibai' + res);
  160. // 转发失败
  161. }
  162. }
  163. },
  164. data: {
  165. urlHttp: '',//图片访问线上路径
  166. cardList: cardList,
  167. userInfo: {},
  168. src: '',
  169. id: '',
  170. msg: '',
  171. msgCopy: '',
  172. order_number: '',
  173. order_userid: '',
  174. uploadImgList: [],
  175. uploadImgListLength: 0,
  176. shortTimeList: [],
  177. selectFlag: false, //场景是否选中,默认为选中
  178. selectId: -1, //默认勾选为不勾选
  179. flagId: -1, //记录当前点击的卡片id
  180. cardSrc: '', //选中的卡片的图片地址
  181. cardIntro: '', //选中的卡片的描述
  182. goodsList: [],
  183. flag: '0', //来源标志【0:来自订单或者订单详情 1:来自礼物详情页】
  184. order_number_send:'',
  185. shareNum: 0,//点击分享的次数
  186. },
  187. onLoad: function (options) {
  188. var that = this;
  189. var host = getApp().globalData.servsers;
  190. var goodsListNew =options.goodsList;
  191. goodsListNew = goodsListNew.replace(/zss/g, "&");
  192. goodsListNew = JSON.parse(goodsListNew);
  193. console.log(goodsListNew);
  194. console.log("shareGift - formId:" + options.formId);
  195. that.setData({
  196. urlHttp: host,
  197. src: options.src,
  198. id: options.id,
  199. order_number: options.order_number,
  200. order_userid: options.order_userid,
  201. goodsNme: options.goodsNme,
  202. goodsNum: options.goodsNum,
  203. goodsList: goodsListNew,
  204. flag: options.flag,
  205. order_number_send: options.order_number_send,
  206. addGiftListClick: false, //判断“放入礼物盒”按钮是否点击过
  207. formId: options.formId,
  208. userInfo: getApp().globalData.userInfo
  209. })
  210. console.log("order_number:" + options.order_number);
  211. console.log("order_number_send:" + options.order_number_send);
  212. },
  213. textFocus: function (e) {
  214. var that = this;
  215. that.setData({
  216. msg: e.detail.value,
  217. msgCopy: e.detail.value
  218. })
  219. },
  220. //选择场景
  221. cardSelect: function (e) {
  222. var that = this;
  223. var id = e.currentTarget.dataset.id;
  224. var selectId = id;
  225. var cardSrc = e.currentTarget.dataset.src;
  226. var cardIntro = e.currentTarget.dataset.intro;
  227. var selectFlag = that.data.selectFlag;
  228. var flagId = that.data.flagId;
  229. var msg = that.data.msg;//留言区内容
  230. var msgCopy = that.data.msgCopy;
  231. console.log(msgCopy)
  232. if (flagId == id) {//相同卡片的点击
  233. if (selectFlag) {
  234. selectFlag = false;
  235. cardSrc = '';
  236. msg = msgCopy;
  237. } else {
  238. selectFlag = true;
  239. if (msgCopy == '' || msgCopy == undefined || msgCopy == null) {
  240. msg = cardIntro;
  241. }
  242. }
  243. } else {
  244. selectId = selectId;
  245. flagId = id;
  246. selectFlag = true;
  247. if (msgCopy == '' || msgCopy == undefined || msgCopy == null) {
  248. msg = cardIntro;
  249. }
  250. }
  251. that.setData({
  252. selectId: selectId,
  253. flagId: flagId,
  254. selectFlag: selectFlag,
  255. cardSrc: cardSrc,
  256. msg: msg
  257. })
  258. },
  259. uploadImg: function (e) {//上传图片
  260. var that = this;
  261. var host = getApp().globalData.servsers;
  262. var un_id = getApp().globalData.un_id;
  263. wx.chooseImage({
  264. count: 9, // 默认9
  265. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  266. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  267. success: function (res) {
  268. for (var i = 0; i < res.tempFilePaths.length; i++) {
  269. var filePath = res.tempFilePaths[i];
  270. wx.uploadFile({
  271. url: host + "UploadFileOneforxcx",
  272. filePath: filePath,
  273. name: 'file',
  274. header: {
  275. "Content-Type": "multipart/form-data"
  276. },
  277. formData: {
  278. //和服务器约定的token, 一般也可以放在header中
  279. //'session_token': wx.getStorageSync('session_token')
  280. userId: un_id,
  281. orderNumber: that.data.orderNumber
  282. },
  283. success: function (res) {
  284. var newList = that.data.uploadImgList.push(res.data);
  285. that.setData({
  286. uploadImgList: that.data.uploadImgList
  287. })
  288. if (res.statusCode != 200) {
  289. wx.showModal({
  290. title: '提示',
  291. content: '上传失败',
  292. showCancel: false
  293. })
  294. return;
  295. }
  296. },
  297. fail: function (e) {
  298. console.log(e);
  299. wx.showModal({
  300. title: '提示',
  301. content: '上传失败',
  302. showCancel: false
  303. })
  304. },
  305. complete: function () {
  306. wx.hideToast(); //隐藏Toast
  307. }
  308. })
  309. }
  310. }
  311. })
  312. },
  313. deleteUploadImg: function (e) {//删除上传图片
  314. var that = this;
  315. var id = e.currentTarget.dataset.id;
  316. var uploadImgList = that.data.uploadImgList;
  317. uploadImgList.splice(id, 1);
  318. that.setData({
  319. uploadImgList: uploadImgList
  320. });
  321. }
  322. })
  323. var that;
  324. var Util = require('../../utils/util.js');