stock-edit.php 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template id="stock-edit">
  2. <el-dialog :visible.sync="edit.visible" width="30%" title="添加亲友卡" center>
  3. <el-form @submit.native.prevent size="small" label-width="100px">
  4. <el-form-item label="用户昵称" required>
  5. <el-autocomplete size="small" v-model="edit.nickname" value-key="nickname" @keyup.enter.native="keyUp"
  6. :fetch-suggestions="querySearchAsync" placeholder="请输入用户昵称/id/手机号"
  7. @select="shareClick"></el-autocomplete>
  8. </el-form-item>
  9. </el-form>
  10. <el-form @submit.native.prevent size="small" label-width="100px">
  11. <el-form-item label="选择亲友卡" required>
  12. <el-autocomplete size="small" v-model="edit.name" value-key="name" @keyup.enter.native="keyUp"
  13. :fetch-suggestions="querySearchAsync1" placeholder="请输入亲友卡名称"
  14. @select="shareClick1"></el-autocomplete>
  15. </el-form-item>
  16. </el-form>
  17. <el-form @submit.native.prevent size="small" label-width="100px">
  18. <el-form-item label="有效期" required style="width: 50%;">
  19. <el-input placeholder="请输入有效期" v-model="edit.expired_days" onInput="value=toNumber(value,0)">
  20. <template slot="append">天</template>
  21. </el-input>
  22. </el-form-item>
  23. </el-form>
  24. <span slot="footer" class="dialog-footer">
  25. <el-button @click="editCancel" type="default" size="small">取消</el-button>
  26. <el-button type="primary" :loading="edit.btnLoading" style="margin-bottom: 10px;" size="small"
  27. @click="editSave">保存</el-button>
  28. </span>
  29. </el-dialog>
  30. </template>
  31. <script>
  32. Vue.component('stock-edit', {
  33. template: '#stock-edit',
  34. props: {
  35. value: {
  36. type: Boolean,
  37. default: false
  38. }
  39. },
  40. data() {
  41. return {
  42. edit: {
  43. visible: false,
  44. keyword: '',
  45. keyword1: '',
  46. nickname: '',
  47. id: '',
  48. user_id:"",
  49. btnLoading: false,
  50. name:'',
  51. card_give_id:0,
  52. expired_days:0,
  53. },
  54. level_list: [],
  55. level: '',
  56. listLoading:false,
  57. list:[],
  58. page:1,
  59. pageCount:0,
  60. radioSelection:0,
  61. keyword:'',
  62. keyword1: '',
  63. selectUser:null
  64. }
  65. },
  66. watch: {
  67. value() {
  68. //console.log(113)
  69. this.radioSelection=0;
  70. this.keyword='';
  71. this.keyword1 = '';
  72. this.selectUser=null;
  73. if (this.value) {
  74. //console.log(115)
  75. this.edit.visible = true;
  76. this.getUser();
  77. this.getCard();
  78. } else {
  79. this.edit.id = '';
  80. this.edit.nickname = '';
  81. this.edit.keyword = '';
  82. this.edit.keyword1 = '';
  83. this.edit.name = '';
  84. this.edit.card_give_id = '';
  85. this.edit.expired_days = 0;
  86. this.edit.visible = false;
  87. }
  88. }
  89. ,
  90. 'edit.visible'() {
  91. if (!this.edit.visible) {
  92. this.editCancel();
  93. }
  94. },
  95. keyword(val){//监听用户昵称的输入框 如果为空(选择后删除了用户)则重新请求用户的数据 改为实时请求
  96. /* if(val == ''){
  97. this.page = 1;
  98. this.pageCount = 0;
  99. this.getUser();
  100. } */
  101. this.page = 1;
  102. this.pageCount = 0;
  103. this.getUser();
  104. },
  105. keyword1(val){//监听用户昵称的输入框 如果为空(选择后删除了用户)则重新请求用户的数据 改为实时请求
  106. /* if(val == ''){
  107. this.page = 1;
  108. this.pageCount = 0;
  109. this.getUser();
  110. } */
  111. this.page = 1;
  112. this.pageCount = 0;
  113. this.getCard();
  114. },
  115. },
  116. created() {
  117. //this.getLevelList();//获取等级列表
  118. },
  119. methods: {
  120. getUser(){//请求用户的列表
  121. //console.log('请求了getUser!page='+this.page+'----keyword='+this.keyword)
  122. this.listLoading = true;
  123. request({
  124. params: {
  125. r: 'members-card/default/search-user',
  126. page:this.page,
  127. limit:20,
  128. keyword:this.keyword
  129. },
  130. method: 'get',
  131. }).then(response => {
  132. this.listLoading = false;
  133. //console.log('请求用户的列表结果='+JSON.stringify(response))
  134. if (response.data.code == 0) {
  135. this.list = response.data.data.list;
  136. this.pageCount = response.data.data.page_count;
  137. } else {
  138. this.$message.error(response.data.msg);
  139. }
  140. }).catch(response => {
  141. this.listLoading = false;
  142. });
  143. },
  144. getCard(){//请求用户的列表
  145. //console.log('请求了getUser!page='+this.page+'----keyword='+this.keyword)
  146. this.listLoading = true;
  147. request({
  148. params: {
  149. r: 'members-card/default/search-card',
  150. page:this.page,
  151. limit:20,
  152. keyword:this.keyword
  153. },
  154. method: 'get',
  155. }).then(response => {
  156. this.listLoading = false;
  157. //console.log('请求用户的列表结果='+JSON.stringify(response))
  158. if (response.data.code == 0) {
  159. this.list = response.data.data.list;
  160. } else {
  161. this.$message.error(response.data.msg);
  162. }
  163. }).catch(response => {
  164. this.listLoading = false;
  165. });
  166. },
  167. pagination(currentPage) {
  168. this.page = currentPage;
  169. this.getUser();
  170. },
  171. selectionChange(e){
  172. //console.log('选中了='+JSON.stringify(e))
  173. this.selectUser = e;
  174. // this.keyword = this.selectUser.nickname;
  175. // 修改为查询ID,昵称存在空的情况
  176. this.keyword = this.selectUser.id;
  177. },
  178. querySearchAsync(queryString, cb) {
  179. this.edit.keyword = queryString;
  180. this.get_user(cb);
  181. },
  182. querySearchAsync1(queryString, cb) {
  183. this.edit.keyword1 = queryString;
  184. this.get_user1(cb);
  185. },
  186. get_user(cb) {
  187. request({
  188. params: {
  189. r: 'members-card/default/search-user',
  190. keyword: this.edit.keyword
  191. }
  192. }).then(res => {
  193. if (res.data.code == 0) {
  194. cb(res.data.data.list)
  195. } else {
  196. this.$message.error(res.data.msg);
  197. }
  198. });
  199. },
  200. get_user1(cb) {
  201. request({
  202. params: {
  203. r: 'members-card/default/search-card',
  204. keyword: this.edit.keyword1
  205. }
  206. }).then(res => {
  207. if (res.data.code == 0) {
  208. cb(res.data.data.list)
  209. } else {
  210. this.$message.error(res.data.msg);
  211. }
  212. });
  213. },
  214. agentClick(row) {
  215. this.edit.id = row.id
  216. },
  217. shareClick(row) {
  218. this.edit.user_id = row.id
  219. },
  220. shareClick1(row) {
  221. console.log(row)
  222. this.edit.card_give_id = row.id
  223. },
  224. editCancel() {
  225. /* 重置表单中原来填入的数据 */
  226. this.level = '';
  227. this.selectUser = null;
  228. this.keyword = '';
  229. this.$emit('input', false);
  230. /* navigateTo({
  231. r: 'plugin/cloud_stock/mall/cloud-stock-two/index',
  232. }) */
  233. //this.value = false;
  234. },
  235. editSave() {
  236. if(!this.edit.card_give_id){
  237. return this.$message.error('请选择亲友卡');
  238. }
  239. if(!this.edit.user_id){
  240. return this.$message.error('请选择下拉列表里的会员!');
  241. }
  242. if(!this.edit.expired_days){
  243. return this.$message.error('请输入有效期!');
  244. }
  245. this.edit.btnLoading = true;
  246. request({
  247. params: {
  248. r: 'members-card/default/card-edit'//代理商添加//'plugin/stock/mall/stock/edit',
  249. },
  250. method: 'post',
  251. data: {
  252. user_id:this.edit.user_id,
  253. card_give_id:this.edit.card_give_id,
  254. expired_days:this.edit.expired_days,
  255. }
  256. }).then(response => {
  257. this.edit.btnLoading = false;
  258. if (response.data.code == 0) {
  259. this.$message.success('添加成功');
  260. this.$emit('savesuccess')
  261. this.editCancel();
  262. } else {
  263. this.$message.error(response.data.msg);
  264. }
  265. }).catch(response => {
  266. this.edit.btnLoading = false;
  267. });
  268. },
  269. keyUp() {
  270. console.log('key up')
  271. },
  272. searchFun(){
  273. this.page = 1;
  274. this.getUser();
  275. }
  276. }
  277. });
  278. </script>