detail.js 4.9 KB

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