detail.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. const _Http = getApp().globalData.http;
  2. let sa_brandid = null,
  3. sys_enterpriseid = null;
  4. import {
  5. fileList
  6. } from "../../utils/FormatTheAttachment";
  7. import currency from "../../utils/currency";
  8. Page({
  9. data: {
  10. loading: true
  11. },
  12. onLoad(options) {
  13. if (options.id) this.setData({
  14. sa_itemgroupid: options.id,
  15. itemno: options.itemno
  16. })
  17. sa_brandid = options.sa_brandid;
  18. this.setData({
  19. userrole: wx.getStorageSync('userrole')
  20. })
  21. if (wx.getStorageSync('userrole') == '业务员') sys_enterpriseid = options.sys_enterpriseid
  22. this.getDetail();
  23. },
  24. /* 获取详情 */
  25. getDetail() {
  26. let content = {
  27. "sa_itemgroupid": this.data.sa_itemgroupid,
  28. pageSize: 999 ,
  29. // "itemno": "80409006",
  30. "spec": "",
  31. "color": "",
  32. "material": ""
  33. }
  34. if (sys_enterpriseid) content.sys_enterpriseid = sys_enterpriseid;
  35. console.log(sys_enterpriseid)
  36. _Http.basic({
  37. "id": "20221223165503",
  38. content
  39. }).then(res => {
  40. console.log("商品详情", res)
  41. if (res.msg != '成功') return wx.showToast({
  42. title: res.msg,
  43. icon: "none"
  44. })
  45. if (res.data.length == 0) {
  46. wx.showToast({
  47. title: '未查询到商品',
  48. icon: "none",
  49. mask: true
  50. })
  51. setTimeout(() => {
  52. wx.navigateBack();
  53. }, 500)
  54. return;
  55. }
  56. this.handleFiles(res.data[0].attinfos)
  57. const CNY = sum => currency(sum, {
  58. symbol: "¥",
  59. precision: 2
  60. }).format();
  61. this.setData({
  62. detail: res.data[0],
  63. rows: res.data.map(v => {
  64. v.gradeprice = CNY(v.gradeprice);
  65. v.marketprice = CNY(v.marketprice);
  66. return v
  67. }),
  68. loading: false
  69. })
  70. })
  71. },
  72. /* 预览媒体 */
  73. viewMedias(e) {
  74. const {
  75. index,
  76. type
  77. } = e.currentTarget.dataset;
  78. wx.previewMedia({
  79. current: index,
  80. sources: type == 'image' ? this.data.files.viewImages : this.data.files.viewVideos,
  81. })
  82. },
  83. /* 处理附件 */
  84. handleFiles(arr) {
  85. let files = {
  86. images: [],
  87. viewImages: [],
  88. videos: [],
  89. viewVideos: [],
  90. files: []
  91. },
  92. list = fileList(arr);
  93. list.forEach(v => {
  94. switch (v.fileType) {
  95. case "video":
  96. files.videos.push(v)
  97. files.viewVideos.push({
  98. url: v.url,
  99. type: "video",
  100. poster: v.subfiles[0].url
  101. })
  102. break;
  103. case "image":
  104. files.images.push(v)
  105. files.viewImages.push({
  106. url: v.url,
  107. type: "image"
  108. })
  109. break;
  110. default:
  111. files.files.push(v)
  112. break;
  113. }
  114. });
  115. this.setData({
  116. files
  117. })
  118. },
  119. /* 切换产品 */
  120. changeItemno(e) {
  121. const {
  122. item
  123. } = e.currentTarget.dataset;
  124. if (item.itemno == this.data.itemno) return;
  125. this.handleFiles(item.attinfos)
  126. this.setData({
  127. detail: item,
  128. itemno: item.itemno
  129. })
  130. },
  131. clickBut() {
  132. this.data.detail.tradefield.length >= 2 ? wx.showToast({
  133. title: '请选择加入产品领域',
  134. icon: "none",
  135. duration: 3000
  136. }) : this.handleStorage(0);
  137. },
  138. /* 打开文档 */
  139. openDocument(e) {
  140. const {
  141. item
  142. } = e.currentTarget.dataset;
  143. console.log(item)
  144. wx.showLoading({
  145. title: '加载中...',
  146. mask: true,
  147. })
  148. wx.downloadFile({
  149. url: item.url,
  150. success: function (res) {
  151. const filePath = res.tempFilePath
  152. wx.openDocument({
  153. filePath: filePath,
  154. showMenu: true,
  155. fileType: item.postfix,
  156. success: function (res) {
  157. wx.hideLoading();
  158. console.log('打开文档成功')
  159. },
  160. fail(e) {
  161. console.log(e)
  162. wx.showToast({
  163. title: '打开失败',
  164. icon: "error",
  165. mask: true
  166. })
  167. }
  168. })
  169. },
  170. fail(e) {
  171. console.log(e)
  172. wx.showToast({
  173. title: '打开失败',
  174. icon: "error",
  175. mask: true
  176. })
  177. }
  178. })
  179. },
  180. /* 选择领域 */
  181. storage(e) {
  182. this.handleStorage(e.detail.value)
  183. },
  184. handleStorage(index) {
  185. let detail = this.data.detail;
  186. _Http.basic({
  187. "id": 20220924095102,
  188. "content": {
  189. sa_brandid,
  190. "itemid": detail.itemid, //货品id
  191. "qty": detail.orderminqty, //数量
  192. "itemno": this.data.itemno, //货品编号
  193. tradefield: detail.tradefield[index].tradefield
  194. },
  195. }).then(res => {
  196. console.log("加入购物车", res)
  197. if (res.msg != '成功') return wx.showToast({
  198. title: res.msg,
  199. icon: "none"
  200. });
  201. _Http.basic({
  202. "id": 20220927093202,
  203. "content": {}
  204. }, false).then(res => {
  205. console.log("购物车数量", res)
  206. getApp().globalData.num = res.data.num;
  207. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(res.data.num)
  208. setTimeout(() => {
  209. wx.showToast({
  210. title: '加入成功',
  211. icon: "none",
  212. icon: "none"
  213. });
  214. }, 200);
  215. });
  216. })
  217. },
  218. onShow() {
  219. if (this.data.userrole == '经销商') this.selectComponent("#Float").setNum(getApp().globalData.num)
  220. },
  221. })