manager.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <view class="page" :style="{height:height}">
  3. <view class="flex-row justify-between outView" :style="{marginTop:'24rpx'}" v-if="roleList.length>0" @click="selectRole">
  4. <view class="roleName">
  5. <text>角色</text>
  6. </view>
  7. <view class="flex-row" >
  8. <text class="roleName">{{roleList[confirmRoleIndex].name}}</text>
  9. <u-icon name="arrow-right" color="#666" size="18"></u-icon>
  10. </view>
  11. </view>
  12. <view class="dataNullView flex-col" v-if="roleBindRuleList.length===0">
  13. <view class="flex-row justify-center">
  14. <image class="dataNullImage" src="/static/zhanwu.png"></image>
  15. </view>
  16. <text v-if="roleList[confirmRoleIndex]" class="roleName1">{{roleList[confirmRoleIndex].name}}<text class="roleHint">角色没有拓客规则,点击下方“添加规则”按钮可添加拓客规则</text></text>
  17. </view>
  18. <view v-else class="scroll-Y">
  19. <view class="flex-col outView" v-for="(item,index) in roleBindRuleList" :key="index">
  20. <view class="flex-row justify-between">
  21. <text class="title">{{item.title}}</text>
  22. <u-icon name="trash" color="#666" size="24" @click="deleteRule(item)"></u-icon>
  23. </view>
  24. <view class="flex-row justify-between awardView">
  25. <text>直推:</text>
  26. <view>
  27. <view class="flex-row award justify-between">
  28. <text class="awardItem">注册现金:{{item.awardAmount}}元</text>
  29. </view>
  30. <view class="flex-row award justify-between">
  31. <text class="awardItem">消费现金:{{item.consumeAmount}}元</text>
  32. <text class="awardItem">消费比例:{{item.consumeRatio * 100}}%</text>
  33. </view>
  34. </view>
  35. </view>
  36. <view class="flex-row justify-between awardView">
  37. <text>间推:</text>
  38. <view class="flex-row award justify-between">
  39. <text class="awardItem">间推现金:{{item.indirectAmount}}元</text>
  40. <text class="awardItem">间推比例:{{item.indirectRatio * 100}}%</text>
  41. </view>
  42. </view>
  43. <view class="flex-row justify-between awardView">
  44. <text>优惠券:</text>
  45. <view class="flex-col">
  46. <view class="flex-col discount award" v-for="(item1,index1) in item.strategyList" :key="index1">
  47. <text>{{item1.name}} * {{item1.degree}}张</text>
  48. <text>有效期:{{item1.startTime.substring(0,10)}} 至 {{item1.endTime.substring(0,10)}}</text>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="addButton" @click="addRule">
  55. <text>+添加规则</text>
  56. </view>
  57. <view class="confirmButton" @click="createQrCode">
  58. <text>生成二维码</text>
  59. </view>
  60. <!--邀请专员二维码-->
  61. <uni-popup ref="createQrCodePopup" type="center">
  62. <view class="createQrCodePopup">
  63. <view class="flex-row justify-center">
  64. <text class="popupTitle">邀请专员二维码</text>
  65. </view>
  66. <view class="xoIcon" @click="closePopup">
  67. <u-icon name="close-circle" color="#666" size="24"></u-icon>
  68. </view>
  69. <view class="flex-row justify-center">
  70. <uv-qrcode ref="qrcode" size="540rpx" :value="qrcodeUrl" :options="options"></uv-qrcode>
  71. </view>
  72. </view>
  73. </uni-popup>
  74. <!--选择规则-->
  75. <uni-popup ref="rulePopup" type="bottom" @change="popupChange">
  76. <view class="rulePopup">
  77. <view class="flex-row justify-between">
  78. <text class="popupTitle">选择规则</text>
  79. <u-icon name="close-circle" color="#666" size="24" @click="closePopup"></u-icon>
  80. </view>
  81. <scroll-view scroll-y class="scroll-Y1">
  82. <view class="dataNullView flex-col" v-if="roleNoBindRuleList.length===0">
  83. <view class="flex-row justify-center">
  84. <image class="dataNullImage" src="/static/dataNull.png"></image>
  85. </view>
  86. <text class="roleHint">暂无可添加的拓客规则</text>
  87. </view>
  88. <view v-else>
  89. <view class="flex-col outView " :class="{selectRoleName1: item.select }"
  90. v-for="(item,index) in roleNoBindRuleList" :style="{marginTop: '24rpx'}" @click="selectRule(item,index)" :key="index">
  91. <view class="flex-row justify-between">
  92. <text class="title">{{item.title}}</text>
  93. </view>
  94. <view class="flex-row justify-between awardView">
  95. <text>直推:</text>
  96. <view>
  97. <view class="flex-row award justify-between">
  98. <text class="awardItem">注册现金:{{item.awardAmount}}元</text>
  99. </view>
  100. <view class="flex-row award justify-between">
  101. <text class="awardItem">消费现金:{{item.consumeAmount}}元</text>
  102. <text class="awardItem">消费比例:{{item.consumeRatio * 100}}%</text>
  103. </view>
  104. </view>
  105. </view>
  106. <view class="flex-row justify-between awardView">
  107. <text>间推:</text>
  108. <view class="flex-row award justify-between">
  109. <text class="awardItem">间推现金:{{item.indirectAmount}}元</text>
  110. <text class="awardItem">间推比例:{{item.indirectRatio * 100}}%</text>
  111. </view>
  112. </view>
  113. <view class="flex-row justify-between awardView">
  114. <text>优惠券:</text>
  115. <view class="flex-col">
  116. <view class="flex-col discount award" v-for="(item1,index1) in item.strategyList" :key="index1">
  117. <text>{{item1.name}} * {{item1.degree}}张</text>
  118. <text>有效期:{{item1.startTime.substring(0,10)}} 至 {{item1.endTime.substring(0,10)}}</text>
  119. </view>
  120. </view>
  121. </view>
  122. </view>
  123. </view>
  124. </scroll-view>
  125. <view class="confirmButton" @click="confirmAddRule">
  126. <text>确定</text>
  127. </view>
  128. </view>
  129. </uni-popup>
  130. <!--选择角色-->
  131. <uni-popup ref="rolePopup" type="bottom" @change="popupChange">
  132. <view class="rolePopup">
  133. <view class="flex-row justify-between">
  134. <text class="popupTitle">选择角色</text>
  135. <u-icon name="close-circle" color="#666" size="24" @click="closePopup"></u-icon>
  136. </view>
  137. <scroll-view scroll-y class="scroll-Y2">
  138. <view class="roleName1" :class="{selectRoleName1: selectRoleIndex === index }" v-for="(item,index) in roleList" :key="index" @click="selectRoleIndex = index">
  139. <text>{{item.name}}</text>
  140. <text class="tag">{{item.tag=='0'?'拓客专员':'合作伙伴'}}</text>
  141. </view>
  142. </scroll-view>
  143. <view class="confirmButton" @click="confirmRole">
  144. <text>确定</text>
  145. </view>
  146. </view>
  147. </uni-popup>
  148. </view>
  149. </template>
  150. <script>
  151. export default {
  152. props:{
  153. height: {
  154. type: String,
  155. default () {
  156. return ''
  157. }
  158. },
  159. },
  160. data() {
  161. return {
  162. selectRoleIndex:0, //正在选择的角色下标
  163. confirmRoleIndex:0, //当前选中的角色下标
  164. roleList:[],
  165. roleBindRuleList:[], //角色已经绑定的规则
  166. roleNoBindRuleList:[], //角色没有绑定的规则
  167. roleBindRuleParam:{},
  168. value: 1,
  169. qrcodeUrl:this.$tkUrl+'?roleId={roleId}&parentId={parentId}&timestamp={timestamp}',
  170. options: {
  171. // 指定二维码前景,一般可在中间放logo
  172. foregroundImagePadding:2,
  173. foregroundImageBorderRadius:5,
  174. foregroundImageSrc: '/static/logo.png'
  175. },
  176. }
  177. },
  178. created() {
  179. this.userInfo = uni.getStorageSync('spreadUserInfo')
  180. this.getRoleList()
  181. },
  182. methods: {
  183. deleteRule(item){
  184. let that =this
  185. uni.showModal({
  186. title: '温馨提示',
  187. content: '是否确认删除该规则!',
  188. success: function (res) {
  189. if (res.confirm) {
  190. console.log('用户点击确定');
  191. that.$api.service.cancelRoleBindRule({
  192. roleId:that.roleList[that.confirmRoleIndex].id,
  193. ruleIds:[item.id]
  194. }).then(res=>{
  195. that.getRuleByRoleId(that.roleList[that.confirmRoleIndex].id)
  196. that.getNewRules(that.roleList[that.confirmRoleIndex].id)
  197. })
  198. } else if (res.cancel) {
  199. console.log('用户点击取消');
  200. }
  201. }
  202. });
  203. },
  204. selectRule(item,index){
  205. console.log(item)
  206. item.select = !item.select
  207. this.$set(this.roleNoBindRuleList,index,item)
  208. },
  209. confirmAddRule(){
  210. let ruleIds =[]
  211. for (const rule of this.roleNoBindRuleList) {
  212. if (rule.select){
  213. ruleIds.push(rule.id)
  214. }
  215. }
  216. if (ruleIds.length === 0){
  217. this.closePopup()
  218. return
  219. }
  220. this.$api.service.roleBindRule({
  221. roleId:this.roleList[this.confirmRoleIndex].id,
  222. ruleIds:ruleIds
  223. }).then(res=>{
  224. this.getRuleByRoleId(this.roleList[this.confirmRoleIndex].id)
  225. this.getNewRules(this.roleList[this.confirmRoleIndex].id)
  226. })
  227. this.closePopup()
  228. },
  229. confirmRole(){
  230. this.confirmRoleIndex = this.selectRoleIndex
  231. this.getRuleByRoleId(this.roleList[this.confirmRoleIndex].id)
  232. this.getNewRules(this.roleList[this.confirmRoleIndex].id)
  233. this.closePopup()
  234. },
  235. popupChange(e){
  236. if (e.show){
  237. uni.hideTabBar()
  238. }
  239. if (!e.show){
  240. uni.showTabBar()
  241. }
  242. },
  243. closePopup(){
  244. this.$refs.rolePopup.close()
  245. this.$refs.createQrCodePopup.close()
  246. this.$refs.rulePopup.close()
  247. },
  248. selectRole(){
  249. this.$refs.rolePopup.open()
  250. },
  251. createQrCode(){
  252. if (!this.roleBindRuleList || this.roleBindRuleList.length === 0){
  253. uni.showToast({
  254. icon: 'error',
  255. duration: 3000,
  256. title: '请先添加规则!'
  257. });
  258. return
  259. }
  260. let data = {
  261. roleId:this.roleList[this.confirmRoleIndex].id,
  262. parentId:this.userInfo.id,
  263. timestamp:new Date().getTime() + (5 * 60 * 1000)
  264. };
  265. for (let key in data) {
  266. let regexp = new RegExp("{" + key + "}"); // 构造正则表达式
  267. this.qrcodeUrl = this.qrcodeUrl.replace(regexp, data[key]); // 执行替换操作
  268. }
  269. console.log('++++qrcodeUrl+++++',this.qrcodeUrl)
  270. this.$refs.createQrCodePopup.open()
  271. },
  272. addRule(){
  273. this.$refs.rulePopup.open()
  274. },
  275. change(e) {
  276. console.log("e:", e);
  277. },
  278. //查询规则
  279. getRuleList(){
  280. this.$api.service.getRuleList().then(res=>{
  281. console.log(res)
  282. this.ruleList = res.data.data
  283. })
  284. },
  285. //查询角色
  286. getRoleList(){
  287. this.$api.service.getRoleList().then(res=>{
  288. console.log(res)
  289. this.roleList = res.data.data
  290. this.getRuleByRoleId(this.roleList[this.confirmRoleIndex].id)
  291. this.getNewRules(this.roleList[this.confirmRoleIndex].id)
  292. })
  293. },
  294. //查询角色已经绑定的规则
  295. getRuleByRoleId(roleId){
  296. this.$api.service.getRuleByRoleId({
  297. roleId:roleId
  298. }).then(res=>{
  299. this.roleBindRuleList = res.data.data
  300. })
  301. },
  302. //查询角色没有绑定的规则
  303. getNewRules(roleId){
  304. this.$api.service.getNewRules({
  305. roleId:roleId
  306. }).then(res=>{
  307. this.roleNoBindRuleList = res.data.data
  308. })
  309. },
  310. }
  311. }
  312. </script>
  313. <style scoped lang="scss">
  314. @import './index.rpx.css';
  315. </style>