LeaseInfo.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /**
  2. * 租赁
  3. */
  4. import gameToast from "../Network/gameToast"
  5. cc.Class({
  6. extends: cc.Component,
  7. properties: {
  8. inputInviteValue: {
  9. default: 1,
  10. visible: false
  11. },
  12. //1 对应3个月,2对应1年,3对应5年
  13. toggleInputValue: {
  14. default: '2',
  15. visible: false
  16. },
  17. totalPriceLabel: {
  18. default: null,
  19. type: cc.Label,
  20. serializable: true
  21. },
  22. totalPriceValue: {
  23. default: 0,
  24. visible: false
  25. },
  26. ToastParent: {
  27. default: null,
  28. type: cc.Node,
  29. serializable: true
  30. },
  31. //输入节点
  32. inputContainer: {
  33. default: null,
  34. type: cc.Node,
  35. serializable: true
  36. },
  37. toggle1: {
  38. default: null,
  39. type: cc.Toggle,
  40. serializable: true
  41. },
  42. toggle2: {
  43. default: null,
  44. type: cc.Toggle,
  45. serializable: true
  46. },
  47. toggle3: {
  48. default: null,
  49. type: cc.Toggle,
  50. serializable: true
  51. },
  52. //这个显示的时候,拦截输入
  53. blockInput: {
  54. default: null,
  55. type: cc.Node,
  56. serializable: true
  57. },
  58. leaseFarmlandInfoNode: {
  59. default: null,
  60. type: cc.Node,
  61. serializable: true,
  62. visible: false,
  63. toolTip: "操作的土地对象,初始化时候传入"
  64. },
  65. //轮询土地状态
  66. AutoGetLandData: null,
  67. },
  68. // LIFE-CYCLE CALLBACKS:
  69. // onLoad () {},
  70. // start() {
  71. // },
  72. onOpenInfo() {
  73. this.node.active = true;
  74. },
  75. //初始化时候需要初始化一次默认值
  76. onToggleInput(value, evnentData) {
  77. // console.log(value.isChecked, evnentData);
  78. this.toggleInputValue = evnentData;
  79. this._updatePrice();
  80. },
  81. inputLeaseValue(value, e) {
  82. var numberTemp = new RegExp("^[A-Za-z0-9]+$");
  83. if (numberTemp.test(value)) {
  84. if (Number(value) >= 1 && Number(value) <= 100) {
  85. this.inputInviteValue = Number(value);
  86. } else if (Number(value) > 100) {
  87. //限制只能输入100
  88. this.inputInviteValue = 100;
  89. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  90. } else {
  91. this.inputInviteValue = 1;
  92. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  93. }
  94. } else {
  95. this.inputInviteValue = 1;
  96. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  97. console.log("请输入整数的倍数", this.inputInviteValue);
  98. }
  99. this._updatePrice();
  100. },
  101. _updatePrice() {
  102. //this.inputInviteValue 默认是1倍
  103. // console.log( this.inputInviteValue);
  104. switch (this.toggleInputValue) {
  105. case "1":
  106. this.totalPriceValue = 700 * this.inputInviteValue;
  107. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  108. break;
  109. case "2":
  110. this.totalPriceValue = 2500 * this.inputInviteValue;
  111. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  112. break;
  113. case "3":
  114. this.totalPriceValue = 5000 * this.inputInviteValue;
  115. this.totalPriceLabel.string = this.totalPriceValue + "CNT";
  116. break;
  117. default:
  118. console.error("this.toggleInputValue 不是1 2 3!", this.toggleInputValue);
  119. break;
  120. }
  121. },
  122. /**
  123. * 显示面板时候,设置一下初始化数据
  124. */
  125. onInitLeaseInfo(multiple) {
  126. //这里处理倍数
  127. this.inputInviteValue = multiple;
  128. this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
  129. this._updatePrice();
  130. },
  131. //租赁支付
  132. onLeaseInfo() {
  133. console.log('支付总额:' + this.totalPriceValue);
  134. if (!GlobalD.dapp) {
  135. console.error("onBindInviteInfo warn,dapp未初始化!");
  136. return;
  137. }
  138. let _self = this;
  139. //cntAmount,payType,itemType,callback
  140. let _configLandInfo = this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").configLandInfo
  141. //租赁的itemType 要处理一下
  142. let _itemType = this.toggleInputValue + "or" + _configLandInfo.id;
  143. GlobalD.GameData.payCNT(this.totalPriceValue, 1, _itemType, (data) => {
  144. console.log("土地支付:", this.totalPriceValue, "== playType=", 1, ",item_type==", _itemType);
  145. console.log("支付data:", data);
  146. const [err, tx] = data;
  147. if (err === null) {
  148. // TODO 成功, 支付为链上操作,需要提供回调接口给这边服务端确认交易成功后修改购买订单结果
  149. console.log(tx) // 交易hash,唯一标识符
  150. //todo 如果是土地租赁,轮询土地状态
  151. if (this.AutoGetLandData) {
  152. this.unschedule(this.AutoGetLandData);
  153. this.AutoGetLandData = null;
  154. }
  155. this.AutoGetLandData = () => {
  156. GlobalD.GameData.getLandState({
  157. landId: _configLandInfo.id,
  158. callback: (res, value) => {
  159. console.log("轮询土地数据:" + JSON.stringify(value.msg));
  160. if (0 === value.code) {
  161. this.unschedule(this.AutoGetLandData);
  162. console.log("轮询到土地购买成功!");
  163. GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "土地购买成功!", 5);
  164. //解锁土地操作
  165. let _landData = value.data;
  166. this.leaseFarmlandInfoNode.getComponent("LeaseFarmlandInfo").setLeaseLandInfo(_landData);
  167. this.onClose();
  168. }
  169. }
  170. });
  171. };
  172. this.schedule(this.AutoGetLandData, 5);
  173. } else {
  174. console.log(err)
  175. }
  176. });
  177. // GlobalD.dapp.bindParent(_self.inputInviteValue).then((data) => {
  178. // if (data.err === null) {
  179. // // 返回成功,见下面消息体
  180. // console.log(data.res)
  181. // //绑定成功时候,隐藏输入框,设置父节点
  182. // GlobalD.Dapp.UserInfo.parent = data.res;
  183. // _self.parentInviteValue.string = GlobalD.Dapp.UserInfo.parent.invite_code;
  184. // //如果存在父节点,隐藏输入框
  185. // _self.inputContainer.active = false;
  186. // } else {
  187. // //TODO 服务错误
  188. // console.log(data.err)
  189. // }
  190. // })
  191. },
  192. onClose() {
  193. this.node.destroy();
  194. },
  195. });