pay.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <view class="content">
  3. <view class="supplyInfo">
  4. <view class="tel flex">
  5. <label>缴费名称:</label>
  6. <input type="text" class="card input" v-model="payInfo.name" disabled/>
  7. </view>
  8. <view class="tel flex">
  9. <label>订单编号:</label>
  10. <input type="text" class="card input" v-model="payInfo.code" disabled/>
  11. </view>
  12. <view class="tel flex">
  13. <label>住宅地址:</label>
  14. <input type="text" class="card input" v-model="payInfo.address" disabled/>
  15. </view>
  16. <view class="tel flex">
  17. <label>户主姓名:</label>
  18. <input type="text" class="card input" v-model="payInfo.owner_name" disabled/>
  19. </view>
  20. <view class="tel flex">
  21. <label>住宅面积:</label>
  22. <input type="text" class="card input" v-model="payInfo.area" disabled/>
  23. </view>
  24. <view class="tel flex">
  25. <label>缴费类型:</label>
  26. <radio-group @change="payChange">
  27. <radio value="1" :checked="payInfo.type!=2" style="margin-right: 30rpx;transform: scale(0.85);" >全额</radio>
  28. <radio value="2" :checked="payInfo.type==2" style="transform: scale(0.85);" :disabled="payInfo.status==1 || payInfo.status==3">空置</radio>
  29. </radio-group>
  30. </view>
  31. <view class="tel flex">
  32. <label>缴费金额:</label>
  33. <input type="text" class="card input" id="real_fee" v-model="payInfo.real_fee" disabled/>
  34. </view>
  35. <view class="tel flex">
  36. <label>订单状态:</label>
  37. <input type="text" class="card input" id="status" :style="{color:statusColor[payInfo.status]}" v-model="statusObj[payInfo.status]" disabled/>
  38. </view>
  39. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  40. <label>发票抬头:</label>
  41. <input type="text" class="card input" id="real_fee" v-model="payInfo.invoice" disabled/>
  42. </view>
  43. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  44. <label>发票备注:</label>
  45. <input type="text" class="card input" id="real_fee" v-model="payInfo.invoice_remark" disabled/>
  46. </view>
  47. <view class="tel flex" v-if="payInfo.invoice_status > 0">
  48. <label>发票状态:</label>
  49. <input type="text" class="card input" id="real_fee" v-model="invoiceStatusStr" disabled/>
  50. </view>
  51. </view>
  52. <button class="submit" style="margin-bottom:20rpx" @tap="paySubmit" v-if="needPay">{{payStatusStr}}</button>
  53. <button class="submit" style="margin-top:20rpx" @tap="openPopup" v-if="needInvoice">申请开票</button>
  54. <uni-popup ref="popup" :mask-click="false" popHeight="55%">
  55. <view class="popup-box">
  56. <view>
  57. <view class="popup-title">申请开票</view>
  58. <view class="popup-content-box">
  59. <view class="popup-content">
  60. <view class="popup-type">
  61. <view>开票抬头:</view><input class="card input" style="width: 75%;" type="text" v-model="invoiceName" />
  62. </view>
  63. <view class="popup-type">
  64. <view>手机号:</view><input class="card input" style="width: 75%;" type="tel" v-model="invoicePhone" />
  65. </view>
  66. <view class="popup-type">
  67. <view>邮箱:</view><input class="card input" style="width: 75%;" type="text" v-model="invoiceEmail" />
  68. </view>
  69. <view class="popup-type">
  70. <view>备注:</view><input class="card input" style="width: 75%;" type="text" v-model="invoiceRemark" />
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="popup-footer">
  76. <button class="popup-cancel" @click="cancelInvocie">取消</button>
  77. <button class="popup-submit" @click="submitInvocie">提交</button>
  78. </view>
  79. </view>
  80. </uni-popup>
  81. </view>
  82. </template>
  83. <script>
  84. import md5 from "@/common/md5.js";
  85. export default {
  86. data() {
  87. return {
  88. payInfo: {
  89. },
  90. payStatus:0,
  91. payStatusStr : '缴费',
  92. needPay : 1,
  93. needInvoice : 0,
  94. invoiceStatusStr : "待开票",
  95. pay_code : '',
  96. statusObj:getApp().globalData.statusObj,
  97. statusColor:getApp().globalData.statusColor,
  98. invoiceName : '',
  99. invoiceRemark : '',
  100. invoicePhone:getApp().globalData.user_phone,
  101. invoiceEmail:''
  102. };
  103. },
  104. onLoad(option) {
  105. this.getPayDetail(option.id);
  106. this.pay_code = option.id;
  107. },
  108. methods: {
  109. reload(){
  110. this.getPayDetail(this.pay_code);
  111. },
  112. getPayDetail(payId) {
  113. let url = getApp().makeApiUrl("user",'user','get_order_info');
  114. let postData = {
  115. code:payId,
  116. openId: getApp().globalData.open_id,
  117. };
  118. uni.request({
  119. url: url,
  120. method: "POST",
  121. header: {
  122. "content-type": "application/x-www-form-urlencoded",
  123. },
  124. data: postData,
  125. success: (res) => {
  126. if (res.data.code === 200) {
  127. this.payInfo = res.data.data;
  128. this.payInfo.address = this.payInfo.estate_name + this.payInfo.building_name + this.payInfo.unit + this.payInfo.room;
  129. if (this.payInfo.status > 0 && this.payInfo.invoice_status == 0){
  130. this.needInvoice = 1;
  131. }
  132. else{
  133. this.needInvoice = 0;
  134. }
  135. if (this.payInfo.status == 2){
  136. this.payStatusStr = '补充缴费';
  137. }
  138. if (this.payInfo.status == 1 || this.payInfo.status == 3){
  139. this.needPay = 0;
  140. }
  141. if (this.payInfo.invoice_status == 2){
  142. this.invoiceStatusStr = "已开票";
  143. }
  144. } else {
  145. uni.showToast({
  146. title: res.data.msg,
  147. icon: "none",
  148. duration: 2500,
  149. });
  150. }
  151. },
  152. fail: () => {
  153. console.log("连接失败");
  154. },
  155. });
  156. },
  157. payChange(e){
  158. let v = e.detail.value;
  159. if (v == 2)
  160. {
  161. let value = this.payInfo.part_fee - this.payInfo.reduction;
  162. value = Math.round(value * 100) / 100;
  163. this.payInfo.real_fee = value.toFixed(2);
  164. }
  165. else
  166. {
  167. let value = this.payInfo.total_fee - this.payInfo.reduction;
  168. value = Math.round(value * 100) / 100;
  169. this.payInfo.real_fee = value.toFixed(2);
  170. }
  171. this.payInfo.type = e.detail.value;
  172. },
  173. paySubmit(){
  174. if (this.payInfo.before > 0){
  175. uni.showToast({
  176. title: "您有历史供暖订单未完成缴费,请先完成后再次尝试",
  177. icon: "none",
  178. duration: 2500,
  179. });
  180. return;
  181. }
  182. let that = this;
  183. let type = this.payInfo.type;
  184. if (this.payInfo.status == 2)
  185. {
  186. type = 3;
  187. }
  188. let url = getApp().makeApiUrl("user",'user','prepay');
  189. let postData = {
  190. code:this.pay_code,
  191. type : type,
  192. openId: getApp().globalData.open_id,
  193. };
  194. uni.request({
  195. url: url,
  196. method: "POST",
  197. header: {
  198. "content-type": "application/x-www-form-urlencoded",
  199. },
  200. data: postData,
  201. success: (res) => {
  202. if (res.data.code === 200) {
  203. let r = res.data.data;
  204. let timeStamp = Date.now().toString();
  205. let nonceStr = getApp().randomStr(32);
  206. let p = 'prepay_id=' + r.prepay_id;
  207. let appId = "wx3cf5d0fd376116e2";
  208. let key = 'd2452k56khlk987HJ456uy7856HKJsd3'; //支付的key
  209. let origin = "appId="+appId+"&nonceStr="+nonceStr+"&package="+p+"&signType=MD5&timeStamp="+timeStamp+"&key="+key;
  210. let md5Sign = getApp().MD5(origin);
  211. // console.log('md5Sign_origin:' + origin);
  212. // console.log('md5Sign:' + md5Sign);
  213. uni.requestPayment({
  214. appId: appId,
  215. timeStamp: timeStamp,
  216. nonceStr: nonceStr,
  217. package: p,
  218. signType: 'MD5',
  219. paySign: md5Sign,
  220. success: function (res) {
  221. console.log('success:' + JSON.stringify(res));
  222. setTimeout(function() {
  223. that.reload();
  224. }, 500);
  225. },
  226. fail: function (err) {
  227. console.log('fail:' + JSON.stringify(err));
  228. }
  229. });
  230. } else {
  231. uni.showToast({
  232. title: res.data.msg,
  233. icon: "none",
  234. duration: 2500,
  235. });
  236. }
  237. },
  238. fail: () => {
  239. console.log("连接失败");
  240. },
  241. });
  242. //支付这里缺少签名参数 还需要后台配合调用微信那边的接口
  243. //参考https://github.com/dcloudio/H5P.Server/tree/master/payment
  244. },
  245. submitInvocie(){
  246. this.closePopup();
  247. },
  248. cancelInvocie(){
  249. this.$refs.popup.close();
  250. },
  251. openPopup() {
  252. this.$refs.popup.open('center');
  253. },
  254. closePopup() {
  255. if (this.invoicePhone === '' && this.invoiceEmail){
  256. uni.showToast({
  257. title: '手机号和邮箱至少填写一项!',
  258. icon: "none",
  259. duration: 2500,
  260. });
  261. return;
  262. }
  263. this.$refs.popup.close();
  264. let that = this;
  265. let url = getApp().makeApiUrl("user",'user','invoice');
  266. let postData = {
  267. code:this.pay_code,
  268. invoice : this.invoiceName,
  269. remark : this.invoiceRemark,
  270. phone:this.invoicePhone,
  271. email:this.invoiceEmail,
  272. openId: getApp().globalData.open_id,
  273. };
  274. uni.request({
  275. url: url,
  276. method: "POST",
  277. header: {
  278. "content-type": "application/x-www-form-urlencoded",
  279. },
  280. data: postData,
  281. success: (res) => {
  282. if (res.data.code === 200) {
  283. uni.showToast({
  284. title: res.data.msg,
  285. icon: "none",
  286. duration: 2500,
  287. });
  288. setTimeout(function() {
  289. that.reload();
  290. }, 500);
  291. } else {
  292. uni.showToast({
  293. title: res.data.msg,
  294. icon: "none",
  295. duration: 2500,
  296. });
  297. }
  298. },
  299. fail: () => {
  300. console.log("连接失败");
  301. },
  302. });
  303. },
  304. },
  305. };
  306. </script>
  307. <style lang="scss" scoped>
  308. .content {
  309. font-size: 28rpx;
  310. font-weight: 200;
  311. padding: 1% 2%;
  312. .title {
  313. font-size: 30rpx;
  314. margin: 4% 0;
  315. }
  316. label {
  317. display: inline-block;
  318. width: 25%;
  319. vertical-align: middle;
  320. }
  321. .card {
  322. background-color: rgb(248, 247, 247);
  323. border-radius: 10rpx;
  324. }
  325. .flex {
  326. display: flex;
  327. align-items: center;
  328. margin-bottom: 2%;
  329. }
  330. .input {
  331. padding: 0 2%;
  332. margin: 2% 0;
  333. display: inline-block;
  334. width: 80%;
  335. height: 70rpx;
  336. }
  337. .supplyInfo {
  338. border-radius: 40rpx;
  339. padding: 4%;
  340. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  341. margin: 30rpx 0 30rpx 0;
  342. }
  343. .info {
  344. margin-top: 2%;
  345. border-radius: 40rpx;
  346. padding: 2% 4%;
  347. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  348. }
  349. .submit {
  350. color: white;
  351. font-weight: normal;
  352. width: 55%;
  353. border-radius: 20rpx;
  354. background-color: #02a7f0;
  355. margin: 120rpx auto;
  356. }
  357. }
  358. .popup-box {
  359. height: 95%;
  360. display: flex;
  361. flex-direction: column;
  362. justify-content: space-between;
  363. }
  364. .popup-title {
  365. text-align: center;
  366. font-weight: bold;
  367. height: 30px;
  368. border-bottom: 1px solid #d8d8d8;
  369. }
  370. .popup-content {
  371. font-size: 28rpx;
  372. padding: 10rpx 0 10rpx 0;
  373. }
  374. .uni-popup__wrapper-box {
  375. height: 65%!important;
  376. }
  377. .popup-type {
  378. display: flex;
  379. height: 80rpx;
  380. align-items: center;
  381. margin-top: 40rpx;
  382. view {
  383. width: 30%;
  384. }
  385. }
  386. .popup-footer {
  387. display: flex;
  388. button{
  389. font-size: 26rpx;
  390. height: 60rpx;
  391. width: 150rpx;
  392. line-height: 60rpx;
  393. color: #FFFFFF;
  394. }
  395. }
  396. .popup-cancel {
  397. background-color: #AAAAAA;
  398. }
  399. .popup-submit {
  400. background-color: #249CD3;
  401. }
  402. </style>