pay.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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);">空置</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">
  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 type="text" v-model="invoiceName" />
  62. </view>
  63. <view class="popup-type">
  64. <view>备注:</view><input type="text" v-model="invoiceRemark" />
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="popup-footer">
  70. <button class="popup-submit" @click="submitInvocie">提交</button>
  71. </view>
  72. </view>
  73. </uni-popup>
  74. </view>
  75. </template>
  76. <script>
  77. import md5 from "@/common/md5.js";
  78. export default {
  79. data() {
  80. return {
  81. payInfo: {
  82. },
  83. payStatus:0,
  84. payStatusStr : '缴费',
  85. needPay : 1,
  86. needInvoice : 0,
  87. invoiceStatusStr : "待开票",
  88. pay_code : '',
  89. statusObj:getApp().globalData.statusObj,
  90. statusColor:getApp().globalData.statusColor,
  91. invoiceName : '',
  92. invoiceRemark : '',
  93. };
  94. },
  95. onLoad(option) {
  96. this.getPayDetail(option.id);
  97. this.pay_code = option.id;
  98. },
  99. methods: {
  100. getPayDetail(payId) {
  101. let url = getApp().makeApiUrl("user",'user','get_order_info');
  102. let postData = {
  103. code:payId,
  104. openId: getApp().globalData.open_id,
  105. };
  106. uni.request({
  107. url: url,
  108. method: "POST",
  109. header: {
  110. "content-type": "application/x-www-form-urlencoded",
  111. },
  112. data: postData,
  113. success: (res) => {
  114. if (res.data.code === 200) {
  115. this.payInfo = res.data.data;
  116. this.payInfo.address = this.payInfo.estate_name + this.payInfo.building_name + this.payInfo.unit + this.payInfo.room;
  117. if (this.payInfo.status > 0 && this.payInfo.invoice_status == 0){
  118. this.needInvoice = 1;
  119. }
  120. if (this.payInfo.status == 2){
  121. this.payStatusStr = '补充缴费';
  122. }
  123. if (this.payInfo.status == 1 || this.payInfo.status == 3){
  124. this.needPay = 0;
  125. }
  126. if (this.payInfo.invoice_status == 2){
  127. this.invoiceStatusStr = "已开票";
  128. }
  129. } else {
  130. uni.showToast({
  131. title: res.data.msg,
  132. icon: "none",
  133. duration: 2500,
  134. });
  135. }
  136. },
  137. fail: () => {
  138. console.log("连接失败");
  139. },
  140. });
  141. },
  142. payChange(e){
  143. let v = e.detail.value;
  144. if (v == 2)
  145. {
  146. let value = this.payInfo.part_fee - this.payInfo.reduction;
  147. this.payInfo.real_fee = value;
  148. }
  149. else
  150. {
  151. let value = this.payInfo.total_fee - this.payInfo.reduction;
  152. this.payInfo.real_fee = value;
  153. }
  154. this.payInfo.type = e.detail.value;
  155. },
  156. paySubmit(){
  157. let type = this.payInfo.type;
  158. if (this.payInfo.status == 2)
  159. {
  160. type = 3;
  161. }
  162. let url = getApp().makeApiUrl("user",'user','prepay');
  163. let postData = {
  164. code:this.pay_code,
  165. type : type,
  166. openId: getApp().globalData.open_id,
  167. };
  168. uni.request({
  169. url: url,
  170. method: "POST",
  171. header: {
  172. "content-type": "application/x-www-form-urlencoded",
  173. },
  174. data: postData,
  175. success: (res) => {
  176. if (res.data.code === 200) {
  177. let r = res.data.data;
  178. uni.requestPayment({
  179. provider: 'wxpay',
  180. timeStamp: String(Date.now()),
  181. nonceStr: r.nonce_str,
  182. package: 'prepay_id=' + r.prepay_id,
  183. signType: 'MD5',
  184. paySign: r.sign,
  185. success: function (res) {
  186. console.log('success:' + JSON.stringify(res));
  187. setTimeout(function() {
  188. Location.reload();
  189. }, 2500);
  190. },
  191. fail: function (err) {
  192. console.log('fail:' + JSON.stringify(err));
  193. }
  194. });
  195. } else {
  196. uni.showToast({
  197. title: res.data.msg,
  198. icon: "none",
  199. duration: 2500,
  200. });
  201. }
  202. },
  203. fail: () => {
  204. console.log("连接失败");
  205. },
  206. });
  207. //支付这里缺少签名参数 还需要后台配合调用微信那边的接口
  208. //参考https://github.com/dcloudio/H5P.Server/tree/master/payment
  209. },
  210. submitInvocie(){
  211. this.closePopup();
  212. },
  213. openPopup() {
  214. this.$refs.popup.open('center');
  215. },
  216. closePopup() {
  217. this.$refs.popup.close();
  218. let url = getApp().makeApiUrl("user",'user','invoice');
  219. let postData = {
  220. code:this.pay_code,
  221. invoice : this.invoiceName,
  222. remark : this.invoiceRemark,
  223. openId: getApp().globalData.open_id,
  224. };
  225. uni.request({
  226. url: url,
  227. method: "POST",
  228. header: {
  229. "content-type": "application/x-www-form-urlencoded",
  230. },
  231. data: postData,
  232. success: (res) => {
  233. if (res.data.code === 200) {
  234. /*
  235. uni.showToast({
  236. title: res.data.msg,
  237. icon: "none",
  238. duration: 2500,
  239. });
  240. */
  241. window.location.reload();
  242. } else {
  243. uni.showToast({
  244. title: res.data.msg,
  245. icon: "none",
  246. duration: 2500,
  247. });
  248. }
  249. },
  250. fail: () => {
  251. console.log("连接失败");
  252. },
  253. });
  254. },
  255. },
  256. };
  257. </script>
  258. <style lang="scss" scoped>
  259. .content {
  260. font-size: 28rpx;
  261. font-weight: 200;
  262. padding: 1% 2%;
  263. .title {
  264. font-size: 30rpx;
  265. margin: 4% 0;
  266. }
  267. label {
  268. display: inline-block;
  269. width: 25%;
  270. vertical-align: middle;
  271. }
  272. .card {
  273. background-color: rgb(248, 247, 247);
  274. border-radius: 10rpx;
  275. }
  276. .flex {
  277. display: flex;
  278. align-items: center;
  279. margin-bottom: 2%;
  280. }
  281. .input {
  282. padding: 0 2%;
  283. margin: 2% 0;
  284. display: inline-block;
  285. width: 80%;
  286. height: 70rpx;
  287. }
  288. .supplyInfo {
  289. border-radius: 40rpx;
  290. padding: 4%;
  291. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  292. margin: 30rpx 0 30rpx 0;
  293. }
  294. .info {
  295. margin-top: 2%;
  296. border-radius: 40rpx;
  297. padding: 2% 4%;
  298. box-shadow: rgba(100, 100, 111, 0.2) 14rpx 14rpx 40rpx 14rpx;
  299. }
  300. .submit {
  301. color: white;
  302. font-weight: normal;
  303. width: 55%;
  304. border-radius: 20rpx;
  305. background-color: #02a7f0;
  306. margin: 120rpx auto;
  307. }
  308. }
  309. .popup-box {
  310. height: 100%;
  311. display: flex;
  312. flex-direction: column;
  313. justify-content: space-between;
  314. }
  315. .popup-title {
  316. text-align: center;
  317. font-weight: bold;
  318. height: 30px;
  319. border-bottom: 1px solid #d8d8d8;
  320. }
  321. .popup-content {
  322. font-size: 28rpx;
  323. padding: 10rpx 0 10rpx 0;
  324. }
  325. .popup-type {
  326. display: flex;
  327. height: 80rpx;
  328. align-items: center;
  329. margin-top: 60rpx;
  330. view {
  331. width: 30%;
  332. }
  333. input {
  334. border: 1px solid #d7d7d7;
  335. width: 60%;
  336. border-radius: 5rpx;
  337. padding-left: 10rpx;
  338. height: 56rpx;
  339. }
  340. }
  341. .popup-footer {
  342. display: flex;
  343. button{
  344. font-size: 26rpx;
  345. height: 60rpx;
  346. width: 150rpx;
  347. line-height: 60rpx;
  348. color: #FFFFFF;
  349. }
  350. }
  351. .popup-cancel {
  352. background-color: #AAAAAA;
  353. }
  354. .popup-submit {
  355. background-color: #249CD3;
  356. }
  357. </style>