index.ts 11 KB

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