index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <div>
  3. <div class="select-layout">
  4. <p class="sub-title">
  5. <span>筛选设备</span>
  6. </p>
  7. <div class="address-input-con">
  8. <div class="address-input-item">
  9. <div class="address-sub">
  10. <div class="top-title">设备选择</div>
  11. <div class="ant-input prov" @click="handleSelect('device')">
  12. {{activeDevice.childName||'设备选择'}}
  13. <ul v-if="device">
  14. <li
  15. v-for="(item,i) in invoicedevice"
  16. :key="i"
  17. @click="handledeviceClick(item)"
  18. >{{item.childName}}</li>
  19. </ul>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. <div class="select-layout">
  26. <p class="sub-title">
  27. <span>发票金额</span>
  28. </p>
  29. <div class="address-input-con">
  30. <div class="address-input-item">
  31. <div class="address-sub">
  32. <div class="top-title">开票金额</div>
  33. <div class="ant-input">
  34. <input v-model="amount" oninput="value=Math.max(Number(value.replace(/[^\d]/g,'')),1)" type="text" placeholder="请输入开票金额" />
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. <div class="select-layout">
  41. <p class="sub-title">
  42. <span>发票信息</span>
  43. </p>
  44. <div class="invoice-header">
  45. <label class="check-con" @click="type='geren'">
  46. <span class="check-box">
  47. <span class="checkbox-inner" :class="{'checkbox-inner-checked':type==='geren'}"></span>
  48. </span>
  49. <span>个人</span>
  50. </label>
  51. <label class="check-con" @click="type='qiye'">
  52. <span class="check-box">
  53. <span class="checkbox-inner" :class="{'checkbox-inner-checked':type==='qiye'}"></span>
  54. </span>
  55. <span>企业</span>
  56. </label>
  57. </div>
  58. <div class="address-input-con" v-if="type==='qiye'">
  59. <div class="address-input-item">
  60. <div class="address-sub">
  61. <div class="top-title">抬头名称</div>
  62. <div class="ant-input">
  63. <input v-model="tempInvoice3.title" type="text" placeholder="请输入发票抬头" />
  64. </div>
  65. </div>
  66. </div>
  67. <div class="address-input-item">
  68. <div class="address-sub">
  69. <div class="top-title">税号</div>
  70. <div class="ant-input">
  71. <input v-model="tempInvoice3.code" type="text" placeholder="请输入税务登记号" />
  72. </div>
  73. </div>
  74. </div>
  75. <div class="address-input-item">
  76. <div class="address-sub">
  77. <div class="top-title">地址</div>
  78. <div class="ant-input">
  79. <input v-model="tempInvoice3.organizedAddress" type="text" placeholder="公司地址" />
  80. </div>
  81. </div>
  82. </div>
  83. <div class="address-input-item">
  84. <div class="address-sub">
  85. <div class="top-title">电话号码</div>
  86. <div class="ant-input">
  87. <input v-model="tempInvoice3.registerPhone" type="text" placeholder="公司电话号码" />
  88. </div>
  89. </div>
  90. </div>
  91. <div class="address-input-item">
  92. <div class="address-sub">
  93. <div class="top-title">开户银行</div>
  94. <div class="ant-input">
  95. <input v-model="tempInvoice3.bankName" type="text" placeholder="开户银行" />
  96. </div>
  97. </div>
  98. </div>
  99. <div class="address-input-item">
  100. <div class="address-sub">
  101. <div class="top-title">银行账户</div>
  102. <div class="ant-input">
  103. <input v-model="tempInvoice3.bankAccount" type="text" placeholder="银行账户" />
  104. </div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="address-input-con" v-else>
  109. <div class="address-input-item">
  110. <div class="address-sub">
  111. <div class="top-title">抬头名称</div>
  112. <div class="ant-input">
  113. <input v-model="tempInvoice2.title" type="text" placeholder="发票抬头" />
  114. </div>
  115. </div>
  116. </div>
  117. <div class="address-input-item">
  118. <div class="address-sub">
  119. <div class="top-title">税号</div>
  120. <div class="ant-input">
  121. <input v-model="tempInvoice2.code" type="text" placeholder="税务登记号" />
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. </div>
  127. <div class="select-layout">
  128. <p class="sub-title">
  129. <span>收货地址</span>
  130. </p>
  131. <div class="address-input-con">
  132. <div class="address-input-item">
  133. <div class="address-sub address-name">
  134. <div class="top-title">姓名</div>
  135. <div class="ant-input">
  136. <input v-model="tempAddress.shipName" type="text" placeholder="姓名" />
  137. </div>
  138. </div>
  139. <div class="address-sub address-phone">
  140. <div class="top-title">联系电话</div>
  141. <div class="ant-input">
  142. <input v-model="tempAddress.shipMobile" type="text" placeholder="联系电话" />
  143. </div>
  144. </div>
  145. </div>
  146. <div class="address-input-item">
  147. <div class="address-sub prov-name">
  148. <div class="top-title">省份</div>
  149. <div class="ant-input prov" @click="handleSelect('prov')">
  150. {{citylist[currentPID]['p']||'省份'}}
  151. <ul v-if="prov">
  152. <li
  153. v-for="(item,i) in citylist"
  154. :key="i"
  155. @click="handleClick('currentPID',i)"
  156. >{{item.p}}</li>
  157. </ul>
  158. </div>
  159. </div>
  160. <div class="address-sub city-phone">
  161. <div class="top-title">城市</div>
  162. <div class="ant-input city" @click="handleSelect('city')">
  163. {{currentProv[currentCID]['n']||'城市'}}
  164. <ul v-if="city">
  165. <li
  166. v-for="(item,i) in currentProv"
  167. :key="i"
  168. @click="handleClick('currentCID',i)"
  169. >{{item.n}}</li>
  170. </ul>
  171. </div>
  172. </div>
  173. </div>
  174. <div class="address-input-item">
  175. <div class="address-sub">
  176. <div class="top-title">地址</div>
  177. <div class="ant-input dist" @click="handleSelect('dist')">
  178. {{currentCity[currentSID]['s']||'区/县'}}
  179. <ul v-if="dist">
  180. <li
  181. v-for="(item,i) in currentCity"
  182. :key="i"
  183. @click="handleClick('currentSID',i)"
  184. >{{item.s}}</li>
  185. </ul>
  186. </div>
  187. <div class="ant-input">
  188. <input v-model="tempAddress.shipAddress" type="text" placeholder="详细地址" />
  189. </div>
  190. </div>
  191. </div>
  192. <p class="p-dec">请务必详细填写相符无误的地址以免耽误收货</p>
  193. </div>
  194. </div>
  195. <div class="invoice-save">
  196. <button @click="saveInvoice" type="submit" class="ant-btn ant-btn-primary">
  197. <span>提 交</span>
  198. </button>
  199. <button type="submit" class="ant-btn ant-btn-primary cancel" @click="$router.back()">
  200. <span>取 消</span>
  201. </button>
  202. </div>
  203. </div>
  204. </template>
  205. <script>
  206. import { mapState } from 'vuex'
  207. import { citylist } from './city'
  208. let sle = ['prov', 'city', 'dist', 'device']
  209. export default {
  210. data () {
  211. let idArr = ['', '', '']
  212. return {
  213. type: 'geren',
  214. amount: '',
  215. tempInvoice2: {},
  216. tempInvoice3: {},
  217. tempAddress: {},
  218. citylist,
  219. prov: false,
  220. city: false,
  221. dist: false,
  222. device: false,
  223. currentPID: idArr[0] || 18,
  224. currentCID: idArr[1] || 3,
  225. currentSID: idArr[2] || 2,
  226. areaPath: '',
  227. activeDevice: {}
  228. }
  229. },
  230. computed: {
  231. ...mapState({
  232. token: state => state.user.token,
  233. invoicedevice: state => {
  234. let type = Object.prototype.toString.call(state.user.invoicedevice)
  235. if (type === '[object Object]') {
  236. return state.user.invoicedevice
  237. }
  238. let condition = state.user.invoicedevice && state.user.invoicedevice !== 'null'
  239. return (condition ? state.user.invoicedevice : [])
  240. }
  241. }),
  242. currentProv: function () {
  243. let tmp = this.citylist[this.currentPID]
  244. return tmp.c
  245. },
  246. currentCity: function () {
  247. let cprov = this.citylist[this.currentPID]
  248. let tmp = cprov.c[this.currentCID]
  249. return tmp.a
  250. }
  251. },
  252. watch: {
  253. currentProv () {
  254. this.currentCID = 0
  255. this.currentSID = 0
  256. }
  257. },
  258. methods: {
  259. async getAllDevice (searchKey = '') {
  260. let params = {
  261. cameraType: ''
  262. }
  263. await this.$store.dispatch('getInvoiceDevice', params)
  264. this.activeDevice = this.invoicedevice[0]
  265. },
  266. handledeviceClick (item) {
  267. this.activeDevice = item
  268. },
  269. handleSelect (item) {
  270. sle.forEach(i => {
  271. if (i === item) {
  272. this[i] = !this[i]
  273. } else {
  274. this[i] = false
  275. }
  276. })
  277. },
  278. handleClick (id, i) {
  279. this[id] = i
  280. this.handleChange()
  281. },
  282. handleChange () {
  283. let prov = this.citylist[this.currentPID]
  284. let city = prov.c[this.currentCID]
  285. let dist = city.a[this.currentSID]
  286. this.areaPath = [prov.p, city.n, dist.s]
  287. console.log(this.areaPath)
  288. },
  289. async saveInvoice () {
  290. let params = {}
  291. let invoiceType = ''
  292. if (this.type === 'geren') {
  293. invoiceType = 2
  294. let { title = '', code = '' } = this.tempInvoice2
  295. params = {
  296. invoiceType,
  297. title,
  298. code
  299. }
  300. } else {
  301. let {
  302. title = '',
  303. code = '',
  304. organizedAddress = '',
  305. registerPhone = '',
  306. bankName = '',
  307. bankAccount = ''
  308. } = this.tempInvoice3
  309. invoiceType = 3
  310. params = {
  311. invoiceType,
  312. title,
  313. code,
  314. organizedAddress,
  315. registerPhone,
  316. bankName,
  317. bankAccount
  318. }
  319. }
  320. let {
  321. shipName = '',
  322. shipMobile = '',
  323. shipAddress = ''
  324. } = this.tempAddress
  325. this.tempAddress.shipAreaPath = this.areaPath.join(',')
  326. this.tempAddress.amount = Number(this.amount)
  327. this.tempAddress.shipName = shipName || ''
  328. this.tempAddress.shipMobile = shipMobile || ''
  329. this.tempAddress.shipAddress = shipAddress || ''
  330. let temp = Object.keys(this.tempAddress)
  331. temp.forEach(item => {
  332. params[item] = this.tempAddress[item] || ''
  333. })
  334. console.log(params)
  335. let arr = Object.keys(params)
  336. for (let i = 0; i < arr.length; i++) {
  337. if (!params[arr[i]]) {
  338. return this.$toast.show('warn', '信息填写不能为空')
  339. }
  340. }
  341. params['cameraId'] = this.activeDevice.id
  342. let res = await this.$http.post('/user/invoice/add', params, {
  343. headers: {
  344. token: this.token
  345. }
  346. })
  347. let response = res.data
  348. if (response.code === 0) {
  349. this.$toast.show('success', '开票成功', () => {
  350. this.$router.replace({name: 'consumption', params: {id: 2}})
  351. })
  352. } else {
  353. return this.$toast.show('warn', response.msg, () => {})
  354. }
  355. }
  356. },
  357. mounted () {
  358. this.handleChange()
  359. this.getAllDevice()
  360. }
  361. }
  362. </script>
  363. <style lang="scss" scoped>
  364. @import "./style.scss";
  365. </style>