detail.js 5.1 KB

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