manager.vue 11 KB

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