detail.js 5.3 KB

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