detail.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. value.cover = image ? image.cover : "";
  79. }
  80. if (value.islimit == 0) value.groupqty = 0;
  81. if (value.gradeprice) value.gradeprice = (value.gradeprice - 0).toFixed(2)
  82. if (value.oldprice) value.oldprice = (value.oldprice - 0).toFixed(2)
  83. if (value.price) value.price = (value.price - 0).toFixed(2)
  84. return value;
  85. })
  86. this.setData({
  87. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  88. pageNumber: res.pageNumber + 1,
  89. pageTotal: res.pageTotal
  90. })
  91. })
  92. },
  93. /* 预览图片 */
  94. viewImage(e) {
  95. const {
  96. file
  97. } = e.currentTarget.dataset;
  98. if (file.length) wx.previewMedia({
  99. sources: file.filter(value => ['image', 'vadio'].includes(value.fileType)).map(v => {
  100. return {
  101. url: v.url,
  102. type: v.fileType
  103. }
  104. }),
  105. current: 0,
  106. showmenu: true
  107. })
  108. },
  109. /* 预览媒体 */
  110. viewMedias(e) {
  111. const {
  112. index,
  113. type
  114. } = e.currentTarget.dataset;
  115. wx.previewMedia({
  116. current: index,
  117. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  118. })
  119. },
  120. /* 处理附件 */
  121. handleFiles(arr) {
  122. let files = {
  123. images: [],
  124. viewImages: [],
  125. videos: [],
  126. viewVideos: [],
  127. files: []
  128. },
  129. list = fileList(arr);
  130. list.forEach(v => {
  131. switch (v.fileType) {
  132. case "video":
  133. files.videos.push(v)
  134. files.viewVideos.push({
  135. url: v.url,
  136. type: "video",
  137. poster: v.subfiles[0].url
  138. })
  139. break;
  140. case "image":
  141. files.images.push(v)
  142. files.viewImages.push({
  143. url: v.url,
  144. type: "image"
  145. })
  146. break;
  147. default:
  148. files.files.push(v)
  149. break;
  150. }
  151. });
  152. this.setData({
  153. files
  154. })
  155. },
  156. /* 去下单 */
  157. clickBut() {
  158. wx.navigateTo({
  159. url: '/packageA/activity/selectProduct/index?params=' + JSON.stringify({
  160. "id": 20230116094803,
  161. "version": 1,
  162. "content": {
  163. nocache: true,
  164. sa_promotionid: this.data.sa_promotionid,
  165. sa_promotion_itemgroupid: this.data.active,
  166. "where": {
  167. "condition": ""
  168. }
  169. }
  170. }),
  171. });
  172. getApp().globalData.handleSelect = this.creadedOrderForm.bind(this);
  173. },
  174. creadedOrderForm({
  175. list
  176. }) {
  177. let that = this;
  178. wx.showModal({
  179. title: '提示',
  180. content: '是否确定创建促销订单?',
  181. complete: (res) => {
  182. if (res.confirm)
  183. _Http.basic({
  184. "id": 20221128183202,
  185. "content": {
  186. istool: 0,
  187. type: "促销订单",
  188. sa_orderid: 0,
  189. sa_accountclassid: that.data.detail.sa_accountclassid,
  190. rec_contactsid: 0,
  191. pay_enterpriseid: 0,
  192. sa_contractid: 0,
  193. sa_projectid: 0,
  194. sa_promotionid: that.data.detail.sa_promotionid,
  195. "sa_brandid": that.data.detail.sa_brandid, //品牌ID
  196. "type": "促销订单", //订单类型
  197. "tradefield": that.data.detail.tradefield.join(','), //必选
  198. "items": list.map(v => {
  199. return {
  200. "sa_orderitemsid": 0,
  201. "itemid": v.itemid,
  202. "qty": v.qty,
  203. price: v.price,
  204. length: v.length,
  205. width: v.width
  206. }
  207. })
  208. }
  209. }).then(res => {
  210. console.log("转化促销订单", res)
  211. wx.showToast({
  212. title: res.msg != '成功' ? res.msg : '创建成功',
  213. icon: "none"
  214. });
  215. if (res.msg == '成功') setTimeout(() => {
  216. wx.redirectTo({
  217. url: '/packageA/orderForm/detail?id=' + res.data.sa_orderid,
  218. });
  219. }, 300)
  220. })
  221. }
  222. })
  223. },
  224. onReachBottom() {
  225. this.getProductList();
  226. }
  227. })