detail.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. const _Http = getApp().globalData.http;
  2. import {
  3. fileList
  4. } from "../../utils/FormatTheAttachment";
  5. Page({
  6. data: {
  7. hidePrice: wx.getStorageSync('hidePrice'),
  8. loading: true,
  9. active: "",
  10. list: [],
  11. groupList: [],
  12. pageNumber: 1,
  13. pageTotal: 1,
  14. },
  15. onLoad(options) {
  16. if (options.id) this.setData({
  17. sa_promotionid: options.id
  18. })
  19. this.getDetail();
  20. },
  21. /* 获取详情 */
  22. getDetail() {
  23. _Http.basic({
  24. "id": "20221230144703",
  25. "version": 1,
  26. "content": {
  27. "sa_promotionid": this.data.sa_promotionid
  28. }
  29. }).then(res => {
  30. if (res.msg != '成功') return wx.showToast({
  31. title: res.msg,
  32. icon: "none"
  33. })
  34. this.handleFiles(res.data.attinfos)
  35. this.setData({
  36. detail: res.data,
  37. loading: false
  38. });
  39. this.getProductList();
  40. })
  41. },
  42. /* 切换商品tab */
  43. tabChange(e) {
  44. this.setData({
  45. active: e.detail.name,
  46. pageNumber: 1,
  47. pageTotal: 1
  48. });
  49. this.getProductList();
  50. },
  51. /* 获取产品列表 */
  52. getProductList() {
  53. let pageNumber = this.data.pageNumber,
  54. pageTotal = this.data.pageTotal;
  55. if (pageNumber > pageTotal) return;
  56. _Http.basic({
  57. "id": 20230116094803,
  58. "version": 1,
  59. "content": {
  60. sa_promotionid: this.data.sa_promotionid,
  61. "sa_promotion_itemgroupid": this.data.active,
  62. pageNumber,
  63. pageTotal,
  64. "where": {
  65. "condition": ""
  66. }
  67. }
  68. }).then(res => {
  69. console.log('活动产品列表', res)
  70. if (res.msg != '成功') return wx.showToast({
  71. title: res.msg,
  72. icon: "none"
  73. })
  74. res.data = res.data.map(value => {
  75. if (value.attinfos.length != 0) {
  76. value.attinfos = fileList(value.attinfos)
  77. let image = value.attinfos.find(v => v.fileType == "image");
  78. if (image) {
  79. try {
  80. value.cover = image.subfiles.find(v => v.type == "thumbnail").url;
  81. } catch (error) {
  82. value.cover = image.url;
  83. }
  84. }
  85. }
  86. if (value.islimit == 0) value.groupqty = 0;
  87. if (value.gradeprice) value.gradeprice = (value.gradeprice - 0).toFixed(2)
  88. if (value.oldprice) value.oldprice = (value.oldprice - 0).toFixed(2)
  89. if (value.price) value.price = (value.price - 0).toFixed(2)
  90. return value;
  91. })
  92. this.setData({
  93. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  94. pageNumber: res.pageNumber + 1,
  95. pageTotal: res.pageTotal
  96. })
  97. })
  98. },
  99. /* 预览图片 */
  100. viewImage(e) {
  101. const {
  102. file
  103. } = e.currentTarget.dataset;
  104. if (file.length) wx.previewMedia({
  105. sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
  106. return {
  107. url: v.url,
  108. type: v.fileType
  109. }
  110. }),
  111. current: 0,
  112. showmenu: true
  113. })
  114. },
  115. /* 预览媒体 */
  116. viewMedias(e) {
  117. const {
  118. index,
  119. type
  120. } = e.currentTarget.dataset;
  121. wx.previewMedia({
  122. current: index,
  123. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  124. })
  125. },
  126. /* 处理附件 */
  127. handleFiles(arr) {
  128. let files = {
  129. images: [],
  130. viewImages: [],
  131. videos: [],
  132. viewVideos: [],
  133. files: []
  134. },
  135. list = fileList(arr);
  136. list.forEach(v => {
  137. switch (v.fileType) {
  138. case "video":
  139. files.videos.push(v)
  140. files.viewVideos.push({
  141. url: v.url,
  142. type: "video",
  143. poster: v.subfiles[0].url
  144. })
  145. break;
  146. case "image":
  147. files.images.push(v)
  148. files.viewImages.push({
  149. url: v.url,
  150. type: "image"
  151. })
  152. break;
  153. default:
  154. files.files.push(v)
  155. break;
  156. }
  157. });
  158. this.setData({
  159. files
  160. })
  161. },
  162. /* 去下单 */
  163. clickBut() {
  164. wx.navigateTo({
  165. url: '/packageA/activity/selectProduct/index?params=' + JSON.stringify({
  166. "id": 20230116094803,
  167. "version": 1,
  168. "content": {
  169. nocache: true,
  170. sa_brandid: this.data.detail.sa_brandid,
  171. sa_promotionid: this.data.sa_promotionid,
  172. sa_promotion_itemgroupid: this.data.active,
  173. "where": {
  174. "condition": ""
  175. }
  176. }
  177. }),
  178. });
  179. getApp().globalData.handleSelect = this.creadedOrderForm.bind(this);
  180. },
  181. creadedOrderForm({
  182. list
  183. }) {
  184. let that = this;
  185. wx.showModal({
  186. title: '提示',
  187. content: '是否确定创建促销订单?',
  188. complete: (res) => {
  189. if (res.confirm)
  190. _Http.basic({
  191. "id": 20221128183202,
  192. "content": {
  193. istool: 0,
  194. type: "促销订单",
  195. sa_orderid: 0,
  196. sa_accountclassid: that.data.detail.sa_accountclassid,
  197. rec_contactsid: 0,
  198. pay_enterpriseid: 0,
  199. sa_contractid: 0,
  200. sa_projectid: 0,
  201. sa_promotionid: that.data.detail.sa_promotionid,
  202. "sa_brandid": that.data.detail.sa_brandid, //品牌ID
  203. "type": "促销订单", //订单类型
  204. "tradefield": that.data.detail.tradefield.join(','), //必选
  205. "items": list.map(v => {
  206. return {
  207. "sa_orderitemsid": 0,
  208. "itemid": v.itemid,
  209. "qty": v.qty,
  210. price: v.price,
  211. length: v.length,
  212. width: v.width,
  213. sa_promotion_itemsid: v.sa_promotion_itemsid
  214. }
  215. })
  216. }
  217. }).then(res => {
  218. console.log("转化促销订单", res)
  219. wx.showToast({
  220. title: res.msg != '成功' ? res.msg : '创建成功',
  221. icon: "none"
  222. });
  223. if (res.msg == '成功') setTimeout(() => {
  224. wx.redirectTo({
  225. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  226. });
  227. }, 300)
  228. })
  229. }
  230. })
  231. },
  232. onReachBottom() {
  233. this.getProductList();
  234. }
  235. })