share.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. var userRole = that.data.userRole;
  20. console.log("share:" + userRole);
  21. if (this.data.msg == '' || this.data.msg == undefined){
  22. this.setData({
  23. msg: '小小心意'
  24. })
  25. }
  26. if (res.from === 'button') {
  27. // 来自页面内转发按钮
  28. console.log("11:"+res.target)
  29. }
  30. var dataTime = new Date()
  31. var time = Util.formatTime(dataTime); //获赠时间
  32. var shareTime = Date.parse(dataTime);//分享时间
  33. shareTime = shareTime / 1000;
  34. var timestamp = Date.parse(new Date());
  35. timestamp =timestamp / 1000;
  36. that.setData({
  37. time: time,
  38. shareTime: shareTime,
  39. timestamp: timestamp,
  40. })
  41. var cardSrc = that.data.cardSrc;
  42. var src = that.data.src;
  43. if (cardSrc){
  44. this.setData({
  45. src: cardSrc
  46. })
  47. }
  48. var newCarts = JSON.stringify(that.data.goodsList);
  49. newCarts = newCarts.replace(/&/g, "zss");
  50. return {
  51. title: that.data.msg,
  52. path: '/pages/awaitState/awaitState?src=' + that.data.src + '&msg=' + that.data.msg + '&url=' + that.data.userInfo.avatarUrl + '&name=' + that.data.userInfo.nickName + '&order_number=N' + timestamp + '&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' + timestamp + '&userRole=' + userRole,
  53. imageUrl: this.data.src,
  54. success: function (res) {
  55. console.log('成功' + res);
  56. that.setData({
  57. shareNum : 1
  58. })
  59. //消息模版:存储模板消息使用的form_id
  60. wx.request({
  61. url: host + "userapi/insertadduserwxsend",
  62. data: {
  63. user_id: un_id,
  64. form_id_dz: that.data.formId,
  65. order_number: '6' + timestamp,//6开头的单号
  66. },
  67. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  68. header: {
  69. 'Accept': 'application/json'
  70. },
  71. success: function (res) {
  72. if (res == null || res.data == null) {
  73. console.error('网络请求失败');
  74. return;
  75. }
  76. }
  77. })
  78. //插入到分享礼物表【仅有 分享订单号 分享时间(字符串) 分享标志位 三个字段】
  79. wx.request({
  80. url: host + "orderapi/insertorderlink",
  81. data: {
  82. order_number: "N" + timestamp,//拆分后的订单号
  83. order_timeno: shareTime,
  84. order_linkFlag: 0 //是否收下的标志位 0:未被收下 1:已被收下
  85. },
  86. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  87. header: {
  88. 'Accept': 'application/json'
  89. },
  90. success: function (res) {
  91. if (res == null || res.data == null) {
  92. console.error('网络请求失败');
  93. return;
  94. }
  95. }
  96. });
  97. if (un_id != undefined && un_id != '' && un_id != null) {
  98. wx.request({
  99. url: host + "orderapi/insertorder_n",
  100. data: {
  101. order_userid: un_id,
  102. order_sta: '3',//待发货
  103. order_number_o: that.data.order_number,//原始单号
  104. order_number: "N" + timestamp,//新单号
  105. order_type: '3',//赠送 - 送朋友 - 流转
  106. order_Price: that.data.goodsList.list_order_aff_data[0].order_Price,
  107. order_Consignee: '',
  108. order_phone: '',
  109. order_address: '',
  110. order_commodityid: that.data.goodsList.list_order_aff_data[0].id,
  111. order_Specifications: '',
  112. order_gixbox: '',
  113. order_Price: that.data.goodsList.list_order_aff_data[0].newTotal,
  114. invoice_send_flag: 3,
  115. invoice_flag: 3, //发票标志位,如果为3,则为无需发票
  116. },
  117. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  118. header: {
  119. 'Accept': 'application/json'
  120. },
  121. success: function (res) {
  122. console.log(res);
  123. if (res.data.result == 1){
  124. //插入订单
  125. var len = that.data.goodsList.list_order_aff_data.length;
  126. that.insertOrder(len, that.data.order_number, timestamp, un_id);
  127. }else{//请求超时
  128. }
  129. if (res == null || res.data == null) {
  130. console.error('网络请求失败');
  131. return;
  132. }
  133. }
  134. });
  135. }
  136. },
  137. fail: function (res) {
  138. console.log('shibai' + res);
  139. // 转发失败
  140. }
  141. }
  142. },
  143. //插入订单
  144. insertOrder: function (i,order_number_old, timestamp, un_id) {
  145. var that = this;
  146. var host = getApp().globalData.servsers;
  147. var un_id = getApp().globalData.un_id;
  148. var stateNum = that.data.stateNum;//记录带有定制的商品数量
  149. console.log("i:" + i);
  150. if (i == 0) {
  151. //对应插入"送出礼物表"
  152. wx.request({
  153. url: host + "giftapi/insertUserGiftSend",
  154. data: {
  155. userId: un_id,
  156. giftImg: that.data.src,
  157. giftMsg: that.data.msg,
  158. fromUserHead: that.data.userInfo.avatarUrl,
  159. fromUserName: that.data.userInfo.nickName,
  160. orderNumber: "N" + that.data.timestamp,
  161. orderNumberGift: "6" + that.data.timestamp,
  162. cTime: that.data.time,
  163. giftOtherImg: that.data.uploadImgList
  164. },
  165. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  166. header: {
  167. 'Accept': 'application/json'
  168. },
  169. success: function (res) {
  170. //返回订单页
  171. wx.redirectTo({
  172. url: '/pages/orderList/orderList?isSelect=0',
  173. })
  174. if (res == null || res.data == null) {
  175. console.error('网络请求失败');
  176. return;
  177. }
  178. }
  179. });
  180. } else {
  181. i -= 1;
  182. var break_num = that.data.goodsList.list_order_aff_data[i].break_num;
  183. var giftbox_name = that.data.goodsList.list_order_aff_data[i].com_dz;
  184. var process_name = that.data.goodsList.list_order_aff_data[i].com_lh;
  185. var process_id = 20;
  186. var giftbox_id = 20;
  187. if (process_name == '无需定制' || process_name == ''){
  188. process_id = -1;
  189. }
  190. if (giftbox_name == '无需定制' || giftbox_name == '') {
  191. giftbox_id = -1;
  192. }
  193. console.log(that.data.goodsList);
  194. if (break_num >0){
  195. wx.request({
  196. url: host + "orderaffapi/insertOrderAff_n",
  197. data: {
  198. order_number_o: order_number_old,//原始单号
  199. order_number: "N" + timestamp,
  200. cost: that.data.goodsList.list_order_aff_data[i].com_price,
  201. com_id: that.data.goodsList.list_order_aff_data[i].com_id,
  202. logo: that.data.goodsList.list_order_aff_data[i].logo,
  203. name: that.data.goodsList.list_order_aff_data[i].com_name,
  204. num: that.data.goodsList.list_order_aff_data[i].break_num,
  205. process: process_id,
  206. giftbox_name: that.data.goodsList.list_order_aff_data[i].com_dz,
  207. giftbox_id: giftbox_id,
  208. box_price: that.data.goodsList.list_order_aff_data[i].box_price,
  209. process_name: that.data.goodsList.list_order_aff_data[i].com_lh,
  210. process_id: process_id,
  211. logo: that.data.goodsList.list_order_aff_data[i].logo,
  212. style1_name: that.data.goodsList.list_order_aff_data[i].com_style1,
  213. style2_name: that.data.goodsList.list_order_aff_data[i].com_style2,
  214. style3_name: that.data.goodsList.list_order_aff_data[i].com_style3,
  215. style4_name: that.data.goodsList.list_order_aff_data[i].com_style4,
  216. style5_name: that.data.goodsList.list_order_aff_data[i].com_style5,
  217. affId: that.data.goodsList.list_order_aff_data[i].id,
  218. },
  219. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  220. header: {
  221. 'Accept': 'application/json'
  222. },
  223. success: function (res) {
  224. if ((that.data.goodsList.list_order_aff_data[i].process_name != '') && (that.data.goodsList.list_order_aff_data[i].process != -1)) {
  225. that.setData({
  226. stateNum: stateNum + 1
  227. })
  228. }
  229. that.insertOrder(i, order_number_old, timestamp, un_id);
  230. if (res == null || res.data == null) {
  231. console.error('网络请求失败');
  232. return;
  233. }
  234. }
  235. })
  236. } else{
  237. that.insertOrder(i, order_number_old, timestamp, un_id);
  238. }
  239. }
  240. },
  241. data: {
  242. urlHttp: '',//图片访问线上路径
  243. cardList: cardList,
  244. userInfo: {},
  245. src : '',
  246. id : '',
  247. msg : '',
  248. msgCopy : '',
  249. order_number : '',
  250. order_userid : '',
  251. uploadImgList :[],
  252. uploadImgListLength : 0,
  253. shortTimeList : [],
  254. selectFlag : false, //场景是否选中,默认为选中
  255. selectId : -1 , //默认勾选为不勾选
  256. flagId : -1, //记录当前点击的卡片id
  257. cardSrc : '', //选中的卡片的图片地址
  258. cardIntro : '', //选中的卡片的描述
  259. goodsList : [],
  260. flag : '0', //来源标志【0:来自订单或者订单详情 1:来自礼物详情页】
  261. shareNum :0,//点击分享的次数
  262. formId: '', //用于消息模版的formId
  263. time : '',
  264. shareTime: '',
  265. timestamp: '',
  266. flag : '',
  267. formId : '',
  268. userRole : '', //分享者-用户角色【0:普通 1:商务】
  269. },
  270. onLoad: function (options) {
  271. var that = this;
  272. var host = getApp().globalData.servsers;
  273. var goodsList = options.goodsList;
  274. goodsList = goodsList.replace(/zss/g, "&");
  275. goodsList = JSON.parse(goodsList);
  276. var total = 0;
  277. for (var i = 0; i < goodsList.list_order_aff_data.length; i++) {
  278. var boxPrice = goodsList.list_order_aff_data[i].box_price;
  279. var goodsPrice = goodsList.list_order_aff_data[i].cost;
  280. if (boxPrice == '' && boxPrice == null) {
  281. boxPrice = 0;
  282. }
  283. total += (parseFloat(goodsPrice) + parseFloat(boxPrice)) * (goodsList.list_order_aff_data[i].num);
  284. }
  285. for (var i = 0; i < goodsList.list_order_aff_data.length; i++) {
  286. goodsList.list_order_aff_data[i].order_Price = total;
  287. }
  288. console.log(goodsList);
  289. console.log("formId:" + options.formId);
  290. console.log("share-onlload:" + options.userRole);
  291. that.setData({
  292. urlHttp: host,
  293. src: options.src,
  294. id: options.id,
  295. order_number: options.order_number,
  296. order_userid: options.order_userid,
  297. goodsNme: options.goodsNme,
  298. goodsNum: options.goodsNum,
  299. goodsList: goodsList,
  300. flag: options.flag,
  301. formId: options.formId,
  302. userRole: options.userRole,
  303. userInfo: getApp().globalData.userInfo
  304. })
  305. },
  306. textFocus:function(e){
  307. var that = this;
  308. that.setData({
  309. msg: e.detail.value,
  310. msgCopy: e.detail.value
  311. })
  312. },
  313. //选择场景
  314. cardSelect:function(e){
  315. var that = this;
  316. var id = e.currentTarget.dataset.id;
  317. var selectId = id;
  318. var cardSrc = e.currentTarget.dataset.src;
  319. var cardIntro = e.currentTarget.dataset.intro;
  320. var selectFlag = that.data.selectFlag;
  321. var flagId = that.data.flagId;
  322. var msg = that.data.msg;//留言区内容
  323. var msgCopy = that.data.msgCopy;
  324. console.log(msgCopy)
  325. if (flagId == id){//相同卡片的点击
  326. if (selectFlag) {
  327. selectFlag = false;
  328. cardSrc = '';
  329. msg = msgCopy;
  330. }else{
  331. selectFlag = true;
  332. if (msgCopy == '' || msgCopy == undefined || msgCopy == null) {
  333. msg = cardIntro;
  334. }
  335. }
  336. }else{
  337. selectId = selectId;
  338. flagId = id;
  339. selectFlag = true;
  340. if (msgCopy == '' || msgCopy == undefined || msgCopy == null) {
  341. msg = cardIntro;
  342. }
  343. }
  344. that.setData({
  345. selectId: selectId,
  346. flagId: flagId,
  347. selectFlag: selectFlag,
  348. cardSrc: cardSrc,
  349. msg: msg
  350. })
  351. },
  352. uploadImg:function(e){//上传图片
  353. var that = this;
  354. var host = getApp().globalData.servsers;
  355. var un_id = getApp().globalData.un_id;
  356. wx.chooseImage({
  357. count: 9, // 默认9
  358. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  359. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  360. success: function (res) {
  361. for (var i = 0; i < res.tempFilePaths.length;i++){
  362. var filePath = res.tempFilePaths[i];
  363. wx.uploadFile({
  364. url: host + "UploadFileOneforxcx",
  365. filePath: filePath,
  366. name: 'file',
  367. header: {
  368. "Content-Type": "multipart/form-data"
  369. },
  370. formData: {
  371. //和服务器约定的token, 一般也可以放在header中
  372. //'session_token': wx.getStorageSync('session_token')
  373. userId: un_id,
  374. orderNumber: that.data.orderNumber
  375. },
  376. success: function (res) {
  377. var newList = that.data.uploadImgList.push(res.data);
  378. that.setData({
  379. uploadImgList: that.data.uploadImgList
  380. })
  381. if (res.statusCode != 200) {
  382. wx.showModal({
  383. title: '提示',
  384. content: '上传失败',
  385. showCancel: false
  386. })
  387. return;
  388. }
  389. },
  390. fail: function (e) {
  391. console.log(e);
  392. wx.showModal({
  393. title: '提示',
  394. content: '上传失败',
  395. showCancel: false
  396. })
  397. },
  398. complete: function () {
  399. wx.hideToast(); //隐藏Toast
  400. }
  401. })
  402. }
  403. }
  404. })
  405. },
  406. deleteUploadImg:function(e){//删除上传图片
  407. var that = this;
  408. var id = e.currentTarget.dataset.id;
  409. var uploadImgList = that.data.uploadImgList;
  410. uploadImgList.splice(id, 1);
  411. that.setData({
  412. uploadImgList: uploadImgList
  413. });
  414. }
  415. })
  416. var that;
  417. var Util = require('../../utils/util.js');