detail.js 5.5 KB

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