detail.js 5.3 KB

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