release.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. // pages/mine/wxml/release/release.js
  2. const app = getApp();
  3. var util = require('../../../../utils/util.js');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. array: [],
  10. payType: ['线上拍卖', '线下拍卖'],
  11. payTypeValue:"",
  12. index: 0,
  13. indexs: 0,
  14. pics: [],
  15. count: [],
  16. isShow: true,
  17. date: '',
  18. time: '',
  19. dates: '',
  20. imgData: [],
  21. display: false,
  22. close: true,
  23. delayed: "300",
  24. delayeddisabled: true,
  25. textareaVal: '',
  26. src: '',
  27. videoData: [],
  28. indexnew: 0,
  29. parameter: [{
  30. name: '',
  31. cont: ''
  32. }],
  33. formIdArray: [],
  34. onlineFlag:true,
  35. filename1:'',
  36. filename2:'',
  37. bidding_agreement_path:'',
  38. bidding_rules_path:''
  39. },
  40. bindPickerChangePay: function (e) {
  41. var index=e.detail.value;
  42. var payType = this.data.payType;
  43. if(index == 1){
  44. this.setData({
  45. payTypeValue: payType[index],
  46. onlineFlag:false
  47. })
  48. }else if(index == 0 ){
  49. this.setData({
  50. payTypeValue: payType[index],
  51. onlineFlag: true
  52. })
  53. }else {
  54. }
  55. },
  56. bindPickerChange: function(e) {
  57. let _this = this;
  58. if (_this.data.array[e.detail.value]) {
  59. _this.setData({
  60. arrays: _this.data.array[e.detail.value].value
  61. })
  62. }
  63. this.setData({
  64. index: e.detail.value
  65. })
  66. },
  67. bindPickerChanges: function(e) {
  68. this.setData({
  69. indexs: e.detail.value
  70. })
  71. },
  72. bindPickerChangenew: function(e) {
  73. this.setData({
  74. indexs: e.detail.value
  75. })
  76. },
  77. bindPickerChangenew: function(e) {
  78. this.setData({
  79. indexnew: e.detail.value
  80. })
  81. },
  82. bindTimeChange: function(e) {
  83. let _this = this;
  84. this.setData({
  85. time: e.detail.value
  86. }, () => {
  87. _this.verifyTime()
  88. })
  89. },
  90. bindDateChange: function(e) {
  91. let _this = this;
  92. this.setData({
  93. date: e.detail.value
  94. }, () => {
  95. _this.verifyTime()
  96. })
  97. },
  98. bindTimeChanges: function(e) {
  99. let _this = this;
  100. this.setData({
  101. times: e.detail.value
  102. }, () => {
  103. _this.verifyTime()
  104. })
  105. },
  106. bindDateChanges: function(e) {
  107. let _this = this;
  108. this.setData({
  109. dates: e.detail.value
  110. }, () => {
  111. _this.verifyTime()
  112. })
  113. },
  114. //验证开拍关拍时间
  115. verifyTime: function() {
  116. let _this = this;
  117. let stateDate = (_this.data.date + ' ' + _this.data.time).replace(/-/g, '/');
  118. let endDate = (_this.data.dates + ' ' + _this.data.times).replace(/-/g, '/');
  119. let statetimestamp = new Date(stateDate).getTime();
  120. let endtimestamp = new Date(endDate).getTime();
  121. if ((endtimestamp - statetimestamp) < 1800000) {
  122. var t = statetimestamp + 1800000
  123. _this.setData({
  124. endDate: util.formatTimeTwo(t, 'Y-M-D'),
  125. endTime: util.formatTimeTwo(t, 'h:m'),
  126. dates: util.formatTimeTwo(t, 'Y-M-D'),
  127. times: util.formatTimeTwo(t, 'h:m')
  128. });
  129. }
  130. },
  131. //拍卖按钮相应的隐藏与显示
  132. switchChange: function(e) {
  133. var _this = this;
  134. if (e.detail.value) {
  135. _this.setData({
  136. display: e.detail.value,
  137. close: false,
  138. delayed: "15",
  139. isLive: e.detail.value
  140. })
  141. if (_this.data.news.length > 0) {
  142. _this.setData({
  143. liveroom: _this.data.news[0].kid
  144. })
  145. } else {
  146. _this.setData({
  147. liveroom: ''
  148. })
  149. }
  150. } else {
  151. _this.setData({
  152. close: true,
  153. display: e.detail.value,
  154. delayed: "300",
  155. isLive: e.detail.value,
  156. liveroom: ""
  157. })
  158. }
  159. },
  160. //创建拍卖会
  161. establish: function() {
  162. var _this = this
  163. wx.request({
  164. url: app.globalData.prodUrl + 'web-pm/wx/pm/check_live_room',
  165. data: {
  166. shop_id: _this.data.shop_id
  167. },
  168. header: {
  169. 'ydw-token': wx.getStorageSync('key').ydw_token
  170. },
  171. success: function(data) {
  172. if (data.data.success == true) {
  173. wx.navigateTo({
  174. url: '../establish/establish'
  175. })
  176. } else {
  177. wx.showModal({
  178. title: '提示',
  179. content: '一个店铺只能有一个拍卖会,您已有拍卖会',
  180. success: function(res) {
  181. if (res.confirm) {
  182. //'用户点击确定'
  183. } else if (res.cancel) {
  184. //'用户点击取消'
  185. }
  186. }
  187. })
  188. }
  189. },
  190. });
  191. },
  192. //上传图片
  193. chooseImage: function() {
  194. var _this = this,
  195. pics = this.data.pics;
  196. wx.chooseImage({
  197. count: 9 - pics.length, // 最多可以选择的图片张数,默认9
  198. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  199. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  200. success: function(res) {
  201. // success
  202. for (var i = 0; i < res.tempFilePaths.length; i++) {
  203. wx.uploadFile({
  204. url: app.globalData.prodUrl + 'web-cp-all/upload_pm/upload',
  205. filePath: res.tempFilePaths[i],
  206. header: {
  207. 'Content-Type': 'multipart/form-data'
  208. },
  209. formData: {
  210. method: 'POST' //请求方式
  211. },
  212. name: 'file',
  213. success(res) {
  214. if (res.statusCode==200){
  215. _this.data.imgData.push(JSON.parse(res.data).file_id);
  216. }
  217. }
  218. })
  219. }
  220. var imgSrc = res.tempFilePaths;
  221. pics = pics.concat(imgSrc);
  222. // 控制触发添加图片的最多时隐藏
  223. if (pics.length >= 9) {
  224. _this.setData({
  225. isShow: (!_this.data.isShow)
  226. })
  227. } else {
  228. _this.setData({
  229. isShow: (_this.data.isShow)
  230. })
  231. }
  232. _this.setData({
  233. pics: pics
  234. })
  235. },
  236. fail: function() {
  237. // fail
  238. },
  239. complete: function() {
  240. // complete
  241. }
  242. })
  243. },
  244. // 图片预览
  245. previewImage: function(e) {
  246. var current = e.target.dataset.src
  247. wx.previewImage({
  248. current: current,
  249. urls: this.data.pics
  250. })
  251. },
  252. //上传视频
  253. chooseVideo: function() {
  254. var _this = this
  255. wx.chooseVideo({
  256. sourceType: ['album', 'camera'],
  257. maxDuration: 60,
  258. camera: 'back',
  259. success: function(res) {
  260. wx.uploadFile({
  261. url: app.globalData.prodUrl + 'web-cp-all/upload_pm/upload',
  262. filePath: res.tempFilePath,
  263. name: 'file',
  264. success(res) {
  265. _this.data.videoData.push(JSON.parse(res.data).file_id)
  266. }
  267. })
  268. _this.setData({
  269. src: res.tempFilePath
  270. });
  271. }
  272. });
  273. },
  274. upLoadAction1(e){
  275. var _this = this
  276. wx.chooseMessageFile({
  277. count: 1,
  278. type:'file',
  279. extension: ['pdf'],
  280. success(res){
  281. var size = res.tempFiles[0].size;
  282. var filename = res.tempFiles[0].name;
  283. var newfilename = filename + "";
  284. if (newfilename.indexOf(".pdf")==-1){
  285. wx.showToast({
  286. title: '请上传pdf文件',
  287. icon: "none",
  288. duration: 2000,
  289. mask: true
  290. })
  291. }else{
  292. _this.setData({
  293. filename1: filename
  294. })
  295. wx.uploadFile({
  296. url: app.globalData.prodUrl + 'web-cp-all/upload_pm/upload/file',
  297. filePath: res.tempFiles[0].path,
  298. name: 'file',
  299. success(res) {
  300. _this.setData({
  301. bidding_agreement_path: JSON.parse(res.data).file_url
  302. })
  303. }
  304. })
  305. }
  306. }
  307. })
  308. },
  309. upLoadAction2(e){
  310. var _this = this
  311. wx.chooseMessageFile({
  312. count: 1,
  313. type:'file',
  314. extension: ['pdf'],
  315. success(res){
  316. var size = res.tempFiles[0].size;
  317. var filename = res.tempFiles[0].name;
  318. var newfilename = filename + "";
  319. if (newfilename.indexOf(".pdf")==-1){
  320. wx.showToast({
  321. title: '请上传pdf文件',
  322. icon: "none",
  323. duration: 2000,
  324. mask: true
  325. })
  326. }else{
  327. _this.setData({
  328. filename2: filename
  329. })
  330. wx.uploadFile({
  331. url: app.globalData.prodUrl + 'web-cp-all/upload_pm/upload/file',
  332. filePath: res.tempFiles[0].path,
  333. name: 'file',
  334. success(res) {
  335. _this.setData({
  336. bidding_rules_path: JSON.parse(res.data).file_url
  337. })
  338. }
  339. })
  340. }
  341. }
  342. })
  343. },
  344. //上传
  345. formSubmit: function(e) {
  346. let _this = this;
  347. if (_this.data.formIdArray.length < 3) {
  348. _this.data.formIdArray.push(e.detail.formId);
  349. }
  350. if (_this.data.formIdArray.length === 3) {
  351. var date = e.detail.value.startdate + ' ' + e.detail.value.starttime;
  352. var endDate = e.detail.value.closingdate + ' ' + e.detail.value.closingtime;
  353. date = date.substring(0, 19);
  354. date = date.replace(/-/g, '/');
  355. endDate = endDate.substring(0, 19);
  356. endDate = endDate.replace(/-/g, '/');
  357. var timestamp = new Date(date).getTime();
  358. var timesend = new Date(endDate).getTime();
  359. if (_this.data.display) {
  360. var startTime = 0;
  361. var endTime = 0;
  362. } else {
  363. var startTime = timestamp;
  364. var endTime = timesend;
  365. }
  366. var auction_way = "";
  367. if (e.detail.value.payType == 0) {
  368. var price_start = Number(e.detail.value.start);
  369. var update_interval = Number(e.detail.value.delayed);
  370. var priceincrease=e.detail.value.priceincrease;
  371. } else if (e.detail.value.payType == 1) {
  372. var price_start = 0;
  373. var update_interval = 10;
  374. var priceincrease =0;
  375. }
  376. if (e.detail.value.checked == true) {
  377. auction_way = "拍卖会"
  378. } else {
  379. auction_way = "在线拍卖"
  380. };
  381. if (e.detail.value.name === undefined || e.detail.value.name === '') {
  382. wx.showToast({
  383. title: '未填写标题!',
  384. icon: 'none',
  385. duration: 2000
  386. });
  387. } else if (_this.data.textareaVal === "") {
  388. wx.showToast({
  389. title: '未填写拍品描述!',
  390. icon: 'none',
  391. duration: 2000
  392. });
  393. } else if (_this.data.isLive && _this.data.liveroom === '') {
  394. wx.showToast({
  395. title: '您没有选择拍卖会!',
  396. icon: 'none',
  397. duration: 2000
  398. });
  399. } else if (_this.data.isLive && !e.detail.value.auctioneer) {
  400. if (!e.detail.value.auctioneer) {
  401. wx.showToast({
  402. title: '未填写拍卖师!',
  403. icon: 'none',
  404. duration: 2000
  405. });
  406. }
  407. } else if (!_this.data.pics.length) {
  408. wx.showToast({
  409. title: '图片不可少于5张',
  410. icon: 'none',
  411. duration: 2000
  412. });
  413. } else if (price_start === "" || price_start === undefined) {
  414. wx.showToast({
  415. title: '未设置起拍价!',
  416. icon: 'none',
  417. duration: 2000
  418. });
  419. } else if (e.detail.value.bond === "" || e.detail.value.bond === undefined) {
  420. wx.showToast({
  421. title: '未设置保证金!',
  422. icon: 'none',
  423. duration: 2000
  424. });
  425. } else if (priceincrease === '' || priceincrease === undefined ) {
  426. wx.showToast({
  427. title: '未设置加价幅度!',
  428. icon: 'none',
  429. duration: 2000
  430. });
  431. } else if (update_interval === '' || update_interval === undefined) {
  432. wx.showToast({
  433. title: '未设置延时周期!',
  434. icon: 'none',
  435. duration: 2000
  436. });
  437. } else if (!_this.data.isLive && endTime - startTime < 1000 * 60 * 30) {
  438. wx.showToast({
  439. title: '拍卖时间不得小于30分钟',
  440. icon: 'none',
  441. duration: 2000
  442. })
  443. } else if (!_this.data.isLive && startTime < new Date().getTime()) {
  444. wx.showToast({
  445. title: '开拍时间不能晚于当前时间',
  446. icon: 'none',
  447. duration: 2000
  448. })
  449. } else if (e.detail.value.payType === '' || e.detail.value.payType === undefined) {
  450. wx.showToast({
  451. title: '请选择拍卖模式',
  452. icon: 'none',
  453. duration: 2000
  454. });
  455. } else{
  456. wx.request({
  457. url: app.globalData.prodUrl + 'web-pm/wx/pm/new_add_item',
  458. header: {
  459. 'ydw-token': wx.getStorageSync('key').ydw_token
  460. },
  461. data: {
  462. bid_type: e.detail.value.choice,
  463. bid_from: e.detail.value.smalltaxonomy,
  464. item_name: e.detail.value.name,
  465. bid_content: e.detail.value.describe,
  466. bid_file_id: _this.data.imgData + '',
  467. price_start: price_start,
  468. price_guarantee: Number(e.detail.value.bond),
  469. price_add: Number(priceincrease),
  470. time_opening: Number(startTime),
  471. time_end: Number(endTime),
  472. auction_way: auction_way,
  473. shop_id: _this.data.shop_id,
  474. live_room_id: _this.data.liveroom,
  475. auctioneer: e.detail.value.auctioneer,
  476. update_interval: update_interval,
  477. form_id: _this.data.formIdArray[0],
  478. verify_form_id: _this.data.formIdArray[1],
  479. seller_bid_success_form_id: _this.data.formIdArray[2],
  480. video_file_id: _this.data.videoData + '',
  481. bid_parameter: JSON.stringify(_this.data.parameter),
  482. // 提交支付方式
  483. auction_type: e.detail.value.payType,
  484. bidding_agreement_path: _this.data.bidding_agreement_path,
  485. bidding_rules_path:_this.data.bidding_rules_path
  486. },
  487. success: function(data) {
  488. if (data.statusCode === 200) {
  489. wx.showToast({
  490. title: '发布成功!',
  491. icon: 'none',
  492. duration: 3000,
  493. success: function() {
  494. setTimeout(function() {
  495. wx.navigateBack({
  496. delta: 1,
  497. success: function() {
  498. }
  499. });
  500. }, 2000)
  501. }
  502. });
  503. } else {
  504. wx.showToast({
  505. title: '网络出错,商品未发布成功!',
  506. icon: 'none',
  507. duration: 3000
  508. });
  509. };
  510. }
  511. })
  512. }
  513. _this.setData({
  514. formIdArray: []
  515. });
  516. }
  517. },
  518. /**
  519. * 生命周期函数--监听页面加载
  520. */
  521. onLoad: function(options) {
  522. var _this = this;
  523. var currentDate = Date.parse(new Date());
  524. var endDate = currentDate + 1800000;
  525. var stateDate = util.formatTimeTwo(currentDate, 'Y-M-D');
  526. var stateTime = util.formatTimeTwo(currentDate, 'h:m:s');
  527. var defaultDate = util.formatTimeTwo(endDate, 'Y-M-D');
  528. var defaultTime = util.formatTimeTwo(endDate, 'h:m:s');
  529. _this.setData({
  530. currentDate: stateDate,
  531. currentTime: stateTime,
  532. endDate: defaultDate,
  533. endTime: defaultTime.substr(0, 5),
  534. date: stateDate,
  535. dates: defaultDate,
  536. time: stateTime.substr(0, 5),
  537. times: defaultTime.substr(0, 5),
  538. shop_id: options.shop_id
  539. });
  540. wx.request({
  541. url: app.globalData.prodUrl + 'web-pm/wx/pm/list_verify_pass',
  542. header: {
  543. 'ydw-token': wx.getStorageSync('key').ydw_token
  544. },
  545. data: {
  546. shop_id: _this.data.shop_id
  547. },
  548. success: function(data) {
  549. if (data.data.data.length === 0) {
  550. _this.setData({
  551. news: []
  552. })
  553. } else {
  554. _this.setData({
  555. news: data.data.data
  556. })
  557. }
  558. },
  559. });
  560. wx.request({
  561. url: app.globalData.prodUrl + 'web-pm/wx/pm/list_item_classify',
  562. header: {
  563. 'ydw-token': wx.getStorageSync('key').ydw_token
  564. },
  565. data: {
  566. shop_id: _this.data.shop_id
  567. },
  568. success: function(data) {
  569. _this.setData({
  570. array: data.data.data,
  571. arrays: data.data.data[0].value
  572. })
  573. },
  574. });
  575. },
  576. //
  577. bindTextAreaBlur: function(e) {
  578. this.setData({
  579. textareaVal: e.detail.value
  580. })
  581. },
  582. /**添加自定义参数**/
  583. addParameter: function(e) {
  584. let _this = this;
  585. let parameter = _this.data.parameter;
  586. let obj = {
  587. name: '',
  588. cont: ''
  589. };
  590. parameter.push(obj);
  591. _this.setData({
  592. parameter: parameter
  593. })
  594. },
  595. /*获取参数内容*/
  596. setParameter: function(e) {
  597. let _this = this;
  598. let index = e.currentTarget.dataset.index;
  599. if (e.target.id === 'name') {
  600. _this.data.parameter[index].name = e.detail.value
  601. } else if (e.target.id === 'cont') {
  602. _this.data.parameter[index].cont = e.detail.value
  603. }
  604. },
  605. /**
  606. * 生命周期函数--监听页面初次渲染完成
  607. */
  608. onReady: function() {
  609. },
  610. /**
  611. * 生命周期函数--监听页面显示
  612. */
  613. onShow: function() {
  614. },
  615. /**
  616. * 生命周期函数--监听页面隐藏
  617. */
  618. onHide: function() {
  619. },
  620. /**
  621. * 生命周期函数--监听页面卸载
  622. */
  623. onUnload: function() {
  624. }
  625. })