detail.js 5.0 KB

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