Third.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. const template=`
  2. <select-page
  3. ref="yunPage"
  4. v-if="value_"
  5. @change="changeSelectpage"
  6. :url="'ajax/third/selectpage?platform='+platform"
  7. label-field="openname"
  8. key-field="id"
  9. :placeholder="placeholder"
  10. :disabled="!selectable"
  11. :page-size="7"
  12. :value="value_"
  13. :multiple="multiple">
  14. </select-page>
  15. <el-button type="primary" style="margin-top: 5px" @click="showDrawer">微信扫码</el-button>
  16. <el-drawer @close="closeDrawer" size="100%" direction="ttb" :append-to-body="true" v-model="drawer" title="请使用微信扫码" :with-header="false">
  17. <div style="display: flex;flex-direction: column;justify-content: center;align-items: center;">
  18. <img :src="qrcode" style="width: 250px;height: 250px;margin: 20px auto;"/>
  19. <div>
  20. <el-tag style="margin-right: 5px;" @close="removeThird(tag.id)" v-for="(tag,index) in tags" :key="tag.id" closable>{{tag.openname}}</el-tag>
  21. </div>
  22. <el-button type="primary" @click="closeDrawer" style="width: 250px;margin-top: 20px;">关闭</el-button>
  23. </div>
  24. </el-drawer>
  25. `;
  26. import selectpage from "./SelectPage.js";
  27. export default {
  28. name: "Third",
  29. components:{
  30. 'SelectPage':selectpage
  31. },
  32. data: function () {
  33. return {
  34. tags:[],
  35. drawer:false,
  36. foreign_key:'',
  37. qrcode:'',
  38. value_:false
  39. }
  40. },
  41. props: {
  42. value: '',
  43. selectable:{
  44. type:Boolean,
  45. default:true
  46. },
  47. platform: {
  48. type:String,
  49. default:'mpapp'
  50. },
  51. placeholder: {
  52. type:String,
  53. default:'请选择'
  54. },
  55. multiple:{
  56. type:Boolean,
  57. default:false
  58. }
  59. },
  60. mounted:function (){
  61. if(this.value==='' || this.value===null){
  62. this.value_=[];
  63. return;
  64. }
  65. if(typeof this.value==='string'){
  66. this.value_=this.value.split(',');
  67. return;
  68. }
  69. if(typeof this.value==='number'){
  70. this.value_=this.value+'';
  71. return;
  72. }
  73. if(this.value instanceof Array){
  74. this.value_=this.value.map(res=>{
  75. return res.toString();
  76. });
  77. return;
  78. }
  79. this.value_=[];
  80. },
  81. template:template,
  82. emits:['change'],
  83. methods:{
  84. changeSelectpage:function (e){
  85. this.$emit('change',e);
  86. this.getThirdInfo();
  87. },
  88. closeDrawer:function (){
  89. this.drawer=false;
  90. },
  91. showDrawer:function (){
  92. this.drawer=true;
  93. this.foreign_key=(new Date()).getTime();
  94. this.qrcode=Yunqi.config.baseUrl+'ajax/third/qrcode?platform='+this.platform+'&foreign_key='+this.foreign_key;
  95. this.timeloop();
  96. this.getThirdInfo();
  97. },
  98. getThirdInfo:function (){
  99. let list=this.$refs.yunPage.getSelectedData();
  100. this.tags=list;
  101. },
  102. removeThird:function (id){
  103. let index=-1;
  104. for(let i=0;i<this.tags.length;i++){
  105. if(this.tags[i].id==id){
  106. index=i;
  107. break;
  108. }
  109. }
  110. if(index>-1){
  111. this.tags.splice(index,1);
  112. }
  113. this.value_.splice(this.value_.indexOf(id),1);
  114. this.$refs.yunPage.remove(id);
  115. },
  116. timeloop:function (){
  117. let that=this;
  118. Yunqi.ajax.get('ajax/third/check?platform='+that.platform+'&foreign_key='+that.foreign_key).then(res=>{
  119. that.$refs.yunPage.select(res.id+'');
  120. if(res && that.multiple){
  121. Yunqi.message.success('扫码成功,继续扫码或关闭');
  122. that.foreign_key=(new Date()).getTime();
  123. that.qrcode=Yunqi.config.baseUrl+'ajax/third/qrcode?platform='+that.platform+'&foreign_key='+that.foreign_key;
  124. setTimeout(()=>{
  125. that.timeloop();
  126. },1500);
  127. }
  128. if(res && !that.multiple){
  129. Yunqi.message.success('扫码成功');
  130. Vue.nextTick(()=>{
  131. that.drawer=false;
  132. });
  133. }
  134. }).catch(err=>{
  135. if(!that.drawer){
  136. return;
  137. }
  138. setTimeout(()=>{
  139. that.timeloop();
  140. },1500);
  141. });
  142. }
  143. }
  144. };