index.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 { FunCode } from "../../../../constants/enum/funcode"
  7. import { sendMsgToMQ } from "../../../../services/api/common/index"
  8. import { encryptBody } from "../../../../utils/websocket/crypto"
  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', 'forestgreen', 'darksalmon', 'goldenrod', 'khaki', 'rosybrown', 'sandybrown'],
  26. /// 是否开始日期
  27. isstart: true,
  28. /// 开始日期
  29. startdate: formatDate(new Date()),
  30. /// 结束日期
  31. enddate: formatDate(new Date()),
  32. /// 文件上传列表
  33. fileList: [],
  34. /// 上传的文件路径
  35. filePath: '',
  36. /// 商品名称
  37. wrstandname: '',
  38. /// 预售总量
  39. pretotalqty: '0.0',
  40. /// 最小采购单位
  41. minbuyqty: '0.0',
  42. /// 最大采购单位
  43. maxbuyqty: '0.0',
  44. /// 最低成团量
  45. minsuccessqty: '0.0',
  46. /// 采购保证金比例
  47. buymarginvalue: '0.0',
  48. /// 形状
  49. zsshape: '',
  50. /// 颜色
  51. zscolor: '',
  52. /// 净度
  53. zsclarity: '',
  54. /// 尺寸
  55. zssize: '',
  56. /// 抛光
  57. zspolish: '',
  58. /// 对称
  59. zssymmetry: '',
  60. /// 切工
  61. zscut: '',
  62. /// 荧光
  63. zsfluorescence: '',
  64. /// 备注
  65. remark: '',
  66. /// 钻石分类
  67. categorys: [{ text: '单颗裸钻', value: 2 }, { text: '单颗彩钻', value: 5 }],
  68. category: 2,
  69. /// 列头
  70. columns: ['序号', '数量 >=', '价格/(元/克拉)', '操作'],
  71. /// 显示信息
  72. actions: [''],
  73. /// 数据信息
  74. datas: [{ price: 0.0, qty: 0.0, step: 1 }]
  75. },
  76. /**
  77. * 返回上层视图
  78. */
  79. backToParent() {
  80. /// 返回上层视图
  81. wx.navigateBack()
  82. },
  83. /**
  84. * 按钮点击响应事件
  85. */
  86. onButtonClick(e: any) {
  87. switch (e.target.id) {
  88. case 'startdate': /// 开始日期
  89. this.setData({ showCal: true, isstart: true })
  90. break;
  91. case 'enddate': /// 结束日期
  92. this.setData({ showCal: true, isstart: false })
  93. break
  94. case 'submit': /// 申请提交
  95. this.doSubmit()
  96. break
  97. default:
  98. break;
  99. }
  100. },
  101. check(): boolean {
  102. /// 请输入商品名称
  103. if (this.data.wrstandname === '') {
  104. showToast('请输入商品名称')
  105. return false
  106. }
  107. /// 请输入预售总量
  108. if ((this.data.pretotalqty === '') || (Number(this.data.pretotalqty) === 0.0) ) {
  109. showToast('请输入预售总量')
  110. return false
  111. }
  112. /// 请输入最小采购单位
  113. if ((this.data.minbuyqty === '') || (Number(this.data.minbuyqty) === 0.0) ) {
  114. showToast('请输入最小采购单位')
  115. return false
  116. }
  117. /// 请输入最大采购单位
  118. if ((this.data.maxbuyqty === '') || (Number(this.data.maxbuyqty) === 0.0) ) {
  119. showToast('请输入最大采购单位')
  120. return false
  121. }
  122. /// 请输入最低成团量
  123. if ((this.data.minsuccessqty === '') || (Number(this.data.minsuccessqty) === 0.0) ) {
  124. showToast('请输入最低成团量')
  125. return false
  126. }
  127. /// 请输入采购保证金比例
  128. if ((this.data.buymarginvalue === '') || (Number(this.data.buymarginvalue) === 0.0) ) {
  129. showToast('请输入采购保证金比例')
  130. return false
  131. }
  132. return true
  133. },
  134. /// 日期确定触发
  135. onConfirm(e: any) {
  136. this.setData({ showCal: false })
  137. /// 开始日期
  138. if (this.data.isstart) {
  139. this.setData({
  140. startdate: formatDate(e.detail)
  141. })
  142. } else {
  143. this.setData({
  144. enddate: formatDate(e.detail)
  145. })
  146. }
  147. },
  148. /// 日期关闭触发
  149. onCloseCal() {
  150. this.setData({ showCal: false })
  151. },
  152. /// 显示履约模板
  153. showPlanTmps() {
  154. this.setData({ show: true })
  155. },
  156. /// 关闭
  157. onClose() {
  158. this.setData({ show: false })
  159. },
  160. onSelect(e: any) {
  161. /// 默认显示项
  162. const { index } = e.detail;
  163. this.setData({ tmp: this.data.tmps[index], show: false })
  164. },
  165. /// 删除图片
  166. deleteImage(e: any) {
  167. const {index} = e.detail.index
  168. // 上传完成需要更新 fileList
  169. const { fileList = [] } = this.data;
  170. fileList.splice(index, 1)
  171. this.setData({ fileList });
  172. },
  173. onChange(e: any) {
  174. this.setData({ category: e.detail });
  175. },
  176. /// 照片上传
  177. afterRead(e: any) {
  178. const { file } = e.detail;
  179. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  180. wx.uploadFile({
  181. url: services.config.uploadUrl,
  182. filePath: file.url,
  183. name: 'file',
  184. formData: { user: 'test' },
  185. success: (res) => {
  186. if (res.statusCode != 200) {
  187. showToast('图片上传失败,原因:'+res.errMsg)
  188. return
  189. }
  190. // 上传完成需要更新 fileList
  191. const { fileList = [] } = this.data;
  192. fileList.push({ ...file, url: res.data});
  193. this.setData({ fileList });
  194. /// 设置文件路径
  195. this.setData({ filePath: JSON.parse(res.data)[0].filePath })
  196. },
  197. });
  198. },
  199. // input输入中
  200. getInputNum (e: any) {
  201. let amount = e.detail
  202. let num = null
  203. // 小数点后最多只能输入两位
  204. num = amount.replace(new RegExp('^(\\d+\\.\\d{2}).+'), '$1')
  205. // 小数点开头得话,让前面加个0 eg: 0.xx
  206. const startPoint = /^\./g
  207. if (startPoint.test(num)) { num = amount.replace(startPoint, '0.') }
  208. // 若没有小数点,前面输入多个0,去掉0取整
  209. // if(num有值 && 没有小数点 && 不等于'0')
  210. if (num && !num.includes('.') && num !== '0') { num = +num }
  211. // 若出现多个小数点,则替换为1个
  212. const morePoint = /\.+(\d*|\.+)\./g
  213. if (morePoint.test(num)) {
  214. num = amount
  215. .replace(/\.{2,}/g, ".")
  216. .replace(".", "$#$")
  217. .replace(/\./g, "")
  218. .replace("$#$", ".")
  219. }
  220. switch (e.target.id) {
  221. case 'maxbuyqty': /// 最大采购单位
  222. this.setData({ maxbuyqty: num})
  223. break;
  224. case 'pretotalqty': /// 预售总量
  225. this.setData({ pretotalqty: num})
  226. break;
  227. case 'buymarginvalue': /// 采购保证金
  228. this.setData({ buymarginvalue: num})
  229. break;
  230. case 'minbuyqty': /// 最小采购单位
  231. this.setData({ minbuyqty: num})
  232. break;
  233. case 'minsuccessqty': /// 最低成团量
  234. this.setData({ minsuccessqty: num})
  235. break;
  236. default:
  237. break;
  238. }
  239. },
  240. /// 申请提交
  241. doSubmit() {
  242. /// 校验不合规
  243. if (!this.check()) { return }
  244. /// showModel
  245. showModel(() => {
  246. /// showLoading
  247. showLoading(() => {
  248. /// 钻石属性
  249. var list = this.data.datas.map(obj => {
  250. return {
  251. StepIndex: obj.step,
  252. Qty: Number(obj.qty),
  253. Price: Number(obj.price)
  254. }
  255. })
  256. /// 请求参数
  257. const info = JSON.stringify({
  258. Header: protoHeader(FunCode.GZCenterPurchaseApplyReq),
  259. SellUserID: userid(),
  260. SellAccountID: accountid(),
  261. WRStandardName: this.data.wrstandname,
  262. PresaleQty: Number(this.data.pretotalqty),
  263. MinBuyQty: Number(this.data.minbuyqty),
  264. MaxBuyQty: Number(this.data.maxbuyqty),
  265. MinSuccessQty: Number(this.data.minsuccessqty),
  266. StartDate: this.data.startdate,
  267. EndDate: this.data.enddate,
  268. BuyMarginAlgorithm: 1,
  269. BuyMarginValue: this.data.buymarginvalue,
  270. PerformanceTemplateID: this.data.tmp.autoid,
  271. YSZSCategory: this.data.category,
  272. ZSShapeTypeStr: this.data.zsshape,
  273. ZSColorTypeStr: this.data.zscolor,
  274. ZSClarityTypeStr: this.data.zsclarity,
  275. ZSCutTypeStr: this.data.zscut,
  276. ZSSymmetryTypeStr: this.data.zssymmetry,
  277. ZSPolishTypeStr: this.data.zspolish,
  278. ZSFluorescenceTypeStr: this.data.zsfluorescence,
  279. SizeStr: this.data.zssize,
  280. PictureUrls: this.data.filePath,
  281. Remark: this.data.remark,
  282. GZCenterPurchasePriceLists: list,
  283. MarketID: marketid(),
  284. ClientType: clientType(),
  285. ClientSerialNo: timetample().toString()
  286. })
  287. /// 发送请求
  288. sendMsgToMQ({
  289. data: {
  290. data: encryptBody(info),
  291. funCodeReq: FunCode.GZCenterPurchaseApplyReq,
  292. funCodeRsp: FunCode.GZCenterPurchaseApplyRsp,
  293. isEncrypted: isEncrypted()
  294. },
  295. success: (res) => {
  296. /// 解析对象
  297. const data = JSON.parse(res.data.data)
  298. if (data.RetCode != 0) {
  299. hideLoading(() => {}, getErrorMsg(data.RetCode))
  300. return
  301. }
  302. /// 求购发布请求成功
  303. hideLoading(() => {
  304. wx.navigateBack()
  305. }, '提交申请成功', 'success')
  306. },
  307. fail: (emsg) => {
  308. hideLoading(()=>{}, emsg)
  309. }
  310. })
  311. }, '提交申请请求中....')
  312. }, '提示', '确认要提交申请吗?')
  313. },
  314. /// 获取履约模板信息
  315. queryPermancePlanTmp() {
  316. /// showLoading
  317. showLoading(() => {
  318. queryPermancePlanTmp({
  319. // data: {
  320. // marketid: marketid()
  321. // },
  322. success: (res) => {
  323. /// 获取数据
  324. this.setData({
  325. tmps: res.data,
  326. tmp: res.data[0],
  327. actions: res.data.map(obj => { return obj.templatename })
  328. })
  329. },
  330. complete: () => {
  331. /// hideLoading
  332. hideLoading()
  333. }
  334. })
  335. })
  336. },
  337. /**
  338. * 新增价格
  339. */
  340. addPrice(e: any) {
  341. this.setData({
  342. datas: this.data.datas.concat([{price: 0.0, qty: 0.0, step: this.data.datas.length+1}])
  343. })
  344. },
  345. /**
  346. * 删除某一行
  347. */
  348. deleteRow(e: any) {
  349. const row = e.target.id
  350. var obj = this.data.datas[row-1]
  351. if (obj.qty === 0.0 && row === '1') {
  352. showToast('第一条数据信息不能删除')
  353. return
  354. }
  355. /// 删除数据
  356. this.data.datas.splice(row-1, 1)
  357. this.setData({ datas: this.data.datas })
  358. },
  359. /**
  360. * 数据变化
  361. */
  362. onRowChanged(e: any) {
  363. /// 获取对应的id
  364. const ids = (<string> e.target.id).split(' ')
  365. const row = <number><unknown>ids[0]
  366. const id = ids[1]
  367. var obj = this.data.datas[row-1]
  368. let amount = e.detail
  369. let num = null
  370. // 小数点后最多只能输入两位
  371. num = amount.replace(new RegExp('^(\\d+\\.\\d{2}).+'), '$1')
  372. // 小数点开头得话,让前面加个0 eg: 0.xx
  373. const startPoint = /^\./g
  374. if (startPoint.test(num)) { num = amount.replace(startPoint, '0.') }
  375. // 若没有小数点,前面输入多个0,去掉0取整
  376. // if(num有值 && 没有小数点 && 不等于'0')
  377. if (num && !num.includes('.') && num !== '0') { num = +num }
  378. // 若出现多个小数点,则替换为1个
  379. const morePoint = /\.+(\d*|\.+)\./g
  380. if (morePoint.test(num)) {
  381. num = amount
  382. .replace(/\.{2,}/g, ".")
  383. .replace(".", "$#$")
  384. .replace(/\./g, "")
  385. .replace("$#$", ".")
  386. }
  387. /// 数据赋值
  388. if (id === "qty") { obj.qty = num } else { obj.price = num }
  389. /// 删除数据
  390. this.data.datas.splice(row-1, 1)
  391. this.data.datas.splice(row-1, 0, obj)
  392. this.setData({ datas: this.data.datas })
  393. },
  394. /**
  395. * 数据变化重新排序
  396. */
  397. onRowSort() {
  398. /// 数据排序
  399. this.setData({
  400. datas: this.data.datas.sort(function(a, b) {
  401. if (a.qty > b.qty) { return 1; }
  402. if (a.qty < b.qty) { return -1; }
  403. return 0;
  404. })
  405. })
  406. },
  407. /**
  408. * 生命周期函数--监听页面加载
  409. */
  410. onLoad() {
  411. /// 获取履约模板信息
  412. this.queryPermancePlanTmp()
  413. },
  414. /**
  415. * 生命周期函数--监听页面初次渲染完成
  416. */
  417. onReady() {
  418. },
  419. /**
  420. * 生命周期函数--监听页面显示
  421. */
  422. onShow() {
  423. },
  424. /**
  425. * 生命周期函数--监听页面隐藏
  426. */
  427. onHide() {
  428. },
  429. /**
  430. * 生命周期函数--监听页面卸载
  431. */
  432. onUnload() {
  433. },
  434. /**
  435. * 页面相关事件处理函数--监听用户下拉动作
  436. */
  437. onPullDownRefresh() {
  438. },
  439. /**
  440. * 页面上拉触底事件的处理函数
  441. */
  442. onReachBottom() {
  443. },
  444. /**
  445. * 用户点击右上角分享
  446. */
  447. onShareAppMessage() {
  448. }
  449. })