detail.js 6.1 KB

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