index.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. import { queryPermancePlanTmp } from "../../../../services/api/orders/index"
  2. import { accountid, clientType, getErrorMsg, isEncrypted, marketID, protoHeader, timetample, userid } from "../../../../services/utils"
  3. import { hideLoading, showLoading, showModel, showToast } from "../../../../utils/message/index"
  4. import services from "../../../../services/index"
  5. import { formatDate, getDecimalNum } from "../../../../utils/util"
  6. import { sendMsgToMQ } from "../../../../services/api/common/index"
  7. import { encryptBody } from "../../../../utils/websocket/crypto"
  8. import { FunCode } from "../../../../constants/enum/funcode"
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. /// 底部安全区域
  15. safeBottom: getApp().globalData.safeBottom,
  16. /// 履约模板信息
  17. tmps: <GuangZuan.PermancePlanTmp[]>[],
  18. /// 选中履约模板
  19. tmp: <GuangZuan.PermancePlanTmp>({}),
  20. /// 是否显示
  21. show: false,
  22. /// 是否显示日历
  23. showCal: false,
  24. /// 颜色
  25. tcolors: ['rebeccapurple', 'green', 'hotpink', 'orange', 'darkgoldenrod', 'firebrick', 'firebrick', 'hotpink', 'orange', 'darkgoldenrod', 'hotpink', 'orange', 'darkgoldenrod'],
  26. /// 是否开始日期
  27. isstart: true,
  28. /// 开始日期
  29. startdate: formatDate(new Date()),
  30. /// 结束日期
  31. enddate: formatDate(new Date()),
  32. /// 文件上传列表
  33. fileList: <GuangZuan.UploadRsp[]>[],
  34. /// 显示信息
  35. actions: [''],
  36. /// 生产方式条件
  37. options: [{ text: 'HPHT', value: 1 }, { text: 'CVD', value: 2 }],
  38. /// 生产方式
  39. way: 1,
  40. /// 商品名称
  41. wrstandname: '',
  42. /// 预售总量
  43. pretotalqty: '',
  44. /// 预售价格
  45. preprice: '',
  46. /// 最小采购单位
  47. minbuyqty: '',
  48. /// 最大采购单位
  49. maxbuyqty: '',
  50. /// 最低成团量
  51. minsuccessqty: '',
  52. /// 采购保证金比例
  53. buymarginvalue: '',
  54. /// 颜色
  55. zscolor: '',
  56. /// 净度
  57. zsclarity: '',
  58. /// 尺寸
  59. zssize: '',
  60. /// 成品率
  61. zsyield: '',
  62. /// 重量描述
  63. weightdesc: '',
  64. /// 数量描述
  65. qtydesc: '',
  66. /// 备注
  67. remark: ''
  68. },
  69. /**
  70. * 返回上层视图
  71. */
  72. backToParent() {
  73. /// 返回上层视图
  74. wx.navigateBack()
  75. },
  76. /**
  77. * 按钮点击响应事件
  78. */
  79. onButtonClick(e: any) {
  80. switch (e.target.id) {
  81. case 'startdate': /// 开始日期
  82. this.setData({ showCal: true, isstart: true })
  83. break;
  84. case 'enddate': /// 结束日期
  85. this.setData({ showCal: true, isstart: false })
  86. break
  87. case 'submit': /// 申请提交
  88. this.doSubmit()
  89. break
  90. default:
  91. break;
  92. }
  93. },
  94. /// 日期确定触发
  95. onConfirm(e: any) {
  96. this.setData({ showCal: false })
  97. /// 开始日期
  98. if (this.data.isstart) {
  99. this.setData({
  100. startdate: formatDate(e.detail)
  101. })
  102. } else {
  103. this.setData({
  104. enddate: formatDate(e.detail)
  105. })
  106. }
  107. },
  108. check(): boolean {
  109. /// 请输入商品名称
  110. if (this.data.wrstandname === '') {
  111. showToast('请输入商品名称')
  112. return false
  113. }
  114. /// 请输入预售总量
  115. if ((this.data.pretotalqty === '') || (Number(this.data.pretotalqty) === 0.0) ) {
  116. debugger
  117. showToast('请输入预售总量')
  118. return false
  119. }
  120. /// 请输入预售价格
  121. if ((this.data.preprice === '') || (Number(this.data.preprice) === 0.0) ) {
  122. showToast('请输入预售价格')
  123. return false
  124. }
  125. /// 请输入最小采购单位
  126. if ((this.data.minbuyqty === '') || (Number(this.data.minbuyqty) === 0.0) ) {
  127. showToast('请输入最小采购单位')
  128. return false
  129. }
  130. /// 请输入最大采购单位
  131. if ((this.data.maxbuyqty === '') || (Number(this.data.maxbuyqty) === 0.0) ) {
  132. showToast('请输入最大采购单位')
  133. return false
  134. }
  135. /// 请输入最低成团量
  136. if ((this.data.minsuccessqty === '') || (Number(this.data.minsuccessqty) === 0.0) ) {
  137. showToast('请输入最低成团量')
  138. return false
  139. }
  140. /// 请输入采购保证金比例
  141. if ((this.data.buymarginvalue === '') || (Number(this.data.buymarginvalue) === 0.0) ) {
  142. showToast('请输入采购保证金比例')
  143. return false
  144. }
  145. /// 请上传附件
  146. if (this.data.fileList.length === 0) {
  147. showToast('请上传附件')
  148. return false
  149. }
  150. return true
  151. },
  152. /// 日期关闭触发
  153. onCloseCal() {
  154. this.setData({ showCal: false })
  155. },
  156. /// 显示履约模板
  157. showPlanTmps() {
  158. this.setData({ show: true })
  159. },
  160. /// 关闭
  161. onClose() {
  162. this.setData({ show: false })
  163. },
  164. onSelect(e: any) {
  165. /// 默认显示项
  166. const { index } = e.detail;
  167. this.setData({ tmp: this.data.tmps[index], show: false })
  168. },
  169. /// 删除图片
  170. deleteImage(e: any) {
  171. const { index } = e.detail.index
  172. // 上传完成需要更新 fileList
  173. const { fileList = [] } = this.data;
  174. fileList.splice(index, 1)
  175. this.setData({ fileList });
  176. },
  177. onChange(e: any) {
  178. this.setData({ way: e.detail });
  179. },
  180. // input输入中
  181. getInputNum (e: any) {
  182. /// 截取2位小数位
  183. let num = getDecimalNum(e.detail)
  184. switch (e.target.id) {
  185. case 'maxbuyqty': /// 最大采购单位
  186. this.setData({ maxbuyqty: num})
  187. break;
  188. case 'pretotalqty': /// 预售总量
  189. this.setData({ pretotalqty: num})
  190. break;
  191. case 'preprice': /// 预售价格
  192. this.setData({ preprice: num})
  193. break;
  194. case 'buymarginvalue': /// 采购保证金
  195. this.setData({ buymarginvalue: num})
  196. break;
  197. case 'minbuyqty': /// 最小采购单位
  198. this.setData({ minbuyqty: num})
  199. break;
  200. case 'minsuccessqty': /// 最低成团量
  201. this.setData({ minsuccessqty: num})
  202. break;
  203. default:
  204. break;
  205. }
  206. },
  207. /// 照片上传
  208. afterRead(e: any) {
  209. const { file } = e.detail;
  210. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  211. wx.uploadFile({
  212. url: services.config.uploadUrl,
  213. filePath: file.url,
  214. name: 'file',
  215. formData: { user: 'test' },
  216. success: (res) => {
  217. if (res.statusCode != 200) {
  218. showToast('图片上传失败,原因:'+res.errMsg)
  219. return
  220. }
  221. // 上传完成需要更新 fileList
  222. const { fileList = [] } = this.data
  223. fileList.push({ ...file, url: JSON.parse(res.data) })
  224. this.setData({ fileList })
  225. },
  226. });
  227. },
  228. /// 申请提交
  229. doSubmit() {
  230. /// 校验不合规
  231. if (!this.check()) { return }
  232. /// 地址拼接
  233. var fileUrl = ''
  234. for (let i = 0; i < this.data.fileList.length; i++) {
  235. const obj = this.data.fileList[i];
  236. if (i === this.data.fileList.length-1) {
  237. fileUrl = fileUrl+obj.url[0].filePath
  238. } else {
  239. fileUrl = fileUrl+obj.url[0].filePath+","
  240. }
  241. }
  242. /// showModel
  243. showModel(() => {
  244. /// showLoading
  245. showLoading(() => {
  246. /// 请求参数
  247. const info = JSON.stringify({
  248. Header: protoHeader(FunCode.GZPresaleApplyReq, marketID(63)),
  249. SellUserID: userid(),
  250. SellAccountID: accountid(),
  251. WRStandardName: this.data.wrstandname,
  252. PresaleQty: Number(this.data.pretotalqty),
  253. MinBuyQty: Number(this.data.minbuyqty),
  254. MaxBuyQty: Number(this.data.maxbuyqty),
  255. MinSuccessQty: Number(this.data.minsuccessqty),
  256. UnitPrice: Number(this.data.preprice),
  257. StartDate: this.data.startdate,
  258. EndDate: this.data.enddate,
  259. BuyMarginAlgorithm: 1,
  260. BuyMarginValue: Number(this.data.buymarginvalue)/100.0,
  261. ZSColorTypeStr: this.data.zscolor,
  262. ZSClarityTypeStr: this.data.zsclarity,
  263. SizeStr: this.data.zssize,
  264. YieldRate: this.data.zsyield,
  265. QtyDesc: this.data.qtydesc,
  266. WeightDesc: this.data.weightdesc,
  267. YSProductionMode: this.data.way,
  268. PictureUrls: fileUrl,
  269. Remark: this.data.remark,
  270. PerformanceTemplateID: this.data.tmp.autoid,
  271. MarketID: marketID(63),
  272. ClientType: clientType(),
  273. ClientSerialNo: timetample().toString()
  274. })
  275. /// 发送请求
  276. sendMsgToMQ({
  277. data: {
  278. data: encryptBody(info),
  279. funCodeReq: FunCode.GZPresaleApplyReq,
  280. funCodeRsp: FunCode.GZPresaleApplyRsp,
  281. isEncrypted: isEncrypted()
  282. },
  283. success: (res) => {
  284. /// 解析对象
  285. const data = JSON.parse(res.data.data)
  286. if (data.RetCode != 0) {
  287. hideLoading(() => {}, getErrorMsg(data.RetCode))
  288. return
  289. }
  290. /// 求购发布请求成功
  291. hideLoading(() => {
  292. wx.navigateBack()
  293. }, '提交申请成功', 'success')
  294. },
  295. fail: (emsg) => {
  296. hideLoading(()=>{}, emsg)
  297. }
  298. })
  299. }, '提交申请请求中....')
  300. }, '提示', '确认要提交申请吗?')
  301. },
  302. /// 获取履约模板信息
  303. queryPermancePlanTmp() {
  304. /// showLoading
  305. showLoading(() => {
  306. queryPermancePlanTmp({
  307. success: (res) => {
  308. /// 获取数据
  309. this.setData({
  310. tmps: res.data,
  311. tmp: res.data[0],
  312. actions: res.data.map(obj => { return obj.templatename })
  313. })
  314. },
  315. complete: () => {
  316. /// hideLoading
  317. hideLoading()
  318. }
  319. })
  320. })
  321. },
  322. /**
  323. * 生命周期函数--监听页面加载
  324. */
  325. onLoad() {
  326. /// 获取履约模板信息
  327. this.queryPermancePlanTmp()
  328. },
  329. /**
  330. * 生命周期函数--监听页面初次渲染完成
  331. */
  332. onReady() {
  333. },
  334. /**
  335. * 生命周期函数--监听页面显示
  336. */
  337. onShow() {
  338. },
  339. /**
  340. * 生命周期函数--监听页面隐藏
  341. */
  342. onHide() {
  343. },
  344. /**
  345. * 生命周期函数--监听页面卸载
  346. */
  347. onUnload() {
  348. },
  349. /**
  350. * 页面相关事件处理函数--监听用户下拉动作
  351. */
  352. onPullDownRefresh() {
  353. },
  354. /**
  355. * 页面上拉触底事件的处理函数
  356. */
  357. onReachBottom() {
  358. },
  359. /**
  360. * 用户点击右上角分享
  361. */
  362. onShareAppMessage() {
  363. }
  364. })