manager.vue 11 KB

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