index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. const app = getApp()
  2. Page({
  3. data: {
  4. loading: true,
  5. openStore: false,
  6. is_shop: false,
  7. service: false,
  8. store_name:'匿名小店',
  9. lists: [],
  10. page: 0,
  11. types:0,
  12. actions: [],
  13. orderParams: {}, // 支付参数
  14. chickPayBtn: false, //点击了支付按钮(订单信息交由古德云组件)
  15. chickOnPay: false, // 用户是否已经点击了「支付」并成功跳转到 古德云收银台 小程序
  16. },
  17. //每次重新载入
  18. onShow:function(options) {
  19. this.getStore();
  20. },
  21. //上拉加载
  22. onReachBottom: function () {
  23. this.setData({
  24. loading: true,
  25. });
  26. that.getItem(this.data.types);
  27. },
  28. //我的小店
  29. getStore: function () {
  30. var that = this;
  31. app.api().Get('api/v3/fastshop/store/isopen',function (result) {
  32. if (result.code == 200){
  33. that.setData({
  34. is_shop: true,
  35. store_name: result.data.name
  36. });
  37. that.getItem(0);
  38. }
  39. })
  40. },
  41. //点击请求数据
  42. getItem: function (types) {
  43. let that = this;
  44. if (that.data.loading) {
  45. var param = {
  46. types: types,
  47. page:that.data.page + 1
  48. };
  49. app.api().Get('api/v3/fastshop/store/index',param,function (result) {
  50. if (result.code == 200) {
  51. var lists = that.data.lists;
  52. for (let i in result.data) {
  53. lists.push(result.data[i]);
  54. }
  55. that.setData({
  56. lists: lists,
  57. page: param.page,
  58. });
  59. }
  60. that.setData({
  61. loading: false,
  62. });
  63. })
  64. }
  65. },
  66. /**
  67. * 确认委托出售
  68. */
  69. formSubmit:function (e) {
  70. let that = this;
  71. var data = e.detail.value;
  72. var isPost = true;
  73. var service = that.data.service;
  74. if (service == false) {
  75. wx.showModal({
  76. content: '您必须遵守平台用户服务协议', showCancel: false
  77. })
  78. isPost = false;
  79. } else if (app.util().isNull(data.store_name)) {
  80. wx.showModal({
  81. content: '小店名称必须输入', showCancel: false
  82. })
  83. isPost = false;
  84. }
  85. //提交数据
  86. if (isPost == true) {
  87. wx.showLoading({
  88. title: '提交申请中',
  89. mask: true
  90. })
  91. var parms = {
  92. store_name: data.store_name
  93. }
  94. app.api().Post('api/v3/fastshop/store/regStore', parms, function (res) {
  95. wx.showModal({
  96. showCancel: false,
  97. title: '友情提示',
  98. content: res.msg,
  99. complete: function () {
  100. wx.navigateBack({
  101. delta: 1
  102. })
  103. }
  104. })
  105. })
  106. }
  107. },
  108. //操作上下架
  109. onUnder:function(event){
  110. let that = this;
  111. var id = event.currentTarget.dataset.id, key = event.currentTarget.dataset.key;
  112. var lists = that.data.lists;
  113. wx.showModal({
  114. content: "你确认要操作当前宝贝",
  115. success(res) {
  116. if (res.confirm) {
  117. app.api().Post('api/v3/fastshop/store/onUnder', {id: id}, function (res) {
  118. wx.showModal({
  119. showCancel: false,
  120. content: res.msg
  121. })
  122. lists[key].is_under = lists[key].is_under == 0 ? 1 : 0,
  123. that.setData({
  124. lists: lists,
  125. });
  126. })
  127. }
  128. }
  129. });
  130. },
  131. //操作提货
  132. wchatPayment: function (buytype,id) {
  133. let that = this;
  134. wx.showModal({
  135. content: "提货,将无法再次委托,默认以上一次收货地址为准,需单独支付快递费",
  136. success(res) {
  137. if (res.confirm) {
  138. var param = {
  139. id: id,
  140. buytype: buytype,
  141. }
  142. app.api().Post('api/v3/fastshop/store/onOrder', param,function (rel) {
  143. if (200 == rel.code) {
  144. if (rel.data.type == 1) {
  145. that.setData({
  146. chickPayBtn: true,
  147. orderParams: rel.data.order
  148. })
  149. } else {
  150. app.doWechatPay(rel.data.orde, function (res) {
  151. wx.navigateTo({url: '../order/index' });
  152. }, function (res) {
  153. wx.showModal({
  154. content: '支付失败或取消',
  155. showCancel: false
  156. })
  157. })
  158. }
  159. }
  160. })
  161. }
  162. }
  163. });
  164. },
  165. //点击切换
  166. onChange(event) {
  167. this.setData({
  168. types: event.detail.name,
  169. lists: [],
  170. page: 0,
  171. loading: true,
  172. })
  173. this.getItem(event.detail.name);
  174. },
  175. //咨询客服层
  176. toggleServicePopup: function () {
  177. let that = this;
  178. that.setData({
  179. openStore: !this.data.openStore
  180. });
  181. },
  182. /**
  183. * 是否选择用户服务协议
  184. */
  185. onService(event) {
  186. this.setData({
  187. service: event.detail
  188. });
  189. },
  190. /**
  191. * 服务协议
  192. */
  193. service() {
  194. let that = this;
  195. let config = app.globalData.wechat_config;
  196. wx.navigateTo({
  197. url: '/pages/helper/webview?src='+ app.api_root + '/api-' + config.app_id + '/v3/fastshop/webview/service'
  198. })
  199. },
  200. //移除触摸限制
  201. moveTouch: function () {
  202. },
  203. //是否弹出支付菜单
  204. onClose() {
  205. this.setData({
  206. show: false,
  207. disabled: false
  208. });
  209. },
  210. //支付方式
  211. payTypes: function (event) {
  212. let that = this;
  213. that.setData({
  214. show: true,
  215. });
  216. if (that.data.show) {
  217. app.api().Get('api/v3/fastshop/index/shopBuyTypes', { 'signkey': 'shopBuyTypes' }, function (result) {
  218. that.setData({
  219. actions: result.data,
  220. item_id: event.currentTarget.dataset.id,
  221. });
  222. })
  223. }
  224. },
  225. //选择支付方式
  226. onSelect(event) {
  227. var payTypes = event.detail.types;
  228. this.setData({
  229. disabled: true
  230. });
  231. switch (payTypes) {
  232. case 1:
  233. this.wchatPayment("wepay",this.data.item_id);
  234. break;
  235. case 2:
  236. this.wchatPayment("point",this.data.item_id);
  237. break;
  238. default:
  239. this.onClose();
  240. }
  241. },
  242. /**
  243. * 支付成功的事件处理函数
  244. * res.detail 为 payjs 小程序返回的订单信息
  245. * 可通过 res.detail.payjsOrderId 拿到 payjs 订单号
  246. * 可通过 res.detail.responseData 拿到详细支付信息
  247. */
  248. goodPaySuccess: function (res) {
  249. if (res.detail.return_code = "SUCCESS") {
  250. wx.navigateTo({
  251. url: '/pages/order/index'
  252. })
  253. }
  254. },
  255. /**
  256. * 支付失败的事件处理函数
  257. * res.detail.error 为 true 代表传入小组件的参数存在问题
  258. * res.detail.navigateSuccess 代表了是否成功跳转到 PAYJS 小程序
  259. * res.detail.event 可能存有失败的原因
  260. * 如果下单成功但是用户取消支付则 res.detail.event.return_code == FAIL
  261. */
  262. goodPayFail: function (res) {
  263. this.setData({
  264. chickPayBtn: false,
  265. })
  266. },
  267. /**
  268. * 支付完毕的事件处理函数
  269. * 无论支付成功或失败均会执行
  270. */
  271. goodPayComplete: function () {
  272. this.setData({
  273. chickPayBtn: false,
  274. })
  275. },
  276. /**
  277. * 组件内部数据被修改时的事件
  278. * 当用户跳转到 云收银台 小程序并等待返回的过程中 chickOnPay 值为 true
  279. */
  280. goodPayChange(res) {
  281. if (res.detail.chickOnPay) {
  282. this.setData({
  283. chickOnPay: res.detail.chickOnPay
  284. })
  285. }
  286. }
  287. })