detail.js 5.8 KB

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